]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/internal/auth/CmsUserManagerImpl.java
Improve naming. Fix Argeo namespace base.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / auth / CmsUserManagerImpl.java
index 782487a9ad7b083275e3db8d65810f750d0fbdcd..6e2c6c435df469d5256ab27f4b3472710e2187e7 100644 (file)
@@ -16,7 +16,10 @@ import java.util.Hashtable;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.NavigableMap;
 import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
 import java.util.UUID;
 
 import javax.naming.InvalidNameException;
@@ -28,13 +31,13 @@ import org.argeo.api.cms.CmsLog;
 import org.argeo.cms.CmsUserManager;
 import org.argeo.cms.auth.CurrentUser;
 import org.argeo.cms.auth.UserAdminUtils;
-import org.argeo.osgi.transaction.WorkTransaction;
 import org.argeo.osgi.useradmin.TokenUtils;
-import org.argeo.osgi.useradmin.UserAdminConf;
 import org.argeo.osgi.useradmin.UserDirectory;
+import org.argeo.util.directory.DirectoryConf;
+import org.argeo.util.directory.ldap.SharedSecret;
 import org.argeo.util.naming.LdapAttrs;
 import org.argeo.util.naming.NamingUtils;
-import org.argeo.util.naming.SharedSecret;
+import org.argeo.util.transaction.WorkTransaction;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.useradmin.Authorization;
 import org.osgi.service.useradmin.Group;
@@ -229,7 +232,7 @@ public class CmsUserManagerImpl implements CmsUserManager {
                Map<String, String> dns = new HashMap<String, String>();
                for (UserDirectory userDirectory : userDirectories.keySet()) {
                        Boolean readOnly = userDirectory.isReadOnly();
-                       String baseDn = userDirectory.getBasePath();
+                       String baseDn = userDirectory.getContext();
 
                        if (onlyWritable && readOnly)
                                continue;
@@ -237,20 +240,26 @@ public class CmsUserManagerImpl implements CmsUserManager {
                                continue;
                        if (baseDn.equalsIgnoreCase(CmsConstants.TOKENS_BASEDN))
                                continue;
-                       dns.put(baseDn, UserAdminConf.propertiesAsUri(userDirectories.get(userDirectory)).toString());
+                       dns.put(baseDn, DirectoryConf.propertiesAsUri(userDirectories.get(userDirectory)).toString());
 
                }
                return dns;
        }
 
+       public Set<UserDirectory> getUserDirectories() {
+               TreeSet<UserDirectory> res = new TreeSet<>((o1, o2) -> o1.getContext().compareTo(o2.getContext()));
+               res.addAll(userDirectories.keySet());
+               return res;
+       }
+
        public String buildDistinguishedName(String localId, String baseDn, int type) {
                Map<String, String> dns = getKnownBaseDns(true);
-               Dictionary<String, ?> props = UserAdminConf.uriAsProperties(dns.get(baseDn));
+               Dictionary<String, ?> props = DirectoryConf.uriAsProperties(dns.get(baseDn));
                String dn = null;
                if (Role.GROUP == type)
-                       dn = LdapAttrs.cn.name() + "=" + localId + "," + UserAdminConf.groupBase.getValue(props) + "," + baseDn;
+                       dn = LdapAttrs.cn.name() + "=" + localId + "," + DirectoryConf.groupBase.getValue(props) + "," + baseDn;
                else if (Role.USER == type)
-                       dn = LdapAttrs.uid.name() + "=" + localId + "," + UserAdminConf.userBase.getValue(props) + "," + baseDn;
+                       dn = LdapAttrs.uid.name() + "=" + localId + "," + DirectoryConf.userBase.getValue(props) + "," + baseDn;
                else
                        throw new IllegalStateException("Unknown role type. " + "Cannot deduce dn for " + localId);
                return dn;
@@ -431,6 +440,20 @@ public class CmsUserManagerImpl implements CmsUserManager {
                }
        }
 
+       @Override
+       public UserDirectory getDirectory(Role user) {
+               String name = user.getName();
+               NavigableMap<String, UserDirectory> possible = new TreeMap<>();
+               for (UserDirectory userDirectory : userDirectories.keySet()) {
+                       if (name.endsWith(userDirectory.getContext())) {
+                               possible.put(userDirectory.getContext(), userDirectory);
+                       }
+               }
+               if (possible.size() == 0)
+                       throw new IllegalStateException("No user directory found for user " + name);
+               return possible.lastEntry().getValue();
+       }
+
 //     public User createUserFromPerson(Node person) {
 //             String email = JcrUtils.get(person, LdapAttrs.mail.property());
 //             String dn = buildDefaultDN(email, Role.USER);