AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("cn", user));
//find DN of user
AttributesMapper mapper =
new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs) throws NamingException {
return attrs.get("distinguishedName").get();
}
};
@SuppressWarnings("rawtypes")
List users =
ldap.search(
"OU=users,DC=emea,DC=mycompany,DC=com",
filter.toString(),
SearchControls.SUBTREE_SCOPE,
mapper
);
Assert.isTrue(users.size() == 1, "Only one user expected");
dn = (String)users.get(0);
// get attributes
AttributesMapper mapper2 =
new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs) throws NamingException {
Map<String, String> map = new HashMap<String, String>();
NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll();
while (attrEnum.hasMore()) {
Attribute att = attrEnum.next();