Example usage for javax.naming Context INITIAL_CONTEXT_FACTORY

List of usage examples for javax.naming Context INITIAL_CONTEXT_FACTORY

Introduction

In this page you can find the example usage for javax.naming Context INITIAL_CONTEXT_FACTORY.

Prototype

String INITIAL_CONTEXT_FACTORY

To view the source code for javax.naming Context INITIAL_CONTEXT_FACTORY.

Click Source Link

Document

Constant that holds the name of the environment property for specifying the initial context factory to use.

Usage

From source file:org.wso2.carbon.connector.integration.test.ldap.LdapConnectorIntegrationTest.java

public void deleteSampleEntry() throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

    env.put(Context.PROVIDER_URL, providerUrl);
    env.put(Context.SECURITY_PRINCIPAL, securityPrincipal);
    env.put(Context.SECURITY_CREDENTIALS, securityCredentials);

    DirContext ctx = new InitialDirContext(env);
    String dn = "uid=" + testUserId + "," + userBase;
    ctx.destroySubcontext(dn);//  w  w w  . ja  va 2s . co m
}

From source file:org.rhq.enterprise.server.resource.group.LdapGroupManagerBean.java

/**
 * Load a default set of properties to use when connecting to the LDAP server. If basic authentication is needed,
 * the caller must set Context.SECURITY_PRINCIPAL, Context.SECURITY_CREDENTIALS and Context.SECURITY_AUTHENTICATION
 * appropriately./*from  w ww .  ja va2 s  .  c o  m*/
 *
 * @return properties that are to be used when connecting to LDAP server
 */
private Properties getProperties(Properties systemConfig) {
    Properties env = new Properties(systemConfig);
    // Set our default factory name if one is not given
    String factoryName = env.getProperty(RHQConstants.LDAPFactory);
    env.setProperty(Context.INITIAL_CONTEXT_FACTORY, factoryName);

    // Setup SSL if requested
    String value = env.getProperty(SystemSetting.USE_SSL_FOR_LDAP.getInternalName());
    boolean ldapSsl = "ssl".equalsIgnoreCase(value);
    if (ldapSsl) {
        String ldapSocketFactory = env.getProperty("java.naming.ldap.factory.socket");
        if (ldapSocketFactory == null) {
            env.put("java.naming.ldap.factory.socket", UntrustedSSLSocketFactory.class.getName());
        }
        env.put(Context.SECURITY_PROTOCOL, "ssl");
    }

    // Set the LDAP url
    String providerUrl = env.getProperty(RHQConstants.LDAPUrl);
    if (providerUrl == null) {
        int port = (ldapSsl) ? 636 : 389;
        providerUrl = "ldap://localhost:" + port;
    }

    env.setProperty(Context.PROVIDER_URL, providerUrl);

    // Follow referrals automatically
    env.setProperty(Context.REFERRAL, "ignore"); //BZ:582471- active directory query change

    return env;
}

From source file:org.mule.transport.ldap.util.DSManager.java

protected void setContexts(final String user, final String passwd) throws Exception {
    final Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(DirectoryService.JNDI_KEY, directoryService);
    env.put(Context.SECURITY_PRINCIPAL, user);
    env.put(Context.SECURITY_CREDENTIALS, passwd);
    env.put(Context.SECURITY_AUTHENTICATION, "none");
    env.put(Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName());
    setContexts(env);/*from  w  w  w  .ja v  a2s  .c  o  m*/
}

From source file:com.adaptris.core.SharedComponentListTest.java

public void testBindJNDI() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(getName());/*from   w w  w .  j a v a  2  s .  c om*/
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, JndiContextFactory.class.getName());
    InitialContext initialContext = new InitialContext(env);

    try {
        start(adapter);
        adapter.getSharedComponents().addConnection(new NullConnection(getName()));
        adapter.getSharedComponents().bindJNDI(getName());
        NullConnection lookedup = (NullConnection) initialContext.lookup("adapter:comp/env/" + getName());
        assertNotNull(lookedup);
        assertEquals(getName(), lookedup.getUniqueId());
        adapter.getSharedComponents().bindJNDI("ShouldGetIgnored");
    } finally {
        stop(adapter);
    }
}

From source file:com.adaptris.core.SharedComponentListTest.java

