title: Using javax.naming.spi.DirObjectFactory to lookup objects from an LDAP
body: <p>I've implemented an object factory to lookup LDAP objects, but the supplied context does not return the DN (via nameCtx.getNameInNamespace()) from the LDAP. Am i doing it wrong in some way?</p>
  
  <pre><code>public class LdapPersonFactory implements DirObjectFactory {
          @Override
          public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                  Hashtable&lt;?, ?&gt; environment, Attributes attrs) throws Exception {
              if (attrs == null)
                  return null;
              Attribute oc = attrs.get("objectclass");
              if (oc != null &amp;&amp; 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;
          }
      }
  </code></pre>
  
  <p>nameCtx.getNameInNamespace() only returns an empty string.</p>