How to search LDAP by person's name? -
i'm getting error message
org.springframework.web.util.nestedservletexception: request processing failed; nested 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 'cn=kirsi' org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:659) org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:552) javax.servlet.http.httpservlet.service(httpservlet.java:617) javax.servlet.http.httpservlet.service(httpservlet.java:717) org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:143) org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:237) org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:167) org.jasig.cas.client.session.singlesignoutfilter.dofilter(singlesignoutfilter.java:110) org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88) org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:76)
root cause
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 'cn=kirsi' org.springframework.ldap.support.ldaputils.convertldapexception(ldaputils.java:172) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:306) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:237) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:624) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:535) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:462) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:483) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:503) fi.utu.userdetails.ldapmanager.findbynamewildcard(ldapmanager.java:43) net.viralpatel.spring3.controller.researchercontroller.addresearcher(researchercontroller.java:40) sun.reflect.nativemethodaccessorimpl.invoke0(native method) sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) java.lang.reflect.method.invoke(method.java:597) org.springframework.web.bind.annotation.support.handlermethodinvoker.doinvokemethod(handlermethodinvoker.java:710) org.springframework.web.bind.annotation.support.handlermethodinvoker.invokehandlermethod(handlermethodinvoker.java:167) org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter.invokehandlermethod(annotationmethodhandleradapter.java:414) org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter.handle(annotationmethodhandleradapter.java:402) org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:771) org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:716) org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:647) org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:552) javax.servlet.http.httpservlet.service(httpservlet.java:617) javax.servlet.http.httpservlet.service(httpservlet.java:717) org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:143) org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:237) org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:167) org.jasig.cas.client.session.singlesignoutfilter.dofilter(singlesignoutfilter.java:110) org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88) org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:76)
root cause
javax.naming.namenotfoundexception: [ldap: error code 32 - no such object]; remaining name 'cn=kirsi' com.sun.jndi.ldap.ldapctx.maperrorcode(ldapctx.java:3066) com.sun.jndi.ldap.ldapctx.processreturncode(ldapctx.java:2987) com.sun.jndi.ldap.ldapctx.processreturncode(ldapctx.java:2794) com.sun.jndi.ldap.ldapctx.searchaux(ldapctx.java:1826) com.sun.jndi.ldap.ldapctx.c_search(ldapctx.java:1749) com.sun.jndi.toolkit.ctx.componentdircontext.p_search(componentdircontext.java:368) com.sun.jndi.toolkit.ctx.partialcompositedircontext.search(partialcompositedircontext.java:338) javax.naming.directory.initialdircontext.search(initialdircontext.java:257) org.springframework.ldap.core.ldaptemplate$3.executesearch(ldaptemplate.java:231) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:293) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:237) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:624) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:535) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:462) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:483) org.springframework.ldap.core.ldaptemplate.search(ldaptemplate.java:503) fi.utu.userdetails.ldapmanager.findbynamewildcard(ldapmanager.java:43) net.viralpatel.spring3.controller.researchercontroller.addresearcher(researchercontroller.java:40) sun.reflect.nativemethodaccessorimpl.invoke0(native method) sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) java.lang.reflect.method.invoke(method.java:597) org.springframework.web.bind.annotation.support.handlermethodinvoker.doinvokemethod(handlermethodinvoker.java:710) org.springframework.web.bind.annotation.support.handlermethodinvoker.invokehandlermethod(handlermethodinvoker.java:167) org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter.invokehandlermethod(annotationmethodhandleradapter.java:414) org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter.handle(annotationmethodhandleradapter.java:402) org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:771) org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:716) org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:647) org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:552) javax.servlet.http.httpservlet.service(httpservlet.java:617) javax.servlet.http.httpservlet.service(httpservlet.java:717) org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:143) org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:237) org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:167) org.jasig.cas.client.session.singlesignoutfilter.dofilter(singlesignoutfilter.java:110) org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88) org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:76)
by googling found out because configured dn. tried remove contextsource
, no help. contextsource
orginally
<bean id="contextsource" class="org.springframework.ldap.core.support.ldapcontextsource"> <property name="url" value=" ldap://ldap.utu.fi " /> <property name="base" value="dc=utu,dc=fi" /> <property name="userdn" value="uid=sysbind,ou=special users,dc=utu,dc=fi" /> <property name="password" value="footogsep2" /> </bean>
and class:
package fi.utu.userdetails; import java.util.list; import javax.naming.namingexception; import javax.naming.directory.attributes; import org.springframework.ldap.core.attributesmapper; import org.springframework.ldap.core.dircontextoperations; import org.springframework.ldap.core.distinguishedname; import org.springframework.ldap.core.ldaptemplate; import org.springframework.ldap.core.support.abstractcontextmapper; import org.springframework.ldap.filter.andfilter; import org.springframework.ldap.filter.equalsfilter; import org.springframework.ldap.filter.orfilter; public class ldapmanager { private ldaptemplate ldap; private final static string[] person_attrs = new string[]{"uid", "mail", "givenname", "sn","cn"}; public ldapmanager(ldaptemplate template) { this.ldap = template; } public list<person> findbynamewildcard(string fullname) { distinguishedname dn = new distinguishedname(); dn.add("cn", fullname); andfilter andfilter = new andfilter(); andfilter.and(new equalsfilter("objectclass", "person")); orfilter affiliationfilter = new orfilter(); return ldap.search(dn, andfilter.encode(), new personcontextmapper()); } private class personattributesmapper implements attributesmapper { public object mapfromattributes(attributes attrs) throws namingexception { string uid = (string) attrs.get("uid").get(); string mail = (string) attrs.get("mail").get(); string lastname = (string) attrs.get("sn").get(); string firstname = (string) attrs.get("givenname").get(); string fullname = (string) attrs.get("cn").get(); //string status = (string) attrs.get("inetuserstatus").get(); person person = new person(); person.setlname(lastname); person.setfname(firstname); person.setemail(mail); person.setusername(uid); person.setfullname(fullname); return person; } } private static class personcontextmapper extends abstractcontextmapper { @override protected object domapfromcontext(dircontextoperations context) { person person = new person(); person.setusername(context.getstringattribute("uid")); person.setemail((context.getstringattribute("mail"))); person.setlname((context.getstringattribute("sn"))); person.setfname(context.getstringattribute("givenname")); person.setfname(context.getstringattribute("cn")); return person; } } }
what wrong?
it looks error, not using full dn of user, cn=kirsi fragment.
you need first query based on (username, email) find full dn of user, try bind it.
Comments
Post a Comment