Results 1 to 6 of 6

Thread: Acegi, UserDetails

  1. #1
    Join Date
    Aug 2004
    Location
    Allentown, PA
    Posts
    141

    Default Acegi, UserDetails

    I have created a custom UserDetails implementation that contains my existing User object, as well as the user name, pass, ect. Is there any way that I can access that object using jstl <c:out ... />. ie. I would like to put a welcome message in the header of each page, the info is stored in the UserDetailsImpl.

    Thanks,
    Dan

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

    Default

    You can access it via:

    ((SecureContext) ContextHolder.getContext()).getAuthentication().ge tPrincipal()

    The getPrincipal() returns an Object. If you are running DaoAuthenticationProvider with forcePrincipalAsString = false (the default) you will be able to cast that Object to UserDetails. If you've set this property to true, it will be a String representation of the username.

  3. #3
    Join Date
    Aug 2004
    Location
    Allentown, PA
    Posts
    141

    Default

    Ben,

    That is how I am accessing it from my controller. That is fine, but I was looking for a way to access the context from, for instance, a header file that gets included in every request. It is not a problem if that can't be done. I already created a filter that will add that to the request when the SecureContext exists, this way it is available to every request.

    Dan

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

    Default

    Hi Dan

    Your approach would work as a general-purpose solution. Alternatively, you can always read it directly from the HttpSession attribute keyed against net.sf.acegisecurity.ui.webapp.HttpSessionIntegrat ionFilter.ACEGI_SECURITY_AUTHENTICATION_KEY if you're using the default HttpSession-based storage of the user credentials.

    Generally it's a view-specific issue to expose the Authentication more easily. You could add it to the Model returned by your controller. Or use a taglib like net.sf.acegisecurity.taglibs.authz.AuthorizeTag. Or (as we do with FreeMarer) extend FreeMarkerView and add it in the protected void exposeHelpers(Map, HttpServletRequest) method so it's accessible to a FreeMarker macro.

  5. #5
    Join Date
    Aug 2004
    Location
    Allentown, PA
    Posts
    141

    Default

    Ben,

    Thanks for you input. I think for right now, the filter will work fine. I am limiting what type of session attibutes the view can access, and I don't want to make every call the controller returns have to check for that info in the request. The filter seems like a viable solution.

    Thanks again.
    Dan

  6. #6
    Join Date
    Sep 2004
    Location
    Portland, OR
    Posts
    54

    Default

    Although probably not recommended:

    Code:
    <c&#58;out value="$&#123;sessionScope&#91;'ACEGI_SECURITY_AUTHENTICATION'&#93;.principal.username&#125;"/>
    This worked for me.

Similar Threads

  1. Replies: 8
    Last Post: Mar 19th, 2008, 11:13 AM
  2. Acegi running fine. Howto add roles, ...
    By ThomasBecker in forum Security
    Replies: 9
    Last Post: Sep 16th, 2007, 08:16 AM
  3. Replies: 3
    Last Post: Oct 8th, 2005, 04:05 AM
  4. Acegi for LDAP
    By vaibhav.gandhi in forum Security
    Replies: 12
    Last Post: Jul 13th, 2005, 12:33 AM
  5. Replies: 4
    Last Post: Nov 2nd, 2004, 02:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •