Announcement Announcement Module
Collapse
No announcement yet.
ldapTemplate.search() Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ldapTemplate.search()

    Hi,

    I am using spring-ldap-1.3.0.
    I am trying to find entries in an OpenDS ldap server.
    I referred the following method from Spring ldap api
    public List search(Name base,
    String filter,
    ContextMapper mapper)


    The code snippet I use is as follows

    Code:
       PersonLP4LDAP person = null;
            try
            {
                List<PersonLP4LDAP> people = ldapTemplateLP4.search("", "uid=328996863458585, ou=xxx, o=xxx, o=cp" ,
                        new PersonContextMapper());
                if (people.size() > 0)
                {
                    person = (PersonLP4LDAP) people.iterator().next();
                }
               
            
            return person;
    The Spring configuration file is as follows
    Code:
    <bean id="contextSourceLP4"
            class="org.springframework.ldap.core.support.LdapContextSource">
            <property name="url" value="ldap://tsetsserver:389" />
            <property name="base" value="o=cp" />
            <property name="userDn" value="Directory Manager" />
            <property name="password" value="pswd" />
        </bean>
        <bean id="ldapTemplateLP4" class="org.springframework.ldap.core.LdapTemplate">
            <constructor-arg ref="contextSourceLP4" />
        </bean>
    with this set up Ia m getting the org.springframework.ldap.NameNotFoundException: [LDAP: error code 32 - No Such Object]

    Can you please suggest me wht is the exact parameter I need to pass to the search method?
    I need to get the uid entries from the LDAP.I have passed the entire root to search method.I have not passed the basedn as parameter to search method.
    Kindly help me solve the problem ASAP

  • #2
    You have specified a base in your configuration.

    Code:
    <property name="base" value="o=cp" />
    That means you should not use that part in your search base. Also, you have mixed up the search base and the filter, I think. If you want to search for all occurrences of "uid=328996863458585", starting from "ou=xxx, o=xxx", then it should look something like this:

    Code:
    List<PersonLP4LDAP> people = ldapTemplateLP4.search("ou=xxx, o=xxx", "(uid=328996863458585)", mapper);
    If you know the complete path (distinguished name) to the entry, you should instead perform a lookup:

    Code:
    PersonLP4LDAP person = ldapTemplateLP4.lookup("uid=328996863458585, ou=xxx, o=xxx", mapper);
    Note that the lookup path as well as the search base should not contain the configured base.
    Last edited by ulsa; May 5th, 2010, 10:09 AM. Reason: Forgot some code tags

    Comment


    • #3
      Thank you very much for your suggestion.
      It worked.

      Comment

      Working...
      X