I am trying to work on Ajax based login system using Spring Security and it was working fine, till I got with another requirement where I need to configure authentication-success-handler, so as I can do some post processing once user is authenticated by Spring security.
Earlier I was not using for showing Login page.My Login section is a drop down and part of header section which is common for entire application.
This is how I am trying to configure Spring security
authentication-success-handler-ref="webshopAuthenticationSuccessHandler" />
logout-success-url="/customer/home.html"
logout-url="/customer/j_spring_security_logout" />
With these configuration, when ever I am clicking on login button with correct credentials, i am getting HTTP 302 error
http://localhost:8080/shop/customer/logon.html 302 found
Not sure what exactly I am doing wrong?
Login
Ajax Code
var data = $(this).serializeObject();
$.ajax({
'type': 'POST',
'url': "",
'contentType': 'application/json',
'data': JSON.stringify(data),
'dataType': 'json',
....
}}:
Login Section
Authentication authenticationToken = new UsernamePasswordAuthenticationToken(customer.getUserName(), customer.getPassword());
try {
Authentication authentication = customerAuthenticationManager.authenticate(authenticationToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
resp.setStatus(AjaxResponse.RESPONSE_STATUS_SUCCESS);
} catch (AuthenticationException ex) {
resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
}
Any inputs? With all my efforts, I am still getting 302 and with above configuration, even my logon.html controller is not getting called.
My main issue is when I am enabling Spring security using
authentication-success-handler-ref="webshopAuthenticationSuccessHandler" />
I am getting 302 from logon.html and even logon.html Controller is not being triggered (placed debugger on it)