SPENAPOLO
Jun 1st, 2007, 12:07 PM
:confused: 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.PropertyP laceholderConfigurer">
<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.LdapContextS ource">
<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.dao.LdapA uthenticationDAOImpl">
<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();
}
}
BEANS
------
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyP laceholderConfigurer">
<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.LdapContextS ource">
<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.dao.LdapA uthenticationDAOImpl">
<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();
}
}