Search in sources :

Example 1 with SavedRequest

use of org.springframework.security.web.savedrequest.SavedRequest in project ORCID-Source by ORCID.

the class LocaleChangeInterceptor method preHandle.

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
    String newLocale = request.getParameter(this.paramName);
    if (newLocale == null) {
        SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
        if (savedRequest != null) {
            String url = savedRequest.getRedirectUrl();
            Matcher matcher = langPattern.matcher(url);
            if (matcher.find()) {
                newLocale = matcher.group(2);
            }
        }
    }
    if (newLocale != null) {
        LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
        if (localeResolver == null) {
            throw new IllegalStateException("No LocaleResolver found: not in a DispatcherServlet request?");
        }
        try {
            localeResolver.setLocale(request, response, StringUtils.parseLocaleString(newLocale));
        } catch (Exception e) {
        /* 
                             * Ignore exceptions from invalid locales as it will cause a 500 error and
                             * continue with the last valid locale set.
                             */
        }
    }
    // Proceed in any case.
    return true;
}
Also used : LocaleResolver(org.springframework.web.servlet.LocaleResolver) Matcher(java.util.regex.Matcher) HttpSessionRequestCache(org.springframework.security.web.savedrequest.HttpSessionRequestCache) ServletException(javax.servlet.ServletException) SavedRequest(org.springframework.security.web.savedrequest.SavedRequest)

Example 2 with SavedRequest

use of org.springframework.security.web.savedrequest.SavedRequest in project ORCID-Source by ORCID.

the class RegistrationController method register.

@RequestMapping(value = "/register", method = RequestMethod.GET)
public ModelAndView register(HttpServletRequest request, HttpServletResponse response) {
    ModelAndView mav = new ModelAndView("register");
    SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
    LOGGER.debug("Saved url before registration is: " + (savedRequest != null ? savedRequest.getRedirectUrl() : " no saved request"));
    return mav;
}
Also used : HttpSessionRequestCache(org.springframework.security.web.savedrequest.HttpSessionRequestCache) ModelAndView(org.springframework.web.servlet.ModelAndView) SavedRequest(org.springframework.security.web.savedrequest.SavedRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with SavedRequest

use of org.springframework.security.web.savedrequest.SavedRequest in project ORCID-Source by ORCID.

the class OrcidUrlManager method determineFullTargetUrlFromSavedRequest.

public String determineFullTargetUrlFromSavedRequest(HttpServletRequest request, HttpServletResponse response) {
    SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
    String url = null;
    if (savedRequest != null) {
        url = savedRequest.getRedirectUrl();
        if (url != null) {
            String contextPath = request.getContextPath();
            // run behind nginx.
            if (getBasePath().equals("/") && !contextPath.equals("/"))
                url = url.replaceFirst(contextPath.replace("/", "\\/"), "");
            // example.
            if (!SAVED_REQUEST_PATTERN.matcher(url).find()) {
                url = null;
            }
        }
    }
    return url;
}
Also used : HttpSessionRequestCache(org.springframework.security.web.savedrequest.HttpSessionRequestCache) SavedRequest(org.springframework.security.web.savedrequest.SavedRequest)

Example 4 with SavedRequest

use of org.springframework.security.web.savedrequest.SavedRequest in project nikita-noark5-core by HiOA-ABI.

the class NikitaAuthenticationSuccessHandler method onAuthenticationSuccess.

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
    SavedRequest savedRequest = requestCache.getRequest(request, response);
    if (savedRequest == null) {
        clearAuthenticationAttributes(request);
        return;
    }
    String targetUrlParam = getTargetUrlParameter();
    if (isAlwaysUseDefaultTargetUrl() || (targetUrlParam != null && StringUtils.hasText(request.getParameter(targetUrlParam)))) {
        requestCache.removeRequest(request, response);
        clearAuthenticationAttributes(request);
        return;
    }
    clearAuthenticationAttributes(request);
}
Also used : SavedRequest(org.springframework.security.web.savedrequest.SavedRequest)

Example 5 with SavedRequest

use of org.springframework.security.web.savedrequest.SavedRequest in project tutorials by eugenp.

the class MySavedRequestAwareAuthenticationSuccessHandler method onAuthenticationSuccess.

@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;
    }
    final String targetUrlParameter = getTargetUrlParameter();
    if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && StringUtils.hasText(request.getParameter(targetUrlParameter)))) {
        requestCache.removeRequest(request, response);
        clearAuthenticationAttributes(request);
        return;
    }
    clearAuthenticationAttributes(request);
// Use the DefaultSavedRequest URL
// final String targetUrl = savedRequest.getRedirectUrl();
// logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
// getRedirectStrategy().sendRedirect(request, response, targetUrl);
}
Also used : SavedRequest(org.springframework.security.web.savedrequest.SavedRequest)

Aggregations

SavedRequest (org.springframework.security.web.savedrequest.SavedRequest)27 HttpSessionRequestCache (org.springframework.security.web.savedrequest.HttpSessionRequestCache)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 HttpSession (javax.servlet.http.HttpSession)4 Test (org.junit.jupiter.api.Test)4 Authentication (org.springframework.security.core.Authentication)4 Test (org.junit.Test)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 DefaultSavedRequest (org.springframework.security.web.savedrequest.DefaultSavedRequest)3 RedirectView (org.springframework.web.servlet.view.RedirectView)3 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)2 MockHttpServletRequest (com.thoughtworks.go.http.mocks.MockHttpServletRequest)2 MockHttpServletResponse (com.thoughtworks.go.http.mocks.MockHttpServletResponse)2 RequestInfoForm (org.orcid.pojo.ajaxForm.RequestInfoForm)2 AuthenticationException (org.springframework.security.core.AuthenticationException)2 RequestCache (org.springframework.security.web.savedrequest.RequestCache)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ModuleAuthentication (com.evolveum.midpoint.authentication.api.config.ModuleAuthentication)1 ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl)1