Announcement Announcement Module
Collapse
No announcement yet.
LDAP: error code 32 - No Such Object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LDAP: error code 32 - No Such Object

    When I call

    Code:
    user= (User) ldapTemplate.lookup(buildDn(username), new UserAttributesMapper());
    I got below exception:
    Code:
    org.springframework.ldap.UncategorizedLdapException: Operation failed; nested exception is javax.naming.AuthenticationException: [LDAP: error code 32 - No Such Object]
    javax.naming.AuthenticationException: [LDAP: error code 32 - No Such Object]
    	at com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:272)
    	at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2640)
    	at com.sun.jndi.ldap.LdapCtx.(LdapCtx.java:290)
    	at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)
    	at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193)
    	at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136)
    	at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66)
    	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
    	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
    	at javax.naming.InitialContext.init(InitialContext.java:219)
    	at javax.naming.ldap.InitialLdapContext.(InitialLdapContext.java:133)
    	at org.springframework.ldap.support.LdapContextSource.getDirContextInstance(LdapContextSource.java:45)
    	at org.springframework.ldap.support.AbstractContextSource.createContext(AbstractContextSource.java:193)
    	at org.springframework.ldap.support.AbstractContextSource.getReadOnlyContext(AbstractContextSource.java:104)
    buildDN method:
    Code:
    private Name buildDn(String username) {
    	      DistinguishedName dn = new DistinguishedName("dc=example,dc=com");
    	      dn.add("ou","People");
    	      dn.add("uid", username );
    	      
    	      Log.info(CLASS_NAME+ " buildDn(String username) dn.toString()="+dn.toString()) ;
    	      return dn;
    	   }
    UserAttributeMapper:
    Code:
    	private class UserAttributesMapper implements AttributesMapper {
    	      public Object mapFromAttributes(Attributes attrs) throws NamingException {
    	         User user = new User();
    	         Log.info(CLASS_NAME+ " UserAttributesMapper.mapFromAttributes attrs.toString()="+attrs.toString()) ;
    	         user.setUsername((String)attrs.get("uid").get());
    	         attrs.toString() ;
    	     	         
    	         return user;
    	      }
    	   }
    My applicaitoncontext :
    Code:
    	<bean id="ldapContextSource"
    		class="org.springframework.ldap.support.LdapContextSource">
    		<property name="url" value="ldap://spring.com:12345"/>
    		<property name="base" value="dc=example,dc=com"/>
    		<property name="userName" value="uid=admin,ou=People"/>
    		<property name="password" value="admin"/>
    	</bean>
    	
    	<bean id="ldapTemplate"
    		class="org.springframework.ldap.LdapTemplate">
    		<constructor-arg ref="ldapContextSource"/>
    	</bean>


    And LDAP connection string works fine in my acigi authentication.
    my acigi authentication applicationcontext:
    Code:
    	<bean id="initialDirContextFactory" class="org.acegisecurity.providers.ldap.DefaultInitialDirContextFactory">
         <constructor-arg value="ldap://spring.com:12345/ou=People,dc=example,dc=com"/>
         <property name="managerDn"><value>uid=admin,ou=People,dc=example,dc=com</value></property>
         <property name="managerPassword"><value>admin</value></property>
      </bean>
    Last edited by panfl; Nov 9th, 2006, 02:40 AM.

  • #2
    The base DN should not be included in the lookup DN if base is specified on the ContextSource.

    Comment


    • #3
      Thank you rasky for your quick reply.

      I change my buildDn method to:
      Code:
      private Name buildDn(String username) {
      	      DistinguishedName dn = new DistinguishedName();
      	      dn.add("uid", username );
      	      
      	      Log.info(CLASS_NAME+ " buildDn(String username) dn.toString()="+dn.toString()) ;
      	      return dn;
      	   }
      And Applicaiton context to:
      Code:
      <bean id="ldapContextSource"
      		class="org.springframework.ldap.support.LdapContextSource">
      		<property name="url" value="ldap://spring.com:12345"/>
      		<property name="base" value="ou=People,dc=example,dc=com"/>
      		<property name="userName" value="uid=admin"/>
      		<property name="password" value="admin"/>
      	</bean>
      	
      	<bean id="ldapTemplate"
      		class="org.springframework.ldap.LdapTemplate">
      		<constructor-arg ref="ldapContextSource"/>
      	</bean>
      But I still got the same exception.

      What can I do now?

      Comment


      • #4
        Ouch, sorry - I didn't take a good enough look at your stack trace.

        The problem is that the userName you configure in your ContextSource needs to be the full DN of the admin user, regardless whether you have set a base path or not.

        This differs from DNs you use in your code for searches and lookups, where the base path should not be included.

        I'm aware this is a little bit confusing, but there's really not much we can do about it - it's just the way the Java LDAP provider works.

        Comment


        • #5

          WOW, It realy works.
          Thank you very much.

          I change my ContextSource configuration to:
          Code:
          	<bean id="ldapContextSource"
          		class="org.springframework.ldap.support.LdapContextSource">
          		<property name="url" value="ldap://spring.com:12345"/>
          		<property name="base" value="ou=People,dc=example,dc=com"/>
          		<property name="userName" value="uid=admin,ou=People,dc=example,dc=com"/>
          		<property name="password" value="admin"/>
          	</bean>

          Comment


          • #6
            LDAP error code 32 - No Such Object

            Hi,

            I have the same problem, but following the above advice still not resolved.

            stacktrace:
            Caused by: javax.naming.AuthenticationException: [LDAP: error code 32 - No Such Object]
            at com.sun.jndi.ldap.LdapClient.authenticate(LdapClie nt.java:272)
            at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:263 7)
            at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:283)
            at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapC txFactory.java:175)
            at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(Ldap CtxFactory.java:193)
            at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstanc e(LdapCtxFactory.java:136)
            at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext (LdapCtxFactory.java:66)
            at javax.naming.spi.NamingManager.getInitialContext(N amingManager.java:667)
            at javax.naming.InitialContext.getDefaultInitCtx(Init ialContext.java:247)
            at javax.naming.InitialContext.init(InitialContext.ja va:223)
            at javax.naming.ldap.InitialLdapContext.<init>(Initia lLdapContext.java:134)
            at org.springframework.ldap.core.support.LdapContextS ource.getDirContextInstance(LdapContextSource.java :43)
            at org.springframework.ldap.core.support.AbstractCont extSource.createContext(AbstractContextSource.java :223)
            ... 151 more

            My config:
            <CODE>
            <bean id="contextSourcePrimary" class="org.springframework.ldap.core.support.LdapC ontextSource">
            <property name="urls" value="ldap://myldapserver1:389,ldap://myldapserver2:389" />
            <property name="base" value="ou=People, dc=abcd, dc=com" />
            <property name="userDn" value="uid=adminuser,ou=people,o=admin" />
            <property name="password" value="password" />
            </bean>
            <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate" >
            <constructor-arg><ref local="contextSourcePrimary" /></constructor-arg>
            </bean>
            </CODE>

            My code:
            <CODE>
            DistinguishedName dn = new DistinguishedName();
            dn.add("uid", userId);
            UserContextMapper mapper = new UserContextMapper();
            try {
            user = (User) ldapTemplate.lookup(dn.encode(), mapper);
            } catch (Exception ex) {
            }
            </CODE>

            I have been working on this all day but going nowhere, can someone shed me some light ?

            Comment


            • #7
              You are not following the advice properly. Reading the previous entries in this thread you would have noticed the following:
              Originally posted by rasky View Post
              The problem is that the userName you configure in your ContextSource needs to be the full DN of the admin user, regardless whether you have set a base path or not.

              This differs from DNs you use in your code for searches and lookups, where the base path should not be included.

              I'm aware this is a little bit confusing, but there's really not much we can do about it - it's just the way the Java LDAP provider works.
              The userDn in your configuration does not seem to specify the full DN of the admin user (including the base DN).

              Comment


              • #8
                Originally posted by rasky View Post
                You are not following the advice properly. Reading the previous entries in this thread you would have noticed the following:


                The userDn in your configuration does not seem to specify the full DN of the admin user (including the base DN).
                Thanks Rasky,
                Actually I did follow your advice and tried:
                Code:
                <property name="base" value="ou=People, dc=abcd, dc=com" />
                <property name="userDn" value="uid=adminuser,ou=people,dc=abcd,dc=com,o=admin" />
                or 
                <property name="base" value="ou=People, dc=abcd, dc=com" />
                <property name="userDn" value="uid=adminuser,ou=people,o=admin,dc=abcd,dc=com" />
                with no luck.
                I solved this in the end, it was a typo in uid.. DOH!!

                Now I bump into another strange problem: The DirContextAdapter in my mapper method seems to have no attributes except uid....

                Rasky, from your experience could this be my config problem or the setting of LDAP server (the LDAP server setting is beyond my control) ?

                Comment


                • #9
                  Originally posted by rasky View Post
                  The problem is that the userName you configure in your ContextSource needs to be the full DN of the admin user, regardless whether you have set a base path or not.
                  I just can't love you enough, this trivial matter solved about a day of head scratching.
                  As you can suppose, i'm a green spring user.

                  Comment

                  Working...
                  X