J'ai implémenté une fabrique d'objets pour rechercher des objets LDAP, mais le contexte fourni ne retourne pas le DN (via nameCtx.getNameInNamespace()) du LDAP. Est-ce que je le fais mal d'une certaine façon?Utilisation de javax.naming.spi.DirObjectFactory pour rechercher des objets à partir d'un LDAP
public class LdapPersonFactory implements DirObjectFactory {
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable<?, ?> environment, Attributes attrs) throws Exception {
if (attrs == null)
return null;
Attribute oc = attrs.get("objectclass");
if (oc != null && oc.contains("inetOrgPerson")) {
String surname = (String) attrs.get("sn").get();
String givenName = (String) attrs.get("givenname").get();
String dn = nameCtx.getNameInNamespace();
return new LdapPerson(dn, givenName, surname);
}
return null;
}
}
nomCtx.getNameInNamespace() renvoie uniquement une chaîne vide.