Search in sources :

Example 31 with UsernamePrincipal

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

the class ExternalAuthenticationManagerTest method testAuthenticatePrincipalCn_OtherComponentsIgnored.

public void testAuthenticatePrincipalCn_OtherComponentsIgnored() throws Exception {
    X500Principal principal = new X500Principal("CN=person, O=My Company Ltd, L=Newbury, ST=Berkshire, C=GB");
    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 32 with UsernamePrincipal

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

the class PrincipalDatabaseAuthenticationManagerTest method testNonSaslAuthenticationSuccess.

public void testNonSaslAuthenticationSuccess() throws Exception {
    setupMocks();
    when(_principalDatabase.verifyPassword("guest", "guest".toCharArray())).thenReturn(true);
    AuthenticationResult result = _manager.authenticate("guest", "guest");
    UsernamePrincipal expectedPrincipal = new UsernamePrincipal("guest", _manager);
    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 33 with UsernamePrincipal

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

the class GroupPrincipalTest method testAddRejected.

public void testAddRejected() {
    final GroupPrincipal principal = new GroupPrincipal("group", (GroupProvider) null);
    final UsernamePrincipal user = new UsernamePrincipal("name", null);
    try {
        principal.addMember(user);
        fail("Exception not thrown");
    } catch (UnsupportedOperationException uso) {
    // PASS
    }
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal)

Aggregations

UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)33 AuthenticationResult (org.apache.qpid.server.security.auth.AuthenticationResult)13 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)9 Principal (java.security.Principal)8 IOException (java.io.IOException)7 Subject (javax.security.auth.Subject)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 InputStream (java.io.InputStream)6 HttpURLConnection (java.net.HttpURLConnection)6 URL (java.net.URL)6 GeneralSecurityException (java.security.GeneralSecurityException)6 Map (java.util.Map)6 TrustStore (org.apache.qpid.server.model.TrustStore)6 IdentityResolverException (org.apache.qpid.server.security.auth.manager.oauth2.IdentityResolverException)6 ConnectionBuilder (org.apache.qpid.server.util.ConnectionBuilder)6 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)6 X500Principal (javax.security.auth.x500.X500Principal)5 SaslNegotiator (org.apache.qpid.server.security.auth.sasl.SaslNegotiator)5 SubjectCreator (org.apache.qpid.server.security.SubjectCreator)4 EventLogger (org.apache.qpid.server.logging.EventLogger)3