Announcement Announcement Module
Collapse
No announcement yet.
What is the right way to get user's details? Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 02:24 PM.

  • #2
    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

    Comment


    • #3
      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?

      Comment


      • #4
        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.

        Comment

        Working...
        X