AuthenticationMethodInformation authenticationMethod = getUsableExistingAuthenticationMethod(
loginContext, shibSession);
if (authenticationMethod != null) {
- LOG
- .debug(
- "An active authentication method is applicable for relying party. "
- + "Using authentication method {} as authentication method to relying party without re-authenticating user.",
- authenticationMethod.getAuthenticationMethod());
+ LOG.debug("An active authentication method is applicable for relying party. Using authentication "
+ + "method {} as authentication method to relying party without re-authenticating user.",
+ authenticationMethod.getAuthenticationMethod());
authenticateUserWithActiveMethod(httpRequest, httpResponse, authenticationMethod);
}
}
HttpServletRequest httpRequest = ((HttpServletRequestAdapter) inTransport).getWrappedRequest();
HttpSession httpSession = httpRequest.getSession();
+ LoginContext loginContext = (LoginContext) httpSession.getAttribute(LoginContext.LOGIN_CONTEXT_KEY);
- if (httpSession.getAttribute(LoginContext.LOGIN_CONTEXT_KEY) == null) {
+ if (loginContext == null) {
log.debug("User session does not contain a login context, processing as first leg of request");
performAuthentication(inTransport, outTransport);
+ }else if (!loginContext.isPrincipalAuthenticated()){
+ log.debug("User session contained a login context but user was not authenticated, processing as first leg of request");
+ performAuthentication(inTransport, outTransport);
} else {
log.debug("User session contains a login context, processing as second leg of request");
completeAuthenticationRequest(inTransport, outTransport);
dispatcher.forward(httpRequest, httpResponse);
return;
} catch (IOException ex) {
+ httpSession.removeAttribute(LoginContext.LOGIN_CONTEXT_KEY);
log.error("Error forwarding Shibboleth SSO request to AuthenticationManager", ex);
throw new ProfileException("Error forwarding Shibboleth SSO request to AuthenticationManager", ex);
} catch (ServletException ex) {
+ httpSession.removeAttribute(LoginContext.LOGIN_CONTEXT_KEY);
log.error("Error forwarding Shibboleth SSO request to AuthenticationManager", ex);
throw new ProfileException("Error forwarding Shibboleth SSO request to AuthenticationManager", ex);
}
public void processRequest(HTTPInTransport inTransport, HTTPOutTransport outTransport) throws ProfileException {
HttpServletRequest servletRequest = ((HttpServletRequestAdapter) inTransport).getWrappedRequest();
HttpSession httpSession = servletRequest.getSession(true);
+ LoginContext loginContext = (LoginContext) httpSession.getAttribute(LoginContext.LOGIN_CONTEXT_KEY);
- if (httpSession.getAttribute(LoginContext.LOGIN_CONTEXT_KEY) == null) {
+ if (loginContext == null) {
+ log.debug("User session does not contain a login context, processing as first leg of request");
+ performAuthentication(inTransport, outTransport);
+ }else if (!loginContext.isPrincipalAuthenticated()){
+ log.debug("User session contained a login context but user was not authenticated, processing as first leg of request");
performAuthentication(inTransport, outTransport);
} else {
+ log.debug("User session contains a login context, processing as second leg of request");
completeAuthenticationRequest(inTransport, outTransport);
}
}
protected void performAuthentication(HTTPInTransport inTransport, HTTPOutTransport outTransport)
throws ProfileException {
HttpServletRequest servletRequest = ((HttpServletRequestAdapter) inTransport).getWrappedRequest();
+ HttpSession httpSession = servletRequest.getSession();
try {
SSORequestContext requestContext = decodeRequest(inTransport, outTransport);
if (loginContext.getRequestedAuthenticationMethods().size() == 0) {
loginContext.getRequestedAuthenticationMethods().add(rpConfig.getDefaultAuthenticationMethod());
}
-
- HttpSession httpSession = servletRequest.getSession();
+
httpSession.setAttribute(Saml2LoginContext.LOGIN_CONTEXT_KEY, loginContext);
RequestDispatcher dispatcher = servletRequest.getRequestDispatcher(authenticationManagerPath);
dispatcher.forward(servletRequest, ((HttpServletResponseAdapter) outTransport).getWrappedResponse());
} catch (MarshallingException e) {
+ httpSession.removeAttribute(LoginContext.LOGIN_CONTEXT_KEY);
log.error("Unable to marshall authentication request context");
throw new ProfileException("Unable to marshall authentication request context", e);
} catch (IOException ex) {
+ httpSession.removeAttribute(LoginContext.LOGIN_CONTEXT_KEY);
log.error("Error forwarding SAML 2 AuthnRequest to AuthenticationManager", ex);
throw new ProfileException("Error forwarding SAML 2 AuthnRequest to AuthenticationManager", ex);
} catch (ServletException ex) {
+ httpSession.removeAttribute(LoginContext.LOGIN_CONTEXT_KEY);
log.error("Error forwarding SAML 2 AuthnRequest to AuthenticationManager", ex);
throw new ProfileException("Error forwarding SAML 2 AuthnRequest to AuthenticationManager", ex);
}