]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifUserAdmin.java
Improve user directory
[lgpl/argeo-commons.git] / org.argeo.enterprise / src / org / argeo / osgi / useradmin / LdifUserAdmin.java
index 521ae8bb6e89916c6b88ea490767658e8b3012fa..aab96dd7ad4cf7c319e34da4fe1c15a9517c003e 100644 (file)
@@ -1,13 +1,14 @@
 package org.argeo.osgi.useradmin;
 
-import static org.argeo.osgi.useradmin.LdifName.inetOrgPerson;
-import static org.argeo.osgi.useradmin.LdifName.objectClass;
+import static org.argeo.naming.LdapAttrs.objectClass;
+import static org.argeo.naming.LdapObjs.inetOrgPerson;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.HashSet;
@@ -17,15 +18,17 @@ import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingEnumeration;
 import javax.naming.directory.Attributes;
 import javax.naming.ldap.LdapName;
 import javax.transaction.TransactionManager;
 
-import org.argeo.util.naming.LdifParser;
-import org.argeo.util.naming.LdifWriter;
+import org.argeo.naming.LdifParser;
+import org.argeo.naming.LdifWriter;
 import org.osgi.framework.Filter;
 import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
 
 /**
  * A user admin based on a LDIF files. Requires a {@link TransactionManager} and
@@ -40,14 +43,26 @@ public class LdifUserAdmin extends AbstractUserDirectory {
        }
 
        public LdifUserAdmin(Dictionary<String, ?> properties) {
-               super(properties);
+               super(null, properties);
        }
 
+       public LdifUserAdmin(URI uri, Dictionary<String, ?> properties) {
+               super(uri, properties);
+       }
+
+       @Deprecated
        public LdifUserAdmin(InputStream in) {
-               super(new Hashtable<String, Object>());
+               super(null, new Hashtable<String, Object>());
                load(in);
        }
 
+       @Override
+       protected AbstractUserDirectory scope(User user) {
+               Dictionary<String, Object> properties = cloneProperties();
+               properties.put(UserAdminConf.readOnly.name(), "true");
+               return new LdifUserAdmin(properties);
+       }
+
        private static Dictionary<String, Object> fromUri(String uri, String baseDn) {
                Hashtable<String, Object> res = new Hashtable<String, Object>();
                res.put(UserAdminConf.uri.name(), uri);
@@ -140,14 +155,16 @@ public class LdifUserAdmin extends AbstractUserDirectory {
                groups = null;
        }
 
-       protected DirectoryUser daoGetRole(LdapName key) {
+       @Override
+       protected DirectoryUser daoGetRole(LdapName key) throws NameNotFoundException {
                if (groups.containsKey(key))
                        return groups.get(key);
                if (users.containsKey(key))
                        return users.get(key);
-               return null;
+               throw new NameNotFoundException(key + " not persisted");
        }
 
+       @Override
        protected Boolean daoHasRole(LdapName dn) {
                return users.containsKey(dn) || groups.containsKey(dn);
        }