use of io.asgardeo.java.oidc.sdk.request.OIDCRequestResolver in project asgardeo-java-oidc-sdk by asgardeo.
the class DefaultOIDCManager method handleOIDCCallback.
/**
* {@inheritDoc}
*/
@Override
public SessionContext handleOIDCCallback(HttpServletRequest request, HttpServletResponse response, RequestContext requestContext) throws SSOAgentException {
OIDCRequestResolver requestResolver = new OIDCRequestResolver(request, oidcAgentConfig);
SessionContext sessionContext = new SessionContext();
Nonce nonce = requestContext.getNonce();
try {
if (requestResolver.isAuthorizationCodeResponse()) {
// Auth code is received.
logger.log(Level.TRACE, "Handling the OIDC Authorization response.");
boolean isAuthenticated = handleAuthentication(request, sessionContext, nonce);
if (isAuthenticated) {
logger.log(Level.TRACE, "Authentication successful. Redirecting to the target page.");
return sessionContext;
}
} else if (requestResolver.isError()) {
// Error occurred.
if (StringUtils.isNotEmpty(request.getParameter(SSOAgentConstants.ERROR_DESCRIPTION))) {
logger.log(Level.ERROR, "Authentication unsuccessful. Error description: " + request.getParameter(SSOAgentConstants.ERROR_DESCRIPTION));
throw new SSOAgentServerException(request.getParameter(SSOAgentConstants.ERROR_DESCRIPTION), SSOAgentConstants.ErrorMessages.AUTHENTICATION_FAILED.getCode());
}
} else {
// Successful logout.
sessionContext.getAdditionalParams().put(SSOAgentConstants.IS_LOGOUT, true);
return sessionContext;
}
logger.log(Level.ERROR, "Authentication unsuccessful. Clearing the active session and redirecting.");
throw new SSOAgentServerException(SSOAgentConstants.ErrorMessages.AUTHENTICATION_FAILED.getMessage(), SSOAgentConstants.ErrorMessages.AUTHENTICATION_FAILED.getCode());
} catch (SSOAgentServerException e) {
throw new SSOAgentException(e.getMessage(), e.getErrorCode());
}
}
Aggregations