Search in sources :

Example 11 with AuthenticationResult

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

the class ExternalAuthenticationManagerTest method testAuthenticatePrincipalCnOnly.

public void testAuthenticatePrincipalCnOnly() throws Exception {
    X500Principal principal = new X500Principal("CN=person");
    UsernamePrincipal expectedPrincipal = new UsernamePrincipal("person", _manager);
    when(_saslSettings.getExternalPrincipal()).thenReturn(principal);
    SaslNegotiator negotiator = _manager.createSaslNegotiator("EXTERNAL", _saslSettings, null);
    AuthenticationResult result = negotiator.handleResponse(new byte[0]);
    assertNotNull(result);
    assertEquals("Expected authentication to be successful", AuthenticationResult.AuthenticationStatus.SUCCESS, result.getStatus());
    assertOnlyContainsWrapped(expectedPrincipal, result.getPrincipals());
    assertEquals("person", result.getMainPrincipal().getName());
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) X500Principal(javax.security.auth.x500.X500Principal) SaslNegotiator(org.apache.qpid.server.security.auth.sasl.SaslNegotiator) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 12 with AuthenticationResult

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

the class ManagedAuthenticationManagerTestBase method testAuthenticateInvalidCredentials.

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

Example 13 with AuthenticationResult

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

the class PlainPasswordDatabaseAuthenticationManagerTest method testAuthenticate.

public void testAuthenticate() {
    _passwordFile = TestFileUtils.createTempFile(this, ".user.password", "user:password");
    String file = _passwordFile.getAbsolutePath();
    Map<String, Object> providerAttrs = new HashMap<>();
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, file);
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
    PasswordCredentialManagingAuthenticationProvider provider = ((PasswordCredentialManagingAuthenticationProvider) _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker));
    {
        AuthenticationResult result = provider.authenticate("user", "password");
        assertThat(result.getStatus(), is(equalTo(SUCCESS)));
    }
    {
        AuthenticationResult result = provider.authenticate("user", "badpassword");
        assertThat(result.getStatus(), is(equalTo(AuthenticationResult.AuthenticationStatus.ERROR)));
    }
    {
        AuthenticationResult result = provider.authenticate("unknownuser", "badpassword");
        assertThat(result.getStatus(), is(equalTo(AuthenticationResult.AuthenticationStatus.ERROR)));
    }
}
Also used : HashMap(java.util.HashMap) PasswordCredentialManagingAuthenticationProvider(org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 14 with AuthenticationResult

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

the class PrincipalDatabaseAuthenticationManagerTest method testSaslAuthenticationSuccess.

/**
 * Tests that the authenticate method correctly interprets an
 * authentication success.
 */
public void testSaslAuthenticationSuccess() throws Exception {
    setupMocks();
    UsernamePrincipal expectedPrincipal = new UsernamePrincipal("guest", _manager);
    when(_saslNegotiator.handleResponse(any(byte[].class))).thenReturn(new AuthenticationResult(expectedPrincipal));
    AuthenticationResult result = _saslNegotiator.handleResponse("12345".getBytes());
    assertOnlyContainsWrapped(expectedPrincipal, result.getPrincipals());
    assertEquals(AuthenticationStatus.SUCCESS, result.getStatus());
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 15 with AuthenticationResult

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

the class SimpleAuthenticationManagerTest method testAuthenticateWithPlainSaslServerInvalidUsername.

public void testAuthenticateWithPlainSaslServerInvalidUsername() throws Exception {
    AuthenticationResult result = authenticatePlain("wrong-user", TEST_PASSWORD);
    assertUnauthenticated(result);
}
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