Announcement Announcement Module
Collapse
No announcement yet.
How to get UserDetails from SecurityContextHolder? Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get UserDetails from SecurityContextHolder?

    Hi,

    i have my own implementation of UserDetails for authentication and authorization with Acegi.
    This works fine.
    my Problem is, that if the User authenticates i think there should be a UserDetails Object in the SecurityContextHolder, is this rigth? but how can i get this object? i need this for getting my own informations from the user.

    Thanks.

    ys Gideon

  • #2
    Hi

    the following snippet should solve your problem:

    import org.acegisecurity.context.SecurityContextHolder;
    ..........

    SecurityContext ctx = SecurityContextHolder.getContext();

    ctx.getAuthentication().getPrincipal should return your currently logged in user, and should be typecasted to a UserDetails object. Some information you may need are also available in the Authentication object.

    The code snippet is taken from appfuse. You may want to consider downloading and installing appfuse, for easy-answer to this kind of problems.
    Last edited by johnny_crash; May 18th, 2006, 01:40 PM.

    Comment


    • #3
      Hi,

      thanks this code works fine for me, its all what i need.

      now i only have to solve the lazy loading Problem only for the UserDetails

      ys Gideon

      Comment


      • #4
        Hi

        If you would be more specific, you would probably receive someone's help. Give us more details

        Comment

        Working...
        X