Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class LogbookUIPreferences
{
@Preference public static String[] default_logbooks;
@Preference public static String default_logbook_query;
@Preference public static boolean save_credentials;
@Preference public static String calendar_view_item_stylesheet;
@Preference public static String level_field_name;
@Preference public static String markup_help;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.phoebus.security.tokens.AuthenticationScope;
import org.phoebus.security.tokens.ScopedAuthenticationToken;
import org.phoebus.security.tokens.SimpleAuthenticationToken;
import org.phoebus.ui.Preferences;
import org.phoebus.ui.dialog.ListSelectionPopOver;
import org.phoebus.ui.javafx.ImageCache;
import org.phoebus.util.time.TimestampFormats;
Expand Down Expand Up @@ -258,7 +259,7 @@ public void initialize() {
}
});
});
if (LogbookUIPreferences.save_credentials) {
if (Preferences.save_credentials) {
fetchStoredUserCredentials();
}

Expand Down Expand Up @@ -439,7 +440,7 @@ public void submit() {
completionHandler.handleResult(result);
}
// Set username and password in secure store if submission of log entry completes successfully
if (LogbookUIPreferences.save_credentials) {
if (Preferences.save_credentials) {
// Get the SecureStore. Store username and password.
try {
SecureStore store = new SecureStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.phoebus.security.tokens.AuthenticationScope;
import org.phoebus.security.tokens.ScopedAuthenticationToken;
import org.phoebus.security.tokens.SimpleAuthenticationToken;
import org.phoebus.ui.Preferences;
import org.phoebus.ui.dialog.ListSelectionPopOver;
import org.phoebus.ui.javafx.ImageCache;
import org.phoebus.util.time.TimestampFormats;
Expand Down Expand Up @@ -241,7 +242,7 @@ public void initialize() {
}
});
});
if (LogbookUIPreferences.save_credentials) {
if (Preferences.save_credentials) {
fetchStoredUserCredentials();
}

Expand Down Expand Up @@ -420,7 +421,7 @@ public void submit() {
completionHandler.handleResult(result);
}
// Set username and password in secure store if submission of log entry completes successfully
if (LogbookUIPreferences.save_credentials) {
if (Preferences.save_credentials) {
// Get the SecureStore. Store username and password.
try {
SecureStore store = new SecureStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ default_logbooks=Scratch Pad
# The default query for logbook applications
default_logbook_query=desc=*&start=12 hours&end=now

# Whether or not to save user credentials to file so they only have to be entered once when making log entries.
save_credentials=false

# Stylesheet for the items in the log calendar view
calendar_view_item_stylesheet=Agenda.css

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class LogbookUiPreferences
{
@Preference public static String[] default_logbooks;
@Preference public static String default_logbook_query;
@Preference public static boolean save_credentials;
@Preference public static String calendar_view_item_stylesheet;
@Preference public static String level_field_name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import javafx.scene.paint.Color;
import org.phoebus.logbook.ui.LogbookUiPreferences;
import org.phoebus.logbook.ui.Messages;
import org.phoebus.ui.Preferences;
import org.phoebus.util.time.TimestampFormats;

import java.net.URL;
Expand Down Expand Up @@ -147,7 +148,7 @@ else if (passwordField.getText().isEmpty())
});

userField.requestFocus();
if (LogbookUiPreferences.save_credentials)
if (Preferences.save_credentials)
{
model.fetchStoredUserCredentials();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.phoebus.logbook.ui.LogbookUiPreferences;
import org.phoebus.security.store.SecureStore;
import org.phoebus.security.tokens.SimpleAuthenticationToken;
import org.phoebus.ui.Preferences;

import javax.imageio.ImageIO;
import java.io.File;
Expand Down Expand Up @@ -84,7 +85,8 @@ public class LogEntryModel {
private final SimpleBooleanProperty readyToSubmit; // Used internally. Backs read only property above.

/**
* Property that allows the model to define when the application needs to update the username and password text fields. Only used if save_credentials=true
* Property that allows the model to define when the application needs to update the username and password text fields.
* Only used if save_credentials=true
*/
private final ReadOnlyBooleanProperty updateCredentialsProperty; // To be broadcast through getUpdateCredentialsProperty.
private final SimpleBooleanProperty updateCredentials; // Used internally. Backs read only property above.
Expand Down Expand Up @@ -517,7 +519,7 @@ public LogEntry submitEntry() throws Exception {

// Sumission should be synchronous such that clients can intercept failures

if (LogbookUiPreferences.save_credentials) {
if (Preferences.save_credentials) {
// Get the SecureStore. Store username and password.
try {
SecureStore store = new SecureStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ default_logbooks=Scratch Pad
# The default query for logbook applications
default_logbook_query=search=*&start=12 hours&end=now

# Whether or not to save user credentials to file so they only have to be entered once when making log entries.
save_credentials=false

# Stylesheet for the items in the log calendar view
calendar_view_item_stylesheet=Agenda.css

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class SaveAndRestoreJerseyClient implements org.phoebus.applications.save

private static final ObjectMapper mapper = new ObjectMapper();

/**
* Should be accessed through {@link #getClient()} to ensure proper usage of cached credentials, if available.
*/
private static final Client client;

private static HTTPBasicAuthFilter httpBasicAuthFilter;
Expand All @@ -70,7 +73,14 @@ public class SaveAndRestoreJerseyClient implements org.phoebus.applications.save
defaultClientConfig.getSingletons().add(jacksonJsonProvider);

client = Client.create(defaultClientConfig);
}

public SaveAndRestoreJerseyClient() {
mapper.registerModule(new JavaTimeModule());
mapper.setSerializationInclusion(Include.NON_NULL);
}

private Client getClient(){
try {
SecureStore store = new SecureStore();
ScopedAuthenticationToken scopedAuthenticationToken = store.getScopedAuthenticationToken(AuthenticationScope.SAVE_AND_RESTORE);
Expand All @@ -85,11 +95,7 @@ public class SaveAndRestoreJerseyClient implements org.phoebus.applications.save
} catch (Exception e) {
logger.log(Level.WARNING, "Unable to retrieve credentials from secure store", e);
}
}

public SaveAndRestoreJerseyClient() {
mapper.registerModule(new JavaTimeModule());
mapper.setSerializationInclusion(Include.NON_NULL);
return client;
}

@Override
Expand All @@ -109,7 +115,7 @@ public Node getNode(String uniqueNodeId) {

@Override
public List<Node> getCompositeSnapshotReferencedNodes(String uniqueNodeId) {
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/composite-snapshot/" + uniqueNodeId + "/nodes");
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/composite-snapshot/" + uniqueNodeId + "/nodes");

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON).get(ClientResponse.class);
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand All @@ -128,7 +134,7 @@ public List<Node> getCompositeSnapshotReferencedNodes(String uniqueNodeId) {

@Override
public List<SnapshotItem> getCompositeSnapshotItems(String uniqueNodeId) {
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/composite-snapshot/" + uniqueNodeId + "/items");
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/composite-snapshot/" + uniqueNodeId + "/items");

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON).get(ClientResponse.class);
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand Down Expand Up @@ -159,7 +165,7 @@ public List<Node> getChildNodes(String uniqueNodeId) throws SaveAndRestoreClient

@Override
public Node createNewNode(String parentNodeId, Node node) {
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/node")
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/node")
.queryParam("parentNodeId", parentNodeId);
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(node, CONTENT_TYPE_JSON)
Expand All @@ -183,7 +189,7 @@ public Node updateNode(Node nodeToUpdate) {

@Override
public Node updateNode(Node nodeToUpdate, boolean customTimeForMigration) {
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/node")
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/node")
.queryParam("customTimeForMigration", customTimeForMigration ? "true" : "false");

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
Expand All @@ -209,7 +215,7 @@ private <T> T getCall(String relativeUrl, Class<T> clazz) {
}

private ClientResponse getCall(String relativeUrl) {
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + relativeUrl);
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + relativeUrl);

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON).get(ClientResponse.class);
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand All @@ -227,7 +233,7 @@ private ClientResponse getCall(String relativeUrl) {

@Override
public void deleteNodes(List<String> nodeIds) {
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/node");
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/node");
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(nodeIds, CONTENT_TYPE_JSON)
.delete(ClientResponse.class);
Expand All @@ -254,7 +260,7 @@ public List<Node> getAllSnapshots() {
@Override
public Node moveNodes(List<String> sourceNodeIds, String targetNodeId) {
WebResource webResource =
client.resource(Preferences.jmasarServiceUrl + "/move")
getClient().resource(Preferences.jmasarServiceUrl + "/move")
.queryParam("to", targetNodeId);

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
Expand All @@ -276,7 +282,7 @@ public Node moveNodes(List<String> sourceNodeIds, String targetNodeId) {
@Override
public Node copyNodes(List<String> sourceNodeIds, String targetNodeId) {
WebResource webResource =
client.resource(Preferences.jmasarServiceUrl + "/copy")
getClient().resource(Preferences.jmasarServiceUrl + "/copy")
.queryParam("to", targetNodeId);

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
Expand All @@ -298,7 +304,7 @@ public Node copyNodes(List<String> sourceNodeIds, String targetNodeId) {
@Override
public String getFullPath(String uniqueNodeId) {
WebResource webResource =
client.resource(Preferences.jmasarServiceUrl + "/path/" + uniqueNodeId);
getClient().resource(Preferences.jmasarServiceUrl + "/path/" + uniqueNodeId);
ClientResponse response = webResource.get(ClientResponse.class);

if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand All @@ -321,7 +327,7 @@ public ConfigurationData getConfigurationData(String nodeId) {
@Override
public Configuration createConfiguration(String parentNodeId, Configuration configuration) {
WebResource webResource =
client.resource(Preferences.jmasarServiceUrl + "/config")
getClient().resource(Preferences.jmasarServiceUrl + "/config")
.queryParam("parentNodeId", parentNodeId);
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(configuration, CONTENT_TYPE_JSON)
Expand All @@ -340,7 +346,7 @@ public Configuration createConfiguration(String parentNodeId, Configuration conf

@Override
public Configuration updateConfiguration(Configuration configuration) {
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/config");
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/config");

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(configuration, CONTENT_TYPE_JSON)
Expand All @@ -366,7 +372,7 @@ public SnapshotData getSnapshotData(String nodeId) {
@Override
public Snapshot createSnapshot(String parentNodeId, Snapshot snapshot) {
WebResource webResource =
client.resource(Preferences.jmasarServiceUrl + "/snapshot")
getClient().resource(Preferences.jmasarServiceUrl + "/snapshot")
.queryParam("parentNodeId", parentNodeId);
ClientResponse response;
try {
Expand All @@ -391,7 +397,7 @@ public Snapshot createSnapshot(String parentNodeId, Snapshot snapshot) {
@Override
public Snapshot updateSnapshot(Snapshot snapshot) {
WebResource webResource =
client.resource(Preferences.jmasarServiceUrl + "/snapshot");
getClient().resource(Preferences.jmasarServiceUrl + "/snapshot");
ClientResponse response;
try {
response = webResource.accept(CONTENT_TYPE_JSON)
Expand All @@ -416,7 +422,7 @@ public Snapshot updateSnapshot(Snapshot snapshot) {
@Override
public CompositeSnapshot createCompositeSnapshot(String parentNodeId, CompositeSnapshot compositeSnapshot) {
WebResource webResource =
client.resource(Preferences.jmasarServiceUrl + "/composite-snapshot")
getClient().resource(Preferences.jmasarServiceUrl + "/composite-snapshot")
.queryParam("parentNodeId", parentNodeId);
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(compositeSnapshot, CONTENT_TYPE_JSON)
Expand All @@ -436,7 +442,7 @@ public CompositeSnapshot createCompositeSnapshot(String parentNodeId, CompositeS
@Override
public List<String> checkCompositeSnapshotConsistency(List<String> snapshotNodeIds) {
WebResource webResource =
client.resource(Preferences.jmasarServiceUrl + "/composite-snapshot-consistency-check");
getClient().resource(Preferences.jmasarServiceUrl + "/composite-snapshot-consistency-check");
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(snapshotNodeIds, CONTENT_TYPE_JSON)
.post(ClientResponse.class);
Expand All @@ -455,7 +461,7 @@ public List<String> checkCompositeSnapshotConsistency(List<String> snapshotNodeI

@Override
public CompositeSnapshot updateCompositeSnapshot(CompositeSnapshot compositeSnapshot) {
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/composite-snapshot");
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/composite-snapshot");

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(compositeSnapshot, CONTENT_TYPE_JSON)
Expand All @@ -474,7 +480,7 @@ public CompositeSnapshot updateCompositeSnapshot(CompositeSnapshot compositeSnap

@Override
public SearchResult search(MultivaluedMap<String, String> searchParams) {
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/search")
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/search")
.queryParams(searchParams);
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.get(ClientResponse.class);
Expand All @@ -492,7 +498,7 @@ public SearchResult search(MultivaluedMap<String, String> searchParams) {

@Override
public Filter saveFilter(Filter filter) {
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/filter");
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/filter");
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(filter, CONTENT_TYPE_JSON)
.put(ClientResponse.class);
Expand All @@ -510,7 +516,7 @@ public Filter saveFilter(Filter filter) {

@Override
public List<Filter> getAllFilters() {
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/filters");
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/filters");
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.get(ClientResponse.class);
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand All @@ -530,7 +536,7 @@ public List<Filter> getAllFilters() {
public void deleteFilter(String name) {
// Filter name may contain space chars, need to URL encode these.
String filterName = name.replace(" ", "%20");
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/filter/" + filterName);
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/filter/" + filterName);
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.delete(ClientResponse.class);
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand All @@ -554,7 +560,7 @@ public void deleteFilter(String name) {
public List<Node> addTag(TagData tagData) {

WebResource webResource =
client.resource(Preferences.jmasarServiceUrl + "/tags");
getClient().resource(Preferences.jmasarServiceUrl + "/tags");
ClientResponse response;
try {
response = webResource.accept(CONTENT_TYPE_JSON)
Expand Down Expand Up @@ -585,7 +591,7 @@ public List<Node> addTag(TagData tagData) {
*/
public List<Node> deleteTag(TagData tagData) {
WebResource webResource =
client.resource(Preferences.jmasarServiceUrl + "/tags");
getClient().resource(Preferences.jmasarServiceUrl + "/tags");
ClientResponse response;
try {
response = webResource.accept(CONTENT_TYPE_JSON)
Expand All @@ -610,7 +616,7 @@ public List<Node> deleteTag(TagData tagData) {
@Override
public UserData authenticate(String userName, String password) {
WebResource webResource =
client.resource(Preferences.jmasarServiceUrl + "/login")
getClient().resource(Preferences.jmasarServiceUrl + "/login")
.queryParam("username", userName)
.queryParam("password", password);
ClientResponse response;
Expand Down
1 change: 1 addition & 0 deletions core/ui/src/main/java/org/phoebus/ui/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class Preferences
@Preference public static int[] alarm_area_panel_undefined_severity_background_color;
/** cache_hint_for_picture_and_symbol_widgets */
@Preference public static String cache_hint_for_picture_and_symbol_widgets;
@Preference public static boolean save_credentials;

static
{
Expand Down
Loading