use of org.phoebus.security.tokens.ScopedAuthenticationToken in project phoebus by ControlSystemStudio.
the class SecureStoreTest method testSetInvalidAuthenticationToken.
@Test
public void testSetInvalidAuthenticationToken() throws Exception {
try {
secureStore.setScopedAuthentication(new ScopedAuthenticationToken("username", null));
fail("Null user name should fail");
} catch (Exception exception) {
}
try {
secureStore.setScopedAuthentication(new ScopedAuthenticationToken(null, "password"));
fail("Null password should fail");
} catch (Exception exception) {
}
try {
secureStore.setScopedAuthentication(new ScopedAuthenticationToken("", null));
fail("Empty user name should fail");
} catch (Exception exception) {
}
try {
secureStore.setScopedAuthentication(new ScopedAuthenticationToken(null, ""));
fail("Empty password should fail");
} catch (Exception exception) {
}
}
use of org.phoebus.security.tokens.ScopedAuthenticationToken in project phoebus by ControlSystemStudio.
the class SecureStoreTest method testOverwriteScopedAuthentication.
@Test
public void testOverwriteScopedAuthentication() throws Exception {
secureStore.setScopedAuthentication(new ScopedAuthenticationToken("Scope1", "username1", "password1"));
ScopedAuthenticationToken token = secureStore.getScopedAuthenticationToken("Scope1");
assertEquals("username1", token.getUsername());
secureStore.setScopedAuthentication(new ScopedAuthenticationToken("scope1", "username2", "password1"));
token = secureStore.getScopedAuthenticationToken("scope1");
assertEquals("username2", token.getUsername());
}
use of org.phoebus.security.tokens.ScopedAuthenticationToken in project phoebus by ControlSystemStudio.
the class ScopedAuthenticationTokenTest method testScopedAuthenticationToken.
@Test
public void testScopedAuthenticationToken() {
ScopedAuthenticationToken scopedAuthenticationToken = new ScopedAuthenticationToken("username", "password");
assertEquals("username", scopedAuthenticationToken.getUsername());
assertNull(scopedAuthenticationToken.getScope());
scopedAuthenticationToken = new ScopedAuthenticationToken(" ", "username", "password");
assertNull(scopedAuthenticationToken.getScope());
scopedAuthenticationToken = new ScopedAuthenticationToken("", "username", "password");
assertNull(scopedAuthenticationToken.getScope());
scopedAuthenticationToken = new ScopedAuthenticationToken(null, "username", "password");
assertNull(scopedAuthenticationToken.getScope());
scopedAuthenticationToken = new ScopedAuthenticationToken("scope", "username", "password");
assertEquals("scope", scopedAuthenticationToken.getScope());
}
use of org.phoebus.security.tokens.ScopedAuthenticationToken in project phoebus by ControlSystemStudio.
the class FieldsViewController method fetchStoredUserCredentials.
public void fetchStoredUserCredentials() {
// Perform file IO on background thread.
JobManager.schedule("Access Secure Store", monitor -> {
// Get the SecureStore. Retrieve username and password.
try {
SecureStore store = new SecureStore();
ScopedAuthenticationToken scopedAuthenticationToken = store.getScopedAuthenticationToken(LogService.AUTHENTICATION_SCOPE);
// Could be accessed from JavaFX Application Thread when updating, so synchronize.
synchronized (usernameProperty) {
usernameProperty.set(scopedAuthenticationToken == null ? "" : scopedAuthenticationToken.getUsername());
}
synchronized (passwordProperty) {
passwordProperty.set(scopedAuthenticationToken == null ? "" : scopedAuthenticationToken.getPassword());
}
// Let anyone listening know that their credentials are now out of date.
updateCredentials.set(true);
// checkIfReadyToSubmit();
} catch (Exception ex) {
logger.log(Level.WARNING, "Secure Store file not found.", ex);
}
});
}
use of org.phoebus.security.tokens.ScopedAuthenticationToken in project phoebus by ControlSystemStudio.
the class LogEntryEditorController method submit.
@FXML
public void submit() {
submissionInProgress.set(true);
JobManager.schedule("Submit Log Entry", monitor -> {
OlogLog ologLog = new OlogLog();
ologLog.setTitle(fieldsViewController.getTitle());
ologLog.setDescription(fieldsViewController.getDescription());
ologLog.setLevel(fieldsViewController.getSelectedLevel());
ologLog.setLogbooks(fieldsViewController.getSelectedLogbooks());
ologLog.setTags(fieldsViewController.getSelectedTags());
ologLog.setAttachments(attachmentsViewController.getAttachments());
ologLog.setProperties(logPropertiesEditorController.getProperties());
LogClient logClient = logFactory.getLogClient(new SimpleAuthenticationToken(fieldsViewController.getUsernameProperty(), fieldsViewController.getPasswordProperty()));
LogEntry result;
try {
if (replyTo == null) {
result = logClient.set(ologLog);
} else {
result = logClient.reply(ologLog, replyTo);
}
if (result != null) {
if (completionHandler != null) {
completionHandler.handleResult(result);
}
// Set username and password in secure store if submission of log entry completes successfully
if (LogbookUIPreferences.save_credentials) {
// Get the SecureStore. Store username and password.
try {
SecureStore store = new SecureStore();
ScopedAuthenticationToken scopedAuthenticationToken = new ScopedAuthenticationToken(LogService.AUTHENTICATION_SCOPE, fieldsViewController.getUsernameProperty(), fieldsViewController.getPasswordProperty());
store.setScopedAuthentication(scopedAuthenticationToken);
} catch (Exception ex) {
logger.log(Level.WARNING, "Secure Store file not found.", ex);
}
}
attachmentsViewController.deleteTemporaryFiles();
// This will close the editor
Platform.runLater(() -> cancel());
}
} catch (LogbookException e) {
logger.log(Level.WARNING, "Unable to submit log entry", e);
Platform.runLater(() -> {
if (e.getCause() != null && e.getCause().getMessage() != null) {
completionMessageLabel.textProperty().setValue(e.getCause().getMessage());
} else if (e.getMessage() != null) {
completionMessageLabel.textProperty().setValue(e.getMessage());
} else {
completionMessageLabel.textProperty().setValue(org.phoebus.logbook.Messages.SubmissionFailed);
}
});
}
submissionInProgress.set(false);
});
}
Aggregations