Search in sources :

Example 6 with AuthenticationResult

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

the class AuthenticationResultCacherTest method testCacheMissDifferentAddress.

public void testCacheMissDifferentAddress() throws Exception {
    Subject.doAs(_subject, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            AuthenticationResult result;
            result = _authenticationResultCacher.getOrLoad(new String[] { "credentials" }, _loader);
            assertEquals("Unexpected AuthenticationResult", _successfulAuthenticationResult, result);
            assertEquals("Unexpected number of loads before cache hit", 1, _loadCallCount);
            return null;
        }
    });
    when(_connection.getRemoteSocketAddress()).thenReturn(new InetSocketAddress("example.com", 8888));
    Subject.doAs(_subject, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            AuthenticationResult result;
            result = _authenticationResultCacher.getOrLoad(new String[] { "credentials" }, _loader);
            assertEquals("Unexpected AuthenticationResult", _successfulAuthenticationResult, result);
            assertEquals("Unexpected number of loads before cache hit", 2, _loadCallCount);
            return null;
        }
    });
}
Also used : InetSocketAddress(java.net.InetSocketAddress) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 7 with AuthenticationResult

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

the class AuthenticationResultCacherTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    _connection = mock(AMQPConnection.class);
    when(_connection.getRemoteSocketAddress()).thenReturn(new InetSocketAddress("example.com", 9999));
    _subject = new Subject(true, Collections.singleton(new ConnectionPrincipal(_connection)), Collections.emptySet(), Collections.emptySet());
    _authenticationResultCacher = new AuthenticationResultCacher(10, 10 * 60L, 2);
    _loadCallCount = 0;
    _loader = new Callable<AuthenticationResult>() {

        @Override
        public AuthenticationResult call() throws Exception {
            _loadCallCount += 1;
            return _successfulAuthenticationResult;
        }
    };
}
Also used : AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) InetSocketAddress(java.net.InetSocketAddress) ConnectionPrincipal(org.apache.qpid.server.connection.ConnectionPrincipal) Subject(javax.security.auth.Subject) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 8 with AuthenticationResult

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

the class ExternalAuthenticationManagerTest method testFullDNMode_Authenticate.

public void testFullDNMode_Authenticate() throws Exception {
    X500Principal principal = new X500Principal("CN=person, DC=example, DC=com");
    when(_saslSettings.getExternalPrincipal()).thenReturn(principal);
    SaslNegotiator negotiator = _managerUsingFullDN.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(principal, result.getPrincipals());
    assertEquals("CN=person,DC=example,DC=com", result.getMainPrincipal().getName());
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) SaslNegotiator(org.apache.qpid.server.security.auth.sasl.SaslNegotiator) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 9 with AuthenticationResult

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

the class ExternalAuthenticationManagerTest method testAuthenticatePrincipalCnDc_OtherComponentsIgnored.

public void testAuthenticatePrincipalCnDc_OtherComponentsIgnored() throws Exception {
    X500Principal principal = new X500Principal("CN=person, DC=example, DC=com, O=My Company Ltd, L=Newbury, ST=Berkshire, C=GB");
    UsernamePrincipal expectedPrincipal = new UsernamePrincipal("person@example.com", _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@example.com", 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 10 with AuthenticationResult

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

the class ExternalAuthenticationManagerTest method testAuthenticatePrincipalNoCn_CausesAuthError.

public void testAuthenticatePrincipalNoCn_CausesAuthError() throws Exception {
    X500Principal principal = new X500Principal("DC=example, DC=com, O=My Company Ltd, L=Newbury, ST=Berkshire, C=GB");
    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 unsuccessful", AuthenticationResult.AuthenticationStatus.ERROR, result.getStatus());
    assertNull(result.getMainPrincipal());
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) SaslNegotiator(org.apache.qpid.server.security.auth.sasl.SaslNegotiator) 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