use of javax.naming.InitialContext in project hibernate-orm by hibernate.
the class JndiServiceImpl method bind.
@Override
public void bind(String jndiName, Object value) {
final InitialContext initialContext = buildInitialContext();
final Name name = parseName(jndiName, initialContext);
try {
bind(name, value, initialContext);
} finally {
cleanUp(initialContext);
}
}
use of javax.naming.InitialContext in project hibernate-orm by hibernate.
the class JndiServiceImpl method addListener.
@Override
public void addListener(String jndiName, NamespaceChangeListener listener) {
final InitialContext initialContext = buildInitialContext();
final Name name = parseName(jndiName, initialContext);
try {
((EventContext) initialContext).addNamingListener(name, EventContext.OBJECT_SCOPE, listener);
} catch (Exception e) {
throw new JndiException("Unable to bind listener to namespace [" + name + "]", e);
} finally {
cleanUp(initialContext);
}
}
use of javax.naming.InitialContext in project hibernate-orm by hibernate.
the class JndiServiceImpl method locate.
@Override
public Object locate(String jndiName) {
final InitialContext initialContext = buildInitialContext();
final Name name = parseName(jndiName, initialContext);
try {
return initialContext.lookup(name);
} catch (NamingException e) {
throw new JndiException("Unable to lookup JNDI name [" + jndiName + "]", e);
} finally {
cleanUp(initialContext);
}
}
use of javax.naming.InitialContext in project hibernate-orm by hibernate.
the class JndiServiceImpl method unbind.
@Override
public void unbind(String jndiName) {
final InitialContext initialContext = buildInitialContext();
final Name name = parseName(jndiName, initialContext);
try {
initialContext.unbind(name);
} catch (Exception e) {
throw new JndiException("Error performing unbind [" + name + "]", e);
} finally {
cleanUp(initialContext);
}
}
use of javax.naming.InitialContext in project nhin-d by DirectProject.
the class LDAPResearchTest method testLdapSearch.
@SuppressWarnings("unchecked")
public void testLdapSearch() throws Exception {
CertCacheFactory.getInstance().flushAll();
int port = configuration.getLdapPort();
String url = "ldap://localhost:" + port + "/" + "cn=lookupTest";
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
env.put(Context.SECURITY_CREDENTIALS, "secret");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
InitialContext initialContext = new InitialContext(env);
assertNotNull(initialContext);
DirContext dirContext = (DirContext) initialContext.lookup("");
Attributes attributes = dirContext.getAttributes("");
assertNotNull(attributes);
NamingEnumeration<Attribute> namingEnum = (NamingEnumeration<Attribute>) attributes.getAll();
while (namingEnum.hasMoreElements()) {
Attribute attr = namingEnum.nextElement();
System.out.println("Name: " + attr.getID() + "\r\nValue: " + attr.get() + "\r\n\r\n");
}
//Set<SearchResult> results = searchDNs( "(email=gm2552@cerner.com)", "", "ou=privKeys, ou=cerner, ou=com",
// SearchControls.SUBTREE_SCOPE , dirContext);
LdapStoreConfiguration ldapStoreConfiguration = new LdapStoreConfiguration(new String[] { url }, "", "email", "privKeyStore", "X509");
LdapCertificateStoreProvider provider = new LdapCertificateStoreProvider(ldapStoreConfiguration, null, null);
LDAPCertificateStore certificateResolver = (LDAPCertificateStore) provider.get();
Collection<X509Certificate> certs = certificateResolver.getCertificates("gm2552@cerner.com");
/*LdapEnvironment ldapEnvironment = new LdapEnvironment(env, "privKeyStore", "", "email");
LdapCertUtilImpl ldapcertUtilImpl = new LdapCertUtilImpl(ldapEnvironment, "", "X.509");
LDAPCertificateStore ldapCertStore = new LDAPCertificateStore(ldapcertUtilImpl, new KeyStoreCertificateStore(), null);
Collection<X509Certificate> certs = ldapCertStore.getCertificates("gm2552@cerner.com");
*/
assertEquals(1, certs.size());
X509Certificate cert = certs.iterator().next();
assertFalse(cert instanceof X509CertificateEx);
assertTrue(cert.getSubjectX500Principal().toString().contains("bob@nhind.hsgincubator.com"));
}
Aggregations