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

  • 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...rnalId=2002229 )

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

    How to get the reference to SecurityContextRepository ?
Working...
X