[cas-dev] Picking attributes from LDAP
Álvaro Manso Gutiérrez
alvaro.manso.gutierrez at gmail.com
Wed Apr 16 06:26:24 EDT 2008
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://tp.its.yale.edu/pipermail/cas-dev/attachments/20080416/753987cb/attachment.html
More information about the cas-dev
mailing list