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 :-).
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 :-).
The DN is a String, so details.getDn() probably isn't what you want. Just the UserDetails object.
Everything is moving along smooth now, I appreciate everyone's help...
Staying on topic, I have the following:
Which outputs the the details of my LDAP User's object - that is what I want.Code:Authentication userAuth = SecurityContextHolder.getContext().getAuthentication(); LdapUserDetails details = (LdapUserDetails) userAuth.getPrincipal(); this.setUserDetails(details.getAttributes().toString());
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
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
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