Search in sources :

Example 1 with Lookup

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;
}
Also used : Hashtable(java.util.Hashtable) Lookup(org.nhindirect.stagent.cert.impl.util.Lookup) Record(org.xbill.DNS.Record) SRVRecord(org.xbill.DNS.SRVRecord) InitialDirContext(javax.naming.directory.InitialDirContext) Name(org.xbill.DNS.Name)

Aggregations

Hashtable (java.util.Hashtable)1 InitialDirContext (javax.naming.directory.InitialDirContext)1 Lookup (org.nhindirect.stagent.cert.impl.util.Lookup)1 Name (org.xbill.DNS.Name)1 Record (org.xbill.DNS.Record)1 SRVRecord (org.xbill.DNS.SRVRecord)1