use of org.phoebus.security.store.SecureStore in project phoebus by ControlSystemStudio.
the class SecureStoreTest method init.
@BeforeClass
public static void init() throws Exception {
File secureStoreFile;
secureStoreFile = new File(System.getProperty("user.home"), "TestOnlySecureStore.dat");
secureStoreFile.deleteOnExit();
String password = "forTestPurposesOnly";
secureStore = new SecureStore(secureStoreFile, password.toCharArray());
}
use of org.phoebus.security.store.SecureStore 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.store.SecureStore 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);
});
}
use of org.phoebus.security.store.SecureStore in project phoebus by ControlSystemStudio.
the class LogEntryModel method submitEntry.
/**
* Create and return a log entry with the current data in the log entry form.
* NOTE: this method calls the remote service in a synchronous manner. Calling code should handle potential
* threading issues, e.g. invoking this method on the UI thread. Using a synchronous approach facilitates
* handling of connection or authentication issues.
*
* @throws IOException
*/
public LogEntry submitEntry() throws Exception {
// Create a log entry with the form data.
LogEntryBuilder logEntryBuilder = new LogEntryBuilder();
logEntryBuilder.title(title).description(text).level(level);
for (String selectedLogbook : selectedLogbooks) logEntryBuilder.appendToLogbook(LogbookImpl.of(selectedLogbook));
for (String selectedTag : selectedTags) logEntryBuilder.appendTag(TagImpl.of(selectedTag));
// List of temporary image files to delete.
List<File> toDelete = new ArrayList<>();
// Add Images
for (Image image : images) {
File imageFile = File.createTempFile("log_entry_image_", ".png");
imageFile.deleteOnExit();
toDelete.add(imageFile);
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", imageFile);
logEntryBuilder.attach(AttachmentImpl.of(imageFile, "image", false));
}
// Add Files
for (File file : files) {
logEntryBuilder.attach(AttachmentImpl.of(file, "file", false));
}
LogEntry logEntry = logEntryBuilder.build();
if (LogbookUiPreferences.save_credentials) {
// Get the SecureStore. Store username and password.
try {
SecureStore store = new SecureStore();
store.set(SecureStore.USERNAME_TAG, username);
store.set(SecureStore.PASSWORD_TAG, password);
} catch (Exception ex) {
logger.log(Level.WARNING, "Secure Store file not found.", ex);
}
}
LogEntry result = null;
if (null != logFactory)
result = logFactory.getLogClient(new SimpleAuthenticationToken(username, password)).set(logEntry);
// Delete the temporary files.
for (File file : toDelete) file.delete();
// Run the onSubmitAction runnable
if (null != onSubmitAction)
onSubmitAction.run();
return result;
}
use of org.phoebus.security.store.SecureStore in project phoebus by ControlSystemStudio.
the class CredentialsManagementApp method create.
@Override
public AppInstance create() {
List<ServiceAuthenticationProvider> authenticationProviders = ServiceLoader.load(ServiceAuthenticationProvider.class).stream().map(Provider::get).collect(Collectors.toList());
try {
SecureStore secureStore = new SecureStore();
new CredentialsManagementStage(authenticationProviders, secureStore).show();
} catch (Exception e) {
ExceptionDetailsErrorDialog.openError(Messages.SecureStoreErrorTitle, Messages.SecureStoreErrorBody, e);
}
return null;
}
Aggregations