Results 1 to 2 of 2

Thread: PreAuthenticationProcessingFilter unique issue

  1. #1
    Join Date
    Aug 2011
    Posts
    2

    Default PreAuthenticationProcessingFilter unique issue

    Hello all,
    I have implemented the remember me (persistence token based) service and that i working fine along with UsernamePasswordAuthenticationFilter. However, after a user logs in, if the user is an administrator, he/she should be able to log in as someone else just by providing JUST the username. The application should behave as if the original user has signed in. I think PreAuthenticationFilter would suffice my needs, just a theory. Any help is appreciated.

  2. #2
    Join Date
    Aug 2011
    Posts
    2

    Default

    Posting the solution just in case if anyone is facing the same issue:
    Create new PreAuthenticatedAuthenticationToken token

    here's the code:

    Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    GrantedAuthority g1 = new GrantedAuthorityImpl("SOMEROLE_SOMEUSER");
    authorities.add(g1);

    PreAuthenticatedAuthenticationToken authentication =
    new PreAuthenticatedAuthenticationToken("userid", "",authorities);

    authentication.setAuthenticated(true);

    SecurityContextHolder.getContext().setAuthenticati on(authentication);
    request.getSession().setAttribute("SPRING_SECURITY _LAST_USERNAME", "userid");

    rememberMeServices.loginSuccess(request, response, authentication);
    customAuthenticationSuccessHandler.onAuthenticatio nSuccess(request, response, authentication);

    - that's it....

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
  •