« Return to Thread: Picking attributes from LDAP

Re: Picking attributes from LDAP

by Álvaro Manso Gutiérrez :: Rate this Message:

Reply to Author | View in Thread

My problem is that the baseDN of my LDAP is dynamic and not static. This is how I've solved the problem, maybe it is not the best way to solve it, so I accept suggestions.

I created a class that implements CredentialsToPrincipalResolver, as in the class AbstractPersonDirectoryCredentialsToPrincipalResolver I have the attribute attributeRepository, I've defined it as LdadPersonAttributeDao in deployerConfigContext.xml but in the definition of the attribute I'm doing:

private IPersonAttributeDao attributeRepository = new StubPersonAttributeDao();

because if I create the object as LdapPersonAttributeDao I always have a NullPointerException because context source is null (¿?).

As I need to change the baseDN for getting my attributes from LDAP, and this attribute is in application level, I have created a temporary variable in the method resovePrincipal. I assigned the value of baseDN to this variable, then I change the value of baseDN, and in the finally assigment I assigne the value of the variable to the baseDN again.
This is a part of my code:

    public final Principal resolvePrincipal(final Credentials credentials) {
        String base =  null;
      [...]
        try{
      [...]
            if(this.attributeRepository.getClass()==org.jasig.services.persondir.support.ldap.LdapPersonAttributeDao.class){
                base =  ((LdapPersonAttributeDao)this.attributeRepository).getBaseDN();                                            ((LdapPersonAttributeDao)this.attributeRepository).setBaseDN("ou=whatever","+ base);
            } 
            attributes = this.attributeRepository.getUserAttributes(principalId);
           
        }finally{
            if (base != null){
                ((LdapPersonAttributeDao)this.attributeRepository).setBaseDN(base);
            }
        }
        [...]
  
    }


As I said, it is not beautiful but it works. Maybe the solution could be easier, but I didn't find a better one.

Cheers

_______________________________________________
cas-dev mailing list
cas-dev@...
http://tp.its.yale.edu/mailman/listinfo/cas-dev

 « Return to Thread: Picking attributes from LDAP

LightInTheBox - Buy quality products at wholesale price!