Wrox Programmer Forums
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 14th, 2005, 10:22 PM
Authorized User
 
Join Date: Aug 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access LDAP


I set up Active Directory on my PC. And my DNS is g10.com

Windows advanced server 2000

I use code is below for search LDAP

*****************************************
String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory";
     String MY_HOST = "ldap://localhost:389";
     String MY_SEARCHBASE = "cn=users,o=g10.com";
     String MY_FILTER = "(sn=*)";
    String MGR_DN = "uid=toan, ou=People, o=g10.com";
    String MGR_PW = "toan";


     try{

         Hashtable env = new Hashtable();

         //Specify which class to use for our JNDI provider
         env.put(Context.INITIAL_CONTEXT_FACTORY,INITCTX);


         //Specify host and port to use for directoty service
         env.put(Context.PROVIDER_URL,MY_HOST);


         //Get a reference to a directory context
         DirContext ctx = new InitialDirContext(env);

         //Specify the scope of the search
         SearchControls constraints = new SearchControls();
         constraints.setSearchScope(SearchControls.SUBTREE_ SCOPE);

         //perform the actual search
         //we give it a searchbase, a filter and the constrains
         //containing the scope of the search
         NamingEnumeration results = ctx.search(MY_SEARCHBASE,MY_FILTER,constraints);

         //now step through the search results
         while(results != null && results.hasMore())
         {
             SearchResult sr = (SearchResult)results.next();

             String dn = sr.getName() + ", " + MY_SEARCHBASE;
             System.out.print("Distinguished Name is: " + dn);

             Attributes attrs = sr.getAttributes();

             for(NamingEnumeration ne = attrs.getAll(); ne.hasMoreElements();)
             {
                Attributes attr = (Attributes)ne.next();

                String attrID = attr.getIDs().toString();

                System.out.print(attrID + ":");

                for(Enumeration vals = attr.getAll();vals.hasMoreElements();)
                {
                    System.out.print("\t" + vals.nextElement());
                }

            } //for
             System.out.println("\n");

        } //while

    }catch(Exception e)
    {
        e.printStackTrace();
        //System.exit(1);
    }

*******************************

When I run it then show error as following:

