LDAP Email Plugin doesn't resolve email

View: New views
1 Messages — Rating Filter:   Alert me  

LDAP Email Plugin doesn't resolve email

by Krieg, Adam :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

LDAP Email Plugin doesn't resolve email

I'm having issues resolving an email address from a Kerberos id. I'm currently using CruiseControl which does work fine. The way Hudson tries to resolve the email address looks wrong to me. I've distilled the differences in a test case, one which shows how CruiseControl resolves the email address and the other which demonstrates how Hudson resolves the email address. CruiseControl uses an attribute search, which from what I've read:

http://www.javaworld.com/javaworld/jw-03-2000/jw-0324-ldap.html?page=4 looks like the right way to do it. Hudson attempts to getAttributes from the root DN, which I don't think can search hierarchically.  Is there any reason why it doesn't use the search method for InitialDirContext?

Thanks,
Adam
import java.util.Hashtable;
import javax.naming.NamingEnumeration;
import javax.naming.directory.Attributes;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import junit.framework.TestCase;
/**
* Unit test for LdapTest
*/
public class LdapTest extends TestCase {
private static final String LDAP_URL = "ldap://ourldap.foo.com:389";
private static final String LDAP_CONTEXT = "com.sun.jndi.ldap.LdapCtxFactory";
private static final String baseDN="ou=People,o=foo.com";
private static final String searchAttribute="kerberosId";
private static final String searchValue="joeblow";
private static final String EMAIL_ATTRIBUTE = "mail";
private static final String EMAIL_ADDRESS = "JoeBlow@...";
/**
* This is how Hudson resolves email from kerberos (works)
* @throws Exception if an error occurs
*/
public void testHudson() throws Exception {
final Hashtable<String,String> env = new Hashtable<String,String>();
env.put("java.naming.provider.url", LDAP_URL);
env.put("java.naming.factory.initial", LDAP_CONTEXT);
final InitialDirContext ctx = new InitialDirContext(env);
final String name = baseDN+","+searchAttribute+"="+searchValue;
final Attributes foo = ctx.getAttributes(name, new String[]{EMAIL_ATTRIBUTE});
assertEquals(EMAIL_ADDRESS,foo.get(EMAIL_ATTRIBUTE).get());
}
/**
* This is how CruiseControl resolves email from kerberos (works)
* @throws Exception if an error occurs
*/
public void testCruiseControl() throws Exception {
final Hashtable<String,String> env = new Hashtable<String,String>();
env.put("java.naming.provider.url", LDAP_URL);
env.put("java.naming.factory.initial", LDAP_CONTEXT);
final InitialDirContext ctx = new InitialDirContext(env);
final SearchControls constraints1 = new SearchControls();
constraints1.setSearchScope(2);
constraints1.setCountLimit(0L);
constraints1.setTimeLimit(0);
constraints1.setReturningAttributes(new String[]{EMAIL_ATTRIBUTE});
final NamingEnumeration<SearchResult> foo = ctx.search(baseDN, searchAttribute+"="+searchValue, constraints1);
while(foo.hasMore()){
assertEquals(EMAIL_ADDRESS,foo.next().getAttributes().get(EMAIL_ATTRIBUTE).get());
}
}
}


LightInTheBox - Buy quality products at wholesale price!