public void testBindJNDIService() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(getName());//from   ww  w  . j  a  v  a2 s. c  om
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, JndiContextFactory.class.getName());
    InitialContext initialContext = new InitialContext(env);

    try {
        start(adapter);

        MockService mockService = new MockService();
        adapter.getSharedComponents().addService(mockService);
        adapter.getSharedComponents().bindJNDI(mockService.getUniqueId());
        Service lookedup = (Service) initialContext.lookup("adapter:comp/env/" + mockService.getUniqueId());
        assertNotNull(lookedup);
        assertEquals(mockService.getUniqueId(), lookedup.getUniqueId());
        adapter.getSharedComponents().bindJNDI("ShouldGetIgnored");
    } finally {
        stop(adapter);
    }
}

From source file:org.apache.synapse.transport.jms.JMSConnectionFactory.java

/**
 * Is this connection factory referring to the same underlying connection factory passed in
 *
 * @param o a JMSOutTransport object which specifies a connection factory
 * @return true if this instance could be substituted for the out-transport
 *///from w ww.j av a 2  s  . c  om
public boolean equals(Object o) {
    if (o instanceof JMSOutTransportInfo) {
        JMSOutTransportInfo trpInfo = (JMSOutTransportInfo) o;

        Map trpProps = trpInfo.getProperties();
        if (equals(trpProps.get(JMSConstants.CONFAC_JNDI_NAME_PARAM),
                jndiProperties.get(JMSConstants.CONFAC_JNDI_NAME_PARAM))
                && equals(trpProps.get(Context.INITIAL_CONTEXT_FACTORY),
                        jndiProperties.get(Context.INITIAL_CONTEXT_FACTORY))
                && equals(trpProps.get(Context.PROVIDER_URL), jndiProperties.get(Context.PROVIDER_URL))
                && equals(trpProps.get(Context.SECURITY_PRINCIPAL),
                        jndiProperties.get(Context.SECURITY_PRINCIPAL))
                && equals(trpProps.get(Context.SECURITY_CREDENTIALS),
                        jndiProperties.get(Context.SECURITY_CREDENTIALS))) {
            return true;
        }
    }
    return false;
}

From source file:com.ibm.soatf.component.jms.JmsComponent.java

private InitialContext getInitialContext(String providerUrl, String userName, String password)
        throws NamingException {
    Hashtable<String, String> ht = new Hashtable<String, String>();

    ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    ht.put(Context.PROVIDER_URL, providerUrl);
    ht.put(Context.SECURITY_PRINCIPAL, userName);
    ht.put(Context.SECURITY_CREDENTIALS, password);

    return new InitialContext(ht);
}

From source file:de.sub.goobi.helper.ldap.Ldap.java

private Hashtable<String, String> getLdapConnectionSettings() {
    // Set up environment for creating initial context
    Hashtable<String, String> env = new Hashtable<>(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, ConfigCore.getParameter("ldap_url"));
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    /* wenn die Verbindung ber ssl laufen soll */
    if (ConfigCore.getBooleanParameter("ldap_sslconnection")) {
        String keystorepath = ConfigCore.getParameter("ldap_keystore");
        String keystorepasswd = ConfigCore.getParameter("ldap_keystore_password");

        // add all necessary certificates first
        loadCertificates(keystorepath, keystorepasswd);

        // set properties, so that the current keystore is used for SSL
        System.setProperty("javax.net.ssl.keyStore", keystorepath);
        System.setProperty("javax.net.ssl.trustStore", keystorepath);
        System.setProperty("javax.net.ssl.keyStorePassword", keystorepasswd);
        env.put(Context.SECURITY_PROTOCOL, "ssl");
    }//  w  ww  . j ava 2s. c  o  m
    return env;
}

From source file:com.adaptris.core.SharedComponentListTest.java

public void testBindJNDITransactionManager() throws Exception {
    Adapter adapter = new Adapter();
    adapter.setUniqueId(getName());//from ww w .  j a v a2s.c  o  m
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, JndiContextFactory.class.getName());
    InitialContext initialContext = new InitialContext(env);

    try {
        start(adapter);
        adapter.getSharedComponents().setTransactionManager(new DummyTransactionManager(getName(), null));
        adapter.getSharedComponents().bindJNDI(getName());
        TransactionManager lookedup = (TransactionManager) initialContext
                .lookup("adapter:comp/env/" + getName());
        assertNotNull(lookedup);
        assertEquals(getName(), lookedup.getUniqueId());
        adapter.getSharedComponents().bindJNDI("ShouldGetIgnored");
    } finally {
        stop(adapter);
    }
}