Results 1 to 4 of 4

Thread: What is the right way to get user's details?

  1. #1
    Join Date
    Mar 2006
    Posts
    11

    Default What is the right way to get user's details?

    Quick question: Web application. Acegi is working/user is logged in. Now I need to get some data from DB and that data is referenced by user id (which is already loaded by Acegi and kept in Authentication/UserDetails, right?)

    The question is, minding the IoC approach - what is the most correct way for a normal Spring's bean in a web application to get that user id (and, possibly, all other user's details) from Acegi?

    Thanks.
    Last edited by Aramir; Apr 2nd, 2006 at 02:24 PM.

  2. #2

    Default

    get the Authentication object out of the SecurityContextHolder like this:

    Code:
    Authentication a = SecurityContextHolder.getContext().getAuthentication();
    Then use the methods on the Authenticatin object to get the info you want.

    Cheers

    Rakesh

  3. #3
    Join Date
    Mar 2006
    Posts
    11

    Default

    Sure, that what I figured.. But that kind of means that I am coupling some dao bean with SecurityContextHolder...

    Is there any other way? Like passing user data to bean as a property via Spring's xml?

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

    Default

    If it worried you binding to Acegi Security, you could write a public static String MyApplicationSecurityIntegration.getUsername() which in its basic implementation would just delegate to SecurityContextHolder. Then you're binding to your own static method, and not Acegi Security.
    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
  •