Java Code Examples for org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#setRetrying()

The following examples show how to use org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#setRetrying() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractLocalApplicationAuthenticator.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * To decide whether need to redirect the user to login page to retry authentication.
 *
 * @param request  the httpServletRequest
 * @param response the httpServletResponse
 * @param context  the authentication context
 * @param e        the authentication failed exception
 * @return authentication flow status
 * @throws AuthenticationFailedException the exception in the authentication flow
 */
protected AuthenticatorFlowStatus handleRetryOnFailure(HttpServletRequest request,
                                                                HttpServletResponse response,
                                                                AuthenticationContext context,
                                                                AuthenticationFailedException e)
        throws AuthenticationFailedException {

    boolean sendToMultiOptionPage =
            isStepHasMultiOption(context) && isRedirectToMultiOptionPageOnFailure();
    if (retryAuthenticationEnabled(context) && !sendToMultiOptionPage) {
        // The Authenticator will re-initiate the authentication and retry.
        context.setRetrying(true);
        return initiateAuthenticationFlow(request, response, context);
    } else {
        context.setProperty(FrameworkConstants.LAST_FAILED_AUTHENTICATOR, getName());
        /*
            By throwing this exception step handler will redirect to multi options page if
            multi-option are available in the step.
         */
        throw e;
    }
}
 
Example 2
Source File: DefaultStepBasedSequenceHandlerTest.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Test
public void testResetAuthenticationContext() throws Exception {

    AuthenticationContext context = new AuthenticationContext();
    context.setSubject(new AuthenticatedUser());
    context.setStateInfo(mock(AuthenticatorStateInfo.class));
    context.setExternalIdP(mock(ExternalIdPConfig.class));

    Map<String, String> authenticatorProperties = new HashMap<>();
    authenticatorProperties.put("Prop1", "Value1");

    context.setAuthenticatorProperties(authenticatorProperties);
    context.setRetryCount(3);
    context.setRetrying(true);
    context.setCurrentAuthenticator("OIDCAuthenticator");

    stepBasedSequenceHandler.resetAuthenticationContext(context);

    assertResetContext(context);
}
 
Example 3
Source File: DefaultStepBasedSequenceHandler.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
protected void resetAuthenticationContext(AuthenticationContext context) throws FrameworkException {
    context.setSubject(null);
    context.setStateInfo(null);
    context.setExternalIdP(null);
    context.setAuthenticatorProperties(new HashMap<String, String>());
    context.setRetryCount(0);
    context.setRetrying(false);
    context.setCurrentAuthenticator(null);
}
 
Example 4
Source File: AbstractLocalApplicationAuthenticator.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * To process the authentication failed flow
 *
 * @param request  the httpServletRequest
 * @param response the httpServletResponse
 * @param context  the authentication context
 * @return authentication flow status
 * @throws AuthenticationFailedException the exception in the authentication flow
 */
protected AuthenticatorFlowStatus initiateAuthenticationFlow(HttpServletRequest request,
                                                             HttpServletResponse response,
                                                             AuthenticationContext context)
        throws AuthenticationFailedException {

    if (getName().equals(context.getProperty(FrameworkConstants.LAST_FAILED_AUTHENTICATOR))) {
        context.setRetrying(true);
    }
    initiateAuthenticationRequest(request, response, context);
    context.setCurrentAuthenticator(getName());
    return AuthenticatorFlowStatus.INCOMPLETE;
}
 
Example 5
Source File: AbstractLocalApplicationAuthenticator.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * To check whether the user's account is being already locked or not.
 *
 * @param context  the authentication context
 * @return true or false
 * @throws AuthenticationFailedException the exception in the authentication flow
 */
protected boolean isAccountLocked(AuthenticationContext context) throws AuthenticationFailedException {

    String errorCode = getErrorCode();
    if (StringUtils.isNotEmpty(errorCode) && errorCode.equals(UserCoreConstants.ErrorCode
            .USER_IS_LOCKED)) {
        context.setRetrying(true);
        context.setCurrentAuthenticator(getName());
        return true;
    }
    return false;
}
 
Example 6
Source File: DefaultStepBasedSequenceHandler.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
protected void resetAuthenticationContext(AuthenticationContext context)
        throws FrameworkException {

    context.setSubject(null);
    context.setStateInfo(null);
    context.setExternalIdP(null);
    context.setAuthenticatorProperties(new HashMap<String, String>());
    context.setRetryCount(0);
    context.setRetrying(false);
    context.setCurrentAuthenticator(null);
}
 
Example 7
Source File: AbstractLocalApplicationAuthenticator.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public AuthenticatorFlowStatus process(HttpServletRequest request, HttpServletResponse response,
                                       AuthenticationContext context) throws AuthenticationFailedException,
        LogoutFailedException {

    // if an authentication flow
    if (!context.isLogoutRequest()) {
        if (!canHandle(request)
                || Boolean.TRUE.equals(request.getAttribute(FrameworkConstants.REQ_ATTR_HANDLED))) {
            context.setRetrying(false);
            return initiateAuthenticationFlow(request, response, context);
        } else {
            try {
                fireEvent(context, IdentityEventConstants.Event.PRE_AUTHENTICATION, false);
                processAuthenticationResponse(request, response, context);
                if (this instanceof LocalApplicationAuthenticator && !context.getSequenceConfig()
                        .getApplicationConfig().isSaaSApp()) {
                    validateNonSaasAppLogin(context);
                }
                request.setAttribute(FrameworkConstants.REQ_ATTR_HANDLED, true);
                context.setProperty(FrameworkConstants.LAST_FAILED_AUTHENTICATOR, null);
                fireEvent(context, IdentityEventConstants.Event.POST_AUTHENTICATION, true);
                return AuthenticatorFlowStatus.SUCCESS_COMPLETED;
            } catch (AuthenticationFailedException e) {
                if (isAccountLocked(context)) {
                    try {
                        String redirectUrl = getRedirectUrlOnAccountLock(context, response);
                        response.sendRedirect(redirectUrl);
                    } catch (IOException e1) {
                        throw new AuthenticationFailedException(" Error while redirecting to the retry page ", e1);
                    }
                    return AuthenticatorFlowStatus.INCOMPLETE;
                }
                fireEvent(context, IdentityEventConstants.Event.POST_AUTHENTICATION, false);
                request.setAttribute(FrameworkConstants.REQ_ATTR_HANDLED, true);
                // Decide whether we need to redirect to the login page to retry authentication.
                return handleRetryOnFailure(request, response, context, e);
            }
        }
        // else a logout flow
    } else {
        return processLogoutFlow(request, response, context);
    }
}