Skip to content

Commit

Permalink
Added preference to remember enable unauthenticated user
Browse files Browse the repository at this point in the history
  • Loading branch information
Rylern committed Feb 21, 2024
1 parent cdf858f commit 7f1d688
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/qupath/ext/omero/core/ClientsPreferencesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public class ClientsPreferencesManager {
"omero_ext.last_username",
""
);
private static final StringProperty enableUnauthenticatedPreference = PathPrefs.createPersistentPreference(
"omero_ext.enable_unauthenticated",
""
);
private static final StringProperty msPixelBufferPortPreference = PathPrefs.createPersistentPreference(
"omero_ext.ms_pixel_buffer_port",
""
Expand Down Expand Up @@ -82,6 +86,7 @@ public static void clearAllPreferences() {
uris.clear();
latestServerPreference.set("");
latestUsernamePreference.set("");
enableUnauthenticatedPreference.set("");
msPixelBufferPortPreference.set("");
webJpegQualityPreference.set("");
iceAddressPreference.set("");
Expand Down Expand Up @@ -157,6 +162,26 @@ public static synchronized void setLastUsername(String username) {
latestUsernamePreference.set(username);
}

/**
* Return whether to enable logging as an unauthenticated user when connecting to the provided URI.
*
* @param serverURI the URI of the OMERO web server to connect to
* @return whether to enable logging as an unauthenticated user, or an empty optional if not defined
*/
public static Optional<Boolean> getEnableUnauthenticated(URI serverURI) {
return getProperty(enableUnauthenticatedPreference, serverURI).map(Boolean::parseBoolean);
}

/**
* Set whether to enable logging as an unauthenticated user when connecting to the provided URI.
*
* @param serverURI the URI of the OMERO web server to connect to
* @param enableUnauthenticated whether to enable logging as an unauthenticated user for this URI
*/
public static void setEnableUnauthenticated(URI serverURI, boolean enableUnauthenticated) {
setProperty(enableUnauthenticatedPreference, serverURI, String.valueOf(enableUnauthenticated));
}

/**
* Get the saved port used by the pixel buffer microservice of the OMERO server
* corresponding to the provided URI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,53 @@ void Check_Last_Username_When_Set_Twice() {
Assertions.assertEquals(expectedUsername, lastUsername);
}

@Test
void Check_Enable_Unauthenticated_Empty() {
URI uri = URI.create("https://github.com/qupath");

Optional<Boolean> enableUnauthenticated = ClientsPreferencesManager.getEnableUnauthenticated(uri);

Assertions.assertTrue(enableUnauthenticated.isEmpty());
}

@Test
void Check_Enable_Unauthenticated() {
boolean expectedEnableUnauthenticated = true;
URI uri = URI.create("https://github.com/qupath");
ClientsPreferencesManager.setEnableUnauthenticated(uri, expectedEnableUnauthenticated);

Boolean enableUnauthenticated = ClientsPreferencesManager.getEnableUnauthenticated(uri).orElse(null);

Assertions.assertEquals(expectedEnableUnauthenticated, enableUnauthenticated);
}

@Test
void Check_Enable_Unauthenticated_When_Set_Twice() {
boolean unexpectedEnableUnauthenticated = false;
boolean expectedEnableUnauthenticated = true;
URI uri = URI.create("https://github.com/qupath");
ClientsPreferencesManager.setEnableUnauthenticated(uri, unexpectedEnableUnauthenticated);
ClientsPreferencesManager.setEnableUnauthenticated(uri, expectedEnableUnauthenticated);

Boolean enableUnauthenticated = ClientsPreferencesManager.getEnableUnauthenticated(uri).orElse(null);

Assertions.assertEquals(expectedEnableUnauthenticated, enableUnauthenticated);
}

@Test
void Check_Enable_Unauthenticated_When_Other_URI_Set() {
URI otherUri = URI.create("https://qupath.readthedocs.io");
boolean otherEnableUnauthenticated = false;
ClientsPreferencesManager.setEnableUnauthenticated(otherUri, otherEnableUnauthenticated);
boolean expectedEnableUnauthenticated = true;
URI uri = URI.create("https://github.com/qupath");
ClientsPreferencesManager.setEnableUnauthenticated(uri, expectedEnableUnauthenticated);

Boolean enableUnauthenticated = ClientsPreferencesManager.getEnableUnauthenticated(uri).orElse(null);

Assertions.assertEquals(expectedEnableUnauthenticated, enableUnauthenticated);
}

@Test
void Check_Ms_Pixel_Buffer_Port_Empty() {
URI uri = URI.create("https://github.com/qupath");
Expand Down

0 comments on commit 7f1d688

Please sign in to comment.