public SAMLSSOReqValidationResponseDTO validateRequest(String authReq, String sessionId,
String rpSessionId, String authnMode) throws IdentityException {
XMLObject request = SAMLSSOUtil.unmarshall(SAMLSSOUtil.decode(authReq));
if (request instanceof AuthnRequest) {
AuthnRequestValidator authnRequestValidator = new AuthnRequestValidator((AuthnRequest)request);
SAMLSSOReqValidationResponseDTO validationResp = authnRequestValidator.validate();
validationResp.setAssertionString(authReq);
if (validationResp.isValid()) {
SSOSessionPersistenceManager sessionPersistenceManager = SSOSessionPersistenceManager.getPersistenceManager();
boolean isExistingSession = sessionPersistenceManager.isExistingSession(sessionId);
if(authnMode.equals(SAMLSSOConstants.AuthnModes.OPENID) && !isExistingSession){
AuthnRequestProcessor authnRequestProcessor = new AuthnRequestProcessor();
try {
return authnRequestProcessor.process(validationResp, sessionId, rpSessionId, authnMode);
} catch (Exception e) {
throw new IdentityException("Error processing the Authentication Request", e);
}
}
if (isExistingSession) {
AuthnRequestProcessor authnRequestProcessor = new AuthnRequestProcessor();
try {
return authnRequestProcessor.process(validationResp, sessionId, rpSessionId, authnMode);
} catch (Exception e) {
throw new IdentityException("Error processing the Authentication Request", e);
}
}
}
validationResp.setRpSessionId(rpSessionId);
return validationResp;
}
else if(request instanceof LogoutRequest){
LogoutRequestProcessor logoutReqProcessor = new LogoutRequestProcessor();
SAMLSSOReqValidationResponseDTO validationResponseDTO = logoutReqProcessor.process(
(LogoutRequest)request, sessionId);
return validationResponseDTO;
}
return null;