private AppleDeviceUserRepository appleDeviceUserRepository;
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws ServletException, IOException {
SavedRequest savedRequest = requestCache.getRequest(request, response);
manageAppleDevice(authentication.getName(), request.getParameter("device_token"));
if (savedRequest == null) {
super.onAuthenticationSuccess(request, response, authentication);
return;
}
if (savedRequest.getHeaderNames().contains("X-Requested-With") &&
"XMLHttpRequest".equals(savedRequest.getHeaderValues("X-Requested-With").get(0))) {
requestCache.removeRequest(request, response);
clearAuthenticationAttributes(request);
response.sendRedirect(getDefaultTargetUrl());
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();
getRedirectStrategy().sendRedirect(request, response, targetUrl);
}