Search in sources :

Example 1 with ScopedAuthenticationToken

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) {
    }
}
Also used : ScopedAuthenticationToken(org.phoebus.security.tokens.ScopedAuthenticationToken) Test(org.junit.Test)

Example 2 with ScopedAuthenticationToken

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());
}
Also used : ScopedAuthenticationToken(org.phoebus.security.tokens.ScopedAuthenticationToken) Test(org.junit.Test)

Example 3 with ScopedAuthenticationToken

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());
}
Also used : ScopedAuthenticationToken(org.phoebus.security.tokens.ScopedAuthenticationToken) Test(org.junit.Test)

Example 4 with ScopedAuthenticationToken

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);
        }
    });
}
Also used : ScopedAuthenticationToken(org.phoebus.security.tokens.ScopedAuthenticationToken) SecureStore(org.phoebus.security.store.SecureStore)

Example 5 with ScopedAuthenticationToken

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);
    });
}
Also used : LogClient(org.phoebus.logbook.LogClient) ScopedAuthenticationToken(org.phoebus.security.tokens.ScopedAuthenticationToken) LogbookException(org.phoebus.logbook.LogbookException) OlogLog(org.phoebus.olog.es.api.model.OlogLog) SecureStore(org.phoebus.security.store.SecureStore) LogEntry(org.phoebus.logbook.LogEntry) LogbookException(org.phoebus.logbook.LogbookException) ExecutionException(java.util.concurrent.ExecutionException) SimpleAuthenticationToken(org.phoebus.security.tokens.SimpleAuthenticationToken) FXML(javafx.fxml.FXML)

Aggregations

ScopedAuthenticationToken (org.phoebus.security.tokens.ScopedAuthenticationToken)12 Test (org.junit.Test)8 SecureStore (org.phoebus.security.store.SecureStore)2 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 FXML (javafx.fxml.FXML)1 LogClient (org.phoebus.logbook.LogClient)1 LogEntry (org.phoebus.logbook.LogEntry)1 LogbookException (org.phoebus.logbook.LogbookException)1 OlogLog (org.phoebus.olog.es.api.model.OlogLog)1 SimpleAuthenticationToken (org.phoebus.security.tokens.SimpleAuthenticationToken)1