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:org.apache.synapse.message.store.impl.jdbc.util.JDBCConfiguration.java
/** * Reading lookup information for existing datasource * * @param parameters - parameters given in configuration *///from ww w. j a v a 2 s . com private void readLookupConfig(Map<String, Object> parameters) { String dataSourceName = (String) parameters.get(JDBCMessageStoreConstants.JDBC_DSNAME); this.setDataSourceName(dataSourceName); if (parameters.get(JDBCMessageStoreConstants.JDBC_ICCLASS) != null) { Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, parameters.get(JDBCMessageStoreConstants.JDBC_ICCLASS)); props.put(Context.PROVIDER_URL, parameters.get(JDBCMessageStoreConstants.JDBC_CONNECTION_URL)); props.put(Context.SECURITY_PRINCIPAL, parameters.get(JDBCMessageStoreConstants.JDBC_USERNAME)); props.put(Context.SECURITY_CREDENTIALS, parameters.get(JDBCMessageStoreConstants.JDBC_PASSWORD)); this.setJndiProperties(props); } }
From source file:org.wso2.carbon.attachment.mgt.core.datasource.impl.BasicDataSourceManager.java
private DataSource lookupInJNDI(String remoteObjectName) throws NamingException { InitialContext ctx = null;/*w ww . j av a 2 s. c o m*/ try { if (dataSourceConfig.getDataSourceJNDIRepoInitialContextFactory() != null && dataSourceConfig.getDataSourceJNDIRepoProviderURL() != null) { Properties jndiProps = new Properties(); jndiProps.setProperty(Context.INITIAL_CONTEXT_FACTORY, dataSourceConfig.getDataSourceJNDIRepoInitialContextFactory()); jndiProps.setProperty(Context.PROVIDER_URL, dataSourceConfig.getDataSourceJNDIRepoProviderURL()); ctx = new InitialContext(jndiProps); } else { ctx = new InitialContext(); } return (DataSource) ctx.lookup(remoteObjectName); } finally { if (ctx != null) { try { ctx.close(); } catch (Exception ex1) { log.error("Error closing JNDI connection.", ex1); } } } }
From source file:de.acosix.alfresco.mtsupport.repo.auth.ldap.LDAPInitialDirContextFactoryImpl.java
/** * {@inheritDoc}//ww w. jav a2s . c o m */ @Override public void afterPropertiesSet() throws Exception { // handled as part of setter in default class if (this.poolSystemProperties != null) { for (final Entry<String, String> entry : this.poolSystemProperties.entrySet()) { System.setProperty(entry.getKey(), entry.getValue()); } } // check anonymous bind final Map<String, String> config = new HashMap<>(this.authenticatedEnvironment.size()); config.putAll(this.authenticatedEnvironment); config.remove(Context.SECURITY_PRINCIPAL); config.remove(Context.SECURITY_CREDENTIALS); if (this.isSSLSocketFactoryRequired(config)) { final KeyStore trustStore = this.initTrustStore(); ThreadSafeSSLSocketFactory.initTrustedSSLSocketFactory(trustStore); config.put("java.naming.ldap.factory.socket", ThreadSafeSSLSocketFactory.class.getName()); } try { new InitialDirContext(new Hashtable<>(config)); LOGGER.warn("LDAP server supports anonymous bind {}", config.get(Context.PROVIDER_URL)); } catch (javax.naming.AuthenticationException | AuthenticationNotSupportedException ax) { // NO-OP - expected } catch (final NamingException nx) { LOGGER.error("Unable to connect to LDAP Server; check LDAP configuration", nx); return; } // Simple DN and password config.put(Context.SECURITY_PRINCIPAL, "daftAsABrush"); config.put(Context.SECURITY_CREDENTIALS, "daftAsABrush"); try { new InitialDirContext(new Hashtable<>(config)); throw new AuthenticationException("The ldap server at " + config.get(Context.PROVIDER_URL) + " falls back to use anonymous bind if invalid security credentials are presented. This is not supported."); } catch (javax.naming.AuthenticationException | AuthenticationNotSupportedException ax) { LOGGER.info("LDAP server does not fall back to anonymous bind for a string uid and password at {}", config.get(Context.PROVIDER_URL)); } catch (final NamingException nx) { LOGGER.info("LDAP server does not support simple string user ids and invalid credentials at {}", config.get(Context.PROVIDER_URL)); } // DN and password config.put(Context.SECURITY_PRINCIPAL, "cn=daftAsABrush,dc=woof"); config.put(Context.SECURITY_CREDENTIALS, "daftAsABrush"); try { new InitialDirContext(new Hashtable<>(config)); throw new AuthenticationException("The ldap server at " + config.get(Context.PROVIDER_URL) + " falls back to use anonymous bind if invalid security credentials are presented. This is not supported."); } catch (javax.naming.AuthenticationException | AuthenticationNotSupportedException ax) { LOGGER.info("LDAP server does not fall back to anonymous bind for a simple dn and password at {}", config.get(Context.PROVIDER_URL)); } catch (final NamingException nx) { LOGGER.info("LDAP server does not support simple DN and invalid credentials at {}", config.get(Context.PROVIDER_URL)); } // Check more if we have a real principal we expect to work final String principal = this.defaultEnvironment.get(Context.SECURITY_PRINCIPAL); if (principal != null) { config.put(Context.SECURITY_PRINCIPAL, principal); config.put(Context.SECURITY_CREDENTIALS, "sdasdasdasdasd123123123"); try { new InitialDirContext(new Hashtable<>(config)); throw new AuthenticationException("The ldap server at " + config.get(Context.PROVIDER_URL) + " falls back to use anonymous bind for a known principal if invalid security credentials are presented. This is not supported."); } catch (final javax.naming.AuthenticationException ax) { LOGGER.info( "LDAP server does not fall back to anonymous bind for known principal and invalid password at {}", config.get(Context.PROVIDER_URL)); } catch (final AuthenticationNotSupportedException ax) { LOGGER.info("LDAP server does not support the required authentication mechanism"); } catch (final NamingException nx) { // NO-OP - covered in previous checks } } }
From source file:org.easy.ldap.LdapContextFactory.java
public DirContext createSecureContext(LdapName rootDn, LdapName principal, String password, String securityMethod) throws NamingException { Hashtable<String, String> environment = getEnviroment(); environment.put(Context.PROVIDER_URL, createProviderUrl(rootDn.toString())); environment.put(Context.SECURITY_AUTHENTICATION, securityMethod); environment.put(Context.SECURITY_PRINCIPAL, principal.toString()); environment.put(Context.SECURITY_CREDENTIALS, password); return createContext(environment); }
From source file:org.apache.directory.server.core.jndi.LdapJndiPropertiesTest.java
License:asdf
@Test public void testAuthWithCredsStrong() throws Exception { Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.SECURITY_PRINCIPAL, ""); env.put(Context.SECURITY_CREDENTIALS, "asdf"); env.put(Context.SECURITY_AUTHENTICATION, "DIGEST-MD5 CRAM-MD5"); env.put(Context.PROVIDER_URL, ""); LdapJndiProperties props = LdapJndiProperties.getLdapJndiProperties(env); assertEquals(AuthenticationLevel.STRONG, props.getAuthenticationLevel()); assertTrue(ArrayUtils.isEquals(Strings.getBytesUtf8("asdf"), props.getCredentials())); }
From source file:com.legstar.mq.client.AbstractCicsMQ.java
/** * Given the endpoint parameters, setup a JNDI context to lookup JMS * resources.//from w ww. java2 s.co m * * @param cicsMQEndpoint the endpoint paramers * @return the JNDI context * @throws CicsMQConnectionException if JNDI context cannot be created */ protected Context createJndiContext(final CicsMQEndpoint cicsMQEndpoint) throws CicsMQConnectionException { try { Properties env = new Properties(); if (cicsMQEndpoint.getInitialContextFactory() != null && cicsMQEndpoint.getInitialContextFactory().length() > 0) { env.put(Context.INITIAL_CONTEXT_FACTORY, cicsMQEndpoint.getInitialContextFactory()); } if (cicsMQEndpoint.getJndiProviderURL() != null && cicsMQEndpoint.getJndiProviderURL().length() > 0) { env.put(Context.PROVIDER_URL, cicsMQEndpoint.getJndiProviderURL()); } if (cicsMQEndpoint.getJndiUrlPkgPrefixes() != null && cicsMQEndpoint.getJndiUrlPkgPrefixes().length() > 0) { env.put(Context.URL_PKG_PREFIXES, cicsMQEndpoint.getJndiUrlPkgPrefixes()); } if (cicsMQEndpoint.getJndiProperties() != null) { env.putAll(getProperties(cicsMQEndpoint.getJndiProperties())); } if (env.size() > 0) { return new InitialContext(env); } else { return new InitialContext(); } } catch (NamingException e) { throw new CicsMQConnectionException(e); } }
From source file:org.grouter.common.jndi.JNDIUtils.java
/** * Get context for remote jboss server./* w ww.j a v a2s .com*/ * * @param jndiUrl the jndiurl, if null a default will be used for jboss * @return initialcontext * @throws NamingException see {@link NamingException} */ @SuppressWarnings({ "UnnecessaryLocalVariable", "SameParameterValue" }) public static InitialContext getJbossInitialContextForServer(String jndiUrl) throws NamingException { if (jndiUrl == null) { jndiUrl = "jnp://127.0.0.1:1099"; } Hashtable<String, String> hashtable = new Hashtable<String, String>(); hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); hashtable.put(Context.PROVIDER_URL, jndiUrl); hashtable.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); InitialContext iniCtx = new InitialContext(hashtable); return iniCtx; }
From source file:org.openiam.idm.srvc.synch.service.generic.LdapAdapterForGenericObject.java
private boolean connect(SynchConfig config) throws NamingException { Hashtable<String, String> envDC = new Hashtable(); System.setProperty("javax.net.ssl.trustStore", keystore); String hostUrl = config.getSrcHost(); // managedSys.getHostUrl(); log.debug("Directory host url:" + hostUrl); envDC.put(Context.PROVIDER_URL, hostUrl); envDC.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); envDC.put(Context.SECURITY_AUTHENTICATION, "simple"); // simple envDC.put(Context.SECURITY_PRINCIPAL, config.getSrcLoginId()); // "administrator@diamelle.local" envDC.put(Context.SECURITY_CREDENTIALS, config.getSrcPassword()); if (hostUrl.contains("ldaps")) { envDC.put(Context.SECURITY_PROTOCOL, "SSL"); }/*from ww w . java 2 s . c o m*/ ctx = new InitialLdapContext(envDC, null); if (ctx != null) { return true; } return false; }
From source file:org.hyperic.hq.plugin.jboss.JBossUtil.java
private static String getServerURL(Metric metric) { return metric.getProperties().getProperty(Context.PROVIDER_URL); }
From source file:OCCIConnectionServlet.java
public static ConnectionPoolDataSource getConnectionPoolDataSource(String baseName) { Context context = null;//w ww. j av a2s .co m ConnectionPoolDataSource cpds = null; try { Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); properties.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC"); context = new InitialContext(properties); cpds = (ConnectionPoolDataSource) context.lookup(baseName); } catch (NamingException e) { System.err.println(e.getMessage() + " creating JNDI context for " + baseName); } return cpds; }