Results 1 to 2 of 2

Thread: how to retrieve an object with in complete path

  1. #1
    Join Date
    Feb 2009
    Location
    France
    Posts
    22

    Red face how to retrieve an object with in complete path

    Hi,

    I'm looking for a solution to retrieve an object with the fully qualified name.
    I've some complete dn : uid=userid,ou=People,dc=mycompany,dc=eu
    The base dn is dc=mycompany,dc=eu

    If use the ldapTemplate.lookup(dn, myAttributeMapper) I've got a "NameNotFoundException[LDAP: error code 32 - No Such Object]" which is (afaik) normal as I'm looking into the basedn context.

    If I delete the base dn, the lookup works well...

    Is there any better solution than substring the dn to remove base dn ?

    Regards

  2. #2
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    Yes, there is a better way:

    1. Define a BaseLdapPathBeanPostProcessor in your configuration file.
    2. Make sure your bean implements BaseLdapPathAware.


    Code:
    <bean class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
    It's quite simple. The post-processor looks for beans implementing BaseLdapPathAware. If it finds any, it injects them with the base path. You can then use that base path in your bean.

    Let's say you have a class called MyCleverClass. Make it implement BaseLdapPathAware. You will automatically have the base DN available for you. When you need to remove the base DN from whatever full DNs you are working with, use the DistinguishedName.removeFirst method.

    Code:
    public class MyCleverClass implements BaseLdapPathAware {
       ...
       private DistinguishedName baseDn;
       public void setBaseLdapPath(DistinguishedName baseLdapPath) {
          this.baseDn = baseLdapPath;
       }
    
       public SomeResult myLookupMethod() {
          DistinguishedName dn = new DistinguishedName("uid=userid,ou=People,dc=mycompany,dc=eu");
          dn.removeFirst(baseDn);
          return ldapTemplate.lookup(dn, myAttributeMapper);
       }
    }
    Define your bean as usual:

    Code:
    <bean class="com.example.MyCleverClass">
       <property name="ldapTemplate" ref="ldapTemplate" />
    </bean>
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •