Announcement Announcement Module
Collapse
No announcement yet.
spring ldap help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring ldap help

    Hi, I´m trying the new spring ldap jar 1.1.2 in a simple console application, but when I execute the program the list method doesn´t return any result, could you help me?, this is the config...thanks.

    application-context.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>

    <bean id="contextSource" class="org.springframework.ldap.support.LdapContex tSource">
    <property name="url">
    <value>ldap://someurl:389</value>
    </property>
    <property name="base">
    <value>dc=intranet,dc=value</value>
    </property>
    <property name="userName"> <value>cn=value,cn=value,dc=intranet,dc=value</value>
    </property>
    <property name="password">
    <value>value</value>
    </property>
    </bean>

    <bean id="ldapTemplate" class="org.springframework.ldap.LdapTemplate">
    <constructor-arg>
    <ref bean="contextSource"/>
    </constructor-arg>
    </bean>

    <bean id="authenticationLdapDAOTarget" class="ldap.AuthenticationLdapDAOImpl" singleton="true">
    <property name="ldapTemplate">
    <ref bean="ldapTemplate" />
    </property>
    </bean>

    </beans>

    AuthenticationLdapDAO:

    import java.util.List;

    import javax.naming.NamingException;

    public interface AuthenticationLdapDAO {
    public List getAllPersonNames() throws NamingException;
    }

    AuthenticationLdapDAOImpl:

    import java.util.List;

    import javax.naming.NamingException;

    import org.springframework.ldap.AttributesMapper;
    import org.springframework.ldap.LdapTemplate;

    public class AuthenticationLdapDAOImpl implements AuthenticationLdapDAO {

    private LdapTemplate ldapTemplate;

    public void setLdapTemplate(LdapTemplate ldapTemplate) {
    this.ldapTemplate = ldapTemplate;
    }


    public List getAllPersonNames() throws NamingException {
    return ldapTemplate.list("dc=intranet,dc=value");

    }

    main

    import java.util.Iterator;

    import javax.naming.NamingException;

    import factoria.Factoria;

    public class Principal {
    /**
    * @param args
    */
    public static void main(String[] args) {

    AuthenticationLdapDAO auth=(AuthenticationLdapDAO)Factoria.getBean("auth enticationLdapDAOTarget");

    try {
    Iterator it=(Iterator)auth.getAllPersonNames().iterator();
    while(it.hasNext()){
    System.out.print(it.next());
    }
    } catch (NamingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }


    }

    }

  • #2
    When specifying a base path to your ContextSource that path should be excluded in all operations.
    Try:
    Code:
    ldapTemplate.list("");

    Comment


    • #3
      Thank you, it works.

      Cheers

      Comment

      Working...
      X