Announcement Announcement Module
No announcement yet.
spring security 3.1 + legacy servlets + ajax login Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring security 3.1 + legacy servlets + ajax login


    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 :

    public class AjaxLoginController {
    AuthenticationManager authenticationManager;

    SecurityContextRepository repository;

    RememberMeServices rememberMeServices;

    public void login() {}

    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 )

    I can access the AuthenticationManager with : AuthenticationManager authenticationManager=(AuthenticationManager)WebAp plicationContextUtils.getWebApplicationContext(get ServletContext()).getBean("authenticationManager") ;

    How to get the reference to SecurityContextRepository ?