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