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

  • Problem with List getAllPersonNames()

    My problem is the personal function getAllPersonNames(), in the traditional form is ok, but with Spring LDAP KO!!

    BEANS
    ------
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:com/bluestarenergy/provisioning/ldap.properties</value>
    </list>
    </property>
    <property name="ignoreResourceNotFound"><value>true</value></property>
    </bean>

    <bean id="contextSource" class="org.springframework.ldap.core.support.LdapC ontextSource">
    <property name="url">
    <value>${ldap.connection.url}</value>
    </property>
    <property name="base">
    <value>${ldap.connection.base}</value>
    </property>
    </bean>

    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate" >
    <constructor-arg ref="contextSource" />
    </bean>
    <bean id="ldapAuthenticationDAO" class="com.bluestarenergy.provisioning.security.da o.LdapAuthenticationDAOImpl">
    <property name="ldapTemplate" ref ="ldapTemplate" />
    </bean>



    CLASS
    ------
    public class LdapAuthenticationDAOImpl implements LdapAuthenticationDAO {

    private LdapTemplate ldapTemplate;

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


    public List getAllPersonNames() {
    return ldapTemplate.search(
    "", "(objectclass=person)",
    new AttributesMapper() {
    public Object mapFromAttributes(Attributes attrs)
    throws NamingException {
    return attrs.get("cn").get();
    }
    });
    }
    }

    TEST
    -----
    public void testgetAllPersonNames(){
    try {
    Iterator it=(Iterator)ldapAuthenticationDAO.getAllPersonNam es().iterator();
    System.out.println("************Resultados testgetAllPersonNames**************");
    while(it.hasNext()){
    System.out.println(">>>LDAPOPEN>>>>> "+it.next());
    }
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
    Last edited by SPENAPOLO; Jun 1st, 2007, 12:17 PM.

  • #2
    It would be helpful to see the stacktrace and the values of url and base in your ldap.properties file. Also, please put the [code][/code] tag around your code or configuration.

    Comment


    • #3
      Hi Ulsa, thank for your help. sorry for my english.

      The properties file, in the traditional form don't problem with the file.
      Code:
      #ldap
      ldap.connection.url=ldap://0.0.0.0:389
      ldap.connection.base=dc=bluestarenergy,dc=com
      ldap.connection.username=cn=Manager
      ldap.connection.password=secret
      I have a debug page in eclipse console
      Code:
      INFO  2007-06-01 18:08:57,305 [main] com.bluestarenergy.provisioning.eisaccess.dao.LdapAuthenticationDAOimplTest: Began transaction (1): transaction manager [[email protected]0998]; default rollback = true
      ************INICIO testgetAllPersonNames SPING LDAP**************
      DEBUG 2007-06-01 18:08:57,305 [main] org.springframework.ldap.core.support.LdapContextSource: Principal: ''
      DEBUG 2007-06-01 18:08:57,305 [main] org.springframework.ldap.core.support.LdapContextSource: Got Ldap context on server 'ldap://0.0.0.0:389/dc=bluestarenergy,dc=com'
      ************Resultados testgetAllPersonNames**************
      DEBUG 2007-06-01 18:08:57,305 [main] org.springframework.orm.hibernate3.HibernateTransactionManager: Triggering beforeCompletion synchronization
      DEBUG 2007-06-01 18:08:57,305 [main] org.springframework.orm.hibernate3.HibernateTransactionManager: Initiating transaction rollback
      DEBUG 2007-06-01 18:08:57,305 [main] org.springframework.orm.hibernate3.HibernateTransactionManager: Rolling back Hibernate transaction on Session [org.hibernate.impl.SessionImpl@194df96]
      I think the problem is
      Code:
      DEBUG 2007-06-01 18:08:57,305 [main] org.springframework.ldap.core.support.LdapContextSource: Principal: ''
      but, where i configure that?
      Last edited by SPENAPOLO; Jun 4th, 2007, 10:30 AM.

      Comment


      • #4
        Right, you're not setting the username and password properties on your ContextSource, that might cause some problems.

        Comment


        • #5
          Hi Rasky. thank for your help.

          I put the userName and password in the contextSource
          Code:
          <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
          	<property name="url">
          		<value>${ldap.connection.url}</value>
          	</property>
          	<property name="base">
          		<value>${ldap.connection.base}</value>
          	</property>
           	<property name="userName">
           		<value>${ldap.connection.username}</value>
           	</property>
          	<property name="password">
          		<value>${ldap.connection.password}</value>
          	</property>
          </bean>
          but, my problem is now......
          Code:
          INFO  2007-06-04 11:33:20,468 [main] com.bluestarenergy.provisioning.eisaccess.dao.LdapAuthenticationDAOimplTest: Began transaction (1): transaction manager [[email protected]abbb]; default rollback = true
          ************INICIO testgetDatos() SPING LDAP**************
          DEBUG 2007-06-04 11:33:20,468 [main] org.springframework.ldap.core.support.LdapContextSource: Principal: 'cn=Manager'
          org.springframework.ldap.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]; nested exception is javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]
          Caused by: javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]
          	at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
          	at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
          	at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
          I don't understand, my userName and password it's correct

          mmmmm, in the traditional form :
          Code:
          Hashtable env = new Hashtable();
          env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL, "ldap://localhost:389/dc=mycompany,dc=com");
          DirContext ctx;
          in Spring-LDAP?????

          Comment


          • #6
            Well, the error message states that the credentials are invalid, so I guess that's your problem. Either the user DN or the password is incorrect.

            Note that the dn supplied to the userName property of ContextSource (cn=Manager in your case) needs to have the full DN of the user - the base context is not applied to this. That means that if your manager is located at cn=Manager, dc=mycompany, dc=com you need to specify that full DN to the userName property, ev.en though you are setting the base context to dc=mycompany, dc=com.

            Then again, from your test code with plain JNDI I get the impression that you don't supply the security.principal and security.credential properties in that code. Is that correct? In that case you should try setting the ContextSource in anonymous mode by setting the 'anonymousReadOnly' property of your ContextSource to true.

            Comment


            • #7
              I think depending on how your connection is setup or how your Active Directory is setup, you may need to provide more information.

              For example, in my organization, I have to pass a username of [email protected]. In my last organization I had to pass DOMAIN\username.

              Try those.

              Comment

              Working...
              X