X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.util%2Fsrc%2Forg%2Fargeo%2Futil%2Fdirectory%2Fldap%2FLdapEntry.java;h=823bc9502e6eb9a57c9e51e6d381c9c29b94f9c8;hb=312ddf6c458f06474caf4df2728af7090b3714a4;hp=c145a6f0ab6e0f8258279011e4158fe685cf9ca9;hpb=e2ffdf6872592aa22d0de2b0ec69ee4eca698c45;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.util/src/org/argeo/util/directory/ldap/LdapEntry.java b/org.argeo.util/src/org/argeo/util/directory/ldap/LdapEntry.java index c145a6f0a..823bc9502 100644 --- a/org.argeo.util/src/org/argeo/util/directory/ldap/LdapEntry.java +++ b/org.argeo.util/src/org/argeo/util/directory/ldap/LdapEntry.java @@ -1,8 +1,20 @@ package org.argeo.util.directory.ldap; +import java.util.Arrays; +import java.util.Collection; +import java.util.Dictionary; +import java.util.List; +import java.util.Locale; +import java.util.Set; +import java.util.StringJoiner; +import java.util.TreeSet; + import javax.naming.directory.Attributes; import javax.naming.ldap.LdapName; +import org.argeo.util.naming.LdapAttrs; + +/** An LDAP entry. */ public interface LdapEntry { LdapName getDn(); @@ -10,4 +22,35 @@ public interface LdapEntry { void publishAttributes(Attributes modifiedAttributes); + List getReferences(String attributeId); + + Dictionary getProperties(); + + boolean hasCredential(String key, Object value); + + /* + * UTILITIES + */ + /** + * Convert a collection of object classes to the format expected by an LDAP + * backend. + */ + public static void addObjectClasses(Dictionary properties, Collection objectClasses) { + String value = properties.get(LdapAttrs.objectClasses.name()).toString(); + Set currentObjectClasses = new TreeSet<>(Arrays.asList(value.toString().split("\n"))); + currentObjectClasses.addAll(objectClasses); + StringJoiner values = new StringJoiner("\n"); + currentObjectClasses.forEach((s) -> values.add(s)); + properties.put(LdapAttrs.objectClasses.name(), values.toString()); + } + + public static Object getLocalized(Dictionary properties, String key, Locale locale) { + if (locale == null) + return null; + Object value = null; + value = properties.get(key + ";lang-" + locale.getLanguage() + "-" + locale.getCountry()); + if (value == null) + value = properties.get(key + ";lang-" + locale.getLanguage()); + return value; + } }