X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.util%2Fsrc%2Forg%2Fargeo%2Futil%2Fdirectory%2Fldap%2FAbstractLdapEntry.java;h=25f233a0104b3805a7e471d45c9800c950678360;hb=df60fd8de17590b8f4ab32fd0278e57aaaedbfa2;hp=be919c020174053af3aa120126f92f3ef429de08;hpb=e2ffdf6872592aa22d0de2b0ec69ee4eca698c45;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.util/src/org/argeo/util/directory/ldap/AbstractLdapEntry.java b/org.argeo.util/src/org/argeo/util/directory/ldap/AbstractLdapEntry.java index be919c020..25f233a01 100644 --- a/org.argeo.util/src/org/argeo/util/directory/ldap/AbstractLdapEntry.java +++ b/org.argeo.util/src/org/argeo/util/directory/ldap/AbstractLdapEntry.java @@ -1,8 +1,16 @@ package org.argeo.util.directory.ldap; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; import javax.naming.ldap.LdapName; +/** An entry in an LDAP (or LDIF) directory. */ public abstract class AbstractLdapEntry implements LdapEntry { private final AbstractLdapDirectory directory; @@ -10,8 +18,10 @@ public abstract class AbstractLdapEntry implements LdapEntry { private Attributes publishedAttributes; - protected AbstractLdapEntry(AbstractLdapDirectory userAdmin, LdapName dn, Attributes attributes) { - this.directory = userAdmin; + protected AbstractLdapEntry(AbstractLdapDirectory directory, LdapName dn, Attributes attributes) { + Objects.requireNonNull(directory); + Objects.requireNonNull(dn); + this.directory = directory; this.dn = dn; this.publishedAttributes = attributes; } @@ -24,6 +34,25 @@ public abstract class AbstractLdapEntry implements LdapEntry { public synchronized Attributes getAttributes() { return isEditing() ? getModifiedAttributes() : publishedAttributes; } + + @Override + public List getReferences(String attributeId){ + Attribute memberAttribute = getAttributes().get(attributeId); + if (memberAttribute == null) + return new ArrayList(); + try { + List roles = new ArrayList(); + NamingEnumeration values = memberAttribute.getAll(); + while (values.hasMore()) { + LdapName dn = new LdapName(values.next().toString()); + roles.add(dn); + } + return roles; + } catch (NamingException e) { + throw new IllegalStateException("Cannot get members", e); + } + + } /** Should only be called from working copy thread. */ protected synchronized Attributes getModifiedAttributes() { @@ -53,10 +82,14 @@ public abstract class AbstractLdapEntry implements LdapEntry { publishedAttributes = modifiedAttributes; } - protected AbstractLdapDirectory getDirectory() { + public AbstractLdapDirectory getDirectory() { return directory; } + public LdapDirectoryDao getDirectoryDao() { + return directory.getDirectoryDao(); + } + @Override public int hashCode() { return dn.hashCode();