X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.util%2Fsrc%2Forg%2Fargeo%2Futil%2Fdirectory%2Fldap%2FAbstractLdapDirectory.java;h=9c35e4660797a252a98505d701f711f4a709e4e6;hb=d26a4ba8f367608590167fb4a866f1f0202ad1aa;hp=d8e8e7d2127a27de54c2aa0906021c6bc6a585ee;hpb=dc27b57704278684e72efcaf72b01c5b91df39f8;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.util/src/org/argeo/util/directory/ldap/AbstractLdapDirectory.java b/org.argeo.util/src/org/argeo/util/directory/ldap/AbstractLdapDirectory.java index d8e8e7d21..9c35e4660 100644 --- a/org.argeo.util/src/org/argeo/util/directory/ldap/AbstractLdapDirectory.java +++ b/org.argeo.util/src/org/argeo/util/directory/ldap/AbstractLdapDirectory.java @@ -38,7 +38,7 @@ public abstract class AbstractLdapDirectory implements Directory, XAResourceProv protected static final String SHARED_STATE_PASSWORD = "javax.security.auth.login.password"; protected final LdapName baseDn; - protected final Hashtable properties; + protected final Hashtable configProperties; private final Rdn userBaseRdn, groupBaseRdn, systemRoleBaseRdn; private final String userObjectClass, groupObjectClass; private String memberAttributeId = "member"; @@ -60,33 +60,33 @@ public abstract class AbstractLdapDirectory implements Directory, XAResourceProv private LdapDirectoryDao directoryDao; public AbstractLdapDirectory(URI uriArg, Dictionary props, boolean scoped) { - this.properties = new Hashtable(); + this.configProperties = new Hashtable(); for (Enumeration keys = props.keys(); keys.hasMoreElements();) { String key = keys.nextElement(); - properties.put(key, props.get(key)); + configProperties.put(key, props.get(key)); } - baseDn = toLdapName(DirectoryConf.baseDn.getValue(properties)); + baseDn = toLdapName(DirectoryConf.baseDn.getValue(configProperties)); this.scoped = scoped; if (uriArg != null) { uri = uriArg.toString(); // uri from properties is ignored } else { - String uriStr = DirectoryConf.uri.getValue(properties); + String uriStr = DirectoryConf.uri.getValue(configProperties); if (uriStr == null) uri = null; else uri = uriStr; } - forcedPassword = DirectoryConf.forcedPassword.getValue(properties); + forcedPassword = DirectoryConf.forcedPassword.getValue(configProperties); - userObjectClass = DirectoryConf.userObjectClass.getValue(properties); - groupObjectClass = DirectoryConf.groupObjectClass.getValue(properties); + userObjectClass = DirectoryConf.userObjectClass.getValue(configProperties); + groupObjectClass = DirectoryConf.groupObjectClass.getValue(configProperties); - String userBase = DirectoryConf.userBase.getValue(properties); - String groupBase = DirectoryConf.groupBase.getValue(properties); - String systemRoleBase = DirectoryConf.systemRoleBase.getValue(properties); + String userBase = DirectoryConf.userBase.getValue(configProperties); + String groupBase = DirectoryConf.groupBase.getValue(configProperties); + String systemRoleBase = DirectoryConf.systemRoleBase.getValue(configProperties); try { // baseDn = new LdapName(UserAdminConf.baseDn.getValue(properties)); userBaseRdn = new Rdn(userBase); @@ -95,36 +95,40 @@ public abstract class AbstractLdapDirectory implements Directory, XAResourceProv // groupBaseDn = new LdapName(groupBase + "," + baseDn); systemRoleBaseRdn = new Rdn(systemRoleBase); } catch (InvalidNameException e) { - throw new IllegalArgumentException("Badly formated base DN " + DirectoryConf.baseDn.getValue(properties), - e); + throw new IllegalArgumentException( + "Badly formated base DN " + DirectoryConf.baseDn.getValue(configProperties), e); } // read only - String readOnlyStr = DirectoryConf.readOnly.getValue(properties); + String readOnlyStr = DirectoryConf.readOnly.getValue(configProperties); if (readOnlyStr == null) { readOnly = readOnlyDefault(uri); - properties.put(DirectoryConf.readOnly.name(), Boolean.toString(readOnly)); + configProperties.put(DirectoryConf.readOnly.name(), Boolean.toString(readOnly)); } else readOnly = Boolean.parseBoolean(readOnlyStr); // disabled - String disabledStr = DirectoryConf.disabled.getValue(properties); + String disabledStr = DirectoryConf.disabled.getValue(configProperties); if (disabledStr != null) disabled = Boolean.parseBoolean(disabledStr); else disabled = false; - - URI u = URI.create(uri); - if (!getRealm().isEmpty() || DirectoryConf.SCHEME_LDAP.equals(u.getScheme()) - || DirectoryConf.SCHEME_LDAPS.equals(u.getScheme())) { + if (!getRealm().isEmpty()) { + // IPA multiple LDAP causes URI parsing to fail + // TODO manage generic redundant LDAP case directoryDao = new LdapDao(this); - } else if (DirectoryConf.SCHEME_FILE.equals(u.getScheme())) { - directoryDao = new LdifDao(this); - } else if (DirectoryConf.SCHEME_OS.equals(u.getScheme())) { - directoryDao = new OsUserDirectory(this); - // singleUser = true; } else { - throw new IllegalArgumentException("Unsupported scheme " + u.getScheme()); + URI u = URI.create(uri); + if (DirectoryConf.SCHEME_LDAP.equals(u.getScheme()) || DirectoryConf.SCHEME_LDAPS.equals(u.getScheme())) { + directoryDao = new LdapDao(this); + } else if (DirectoryConf.SCHEME_FILE.equals(u.getScheme())) { + directoryDao = new LdifDao(this); + } else if (DirectoryConf.SCHEME_OS.equals(u.getScheme())) { + directoryDao = new OsUserDirectory(this); + // singleUser = true; + } else { + throw new IllegalArgumentException("Unsupported scheme " + u.getScheme()); + } } xaResource = new WorkingCopyXaResource<>(directoryDao); } @@ -202,7 +206,7 @@ public abstract class AbstractLdapDirectory implements Directory, XAResourceProv checkEdit(); LdapEntryWorkingCopy wc = getWorkingCopy(); boolean actuallyDeleted; - if (getDirectoryDao().daoHasEntry(dn) || wc.getNewData().containsKey(dn)) { + if (getDirectoryDao().entryExists(dn) || wc.getNewData().containsKey(dn)) { LdapEntry user = doGetRole(dn); wc.getDeletedData().put(dn, user); actuallyDeleted = true; @@ -224,7 +228,7 @@ public abstract class AbstractLdapDirectory implements Directory, XAResourceProv LdapEntryWorkingCopy wc = getWorkingCopy(); LdapEntry user; try { - user = getDirectoryDao().daoGetEntry(dn); + user = getDirectoryDao().doGetEntry(dn); } catch (NameNotFoundException e) { user = null; } @@ -281,6 +285,26 @@ public abstract class AbstractLdapDirectory implements Directory, XAResourceProv return directoryDao.doGetDirectHierarchyUnits(baseDn, functionalOnly); } + @Override + public String getHierarchyUnitName() { + return getName(); + } + + @Override + public HierarchyUnit getParent() { + return null; + } + + @Override + public boolean isFunctional() { + return true; + } + + @Override + public Directory getDirectory() { + return this; + } + /* * PATHS */ @@ -314,9 +338,11 @@ public abstract class AbstractLdapDirectory implements Directory, XAResourceProv LdapName name = (LdapName) getBaseDn().clone(); String[] segments = path.split("/"); Rdn parentRdn = null; - for (String segment : segments) { + // segments[0] is the directory itself + for (int i = 0; i < segments.length; i++) { + String segment = segments[i]; // TODO make attr names configurable ? - String attr = LdapAttrs.ou.name(); + String attr = path.startsWith("accounts/")/* IPA */ ? LdapAttrs.cn.name() : LdapAttrs.ou.name(); if (parentRdn != null) { if (getUserBaseRdn().equals(parentRdn)) attr = LdapAttrs.uid.name(); @@ -386,12 +412,27 @@ public abstract class AbstractLdapDirectory implements Directory, XAResourceProv return true;// read only by default } + /* + * AS AN ENTRY + */ + public LdapEntry asLdapEntry() { + try { + return directoryDao.doGetEntry(baseDn); + } catch (NameNotFoundException e) { + throw new IllegalStateException("Cannot get " + baseDn + " entry", e); + } + } + + public Dictionary getProperties() { + return asLdapEntry().getProperties(); + } + /* * ACCESSORS */ @Override public Optional getRealm() { - Object realm = getProperties().get(DirectoryConf.realm.name()); + Object realm = configProperties.get(DirectoryConf.realm.name()); if (realm == null) return Optional.empty(); return Optional.of(realm.toString()); @@ -421,12 +462,12 @@ public abstract class AbstractLdapDirectory implements Directory, XAResourceProv return systemRoleBaseRdn; } - public Dictionary getProperties() { - return properties; - } +// public Dictionary getConfigProperties() { +// return configProperties; +// } - public Dictionary cloneProperties() { - return new Hashtable<>(properties); + public Dictionary cloneConfigProperties() { + return new Hashtable<>(configProperties); } public String getForcedPassword() {