import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.InvalidNameException;
+import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
+ name);
return res;
} catch (NamingException e) {
- throw new UserDirectoryException("Cannot get role for " + name, e);
+ return null;
}
}
searchBase, searchFilter, searchControls);
ArrayList<DirectoryUser> res = new ArrayList<DirectoryUser>();
- while (results.hasMoreElements()) {
+ results: while (results.hasMoreElements()) {
SearchResult searchResult = results.next();
Attributes attrs = searchResult.getAttributes();
+ Attribute objectClassAttr = attrs.get(objectClass.name());
LdapName dn = toDn(searchBase, searchResult);
LdifUser role;
- if (attrs.get(objectClass.name()).contains(
- getGroupObjectClass()))
+ if (objectClassAttr.contains(getGroupObjectClass()))
role = new LdifGroup(this, dn, attrs);
- else if (attrs.get(objectClass.name()).contains(
- getUserObjectClass()))
+ else if (objectClassAttr.contains(getUserObjectClass()))
role = new LdifUser(this, dn, attrs);
- else
- throw new UserDirectoryException(
- "Unsupported LDAP type for "
- + searchResult.getName());
+ else {
+ log.warn("Unsupported LDAP type for "
+ + searchResult.getName());
+ continue results;
+ }
res.add(role);
}
return res;
}
// add
for (LdapName dn : wc.getNewUsers().keySet()) {
- if (!entryExists(dn))
+ if (entryExists(dn))
throw new UserDirectoryException("User to create found "
+ dn);
}
// modify
for (LdapName dn : wc.getModifiedUsers().keySet()) {
if (!entryExists(dn))
- throw new UserDirectoryException("User to modify no found "
+ throw new UserDirectoryException("User to modify not found "
+ dn);
}
} catch (NamingException e) {
}
private boolean entryExists(LdapName dn) throws NamingException {
- return getLdapContext().getAttributes(dn).size() != 0;
+ try {
+ return getLdapContext().getAttributes(dn).size() != 0;
+ } catch (NameNotFoundException e) {
+ return false;
+ }
}
@Override