Announcement Announcement Module
Collapse
No announcement yet.
Issue with lookup resulting in a Person object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with lookup resulting in a Person object

    Good day,

    I've been able to do what I want using dynamic filters but I'm not sure why can't make it work with the DN-based lookup (
    Code:
    return (Person) ldapTemplate.lookup(dn, new PersonContextMapper());
    )

    My beans look like this...
    Code:
    	<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
    		<property name="url" value="ldap://ldap.some.com:389" />
    	</bean>
    
    	<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
    		<constructor-arg ref="contextSource" />
    	</bean>
    
    	<bean id="personDaoImpl" class="com.some.dao.impl.LdapPersonDaoImpl">
    		<property name="ldapTemplate" ref="ldapTemplate" />
    	</bean>
    And the error I get is this...
    Code:
    Nov 13, 2012 5:29:16 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1113708: startup date [Tue Nov 13 17:29:16 CST 2012]; root of context hierarchy
    Nov 13, 2012 5:29:16 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
    Nov 13, 2012 5:29:16 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1db4f6f: defining beans [contextSource,ldapTemplate,personDaoImpl]; root of factory hierarchy
    Nov 13, 2012 5:29:16 PM org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet
    INFO: Property 'userDn' not set - anonymous context will be used for read-write operations
    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 'o=some.com,ou=People,uid=[email protected]'
    	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:876)
    	at com.some.dao.impl.LdapPersonDaoImpl.findBySimplifiedEmailAddress(LdapPersonDaoImpl.java:43)
    	at LDAPTest.main(LDAPTest.java:26)
    Caused by: javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'o=some.com,ou=People,uid=[email protected]'
    	at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3092)
    	at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3013)
    	at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2820)
    	at com.sun.jndi.ldap.LdapCtx.c_lookup(LdapCtx.java:1014)
    	at com.sun.jndi.toolkit.ctx.ComponentContext.p_lookup(ComponentContext.java:526)
    	at com.sun.jndi.toolkit.ctx.PartialCompositeContext.lookup(PartialCompositeContext.java:159)
    	at javax.naming.InitialContext.lookup(InitialContext.java:396)
    	at org.springframework.ldap.core.LdapTemplate$13.executeWithContext(LdapTemplate.java:878)
    	at org.springframework.ldap.core.LdapTemplate.executeWithContext(LdapTemplate.java:807)
    	... 4 more
    I'm using anonymous access to the LDAP (just need to read data) and constructing the DN like this...
    Code:
    	private DistinguishedName buildDn(String uid, String ou, String o) {
    		DistinguishedName dn = new DistinguishedName();	
    		dn.add("uid", uid);
    		dn.add("ou", ou);
    		dn.add("o", o);
    		
    		return dn;
    	}
    	
    	private DistinguishedName buildDn(Person person) {
    		return buildDn(person.getMail(), person.getOu(), person.getO());
    	}
    I'm using a
    Code:
    ContextMapper
    following the article sample in the spring-ldap distribution.

    Can you spot any obvious issues?

    Thanks in advance!
    Last edited by carloscajina; Nov 13th, 2012, 06:19 PM.

  • #2
    FIXED

    it was just a matter of building the DN correctly (seems order of
    Code:
    dn.add(...
    is key) and then
    Code:
     return (Person) ldapTemplate.lookup(dn.toUrl(), getContextMapper());

    Comment

    Working...
    X