Announcement Announcement Module
Collapse
No announcement yet.
Newbie: Autologin Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie: Autologin

    All:

    I'm using Acegi 0.7.0 (older project and no time to upgrade) and I need to automatically log in a user after he registers. I'm trying the code below, but it's not working. Am I even on the right track? I don't receive any errors. Logging in using the form method works fine. Any assistance is appreciated.

    Code:
    			Authentication auth = new UsernamePasswordAuthenticationToken(user.getUsername(),user.getPassword(),new GrantedAuthority[]{});
    			SecureContext acontext = (SecureContext)ContextHolder.getContext();
    			if (acontext == null) {
    				acontext = new SecureContextImpl();
    			}
    			ContextHolder.setContext(acontext);
    			auth.setAuthenticated(true);
    			acontext.setAuthentication(auth);

  • #2
    damon311, you should use something like this:
    Code:
    Authentication result = authenticationManager.authenticate(auth);
    instead of
    Code:
    auth.setAuthenticated(true);
    See http://acegisecurity.org/docbook/ace...cation-manager for details.

    Comment


    • #3
      Whatever you do, don't deploy 0.7.0 into production, as it has a bug to do with ThreadLocal clearing. Please upgrade, even if it's to the last of the 0.7.x series which fixes this particulr issue.

      Comment

      Working...
      X