SAMLSSOServiceClient ssoServiceClient)
throws IdentityException, IOException {
FESessionManager sessionManager = FESessionManager.getInstance();
String authSessionID = httpServletRequest.getParameter(SAMLSSOProviderConstants.FE_SESSION_KEY);
FESessionBean sessionBean = sessionManager.getFESessionBean(authSessionID);
SAMLSSOReqValidationResponseDTO validationResponseDTO = null;
if (sessionBean != null) {
if (sessionBean.getSessionBean() instanceof SAMLSSOReqValidationResponseDTO) {
validationResponseDTO = (SAMLSSOReqValidationResponseDTO) sessionBean.getSessionBean();
}
}
else{
String errorSessionId = sessionManager.addNewSession(new FESessionBean("This authenticated session is expired.", "Please sign-in again."));
httpServletResponse.sendRedirect(getAdminConsoleURL(httpServletRequest) + "sso-saml/notification_page.jsp?" +
SAMLSSOProviderConstants.FE_SESSION_KEY + "=" + errorSessionId);
return;
}
// Create SAMLSSOAuthnReqDTO using a SAMLSSOReqValidationResponseDTO
SAMLSSOAuthnReqDTO authnReqDTO = new SAMLSSOAuthnReqDTO();
authnReqDTO.setAssertionConsumerURL(validationResponseDTO.getAssertionConsumerURL());
authnReqDTO.setId(validationResponseDTO.getId());
authnReqDTO.setIssuer(validationResponseDTO.getIssuer());
authnReqDTO.setPassword(password);
authnReqDTO.setUsername(username);
authnReqDTO.setSubject(validationResponseDTO.getSubject());
authnReqDTO.setRpSessionId(validationResponseDTO.getRpSessionId());
authnReqDTO.setAssertionString(validationResponseDTO.getAssertionString());
// authenticate the user
SAMLSSORespDTO authRespDTO = ssoServiceClient.authenticate(authnReqDTO, ssoTokenID);
if (authRespDTO.getSessionEstablished()) { // authentication is SUCCESSFUL
storeSSOTokenCookie(ssoTokenID, httpServletRequest, httpServletResponse);
String respSessionAuthID = sessionManager.addNewSession(new FESessionBean(authRespDTO, sessionBean.getRelayState()));
sessionManager.removeSession(authSessionID); // remove the SAMLSSORespDTO
httpServletResponse.sendRedirect(getAdminConsoleURL(httpServletRequest) + "sso-saml/redirect_ajaxprocessor.jsp?" + SAMLSSOProviderConstants.FE_SESSION_KEY + "=" + respSessionAuthID);
} else { // authentication FAILURE
validationResponseDTO.setValid(false);
httpServletResponse.sendRedirect(calculateLoginPage(