use of org.apache.qpid.server.security.SubjectCreator 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.SubjectCreator in project qpid-broker-j by apache.
the class OAuth2PreemptiveAuthenticatorTest method createMockOAuth2AuthenticationProvider.
private OAuth2AuthenticationProvider<?> createMockOAuth2AuthenticationProvider(final HttpPort mockPort) throws URISyntaxException {
OAuth2AuthenticationProvider authenticationProvider = mock(OAuth2AuthenticationProvider.class);
SubjectCreator mockSubjectCreator = mock(SubjectCreator.class);
SubjectAuthenticationResult mockSuccessfulSubjectAuthenticationResult = mock(SubjectAuthenticationResult.class);
SubjectAuthenticationResult mockUnauthorizedSubjectAuthenticationResult = mock(SubjectAuthenticationResult.class);
final Subject successfulSubject = new Subject(true, Collections.singleton(new AuthenticatedPrincipal(new UsernamePrincipal(TEST_AUTHORIZED_USER, null))), Collections.emptySet(), Collections.emptySet());
final Subject unauthorizedSubject = new Subject(true, Collections.singleton(new AuthenticatedPrincipal(new UsernamePrincipal(TEST_UNAUTHORIZED_USER, null))), Collections.emptySet(), Collections.emptySet());
AuthenticationResult mockSuccessfulAuthenticationResult = mock(AuthenticationResult.class);
AuthenticationResult mockUnauthorizedAuthenticationResult = mock(AuthenticationResult.class);
AuthenticationResult failedAuthenticationResult = new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, new Exception("authentication failed"));
SubjectAuthenticationResult failedSubjectAuthenticationResult = new SubjectAuthenticationResult(failedAuthenticationResult);
when(mockPort.getSubjectCreator(any(Boolean.class), anyString())).thenReturn(mockSubjectCreator);
when(authenticationProvider.authenticateViaAccessToken(TEST_VALID_ACCESS_TOKEN, null)).thenReturn(mockSuccessfulAuthenticationResult);
when(authenticationProvider.authenticateViaAccessToken(TEST_INVALID_ACCESS_TOKEN, null)).thenReturn(failedAuthenticationResult);
when(authenticationProvider.authenticateViaAccessToken(TEST_UNAUTHORIZED_ACCESS_TOKEN, null)).thenReturn(mockUnauthorizedAuthenticationResult);
when(mockSuccessfulSubjectAuthenticationResult.getSubject()).thenReturn(successfulSubject);
when(mockUnauthorizedSubjectAuthenticationResult.getSubject()).thenReturn(unauthorizedSubject);
when(mockSubjectCreator.createResultWithGroups(mockSuccessfulAuthenticationResult)).thenReturn(mockSuccessfulSubjectAuthenticationResult);
when(mockSubjectCreator.createResultWithGroups(mockUnauthorizedAuthenticationResult)).thenReturn(mockUnauthorizedSubjectAuthenticationResult);
when(mockSubjectCreator.createResultWithGroups(failedAuthenticationResult)).thenReturn(failedSubjectAuthenticationResult);
return authenticationProvider;
}
use of org.apache.qpid.server.security.SubjectCreator in project qpid-broker-j by apache.
the class AbstractPort method getSubjectCreator.
@Override
public SubjectCreator getSubjectCreator(boolean secure, String host) {
Collection children = _container.getChildren(GroupProvider.class);
NamedAddressSpace addressSpace;
if (host != null) {
addressSpace = getAddressSpace(host);
} else {
addressSpace = null;
}
return new SubjectCreator(getAuthenticationProvider(), children, addressSpace);
}
Aggregations