Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: How do I move part of the set-up in the applicationContext.xml to Java code?

  1. #11
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Yeah your right sorry about that. The principal has the UserDetails. That will teach me for trying to work at the same time as doing something else :-).

  2. #12
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    The DN is a String, so details.getDn() probably isn't what you want. Just the UserDetails object.

  3. #13
    Join Date
    Aug 2006
    Location
    Omaha, NE
    Posts
    37

    Question

    Everything is moving along smooth now, I appreciate everyone's help...

    Staying on topic, I have the following:

    Code:
    Authentication userAuth = SecurityContextHolder.getContext().getAuthentication();
            LdapUserDetails details = (LdapUserDetails) userAuth.getPrincipal();
            this.setUserDetails(details.getAttributes().toString());
    Which outputs the the details of my LDAP User's object - that is what I want.

    Now, from that point - how do I get a specific LDAP attribute from this point?

    For example, I just want to get the values for the memberOf attribute, such as:

    memberOf: CN=Users,OU=exchange dist groups,OU=company Groups,DC=company,DC=com,
    CN=VPN Users,OU=company Groups,DC=company,DC=com


    Since I have a Principle object, the Authentication interface doesn't have a method to get a attribute by ID or name?

    Thanks,
    --Todd

  4. #14

    Default

    Hi!

    The method getAttributes() on a UserDetails object delivers a collection, if I am not wrong.

    See here:
    http://www.acegisecurity.org/multipr...tailsImpl.html

    and here:
    http://java.sun.com/j2se/1.5.0/docs/...ttributes.html

    From the Attributes object you should retrieve all values you need (with get(<attrID>)). As I told before, I am not familiar with Ldap, but this is how I see it from the docs and sources.


    Best regards,

    Danny

  5. #15
    Join Date
    Aug 2006
    Location
    Omaha, NE
    Posts
    37

    Default

    Thanks Danny, I missed that.

    The following is what I needed:

    Code:
    Authentication userAuth = SecurityContextHolder.getContext().getAuthentication();
                LdapUserDetails details = (LdapUserDetails) userAuth.getPrincipal();
                Attributes attributes = details.getAttributes();
                Attribute attr = attributes.get("memberOf");
                String memberOf = String.valueOf(attr.get());
    --Todd

Posting Permissions

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