Package org.springframework.security.web.savedrequest

Examples of org.springframework.security.web.savedrequest.SavedRequest


    private RequestCache requestCache = new HttpSessionRequestCache();

    @Override
    public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) throws ServletException, IOException {
        final SavedRequest savedRequest = requestCache.getRequest(request, response);

        if (savedRequest == null) {
            clearAuthenticationAttributes(request);
            return;
        }
View Full Code Here


    private RequestCache requestCache = new HttpSessionRequestCache();

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
            Authentication authentication) throws ServletException, IOException {
        SavedRequest savedRequest = requestCache.getRequest(request, response);

        if (savedRequest == null) {
            super.onAuthenticationSuccess(request, response, authentication);

            return;
        }
        String targetUrlParameter = getTargetUrlParameter();
        if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && StringUtils.hasText(request.getParameter(targetUrlParameter)))) {
            requestCache.removeRequest(request, response);
            super.onAuthenticationSuccess(request, response, authentication);

            return;
        }

        clearAuthenticationAttributes(request);

        // Use the DefaultSavedRequest URL
        String targetUrl = savedRequest.getRedirectUrl();
        logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
        getRedirectStrategy().sendRedirect(request, response, targetUrl);
    }
View Full Code Here

    @Test
    public void onAuthenticationSuccessHasSavedRequest() throws Exception {
        String redirectUrl = "http://localhost/appcontext/page";
        RedirectStrategy redirectStrategy = mock(RedirectStrategy.class);
        RequestCache requestCache = mock(RequestCache.class);
        SavedRequest savedRequest = mock(SavedRequest.class);
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        when(savedRequest.getRedirectUrl()).thenReturn(redirectUrl);
        when(requestCache.getRequest(request, response)).thenReturn(savedRequest);

        SavedRequestAwareAuthenticationSuccessHandler handler = new SavedRequestAwareAuthenticationSuccessHandler();
        handler.setRequestCache(requestCache);
        handler.setRedirectStrategy(redirectStrategy);
View Full Code Here

        if (session == null) {
            return null;
        }

        HttpSessionRequestCache rc = new HttpSessionRequestCache();
        SavedRequest sr = rc.getRequest(request, new MockHttpServletResponse());

        return sr.getRedirectUrl();
    }
View Full Code Here

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
                                        Authentication authentication) throws ServletException, IOException {
        final String requestRedirect = request.getParameter("r");
        SavedRequest savedRequest = requestCache.getRequest(request, response);

        if (request.getHeader("X-DEV-WEBSITE")!=null) {
            Map<String, Object> status = new HashMap<String, Object>();
            status.put("authd", new Boolean(true));
            response.setContentType("application/json");
            response.getWriter().write(objectMapper.writeValueAsString(status));
            return;
        } else if (request.getHeader("User-Agent").indexOf("Mobile") != -1) {
            logger.debug("Redirecting to mobile default target URL: " + mobileDefaultTargetUrl);
            getRedirectStrategy().sendRedirect(request, response, mobileDefaultTargetUrl);
        } else if (requestRedirect !=null) {
            // if there's an explicit redirect parameter it takes precedence over any saved request
            logger.debug("Redirecting to request redirection parameter: " + requestRedirect);
            getRedirectStrategy().sendRedirect(request, response, requestRedirect);
        }

        if (savedRequest != null) {
            // if saved request was an ajax call or targeting a simple asset, ignore it
            if (savedRequest.getRedirectUrl().indexOf("/api/")!=-1||
                savedRequest.getRedirectUrl().indexOf(env.get("release"))!=-1||
                savedRequest.getRedirectUrl().indexOf("static/")!=-1) {
                requestCache.removeRequest(request, response);
                getRedirectStrategy().sendRedirect(request, response, getDefaultTargetUrl());
                return;
            }
        }
        String targetUrlParameter = getTargetUrlParameter();
        if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && StringUtils.hasText(request.getParameter(targetUrlParameter)))) {
            super.onAuthenticationSuccess(request, response, authentication);
            return;
        }

        clearAuthenticationAttributes(request);

        // Use the DefaultSavedRequest URL
        String targetUrl = savedRequest.getRedirectUrl();
        logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
        getRedirectStrategy().sendRedirect(request, response, targetUrl);

    }
View Full Code Here

        if (!hasTimezoneCookie(request)|| guest ==null)
            return new ModelAndView("redirect:/welcome");
        long guestId = guest.getId();
        checkIn(request, guestId);
        final HttpSessionRequestCache requestCache = new HttpSessionRequestCache();
        SavedRequest savedRequest =
                requestCache.getRequest(request, response);
        if (savedRequest!=null) {
            final String redirectUrl = savedRequest.getRedirectUrl();
            requestCache.removeRequest(request, response);
            return new ModelAndView("redirect:" + redirectUrl);
        }
        return new ModelAndView("redirect:/app");
    }
View Full Code Here

                                      HttpServletResponse response) throws IOException, NoSuchAlgorithmException, URISyntaxException {
        final Guest guest = AuthHelper.getGuest();
        long guestId = guest.getId();
        checkIn(request, guestId);
        final HttpSessionRequestCache requestCache = new HttpSessionRequestCache();
        SavedRequest savedRequest =
                requestCache.getRequest(request, response);
        if (savedRequest!=null) {
            final String redirectUrl = savedRequest.getRedirectUrl();
            requestCache.removeRequest(request, response);
            return new ModelAndView("redirect:" + redirectUrl);
        }
        return new ModelAndView("redirect:/app");
    }
View Full Code Here

      throws IOException, NoSuchAlgorithmException {
        // always reset the target user to the logged in user when the app starts (or a browser reload happens)
        AuthHelper.as(null);
    if (!hasTimezoneCookie(request)|| AuthHelper.getGuest()==null)
      return new ModelAndView("redirect:/welcome?signIn");
        SavedRequest savedRequest =
                new HttpSessionRequestCache().getRequest(request, response);
        if (savedRequest!=null) {
            final String redirectUrl = savedRequest.getRedirectUrl();
            return new ModelAndView(redirectUrl);
        }
        return home(request, response);
    }
View Full Code Here

    private RequestCache requestCache = new HttpSessionRequestCache();

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
            Authentication authentication) throws ServletException, IOException {
        SavedRequest savedRequest = requestCache.getRequest(request, response);

        if (savedRequest == null) {
            super.onAuthenticationSuccess(request, response, authentication);

            return;
        }

        if (isAlwaysUseDefaultTargetUrl() || StringUtils.hasText(request.getParameter(getTargetUrlParameter()))) {
            requestCache.removeRequest(request, response);
            super.onAuthenticationSuccess(request, response, authentication);

            return;
        }

        // Use the DefaultSavedRequest URL
        String targetUrl = savedRequest.getRedirectUrl();
        logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
        getRedirectStrategy().sendRedirect(request, response, targetUrl);
    }
View Full Code Here

  // internal helpers
 
  private String extractOriginalUrl(NativeWebRequest request) {
    HttpServletRequest nativeReq = request.getNativeRequest(HttpServletRequest.class);
    HttpServletResponse nativeRes = request.getNativeResponse(HttpServletResponse.class);
    SavedRequest saved = requestCache.getRequest(nativeReq, nativeRes);
    if (saved == null) {
      return null;
    }
    requestCache.removeRequest(nativeReq, nativeRes);
    removeAutheticationAttributes(nativeReq.getSession(false));
    return saved.getRedirectUrl();
  }
View Full Code Here

TOP

Related Classes of org.springframework.security.web.savedrequest.SavedRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.