login with ajax,Login with Spring security using Ajax

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值