
Originally Posted by
alois.cochard
Thanks!
I have downloaded your sample code.It works,but exception also been thrown.
about Ajax login and Spring security:
I think the main problem is that XHR is different from User-Agent(FireFox IE etc ).
Spring Security works good with standard html form login(data sent by User-Agent) ,how to make it work with Ajax login?(data sent by XHR) we need to change something.(1) use standard form login even you are going to develop a Ajax App(2)Change some class in Spring Security.
I change AbstractProcessingFilter's successfulAuthentication method like this :
PHP Code:
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException, ServletException {
if (logger.isDebugEnabled()) {
logger.debug("Authentication success: " + authResult.toString());
}
SecurityContextHolder.getContext().setAuthentication(authResult);
if (logger.isDebugEnabled()) {
logger.debug("Updated SecurityContextHolder to contain the following Authentication: '" + authResult + "'");
}
if (invalidateSessionOnSuccessfulAuthentication) {
SessionUtils.startNewSessionIfRequired(request, migrateInvalidatedSessionAttributes, sessionRegistry);
}
String targetUrl = determineTargetUrl(request);
if (logger.isDebugEnabled()) {
logger.debug("Redirecting to target URL from HTTP Session (or default): " + targetUrl);
}
onSuccessfulAuthentication(request, response, authResult);
rememberMeServices.loginSuccess(request, response, authResult);
if (this.eventPublisher != null) {
eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass()));
}
response.getWriter().print("{success:true, targetUrl : \'" + determineTargetUrl( request ) + "\'}");
}
let client code to redirect, do not use serverside redirect any more.
-------------------------
Sorry for My poor English