Introduce support for multiple JCR repositories.
[lgpl/argeo-commons.git] / org.argeo.enterprise / src / org / argeo / osgi / useradmin / UserAdminConf.java
index b3ead140c7b5aa641418d5ec54ca204ed853f585..37d6339208486d3d5ec07b428262ac6442a826f3 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Map;
 
 import javax.naming.Context;
 import javax.naming.NamingException;
+import javax.naming.ldap.LdapName;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -43,6 +44,9 @@ public enum UserAdminConf {
        /** Read-only source */
        readOnly(null),
 
+       /** Disabled source */
+       disabled(null),
+
        /** Authentication realm */
        realm(null);
 
@@ -144,6 +148,9 @@ public enum UserAdminConf {
                        if (bDn.endsWith(".ldif"))
                                bDn = bDn.substring(0, bDn.length() - ".ldif".length());
 
+                       // Normalize base DN as LDAP name
+                       bDn = new LdapName(bDn).toString();
+
                        String principal = null;
                        String credentials = null;
                        if (scheme != null)
@@ -254,4 +261,15 @@ public enum UserAdminConf {
                        return "dc=" + hostname;
                }
        }
+
+       /**
+        * Hash the base DN in order to have a deterministic string to be used as a cn
+        * for the underlying user directory.
+        */
+       public static String baseDnHash(Dictionary<String, Object> properties) {
+               String bDn = (String) properties.get(baseDn.name());
+               if (bDn == null)
+                       throw new UserDirectoryException("No baseDn in " + properties);
+               return DigestUtils.sha1str(bDn);
+       }
 }