I’m using the following method in a Spring Controller to allow authentication via Ajax. It works, but it doesn’t seem to create a cookie or anything that makes the authentication persistent.@RequestMapping(method = RequestMethod.POST)@ResponseBodypublic LoginStatus login(@RequestParam(“j_username”) String username, @RequestParam(“j_password”) String password) UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password); try Authentication auth = …
via Java Application Development Tutorial » Search Results » ajax:
Is it possible to programmatically authenticate with Spring
I’m using the following method in a Spring Controller to allow authentication via Ajax. It works, but it doesn’t seem to create a cookie or anything that makes the authentication persistent.
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public LoginStatus login(@RequestParam(“j_username”) String username,
@RequestParam(“j_password”) String password)
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
try
Authentication auth = authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(auth);
return new LoginStatus(auth.isAuthenticated(), auth.getName());
catch (BadCredentialsException e)
return new LoginStatus(false, null);
}What do I need to do to make the authentication persistent?
……………………………………………..
Make sure
you have SecurityContextPersistenceFilter configured
you are not setting create-session attribute of
For more info: Is it possible to programmatically authenticate with Spring
Java Application Development Tutorial » Search Results » ajax