Announcement Announcement Module
Collapse
No announcement yet.
how to get authenticated user information in Struts action 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 authenticated user information in Struts action

    hi,
    i am using Acegi 0.8.1 and Struts 1.2, is it correct to get the authenticated user information in this way:

    String username = session.getAttribute("ACEGI_SECURITY_LAST_USERNAME ");

    how abt roles ? using attribute ACEGI_SECURITY_CONTEXT for both username and authorities ?

    thanks !
    li xin

  • #2
    If you're using the standard SecureContext configuration you can use the SecureContextUtils to find out all about the current user....

    Code:
            Authentication auth = SecureContextUtils.getSecureContext().getAuthentication();
            String username = auth.getPrincipal().toString();
            GrantedAuthority[] authorities = auth.getAuthorities();
    Or, as you yourself have said, you can get the context from...
    Code:
    SecureContext contextObject = (SecureContext) httpSession.getAttribute(ACEGI_SECURITY_CONTEXT_KEY);

    Comment


    • #3
      Thanks !

      Comment


      • #4
        Best practice is definitely using ContextHolder directly, as in some situations (eg BASIC authentication) the HttpSession might not even be used at all. ContextHolder will always be there, though.

        Comment

        Working...
        X