-
Dec 5th, 2011, 05:21 AM
#1
spring security 3.1 + legacy servlets + ajax login
Hello,
As I'm adding spring security 3.1 to legacy servlets, and would avoid mixing legacy servlets and spring controllers, I need to rewrite this controller as a servlet :
@Controller
@RequestMapping("/login")
public class AjaxLoginController {
@Autowired
@Qualifier("authenticationManager")
AuthenticationManager authenticationManager;
@Autowired
SecurityContextRepository repository;
@Autowired
RememberMeServices rememberMeServices;
@RequestMapping(method=RequestMethod.GET)
public void login() {}
@RequestMapping(method=RequestMethod.POST)
@ResponseBody
public String performLogin(
@RequestParam("j_username") String username,
@RequestParam("j_password") String password,
HttpServletRequest request, HttpServletResponse response)
{
UsernamePasswordAuthenticationToken token =
new UsernamePasswordAuthenticationToken(username, password);
try {
Authentication auth = authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthenticati on(auth);
repository.saveContext(SecurityContextHolder.getCo ntext(), request, response);
rememberMeServices.loginSuccess(request, response, auth);
return "{\"status\": true}";
} catch (BadCredentialsException ex) {
return "{\"status\": false, \"error\": \"Bad Credentials\"}";
}
}
}
(example from http://kb.vmware.com/selfservice/mic...alId= 2002229 )
I can access the AuthenticationManager with : AuthenticationManager authenticationManager=(AuthenticationManager)WebAp plicationContextUtils.getWebApplicationContext(get ServletContext()).getBean("authenticationManager") ;
How to get the reference to SecurityContextRepository ?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules