Example usage for org.springframework.security.web.savedrequest RequestCache getRequest

List of usage examples for org.springframework.security.web.savedrequest RequestCache getRequest

Introduction

In this page you can find the example usage for org.springframework.security.web.savedrequest RequestCache getRequest.

Prototype

SavedRequest getRequest(HttpServletRequest request, HttpServletResponse response);

Source Link

Document

Returns the saved request, leaving it cached.

Usage

From source file:csns.security.AuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    User user = (User) authentication.getPrincipal();
    logger.info(user.getUsername() + " signed in from " + request.getRemoteAddr());

    RequestCache requestCache = new HttpSessionRequestCache();
    SavedRequest savedRequest = requestCache.getRequest(request, response);
    if (savedRequest != null) {
        super.onAuthenticationSuccess(request, response, authentication);
        return;// ww w  .j a  va  2s  .c  om
    }

    getRedirectStrategy().sendRedirect(request, response, defaultUrls.userHomeUrl(request));
}

From source file:bookpub.security.AuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    User user = (User) authentication.getPrincipal();
    logger.info(user.getUsername() + " signed in.");

    RequestCache requestCache = new HttpSessionRequestCache();
    SavedRequest savedRequest = requestCache.getRequest(request, response);
    if (savedRequest != null) {
        super.onAuthenticationSuccess(request, response, authentication);
        return;/*  w  w  w .  j  a va 2 s.c o m*/
    }

    if (request.getParameter("mobile") != null)
        objectMapper.writeValue(response.getWriter(), new ServiceResponse());
    else
        getRedirectStrategy().sendRedirect(request, response, "/");
}

From source file:edu.csula.squirrels.security.AuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    User user = (User) authentication.getPrincipal();
    logger.info(user.getUsername() + " signed in.");

    RequestCache requestCache = new HttpSessionRequestCache();
    SavedRequest savedRequest = requestCache.getRequest(request, response);
    if (savedRequest != null) {
        super.onAuthenticationSuccess(request, response, authentication);
        return;// w  w w  .  ja v  a  2 s  .c  o m
    }

    if (request.getParameter("mobile") != null)
        objectMapper.writeValue(response.getWriter(), new ServiceResponse("loggedIn"));
    else
        getRedirectStrategy().sendRedirect(request, response, "/");
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.security.StorefrontAuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response,
        final Authentication authentication) throws IOException, ServletException {
    //if redirected from some specific url, need to remove the cachedRequest to force use defaultTargetUrl
    final RequestCache requestCache = new HttpSessionRequestCache();
    final SavedRequest savedRequest = requestCache.getRequest(request, response);

    if (savedRequest != null) {
        for (final String redirectUrlForceDefaultTarget : getListRedirectUrlsForceDefaultTarget()) {
            if (savedRequest.getRedirectUrl().contains(redirectUrlForceDefaultTarget)) {
                requestCache.removeRequest(request, response);
                break;
            }/*www  .j  a v a2s .c  o m*/
        }
    }
    getCustomerFacade().loginSuccess();
    request.setAttribute(WebConstants.CART_MERGED, Boolean.FALSE);

    // Check if the user is in role admingroup
    if (!isAdminAuthority(authentication)) {
        getCartRestorationStrategy().restoreCart(request);
        getBruteForceAttackCounter().resetUserCounter(getCustomerFacade().getCurrentCustomerUid());
        super.onAuthenticationSuccess(request, response, authentication);
    } else {
        LOG.warn("Invalidating session for user in the " + Constants.USER.ADMIN_USERGROUP + " group");
        invalidateSession(request, response);
    }
}

From source file:cec.easyshop.storefront.security.StorefrontAuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response,
        final Authentication authentication) throws IOException, ServletException {
    //if redirected from some specific url, need to remove the cachedRequest to force use defaultTargetUrl
    final RequestCache requestCache = new HttpSessionRequestCache();
    final SavedRequest savedRequest = requestCache.getRequest(request, response);
    for (final String redirectUrlForceDefaultTarget : getListRedirectUrlsForceDefaultTarget()) {
        if (savedRequest != null && savedRequest.getRedirectUrl().contains(redirectUrlForceDefaultTarget)) {
            requestCache.removeRequest(request, response);
            break;
        }//from w w w  .ja  va 2s. c  o  m
    }

    getCustomerFacade().loginSuccess();
    request.setAttribute(CART_MERGED, Boolean.FALSE);

    if (!getCartFacade().hasEntries()) {
        getSessionService().setAttribute(WebConstants.CART_RESTORATION_SHOW_MESSAGE, Boolean.TRUE);
        try {
            getSessionService().setAttribute(WebConstants.CART_RESTORATION,
                    getCartFacade().restoreSavedCart(null));
        } catch (final CommerceCartRestorationException e) {
            getSessionService().setAttribute(WebConstants.CART_RESTORATION_ERROR_STATUS,
                    WebConstants.CART_RESTORATION_ERROR_STATUS);
        }
    } else {
        final String sessionCartGuid = getCartFacade().getSessionCartGuid();
        final String mostRecentSavedCartGuid = getMostRecentSavedCartGuid(sessionCartGuid);
        if (StringUtils.isNotEmpty(mostRecentSavedCartGuid)) {
            getSessionService().setAttribute(WebConstants.CART_RESTORATION_SHOW_MESSAGE, Boolean.TRUE);
            try {
                getSessionService().setAttribute(WebConstants.CART_RESTORATION,
                        getCartFacade().restoreCartAndMerge(mostRecentSavedCartGuid, sessionCartGuid));
                request.setAttribute(CART_MERGED, Boolean.TRUE);
            } catch (final CommerceCartRestorationException e) {
                getSessionService().setAttribute(WebConstants.CART_RESTORATION_ERROR_STATUS,
                        WebConstants.CART_RESTORATION_ERROR_STATUS);
            } catch (final CommerceCartMergingException e) {
                LOG.error("User saved cart could not be merged");
            }
        }
    }

    getBruteForceAttackCounter().resetUserCounter(getCustomerFacade().getCurrentCustomerUid());
    super.onAuthenticationSuccess(request, response, authentication);
}

From source file:de.hybris.platform.b2bacceleratoraddon.security.B2BStorefrontAuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response,
        final Authentication authentication) throws IOException, ServletException {
    //if redirected from some specific url, need to remove the cachedRequest to force use defaultTargetUrl
    final RequestCache requestCache = new HttpSessionRequestCache();
    final SavedRequest savedRequest = requestCache.getRequest(request, response);

    if (savedRequest != null) {
        for (final String redirectUrlForceDefaultTarget : getListRedirectUrlsForceDefaultTarget()) {
            if (savedRequest.getRedirectUrl().contains(redirectUrlForceDefaultTarget)) {
                requestCache.removeRequest(request, response);
                break;
            }/*  w w  w .  j  a  v  a 2s  .c om*/
        }
    }

    getCustomerFacade().loginSuccess();
    request.setAttribute(CART_MERGED, Boolean.FALSE);

    // Check if the user is in role admingroup
    if (!isAdminAuthority(authentication)) {
        if (!getCartFacade().hasEntries()) {
            restoreSavedCart();
        } else {
            restoreSavedCartAndMerge(request);
        }

        getBruteForceAttackCounter().resetUserCounter(getCustomerFacade().getCurrentCustomerUid());
        super.onAuthenticationSuccess(request, response, authentication);
    } else {
        LOG.warn("Invalidating session for user in the " + Constants.USER.ADMIN_USERGROUP + " group");
        invalidateSession(request, response);
    }
}