**************************************
javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr: DSID-03100684, problem 5012 (DIR_ERROR), data 0
remaining name 'cn=users,o=g10.com'
    java.lang.Throwable(java.lang.String)
    java.lang.Exception(java.lang.String)
    javax.naming.NamingException(java.lang.String)
    void com.sun.jndi.ldap.LdapCtx.processReturnCode(com.su n.jndi.ldap.LdapResult, javax.naming.Name, java.lang.Object, javax.naming.Name, java.util.Hashtable, java.lang.String)
    void com.sun.jndi.ldap.LdapCtx.processReturnCode(com.su n.jndi.ldap.LdapResult, javax.naming.Name)
    javax.naming.NamingEnumeration com.sun.jndi.ldap.LdapCtx.c_search(javax.naming.Na me, java.lang.String, javax.naming.directory.SearchControls, boolean, com.sun.jndi.toolkit.Continuation)
    javax.naming.NamingEnumeration com.sun.jndi.ldap.LdapCtx.c_search(javax.naming.Na me, java.lang.String, javax.naming.directory.SearchControls, com.sun.jndi.toolkit.Continuation)
    javax.naming.NamingEnumeration com.sun.jndi.toolkit.ComponentDirContext.p_search( javax.naming.Name, java.lang.String, javax.naming.directory.SearchControls, com.sun.jndi.toolkit.Continuation)
    javax.naming.NamingEnumeration com.sun.jndi.toolkit.PartialCompositeDirContext.se arch(javax.naming.Name, java.lang.String, javax.naming.directory.SearchControls)
    javax.naming.NamingEnumeration com.sun.jndi.toolkit.PartialCompositeDirContext.se arch(java.lang.String, java.lang.String, javax.naming.directory.SearchControls)
    javax.naming.NamingEnumeration javax.naming.directory.InitialDirContext.search(ja va.lang.String, java.lang.String, javax.naming.directory.SearchControls)
    void active.directory.SearchJNDI.doGet(javax.servlet.ht tp.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    void javax.servlet.http.HttpServlet.service(javax.servl et.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    void javax.servlet.http.HttpServlet.service(javax.servl et.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.webapp.StrictServletInstanc e.doService(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.webapp.StrictLifecycleServl et._service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.webapp.IdleServletState.ser vice(com.ibm.servlet.engine.webapp.StrictLifecycle Servlet, javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.webapp.StrictLifecycleServl et.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.webapp.ServletInstance.serv ice(javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocat ionEvent)
    void com.ibm.servlet.engine.webapp.ValidServletReferenc eState.dispatch(com.ibm.servlet.engine.webapp.Serv letInstanceReference, javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocat ionEvent)
    void com.ibm.servlet.engine.webapp.ServletInstanceRefer ence.dispatch(javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocat ionEvent)
    void com.ibm.servlet.engine.webapp.WebAppRequestDispatc her.handleWebAppDispatch(com.ibm.servlet.engine.we bapp.WebAppRequest, javax.servlet.http.HttpServletResponse, boolean)
    void com.ibm.servlet.engine.webapp.WebAppRequestDispatc her.dispatch(javax.servlet.ServletRequest, javax.servlet.ServletResponse, boolean)
    void com.ibm.servlet.engine.webapp.WebAppRequestDispatc her.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.webapp.InvokerServlet.servi ce(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    void javax.servlet.http.HttpServlet.service(javax.servl et.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.webapp.StrictServletInstanc e.doService(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.webapp.StrictLifecycleServl et._service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.webapp.IdleServletState.ser vice(com.ibm.servlet.engine.webapp.StrictLifecycle Servlet, javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.webapp.StrictLifecycleServl et.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.webapp.ServletInstance.serv ice(javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocat ionEvent)
    void com.ibm.servlet.engine.webapp.ValidServletReferenc eState.dispatch(com.ibm.servlet.engine.webapp.Serv letInstanceReference, javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocat ionEvent)
    void com.ibm.servlet.engine.webapp.ServletInstanceRefer ence.dispatch(javax.servlet.ServletRequest, javax.servlet.ServletResponse, com.ibm.servlet.engine.webapp.WebAppServletInvocat ionEvent)
    void com.ibm.servlet.engine.webapp.WebAppRequestDispatc her.handleWebAppDispatch(com.ibm.servlet.engine.we bapp.WebAppRequest, javax.servlet.http.HttpServletResponse, boolean)
    void com.ibm.servlet.engine.webapp.WebAppRequestDispatc her.dispatch(javax.servlet.ServletRequest, javax.servlet.ServletResponse, boolean)
    void com.ibm.servlet.engine.webapp.WebAppRequestDispatc her.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    void com.ibm.servlet.engine.srt.WebAppInvoker.handleInv ocationHook(java.lang.Object)
    void com.ibm.servlet.engine.invocation.CachedInvocation .handleInvocation(java.lang.Object)
    void com.ibm.servlet.engine.srp.ServletRequestProcessor .dispatchByURI(java.lang.String, com.ibm.servlet.engine.srp.ISRPConnection)
    void com.ibm.servlet.engine.oselistener.OSEListenerDisp atcher.service(com.ibm.servlet.engine.oselistener. api.IOSEConnection)
    void com.ibm.servlet.engine.http_transport.HttpTranspor tHandler.handleConnection(java.net.Socket)
    void com.ibm.servlet.engine.http_transport.HttpTranspor tHandler.run()
    void java.lang.Thread.run()

***********************************

Could you help me?

Thanks.

Sincerely,

Minh Phan






Similar Threads
Thread Thread Starter Forum Replies Last Post
LDAP Authentication -- Need Help avinashraj General .NET 1 May 25th, 2006 12:13 AM
Help with using ActiveDirectory using LDAP aldwinenriquez General .NET 1 July 19th, 2005 02:16 AM
Can I parse an LDAP DN? Kingster XSLT 1 July 30th, 2004 12:40 PM
LDAP bmains ASP.NET 1.0 and 1.1 Professional 0 May 26th, 2004 07:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.