Results 1 to 3 of 3

Thread: Newbie: Autologin

  1. #1
    Join Date
    Feb 2005
    Posts
    7

    Default 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. #2
    Join Date
    Jul 2005
    Posts
    5

    Default

    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.

  3. #3
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    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.
    Ben Alex
    Project Founder, Spring UAA, Spring Roo and Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •