Search in sources :

Example 56 with InitialContext

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);
    }
}
Also used : InitialContext(javax.naming.InitialContext) Name(javax.naming.Name)

Example 57 with 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);
    }
}
Also used : EventContext(javax.naming.event.EventContext) JndiException(org.hibernate.engine.jndi.JndiException) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) JndiException(org.hibernate.engine.jndi.JndiException) JndiNameException(org.hibernate.engine.jndi.JndiNameException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) Name(javax.naming.Name)

Example 58 with 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);
    }
}
Also used : NamingException(javax.naming.NamingException) JndiException(org.hibernate.engine.jndi.JndiException) InitialContext(javax.naming.InitialContext) Name(javax.naming.Name)

Example 59 with 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);
    }
}
Also used : JndiException(org.hibernate.engine.jndi.JndiException) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) JndiException(org.hibernate.engine.jndi.JndiException) JndiNameException(org.hibernate.engine.jndi.JndiNameException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) Name(javax.naming.Name)

Example 60 with 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"));
}
Also used : LdapStoreConfiguration(org.nhindirect.stagent.cert.impl.LdapStoreConfiguration) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) Hashtable(java.util.Hashtable) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) NamingEnumeration(javax.naming.NamingEnumeration) DirContext(javax.naming.directory.DirContext) InitialContext(javax.naming.InitialContext) X509Certificate(java.security.cert.X509Certificate) X509CertificateEx(org.nhindirect.stagent.cert.X509CertificateEx) LDAPCertificateStore(org.nhindirect.stagent.cert.impl.LDAPCertificateStore) LdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider)

Aggregations

InitialContext (javax.naming.InitialContext)1068 Test (org.junit.Test)325 EJBException (javax.ejb.EJBException)228 Properties (java.util.Properties)213 Context (javax.naming.Context)194 RemoteException (java.rmi.RemoteException)173 TestFailureException (org.apache.openejb.test.TestFailureException)172 NamingException (javax.naming.NamingException)168 AssertionFailedError (junit.framework.AssertionFailedError)168 JMSException (javax.jms.JMSException)167 RemoveException (javax.ejb.RemoveException)66 CreateException (javax.ejb.CreateException)57 DataSource (javax.sql.DataSource)55 Hashtable (java.util.Hashtable)54 Assembler (org.apache.openejb.assembler.classic.Assembler)47 EjbJar (org.apache.openejb.jee.EjbJar)41 NameNotFoundException (javax.naming.NameNotFoundException)40 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)38 Connection (java.sql.Connection)37 StatelessBean (org.apache.openejb.jee.StatelessBean)30