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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations