Results 1 to 3 of 3

Thread: ldapTemplate.search()

  1. #1
    Join Date
    Apr 2010
    Posts
    9

    Default 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. #2
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    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 at 10:09 AM. Reason: Forgot some code tags
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

  3. #3
    Join Date
    Apr 2010
    Posts
    9

    Smile

    Thank you very much for your suggestion.
    It worked.

Posting Permissions

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