This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Dec 7, 2011, 11:46 PM
17 Posts
topic has been resolvedResolved

LDAP lookup from an XPage

  • Category: Other
  • Platform: Not Applicable
  • Release: 8.5.3
  • Role: Developer
  • Tags: LDAP
  • Replies: 0
I'm trying to run an LDAP lookup from an XPage. To make it simple I've dumbed it down to 2 lines:
DirContext ctx = new InitialDirContext();
NamingEnumeration answer = ctx.search(url, null);

 
Either I put it in Java agent or LotusScript agent that calls Java class, or I call Java from XPage, JavaScript, the search() method fails with a message:
javax.naming.NotContextException: DirContext object is required.
    at javax.naming.directory.InitialDirContext.castToDirContext(Unknown Source)
    at javax.naming.directory.InitialDirContext.getURLOrDefaultInitDirCtx(Unknown Source)
    at javax.naming.directory.InitialDirContext.search(Unknown Source)
 
However if I run the agent from Notes UI it works perfectly. DirContext object itself seems to get created ok.
 
I'd expect that the answer could be around the lines that XPages on client run in a different JVM with different Java version and all that depends also on its configuration. Or maybe newer Java versions are more attentive to the search format. And providing one long url to the search method is not enough anymore?
 
EDITED. Well Oracle document states that we must be able to pass the URL only. But somehow it does not work anymore. The solution:
        Hashtable env = new Hashtable(2);
        env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL,  "ldap://bluepages.ibm.com:389/o=ibm.com");
        // Create initial context
        DirContext dircontext = new InitialDirContext(env);
        // this way I did not get an error anymore, but also did not have the joy of getting anything back. Yet...
 
        static String DN = "ou=bluepages";
        String filter = "(&(objectClass=person)(" + searchtype + "=" + searchvalue + "))";
        String[] attrIDs = attrlist.split(","); // return attributes
        SearchControls ctls = new SearchControls();
        ctls.setReturningAttributes(attrIDs);
        // specifying SCOPE was the last missing element... by default scope is SINGLELEVEL
        ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        NamingEnumeration answer = dircontext.search(DN, filter, ctls);
 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal