java - OpenLdap server, Spring ldap user bind (inetOrgPerson) No such object -
i installed openldap server , trying connect, add, users,groups on it. since 'm new on ldap nice if share tutorials spring-ldap :/
so here's bind code:
user class:
public class user implements serializable{ private string id; private string username; private string firstname; private string lastname; private string email; private string password; private string department; private string groups[]; }
save method:
public user save( final user user ){ init(); name dn = builddn( user ); attributes attributes = buildattributes( user ); logger.info( "trying save dn " + dn + " , attributes " + attributes ); ldaptemplate.bind( dn, null, attributes ); // update groups for( string group : user.getgroups() ){ try{ distinguishedname groupdn = new distinguishedname(); groupdn.add( "ou", "groups" ); groupdn.add( "cn", group ); dircontextoperations context = ldaptemplate.lookupcontext( groupdn ); context.addattributevalue( "memberuid", user.getusername() ); ldaptemplate.modifyattributes( context ); } catch( exception e ){ e.printstacktrace(); } } logger.info( "successfuly saved " ); return user; }
builddn:
private name builddn( final user user ){ distinguishedname dn = new distinguishedname(); dn.add( "ou", "people" ); if( user.getdepartment() != null ){ dn.add( "ou", user.getdepartment() ); } dn.add( "uid", user.getusername() ); return dn; }
buildattributes:
private attributes buildattributes( final user user ){ attributes attrs = new basicattributes(); basicattribute ocattr = new basicattribute( "objectclass" ); // ocattr.add( "person" ); ocattr.add( "inetorgperson" ); attrs.put( ocattr ); attrs.put( "cn", user.getfirstname() ); // attrs.put( "rdn", "uid" ); // todo check how assign rdn attrs.put( "sn", user.getlastname() ); attrs.put( "userpassword", "{sha}" + this.encrypt( user.getpassword() ) ); attrs.put( "mail", user.getemail() ); return attrs; }
and here's exception:
org.springframework.ldap.namenotfoundexception: [ldap: error code 32 - no such object]; nested exception javax.naming.namenotfoundexception: [ldap: error code 32 - no such object]; remaining name 'uid=sercan,ou=people' @ org.springframework.ldap.support.ldaputils.convertldapexception(ldaputils.java:183) @ org.springframework.ldap.core.ldaptemplate.executewithcontext(ldaptemplate.java:820) @ org.springframework.ldap.core.ldaptemplate.executereadwrite(ldaptemplate.java:812) @ org.springframework.ldap.core.ldaptemplate.bind(ldaptemplate.java:990) @ com.***.usr.mng.library.service.impl.userserviceimpl.save(userserviceimpl.java:101) @ com.***.usr.mng.library.handler.impl.userhandlerimpl.saveuser(userhandlerimpl.java:45) @ com.***.usr.mng.library.handler.impl.usermanagementhandlerimpl.handlerequest(usermanagementhandlerimpl.java:62) @ com.***.usr.mng.service.controller.usermanagementcontroller.processrequest(usermanagementcontroller.java:83) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.springframework.web.method.support.invocablehandlermethod.invoke(invocablehandlermethod.java:215) @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:132) @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:104) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:745) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:685) @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:80) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:919) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:851) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:953) @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:844) @ javax.servlet.http.httpservlet.service(httpservlet.java:620) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:829) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:501) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:98) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:950) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:408) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1040) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:607) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:313) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:745) caused by: javax.naming.namenotfoundexception: [ldap: error code 32 - no such object]; remaining name 'uid=sercan,ou=people' @ com.sun.jndi.ldap.ldapctx.maperrorcode(ldapctx.java:3112) @ com.sun.jndi.ldap.ldapctx.processreturncode(ldapctx.java:3033) @ com.sun.jndi.ldap.ldapctx.processreturncode(ldapctx.java:2840) @ com.sun.jndi.ldap.ldapctx.c_bind(ldapctx.java:420) @ com.sun.jndi.toolkit.ctx.componentdircontext.p_bind(componentdircontext.java:295) @ com.sun.jndi.toolkit.ctx.partialcompositedircontext.bind(partialcompositedircontext.java:215) @ javax.naming.directory.initialdircontext.bind(initialdircontext.java:182) @ org.springframework.ldap.core.ldaptemplate$21.executewithcontext(ldaptemplate.java:992) @ org.springframework.ldap.core.ldaptemplate.executewithcontext(ldaptemplate.java:817)
i found solution,
dn.add( "ou", "people" );
i'm trying add person people organizational unit, not exist !
thanks.
Comments
Post a Comment