List of usage examples for javax.naming Context PROVIDER_URL
String PROVIDER_URL
To view the source code for javax.naming Context PROVIDER_URL.
Click Source Link
From source file:ldap.SearchUtility.java
/** * open the directory connection./*www.ja va2s .c om*/ * * @param url * @param tracing * @return * @throws javax.naming.NamingException */ private DirContext setupJNDIConnection(String url, String userDN, String password, boolean tracing) throws NamingException { /* * First, set up a large number of environment variables to sensible default valuse */ Hashtable env = new Hashtable(); // sanity check if (url == null) throw new NamingException("URL not specified in openContext()!"); // set the tracing level now, since it can't be set once the connection is open. if (tracing) env.put("com.sun.jndi.ldap.trace.ber", System.err); // echo trace to standard error output env.put("java.naming.ldap.version", "3"); // always use ldap v3 - v2 too limited env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); // use default jndi provider env.put("java.naming.ldap.deleteRDN", "false"); // usually what we want env.put(Context.REFERRAL, "ignore"); //could be: follow, ignore, throw env.put("java.naming.ldap.derefAliases", "finding"); // could be: finding, searching, etc. env.put(Context.SECURITY_AUTHENTICATION, "simple"); // 'simple' = username + password env.put(Context.SECURITY_PRINCIPAL, userDN); // add the full user dn env.put(Context.SECURITY_CREDENTIALS, password); // stupid jndi requires us to cast this to a string- env.put(Context.PROVIDER_URL, url); // the ldap url to connect to; e.g. "ldap://ca.com:389" /* * Open the actual LDAP session using the above environment variables */ DirContext newContext = new InitialDirContext(env); if (newContext == null) throw new NamingException( "Internal Error with jndi connection: No Context was returned, however no exception was reported by jndi."); return newContext; }
From source file:org.apache.ranger.ldapusersync.process.LdapDeltaUserGroupBuilder.java
private void createLdapContext() throws Throwable { Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapUrl); if (ldapUrl.startsWith("ldaps") && (config.getSSLTrustStorePath() != null && !config.getSSLTrustStorePath().trim().isEmpty())) { env.put("java.naming.ldap.factory.socket", "org.apache.ranger.ldapusersync.process.CustomSSLSocketFactory"); }/*from w w w .j a v a2s . c om*/ ldapContext = new InitialLdapContext(env, null); if (!ldapUrl.startsWith("ldaps")) { if (config.isStartTlsEnabled()) { tls = (StartTlsResponse) ldapContext.extendedOperation(new StartTlsRequest()); if (config.getSSLTrustStorePath() != null && !config.getSSLTrustStorePath().trim().isEmpty()) { tls.negotiate(CustomSSLSocketFactory.getDefault()); } else { tls.negotiate(); } LOG.info("Starting TLS session..."); } } ldapContext.addToEnvironment(Context.SECURITY_PRINCIPAL, ldapBindDn); ldapContext.addToEnvironment(Context.SECURITY_CREDENTIALS, ldapBindPassword); ldapContext.addToEnvironment(Context.SECURITY_AUTHENTICATION, ldapAuthenticationMechanism); ldapContext.addToEnvironment(Context.REFERRAL, ldapReferral); }
From source file:org.easy.ldap.LdapContextFactory.java
/** * @param orgId/*from w w w. ja va 2 s.com*/ * @return * @throws NamingException */ public DirContext createRolesContext(String orgId) throws NamingException { Hashtable<String, String> properties = getEnviroment(); properties.put(Context.PROVIDER_URL, createProviderUrl(namingFactory.createRolesDn(orgId).toString())); return createContext(properties); }
From source file:it.doqui.index.ecmengine.client.engine.EcmEngineDirectDelegateImpl.java
protected EcmEngineSearchBusinessInterface createSearchService() throws Throwable { this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] BEGIN "); Properties properties = new Properties(); /* Caricamento del file contenenti le properties su cui fare il binding */ rb = ResourceBundle.getBundle(ECMENGINE_PROPERTIES_FILE); /*/* w w w .j a va2 s . c o m*/ * Caricamento delle proprieta' su cui fare il binding all'oggetto di business delle funzionalita' * implementate per la ricerca. */ try { this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] P-Delegata di search."); this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] context factory vale : " + rb.getString(ECMENGINE_CONTEXT_FACTORY)); properties.put(Context.INITIAL_CONTEXT_FACTORY, rb.getString(ECMENGINE_CONTEXT_FACTORY)); this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] url to connect vale : " + rb.getString(ECMENGINE_URL_TO_CONNECT)); properties.put(Context.PROVIDER_URL, rb.getString(ECMENGINE_URL_TO_CONNECT)); /* Controllo che la property cluster partition sia valorizzata per capire se * sto lavorando in una configurazione in cluster oppure no */ String clusterPartition = rb.getString(ECMENGINE_CLUSTER_PARTITION); this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] clusterPartition vale : " + clusterPartition); if (clusterPartition != null && clusterPartition.length() > 0) { properties.put("jnp.partitionName", clusterPartition); this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] disable discovery vale : " + rb.getString(ECMENGINE_DISABLE_DISCOVERY)); properties.put("jnp.disableDiscovery", rb.getString(ECMENGINE_DISABLE_DISCOVERY)); } // Get an initial context InitialContext jndiContext = new InitialContext(properties); log.debug("[" + getClass().getSimpleName() + "::createSearchService] context istanziato"); // Get a reference to the Bean Object ref = jndiContext.lookup(ECMENGINE_SEARCH_JNDI_NAME); // Get a reference from this to the Bean's Home interface EcmEngineSearchHome home = (EcmEngineSearchHome) PortableRemoteObject.narrow(ref, EcmEngineSearchHome.class); // Create an Adder object from the Home interface return home.create(); } catch (Throwable e) { this.log.error("[" + getClass().getSimpleName() + "::createSearchService] " + "Impossibile l'EJB di management: " + e.getMessage()); throw e; } finally { this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] END "); } }
From source file:org.olat.ldap.LDAPLoginManagerImpl.java
/** * Connect to the LDAP server with System DN and Password Configuration: LDAP URL = olatextconfig.xml (property=ldapURL) System DN = olatextconfig.xml * (property=ldapSystemDN) System PW = olatextconfig.xml (property=ldapSystemPW) * // w w w .jav a 2s .com * @return The LDAP connection (LdapContext) or NULL if connect fails * @throws NamingException */ public LdapContext bindSystem() { // set LDAP connection attributes final Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, LDAPLoginModule.getLdapUrl()); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, LDAPLoginModule.getLdapSystemDN()); env.put(Context.SECURITY_CREDENTIALS, LDAPLoginModule.getLdapSystemPW()); // check ssl if (LDAPLoginModule.isSslEnabled()) { enableSSL(env); } try { final InitialLdapContext ctx = new InitialLdapContext(env, new Control[] {}); ctx.getConnectControls(); return ctx; } catch (final NamingException e) { logError("NamingException when trying to bind system with DN::" + LDAPLoginModule.getLdapSystemDN() + " and PW::" + LDAPLoginModule.getLdapSystemPW() + " on URL::" + LDAPLoginModule.getLdapUrl(), e); return null; } catch (final Exception e) { logError("Exception when trying to bind system with DN::" + LDAPLoginModule.getLdapSystemDN() + " and PW::" + LDAPLoginModule.getLdapSystemPW() + " on URL::" + LDAPLoginModule.getLdapUrl(), e); return null; } }
From source file:net.sf.ehcache.distribution.JNDIManualRMICacheManagerPeerProvider.java
/** * Register a new peer by looking it up in JNDI and storing * in a local cache the Context./*from w ww.ja v a 2 s. c om*/ * * @param jndiProviderUrl */ private Context registerPeerToContext(String jndiProviderUrl) { String initialContextFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY); if (LOG.isDebugEnabled()) { LOG.debug("registerPeerToContext: " + jndiProviderUrl + " " + extractProviderUrl(jndiProviderUrl) + " with " + initialContextFactory); } Hashtable hashTable = new Hashtable(1); hashTable.put(Context.PROVIDER_URL, extractProviderUrl(jndiProviderUrl)); Context initialContext = null; try { initialContext = new InitialContext(hashTable); registerPeerToContext(jndiProviderUrl, initialContext); } catch (NamingException e) { LOG.warn(jndiProviderUrl + " " + e.getMessage()); registerPeerToContext(jndiProviderUrl, null); } return initialContext; }
From source file:org.nuxeo.ecm.directory.ldap.LDAPDirectoryTestCase.java
protected void destroyRecursively(String dn, DirContext ctx, int limit) throws NamingException { if (limit == 0) { log.warn("Reach recursion limit, stopping deletion at" + dn); return;// ww w .j ava 2 s. c o m } SearchControls scts = new SearchControls(); scts.setSearchScope(SearchControls.ONELEVEL_SCOPE); String providerUrl = (String) ctx.getEnvironment().get(Context.PROVIDER_URL); NamingEnumeration<SearchResult> children = ctx.search(dn, "(objectClass=*)", scts); try { while (children.hasMore()) { SearchResult child = children.next(); String subDn = child.getName(); if (!USE_EXTERNAL_TEST_LDAP_SERVER && subDn.endsWith(providerUrl)) { subDn = subDn.substring(0, subDn.length() - providerUrl.length() - 1); } else { subDn = subDn + ',' + dn; } destroyRecursively(subDn, ctx, limit); } } catch (SizeLimitExceededException e) { log.warn("SizeLimitExceededException: trying again on partial results " + dn); if (limit == -1) { limit = 100; } destroyRecursively(dn, ctx, limit - 1); } ctx.destroySubcontext(dn); }
From source file:org.webterm.core.plugin.authentication.LdapAuthentication.java
@Override public void init() { LOG.info("Initializing LDAP authentication..."); //$NON-NLS-1$ try {// w w w . j a v a2s . c o m final ConfigurationReader config = ConfigurationReader.getInstance(); final String serverName = config.getApplicationProperty(CONFIG_SERVER_NAME); final String serverPort = config.getApplicationProperty(CONFIG_SERVER_PORT); final String bindDn = config.getApplicationProperty(CONFIG_BIND_DN); final String bindPwd = config.getApplicationProperty(CONFIG_BIND_PWD); this.baseDn = config.getApplicationProperty(CONFIG_BASE_DN); this.attrUser = config.getApplicationProperty(CONFIG_ATTR_USER); this.attrPwd = config.getApplicationProperty(CONFIG_ATTR_PWD); this.checkMethode = this.map.get(config.getApplicationProperty(CONFIG_PASSWORD_ENCODE)); if (this.checkMethode == null) { LOG.fatal("unknown method: " + config.getApplicationProperty(CONFIG_PASSWORD_ENCODE)); //$NON-NLS-1$ } final Hashtable<String, String> ldapEnv = new Hashtable<String, String>(); // NOPMD - HashTable is needed ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); //$NON-NLS-1$ ldapEnv.put(Context.PROVIDER_URL, "ldap://" + serverName + ":" + serverPort); //$NON-NLS-1$ //$NON-NLS-2$ ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple");//$NON-NLS-1$ ldapEnv.put(Context.SECURITY_PRINCIPAL, bindDn); ldapEnv.put(Context.SECURITY_CREDENTIALS, bindPwd); this.ldapContext = new InitialDirContext(ldapEnv); } catch (Exception ex) { LOG.error(ex, ex); } }
From source file:com.adaptris.core.jms.activemq.EmbeddedActiveMq.java
private StandardJndiImplementation applyCfg(StandardJndiImplementation jndi, boolean useJndiOnly, String queueName, String topicName) { jndi.getJndiParams().addKeyValuePair(new KeyValuePair(Context.PROVIDER_URL, DEF_URL_PREFIX + port)); jndi.getJndiParams().addKeyValuePair( new KeyValuePair(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getName())); jndi.getJndiParams().addKeyValuePair(new KeyValuePair("connectionFactoryNames", "connectionFactory, queueConnectionFactory, topicConnectionFactory")); jndi.getJndiParams().addKeyValuePair(new KeyValuePair("queue." + queueName, queueName)); jndi.getJndiParams().addKeyValuePair(new KeyValuePair("topic." + topicName, topicName)); if (useJndiOnly) { jndi.setUseJndiForQueues(true);/* w ww . jav a2s . c om*/ jndi.setUseJndiForTopics(true); } return jndi; }
From source file:org.settings4j.connector.JNDIConnector.java
private InitialContext getJNDIContext() throws NamingException { InitialContext initialContext; if (StringUtils.isEmpty(this.providerUrl) && StringUtils.isEmpty(this.initialContextFactory) && StringUtils.isEmpty(this.urlPkgPrefixes)) { initialContext = new InitialContext(); } else {/*from www . ja v a 2 s .c o m*/ final Properties prop = new Properties(); prop.put(Context.PROVIDER_URL, this.providerUrl); prop.put(Context.INITIAL_CONTEXT_FACTORY, this.initialContextFactory); prop.put(Context.URL_PKG_PREFIXES, this.urlPkgPrefixes); initialContext = new InitialContext(prop); } return initialContext; }