Announcement Announcement Module
Collapse
No announcement yet.
how to retrieve an object with in complete path Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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>

    Comment

    Working...
    X