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

The following examples show how to use org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#isRememberMe() . 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: DefaultAuthenticationRequestHandler.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private void handleRememberMeOptionFromLoginPage(HttpServletRequest request, AuthenticationContext context) {

        // If the remember me flag is already set in one step, we don't need to override.
        if (context.isRememberMe()) {
            return;
        }

        String rememberMe = request.getParameter(FrameworkConstants.RequestParams.REMEMBER_ME);

        if (FrameworkConstants.REMEMBER_ME_OPT_ON.equalsIgnoreCase(rememberMe)) {
            context.setRememberMe(true);
        } else {
            context.setRememberMe(false);
        }
    }
 
Example 2
Source File: DefaultAuthenticationRequestHandler.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private void setAuthCookie(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context,
                           String sessionKey, String tenantDomain) throws FrameworkException {

    Integer authCookieAge = null;

    if (context.isRememberMe()) {
        authCookieAge = IdPManagementUtil.getRememberMeTimeout(tenantDomain);
    }

    FrameworkUtils.storeAuthCookie(request, response, sessionKey, authCookieAge);
}
 
Example 3
Source File: DefaultAuthenticationRequestHandler.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private void setAuthCookie(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context,
                           String sessionKey, String tenantDomain) throws FrameworkException {
    Integer authCookieAge = null;

    if (context.isRememberMe()) {
        authCookieAge = IdPManagementUtil.getRememberMeTimeout(tenantDomain);
    }

    FrameworkUtils.storeAuthCookie(request, response, sessionKey, authCookieAge);
}
 
Example 4
Source File: DefaultAuthenticationRequestHandler.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
protected void sendResponse(HttpServletRequest request, HttpServletResponse response,
                            AuthenticationContext context) throws FrameworkException {

    if (log.isDebugEnabled()) {
        StringBuilder debugMessage = new StringBuilder();
        debugMessage.append("Sending response back to: ");
        debugMessage.append(context.getCallerPath()).append("...\n");
        debugMessage.append(FrameworkConstants.ResponseParams.AUTHENTICATED).append(": ");
        debugMessage.append(String.valueOf(context.isRequestAuthenticated())).append("\n");
        debugMessage.append(FrameworkConstants.ResponseParams.AUTHENTICATED_USER).append(": ");
        if (context.getSequenceConfig().getAuthenticatedUser() != null) {
            debugMessage.append(context.getSequenceConfig().getAuthenticatedUser()
                    .getAuthenticatedSubjectIdentifier()).append("\n");
        } else {
            debugMessage.append("No Authenticated User").append("\n");
        }
        debugMessage.append(FrameworkConstants.ResponseParams.AUTHENTICATED_IDPS).append(": ");
        debugMessage.append(context.getSequenceConfig().getAuthenticatedIdPs()).append("\n");
        debugMessage.append(FrameworkConstants.SESSION_DATA_KEY).append(": ");
        debugMessage.append(context.getCallerSessionKey());

        log.debug(debugMessage);
    }

    // TODO rememberMe should be handled by a cookie authenticator. For now rememberMe flag that
    // was set in the login page will be sent as a query param to the calling servlet so it will
    // handle rememberMe as usual.
    String rememberMeParam = "";

    if (context.isRequestAuthenticated() && context.isRememberMe()) {
        rememberMeParam = rememberMeParam + "chkRemember=on";
    }

    // if request is not authenticated populate error information sent from authenticators/handlers
    if (!context.isRequestAuthenticated()) {
        populateErrorInformation(request, response, context);
    }

    // redirect to the caller
    String redirectURL;
    String commonauthCallerPath = context.getCallerPath();

    try {
        String queryParamsString = "";
        if (context.getCallerSessionKey() != null) {
            queryParamsString = FrameworkConstants.SESSION_DATA_KEY + "=" +
                    URLEncoder.encode(context.getCallerSessionKey(), "UTF-8");
        }

        if (StringUtils.isNotEmpty(rememberMeParam)) {
            queryParamsString += "&" + rememberMeParam;
        }
        redirectURL = FrameworkUtils.appendQueryParamsStringToUrl(commonauthCallerPath, queryParamsString);
        response.sendRedirect(redirectURL);
    } catch (IOException e) {
        throw new FrameworkException(e.getMessage(), e);
    }
}
 
Example 5
Source File: DefaultAuthenticationRequestHandler.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
protected void sendResponse(HttpServletRequest request, HttpServletResponse response,
                            AuthenticationContext context) throws FrameworkException {

    if (log.isDebugEnabled()) {
        StringBuilder debugMessage = new StringBuilder();
        debugMessage.append("Sending response back to: ");
        debugMessage.append(context.getCallerPath()).append("...\n");
        debugMessage.append(FrameworkConstants.ResponseParams.AUTHENTICATED).append(": ");
        debugMessage.append(String.valueOf(context.isRequestAuthenticated())).append("\n");
        debugMessage.append(FrameworkConstants.ResponseParams.AUTHENTICATED_USER).append(": ");
        if (context.getSequenceConfig().getAuthenticatedUser() != null) {
            debugMessage.append(context.getSequenceConfig().getAuthenticatedUser().getAuthenticatedSubjectIdentifier()).append("\n");
        } else {
            debugMessage.append("No Authenticated User").append("\n");
        }
        debugMessage.append(FrameworkConstants.ResponseParams.AUTHENTICATED_IDPS).append(": ");
        debugMessage.append(context.getSequenceConfig().getAuthenticatedIdPs()).append("\n");
        debugMessage.append(FrameworkConstants.SESSION_DATA_KEY).append(": ");
        debugMessage.append(context.getCallerSessionKey());

        log.debug(debugMessage);
    }

    // TODO rememberMe should be handled by a cookie authenticator. For now rememberMe flag that
    // was set in the login page will be sent as a query param to the calling servlet so it will
    // handle rememberMe as usual.
    String rememberMeParam = "";

    if (context.isRequestAuthenticated() && context.isRememberMe()) {
        rememberMeParam = rememberMeParam + "&chkRemember=on";
    }

    // redirect to the caller
    String redirectURL = context.getCallerPath() + "?sessionDataKey="
            + context.getCallerSessionKey() + rememberMeParam;
    try {
        response.sendRedirect(redirectURL);
    } catch (IOException e) {
        throw new FrameworkException(e.getMessage(), e);
    }
}