]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.security.core/src/org/argeo/osgi/useradmin/LdapUserAdmin.java
Fix glitches while testing the Security Perspective with LDAP backend
[lgpl/argeo-commons.git] / org.argeo.security.core / src / org / argeo / osgi / useradmin / LdapUserAdmin.java
index 73dc510eccae80b2a1702564f518aecee8a5242c..22d9a54227b383d629f13e6be760731bd01b972d 100644 (file)
@@ -10,6 +10,7 @@ import java.util.List;
 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;
@@ -106,7 +107,7 @@ public class LdapUserAdmin extends AbstractUserDirectory {
                                                + name);
                        return res;
                } catch (NamingException e) {
-                       throw new UserDirectoryException("Cannot get role for " + name, e);
+                       return null;
                }
        }
 
@@ -193,14 +194,14 @@ public class LdapUserAdmin extends AbstractUserDirectory {
                        }
                        // 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) {
@@ -209,7 +210,11 @@ public class LdapUserAdmin extends AbstractUserDirectory {
        }
 
        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