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);
}
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);
}
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);
}
}
}
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);
}
}
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);
}
Aggregations