Search in sources :

Example 16 with SaslNegotiator

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

the class ExternalAuthenticationManagerTest method testAuthenticatePrincipalCnAndDc.

public void testAuthenticatePrincipalCnAndDc() throws Exception {
    X500Principal principal = new X500Principal("CN=person, DC=example, DC=com");
    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 17 with SaslNegotiator

use of org.apache.qpid.server.security.auth.sasl.SaslNegotiator 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 18 with SaslNegotiator

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

the class ExternalAuthenticationManagerTest method testAuthenticatePrincipalEmptyCn_CausesAuthError.

public void testAuthenticatePrincipalEmptyCn_CausesAuthError() throws Exception {
    X500Principal principal = new X500Principal("CN=, 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)

Example 19 with SaslNegotiator

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

the class ManagedAuthenticationManagerTestBase method testAllSaslMechanisms.

public void testAllSaslMechanisms() throws Exception {
    final SaslSettings saslSettings = mock(SaslSettings.class);
    when(saslSettings.getLocalFQDN()).thenReturn("testhost.example.com");
    for (String mechanism : _authManager.getMechanisms()) {
        final SaslNegotiator negotiator = _authManager.createSaslNegotiator(mechanism, saslSettings, null);
        assertNotNull(String.format("Could not create SASL negotiator for mechanism '%s'", mechanism), negotiator);
    }
}
Also used : SaslSettings(org.apache.qpid.server.security.auth.sasl.SaslSettings) SaslNegotiator(org.apache.qpid.server.security.auth.sasl.SaslNegotiator)

Example 20 with SaslNegotiator

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

the class ManagedAuthenticationManagerTestBase method testUnsupportedSaslMechanisms.

public void testUnsupportedSaslMechanisms() throws Exception {
    final SaslSettings saslSettings = mock(SaslSettings.class);
    when(saslSettings.getLocalFQDN()).thenReturn("testhost.example.com");
    final SaslNegotiator negotiator = _authManager.createSaslNegotiator("UNSUPPORTED MECHANISM", saslSettings, null);
    assertNull("Should not be able to create SASL negotiator for unsupported mechanism", negotiator);
}
Also used : SaslSettings(org.apache.qpid.server.security.auth.sasl.SaslSettings) SaslNegotiator(org.apache.qpid.server.security.auth.sasl.SaslNegotiator)

Aggregations

SaslNegotiator (org.apache.qpid.server.security.auth.sasl.SaslNegotiator)22 AuthenticationResult (org.apache.qpid.server.security.auth.AuthenticationResult)13 X500Principal (javax.security.auth.x500.X500Principal)7 SaslSettings (org.apache.qpid.server.security.auth.sasl.SaslSettings)7 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)5 SubjectCreator (org.apache.qpid.server.security.SubjectCreator)2 InetSocketAddress (java.net.InetSocketAddress)1 Subject (javax.security.auth.Subject)1 HttpSession (javax.servlet.http.HttpSession)1 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)1 EventLogger (org.apache.qpid.server.logging.EventLogger)1 SessionInvalidatedException (org.apache.qpid.server.management.plugin.SessionInvalidatedException)1 AuthenticationProvider (org.apache.qpid.server.model.AuthenticationProvider)1 Broker (org.apache.qpid.server.model.Broker)1 BrokerModel (org.apache.qpid.server.model.BrokerModel)1 Model (org.apache.qpid.server.model.Model)1 SystemConfig (org.apache.qpid.server.model.SystemConfig)1 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)1 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)1 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)1