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

The following examples show how to use org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#setCurrentAuthenticator() . 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 process the logout flow.
 *
 * @param request  the httpServletRequest
 * @param response the httpServletResponse
 * @param context  the authentication context
 * @return the authentication flow status
 * @throws LogoutFailedException the exception in logout flow
 */
protected AuthenticatorFlowStatus processLogoutFlow(HttpServletRequest request, HttpServletResponse response,
                                                    AuthenticationContext context) throws LogoutFailedException {

    try {
        if (!canHandle(request)) {
            context.setCurrentAuthenticator(getName());
            initiateLogoutRequest(request, response, context);
            return AuthenticatorFlowStatus.INCOMPLETE;
        } else {
            processLogoutResponse(request, response, context);
            return AuthenticatorFlowStatus.SUCCESS_COMPLETED;
        }
    } catch (UnsupportedOperationException e) {
        if (log.isDebugEnabled()) {
            log.debug("Ignoring UnsupportedOperationException.", e);
        }
        return AuthenticatorFlowStatus.SUCCESS_COMPLETED;
    }
}
 
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: LoginContextManagementUtil.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public static void handleLoginContext(HttpServletRequest request, HttpServletResponse response)
        throws IOException {

    String sessionDataKey = request.getParameter("sessionDataKey");
    String relyingParty = request.getParameter("relyingParty");
    String tenantDomain = getTenantDomain(request);

    JsonObject result = new JsonObject();
    response.setContentType("application/json");
    if (StringUtils.isBlank(relyingParty) || StringUtils.isBlank(sessionDataKey)) {
        if (log.isDebugEnabled()) {
            log.debug("Required data to proceed is not available in the request.");
        }
        //cannot handle the request without sessionDataKey
        result.addProperty("status", "success");
        response.getWriter().write(result.toString());
        return;
    }

    AuthenticationContext context = FrameworkUtils.getAuthenticationContextFromCache(sessionDataKey);
    // Valid Request
    if (context != null) {
        if (isStepHasMultiOption(context)) {
            context.setCurrentAuthenticator(null);
        }
        result.addProperty("status", "success");
        response.getWriter().write(result.toString());
    } else {
        String redirectUrl = getRelyingPartyRedirectUrl(relyingParty, tenantDomain);
        if (StringUtils.isBlank(redirectUrl)) {
            if (log.isDebugEnabled()) {
                log.debug("Redirect URL is not available for the relaying party - " + relyingParty + " for " +
                        "sessionDataKey: " + sessionDataKey);
            }
            // Can't handle
            result.addProperty("status", "success");
            response.getWriter().write(result.toString());
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Redirect URL is: " + redirectUrl + " for the relaying party - " + relyingParty +
                        " for " + "sessionDataKey: " + sessionDataKey);
            }
            result.addProperty("status", "redirect");
            result.addProperty("redirectUrl", redirectUrl);
            response.getWriter().write(result.toString());
        }
    }
}