Announcement Announcement Module
Collapse
No announcement yet.
NameNotFoundException: [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

  • NameNotFoundException: [LDAP: error code 32 - No Such Object];

    when I call code:
    Code:
    user.initLdapTemplate();
    SuperstatUser sUser = new SuperstatUser(4, "zhangguodong", "1234");
    user.update(sUser);
    I got below exception:
    Code:
    Exception in thread "main" org.springframework.ldap.NameNotFoundException: [LDAP: error code 32 - No Such Object]; nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'cn=zhangguodong,o=superstatUser,cn=Root,dc=cqu,dc=cn'
    	at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:174)
    	at org.springframework.ldap.core.LdapTemplate.executeWithContext(LdapTemplate.java:810)
    	at org.springframework.ldap.core.LdapTemplate.executeReadOnly(LdapTemplate.java:793)
    	at org.springframework.ldap.core.LdapTemplate.lookup(LdapTemplate.java:822)
    	at org.springframework.ldap.core.LdapTemplate.lookupContext(LdapTemplate.java:1315)
    	at superstat.ldap.dbdao.UserDAO.update(UserDAO.java:77)
    	at superstat.ldap.dbdao.UserDAOTest.main(UserDAOTest.java:13)
    Caused by: javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'cn=zhangguodong,o=superstatUser,cn=Root,dc=cqu,dc=cn'
    	at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
    	at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
    	at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
    	at com.sun.jndi.ldap.LdapCtx.c_lookup(Unknown Source)
    	at com.sun.jndi.toolkit.ctx.ComponentContext.p_lookup(Unknown Source)
    	at com.sun.jndi.toolkit.ctx.PartialCompositeContext.lookup(Unknown Source)
    	at javax.naming.InitialContext.lookup(Unknown Source)
    	at org.springframework.ldap.core.LdapTemplate$9.executeWithContext(LdapTemplate.java:824)
    	at org.springframework.ldap.core.LdapTemplate.executeWithContext(LdapTemplate.java:807)
    	... 5 more
    BulidDN method:
    Code:
    	
    private static final String BASE_DN = "o=superstatUser, cn=Root, dc=cqu, dc=cn";
    protected Name buildDn(SuperstatUser user) {
        DistinguishedName dn = new DistinguishedName(BASE_DN);
        dn.add("cn", user.getUserName());
        return dn;
    }
    update, create and delete methods:
    Code:
    public void update(SuperstatUser user) {
            Name dn = buildDn(user);
            DirContextOperations context = ldapTemplate.lookupContext(dn);
            mapToContext(user, context);
            ldapTemplate.modifyAttributes(context);
    }
    public void create(SuperstatUser user) {
        DirContextAdapter context = new DirContextAdapter(buildDn(user));
        mapToContext(user, context);
        ldapTemplate.bind(context);
    }
    public void delete(SuperstatUser user) {
        ldapTemplate.unbind(buildDn(user));
    }
    mapToContext method:
    Code:
    	protected void mapToContext(SuperstatUser user, DirContextOperations context) {
    	    context.setAttributeValue("objectclass", "myUser");
    	    context.setAttributeValue("cn", user.getUserName());
    	    context.setAttributeValue("superstat-uname", user.getUserName());
    	    context.setAttributeValue("superstat-uid", user.getUserId().toString());
    	    context.setAttributeValue("superstat-upwd", user.getUserPwd());
    	}
    My applicaitoncontext:
    Code:
        <bean id="ladpContextSource"  
            class="org.springframework.ldap.core.support.LdapContextSource">  
            <property name="url" value="ldap://10.250.95.40:389" />  
            <property name="base" value="dc=cqu,dc=cn"></property>  
            <property name="userDn" value="cn=Root,dc=cqu,dc=cn" />  
            <property name="password" value="secret" />  
        </bean>
    	
    	<bean id="ldapTemplate"  
            class="org.springframework.ldap.core.LdapTemplate">  
            <property name="contextSource" ref="ladpContextSource" />  
        </bean>
Working...
X