Search in sources :

Example 1 with OIDCRequestResolver

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());
    }
}
Also used : Nonce(com.nimbusds.openid.connect.sdk.Nonce) SSOAgentException(io.asgardeo.java.oidc.sdk.exception.SSOAgentException) OIDCRequestResolver(io.asgardeo.java.oidc.sdk.request.OIDCRequestResolver) SessionContext(io.asgardeo.java.oidc.sdk.bean.SessionContext) SSOAgentServerException(io.asgardeo.java.oidc.sdk.exception.SSOAgentServerException)

Aggregations

Nonce (com.nimbusds.openid.connect.sdk.Nonce)1 SessionContext (io.asgardeo.java.oidc.sdk.bean.SessionContext)1 SSOAgentException (io.asgardeo.java.oidc.sdk.exception.SSOAgentException)1 SSOAgentServerException (io.asgardeo.java.oidc.sdk.exception.SSOAgentServerException)1 OIDCRequestResolver (io.asgardeo.java.oidc.sdk.request.OIDCRequestResolver)1