use of org.apache.qpid.server.management.plugin.SessionInvalidatedException 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);
}
}
}
Aggregations