Search in sources :

Example 1 with SaslSettings

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

the class PrincipalDatabaseAuthenticationManagerTest method testSaslMechanismCreation.

public void testSaslMechanismCreation() throws Exception {
    setupMocks();
    SaslSettings saslSettings = mock(SaslSettings.class);
    SaslNegotiator saslNegotiator = _manager.createSaslNegotiator(MOCK_MECH_NAME, saslSettings, null);
    assertNotNull(saslNegotiator);
}
Also used : SaslSettings(org.apache.qpid.server.security.auth.sasl.SaslSettings) SaslNegotiator(org.apache.qpid.server.security.auth.sasl.SaslNegotiator)

Example 2 with SaslSettings

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

the class SimpleAuthenticationManagerTest method authenticatePlain.

private AuthenticationResult authenticatePlain(String userName, String userPassword) throws Exception {
    SaslSettings saslSettings = mock(SaslSettings.class);
    SaslNegotiator saslNegotiator = _authenticationManager.createSaslNegotiator("PLAIN", saslSettings, null);
    byte[] response = SaslUtil.generatePlainClientResponse(userName, userPassword);
    return saslNegotiator.handleResponse(response);
}
Also used : SaslSettings(org.apache.qpid.server.security.auth.sasl.SaslSettings) SaslNegotiator(org.apache.qpid.server.security.auth.sasl.SaslNegotiator)

Example 3 with SaslSettings

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

the class SaslServlet method doPost.

@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response, final ConfiguredObject<?> managedObject) throws IOException {
    checkSaslAuthEnabled(request);
    final HttpSession session = request.getSession();
    try {
        String mechanism = request.getParameter("mechanism");
        String id = request.getParameter("id");
        String saslResponse = request.getParameter("response");
        SubjectCreator subjectCreator = getSubjectCreator(request);
        AuthenticationProvider<?> authenticationProvider = getAuthenticationProvider(request);
        SaslNegotiator saslNegotiator = null;
        if (mechanism != null) {
            if (id == null && authenticationProvider.getAvailableMechanisms(request.isSecure()).contains(mechanism)) {
                LOGGER.debug("Creating SaslServer for mechanism: {}", mechanism);
                saslNegotiator = subjectCreator.createSaslNegotiator(mechanism, new SaslSettings() {

                    @Override
                    public String getLocalFQDN() {
                        return request.getServerName();
                    }

                    @Override
                    public Principal getExternalPrincipal() {
                        return null;
                    }
                });
            }
        } else {
            if (id != null) {
                if (id.equals(HttpManagementUtil.getSessionAttribute(ATTR_ID, session, request)) && System.currentTimeMillis() < (Long) HttpManagementUtil.getSessionAttribute(ATTR_EXPIRY, session, request)) {
                    saslNegotiator = (SaslNegotiator) HttpManagementUtil.getSessionAttribute(ATTR_SASL_NEGOTIATOR, session, request);
                }
            }
        }
        if (saslNegotiator != null) {
            evaluateSaslResponse(request, response, session, saslResponse, saslNegotiator, subjectCreator);
        } else {
            cleanup(request, session);
            response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
        }
    } catch (SessionInvalidatedException e) {
        response.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
    } finally {
        if (response.getStatus() != HttpServletResponse.SC_OK) {
            HttpManagementUtil.invalidateSession(session);
        }
    }
}
Also used : SaslSettings(org.apache.qpid.server.security.auth.sasl.SaslSettings) SessionInvalidatedException(org.apache.qpid.server.management.plugin.SessionInvalidatedException) HttpSession(javax.servlet.http.HttpSession) SaslNegotiator(org.apache.qpid.server.security.auth.sasl.SaslNegotiator) SubjectCreator(org.apache.qpid.server.security.SubjectCreator)

Example 4 with SaslSettings

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

use of org.apache.qpid.server.security.auth.sasl.SaslSettings 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)6 SaslSettings (org.apache.qpid.server.security.auth.sasl.SaslSettings)6 HttpSession (javax.servlet.http.HttpSession)1 SessionInvalidatedException (org.apache.qpid.server.management.plugin.SessionInvalidatedException)1 SubjectCreator (org.apache.qpid.server.security.SubjectCreator)1 AuthenticationResult (org.apache.qpid.server.security.auth.AuthenticationResult)1