Search in sources :

Example 51 with AuthenticationResult

use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.

the class ManagedAuthenticationManagerTestBase method testAddChildAndThenDelete.

public void testAddChildAndThenDelete() throws ExecutionException, InterruptedException {
    // No children should be present before the test starts
    assertEquals("No users should be present before the test starts", 0, _authManager.getChildren(User.class).size());
    assertEquals("No users should be present before the test starts", 0, _authManager.getUsers().size());
    final Map<String, Object> childAttrs = new HashMap<String, Object>();
    childAttrs.put(User.NAME, getTestName());
    childAttrs.put(User.PASSWORD, "password");
    User user = _authManager.addChildAsync(User.class, childAttrs).get();
    assertNotNull("User should be created but addChild returned null", user);
    assertEquals(getTestName(), user.getName());
    if (!isPlain()) {
        // password shouldn't actually be the given string, but instead hashed value
        assertFalse("Password shouldn't actually be the given string, but instead hashed value", "password".equals(user.getPassword()));
    }
    AuthenticationResult authResult = _authManager.authenticate(getTestName(), "password");
    assertEquals("User should authenticate with given password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
    assertEquals("Manager should have exactly one user child", 1, _authManager.getChildren(User.class).size());
    assertEquals("Manager should have exactly one user child", 1, _authManager.getUsers().size());
    user.delete();
    assertEquals("No users should be present after child deletion", 0, _authManager.getChildren(User.class).size());
    authResult = _authManager.authenticate(getTestName(), "password");
    assertEquals("User should no longer authenticate with given password", AuthenticationResult.AuthenticationStatus.ERROR, authResult.getStatus());
}
Also used : User(org.apache.qpid.server.model.User) HashMap(java.util.HashMap) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 52 with AuthenticationResult

use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.

the class ManagedAuthenticationManagerTestBase method testUpdateUser.

public void testUpdateUser() {
    assertTrue(_authManager.createUser(getTestName(), "password", Collections.<String, String>emptyMap()));
    assertTrue(_authManager.createUser(getTestName() + "_2", "password", Collections.<String, String>emptyMap()));
    assertEquals("Manager should have exactly two user children", 2, _authManager.getChildren(User.class).size());
    AuthenticationResult authResult = _authManager.authenticate(getTestName(), "password");
    assertEquals("User should authenticate with given password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
    authResult = _authManager.authenticate(getTestName() + "_2", "password");
    assertEquals("User should authenticate with given password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
    for (User user : _authManager.getChildren(User.class)) {
        if (user.getName().equals(getTestName())) {
            user.setAttributes(Collections.singletonMap(User.PASSWORD, "newpassword"));
        }
    }
    authResult = _authManager.authenticate(getTestName(), "newpassword");
    assertEquals("User should authenticate with updated password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
    authResult = _authManager.authenticate(getTestName() + "_2", "password");
    assertEquals("User should authenticate with original password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
    authResult = _authManager.authenticate(getTestName(), "password");
    assertEquals("User not authenticate with original password", AuthenticationResult.AuthenticationStatus.ERROR, authResult.getStatus());
    for (User user : _authManager.getChildren(User.class)) {
        if (user.getName().equals(getTestName())) {
            user.setPassword("newerpassword");
        }
    }
    authResult = _authManager.authenticate(getTestName(), "newerpassword");
    assertEquals("User should authenticate with updated password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
}
Also used : User(org.apache.qpid.server.model.User) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 53 with AuthenticationResult

use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.

the class ManagedAuthenticationManagerTestBase method testAuthenticateValidCredentials.

public void testAuthenticateValidCredentials() throws Exception {
    _authManager.createUser(TEST_USER_NAME, TEST_USER_PASSWORD, Collections.<String, String>emptyMap());
    AuthenticationResult result = _authManager.authenticate(TEST_USER_NAME, TEST_USER_PASSWORD);
    assertEquals("Unexpected result status", AuthenticationResult.AuthenticationStatus.SUCCESS, result.getStatus());
    assertEquals("Unexpected result principal", TEST_USER_NAME, result.getMainPrincipal().getName());
}
Also used : AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 54 with AuthenticationResult

use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.

the class PrincipalDatabaseAuthenticationManagerTest method testNonSaslAuthenticationErrored.

public void testNonSaslAuthenticationErrored() throws Exception {
    setupMocks();
    when(_principalDatabase.verifyPassword("guest", "wrongpassword".toCharArray())).thenReturn(false);
    AuthenticationResult result = _manager.authenticate("guest", "wrongpassword");
    assertEquals("Principals was not expected size", 0, result.getPrincipals().size());
    assertEquals(AuthenticationStatus.ERROR, result.getStatus());
}
Also used : AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 55 with AuthenticationResult

use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.

the class PrincipalDatabaseAuthenticationManagerTest method testSaslAuthenticationError.

/**
 * Tests that the authenticate method correctly interprets an
 * authentication error.
 */
public void testSaslAuthenticationError() throws Exception {
    setupMocks();
    when(_saslNegotiator.handleResponse(any(byte[].class))).thenReturn(new AuthenticationResult(AuthenticationStatus.ERROR));
    AuthenticationResult result = _saslNegotiator.handleResponse("12345".getBytes());
    assertEquals("Principals was not expected size", 0, result.getPrincipals().size());
    assertEquals(AuthenticationStatus.ERROR, result.getStatus());
}
Also used : AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Aggregations

AuthenticationResult (org.apache.qpid.server.security.auth.AuthenticationResult)78 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)13 SaslNegotiator (org.apache.qpid.server.security.auth.sasl.SaslNegotiator)13 X500Principal (javax.security.auth.x500.X500Principal)12 SubjectAuthenticationResult (org.apache.qpid.server.security.auth.SubjectAuthenticationResult)9 HashMap (java.util.HashMap)6 SubjectCreator (org.apache.qpid.server.security.SubjectCreator)6 Subject (javax.security.auth.Subject)5 IOException (java.io.IOException)4 OAuth2AuthenticationProvider (org.apache.qpid.server.security.auth.manager.oauth2.OAuth2AuthenticationProvider)4 InetSocketAddress (java.net.InetSocketAddress)3 URISyntaxException (java.net.URISyntaxException)3 Principal (java.security.Principal)3 Broker (org.apache.qpid.server.model.Broker)3 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)3 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)3 URI (java.net.URI)2 AccessControlException (java.security.AccessControlException)2 EventLogger (org.apache.qpid.server.logging.EventLogger)2 User (org.apache.qpid.server.model.User)2