authentication - Spring security : auto login issue -
i trying auto login user after signup. here code auto login
private boolean autologin(httpservletrequest request, user user) { simplegrantedauthority auth = new simplegrantedauthority("admin"); collection<simplegrantedauthority> authorities = new hashset<simplegrantedauthority>(); authorities.add(auth); usernamepasswordauthenticationtoken token = new usernamepasswordauthenticationtoken( user.getemail(), user.getpassword(), authorities); token.setdetails(new webauthenticationdetails(request)); authenticationmanager.authenticate(token); securitycontextholder.getcontext().setauthentication(token); return true; }
and inside interceptor check logged in user code is
object principal = securitycontextholder.getcontext().getauthentication().getprincipal();
problem when debug code (after auto login) principal object has logged in user's email address instead of userdetails object.
things working fine when log in useing spring security login form.
you're missing re-assigning return authenticationmanager.authenticate()
.
this line:
authenticationmanager.authenticate(token);
should be:
token = authenticationmanager.authenticate(token);
that should fix things.
Comments
Post a Comment