use of org.nhindirect.stagent.cert.impl.util.Lookup in project nhin-d by DirectProject.
the class LdapPublicCertUtilImpl method getDirContext.
/**
* Creates the LDAP directory context from an SRV lookup name.
* @param lookupName The SRV record name used to discover the LDAP services.
* @return And InitialDirContext object that is connected to a discoverd LDAP service.
* @throws Exception
*/
protected InitialDirContext getDirContext(String lookupName) throws Exception {
// try the configured servers first
InitialDirContext ctx = null;
Lookup lu = LookupFactory.getFactory().getInstance(new Name(lookupName), Type.SRV);
// default retries is 3, limit to 2
lu.setResolver(createExResolver(servers.toArray(new String[servers.size()]), 2, 3));
final Record[] retRecords = lu.run();
if (retRecords != null && retRecords.length > 0) {
String ldapURL = createLDAPUrl(retRecords);
final Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, LDAP_FACTORY);
env.put(Context.PROVIDER_URL, ldapURL);
env.put(Context.SECURITY_AUTHENTICATION, "none");
env.put(LDAP_TIMEOUT, DEFAULT_LDAP_TIMEOUT);
env.put(LDAP_CONNECT_TIMEOUT, DEFAULT_LDAP_CONNECT_TIMEOUT);
env.put("java.naming.ldap.attributes.binary", "userCertificate, usercertificate");
ctx = new InitialDirContext(env);
}
return ctx;
}