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.cloudstack.ldap.LdapContextFactory.java
private LdapContext createInitialDirContext(final String principal, final String password, final String providerUrl, final boolean isSystemContext, Long domainId) throws NamingException, IOException { Hashtable<String, String> environment = getEnvironment(principal, password, providerUrl, isSystemContext, domainId);/*from w ww.j a v a2s . c om*/ s_logger.debug("initializing ldap with provider url: " + environment.get(Context.PROVIDER_URL)); return new InitialLdapContext(environment, null); }
From source file:org.wso2.carbon.identity.agent.onprem.userstore.manager.ldap.LDAPConnectionContext.java
@SuppressWarnings({ "rawtypes", "unchecked" }) LDAPConnectionContext(Map<String, String> userStoreProperties) throws UserStoreException { String connectionURL = userStoreProperties.get(LDAPConstants.CONNECTION_URL); String connectionName = userStoreProperties.get(LDAPConstants.CONNECTION_NAME); String connectionPassword = userStoreProperties.get(LDAPConstants.CONNECTION_PASSWORD); if (log.isDebugEnabled()) { log.debug("Connection Name :: " + connectionName + ", Connection URL :: " + connectionURL); }//from ww w.ja v a2 s. co m environment = new Hashtable<>(); environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); environment.put(Context.SECURITY_AUTHENTICATION, "simple"); if (connectionName != null) { environment.put(Context.SECURITY_PRINCIPAL, connectionName); } if (connectionPassword != null) { environment.put(Context.SECURITY_CREDENTIALS, connectionPassword); } if (connectionURL != null) { environment.put(Context.PROVIDER_URL, connectionURL); } // Enable connection pooling if property is set in user-mgt.xml boolean isLDAPConnectionPoolingEnabled = false; String value = userStoreProperties.get(LDAPConstants.CONNECTION_POOLING_ENABLED); if (value != null && !value.trim().isEmpty()) { isLDAPConnectionPoolingEnabled = Boolean.parseBoolean(value); } environment.put("com.sun.jndi.ldap.connect.pool", isLDAPConnectionPoolingEnabled ? "true" : "false"); // set referral status if provided in configuration. if (userStoreProperties.get(LDAPConstants.PROPERTY_REFERRAL) != null) { environment.put("java.naming.referral", userStoreProperties.get(LDAPConstants.PROPERTY_REFERRAL)); } //Set connect timeout if provided in configuration. Otherwise set default value String connectTimeout = userStoreProperties.get(CONNECTION_TIME_OUT); String readTimeout = userStoreProperties.get(READ_TIME_OUT); if (connectTimeout != null && !connectTimeout.trim().isEmpty()) { environment.put("com.sun.jndi.ldap.connect.timeout", connectTimeout); } else { environment.put("com.sun.jndi.ldap.connect.timeout", "5000"); } if (StringUtils.isNotEmpty(readTimeout)) { environment.put("com.sun.jndi.ldap.read.timeout", readTimeout); } }
From source file:org.smartfrog.avalanche.shared.jms.MessageListener.java
public void init() throws Exception { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.mom4j.jndi.InitialCtxFactory"); p.put(Context.PROVIDER_URL, "xcp://" + serverName + ":" + port); Context ctx = null;// w ww .j ava 2s . c o m try { ctx = new InitialContext(p); QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("QueueConnectionFactory"); queue = (Queue) ctx.lookup(queueName); qc = qcf.createQueueConnection(userName, password); } finally { if (ctx != null) { ctx.close(); } } }
From source file:org.pegadi.server.user.LDAPUserServerImpl.java
public void init() { env.put("java.naming.ldap.version", "3"); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url + "/" + ldapBaseDN); env.put(Context.SECURITY_AUTHENTICATION, auth); env.put(Context.SECURITY_PRINCIPAL, ldapLoginDN); env.put(Context.SECURITY_CREDENTIALS, ldapPassword); try {/*from ww w. j a v a2s.c om*/ ctx = new InitialDirContext(env); log.info("Successfully created a Context"); } catch (NamingException e) { log.error("Unable to create a Context", e); } catch (Exception e) { log.error("This should never come", e); } }
From source file:py.una.pol.karaku.util.LDAPUtil.java
private DirContext createInitialDirContext() { Map<Object, String> env = new HashMap<Object, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, propertiesUtil.get(LDAP_SERVER_KEY) + "/" + propertiesUtil.get(LDAP_DN_KEY)); env.put(Context.SECURITY_PRINCIPAL, propertiesUtil.get(LDAP_ADMIN_KEY)); env.put(Context.SECURITY_CREDENTIALS, propertiesUtil.get(LDAP_ADMIN_PASS_KEY)); try {//from w w w .ja v a 2 s. c om return new InitialDirContext(new Hashtable<Object, String>(env)); } catch (NamingException e) { throw new KarakuRuntimeException(e.getMessage(), e); } }
From source file:org.wso2.esb.integration.common.utils.clients.jmsclient.JMSQueueMessageProducer.java
public JMSQueueMessageProducer(JMSBrokerConfiguration jmsBrokerConfiguration) throws NamingException { Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, jmsBrokerConfiguration.getInitialNamingFactory()); if (jmsBrokerConfiguration.getProviderURL().startsWith(MB_BROKER_URL_PREFIX)) { //setting property for Qpid running on WSO2 MB properties.put("connectionfactory.QueueConnectionFactory", jmsBrokerConfiguration.getProviderURL()); } else {/*from w w w. j av a 2s .co m*/ //setting property for ActiveMQ properties.setProperty(Context.PROVIDER_URL, jmsBrokerConfiguration.getProviderURL()); } Context context = new InitialContext(properties); connectionFactory = (QueueConnectionFactory) context.lookup("QueueConnectionFactory"); }
From source file:com.marklogic.samplestack.integration.web.LDAPIT.java
@Before public void setup() throws NamingException { env = new Hashtable<String, Object>(); env.put(Context.SECURITY_AUTHENTICATION, "simple"); if (ldapUsername != null) { env.put(Context.SECURITY_PRINCIPAL, ldapUsername); }/*from w w w.ja v a 2 s .c om*/ if (ldapPassword != null) { env.put(Context.SECURITY_CREDENTIALS, ldapPassword); } env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapServer); // ensures that objectSID attribute values // will be returned as a byte[] instead of a String // env.put("java.naming.ldap.attributes.binary", "uid"); // the following is helpful in debugging errors //env.put("com.sun.jndi.ldap.trace.ber", System.err); ctx = new InitialLdapContext(env, null); }
From source file:org.wso2.carbon.deployment.notifier.internal.JMSUtils.java
/** * Return the JMS destination with the given destination name looked up from the context * Borrowed generiously from axis2 jms transport implementation * * @param context the Context to lookup/*from w w w .ja va 2 s. c o m*/ * @param destinationName name of the destination to be looked up * @param destinationType type of the destination to be looked up * @return the JMS destination, or null if it does not exist */ public static Destination lookupDestination(Context context, String destinationName, String destinationType) throws NamingException { try { return lookup(context, Destination.class, destinationName); } catch (NameNotFoundException e) { Properties initialContextProperties = new Properties(); if (context.getEnvironment() != null) { if (context.getEnvironment().get(Context.INITIAL_CONTEXT_FACTORY) != null) { initialContextProperties.put(Context.INITIAL_CONTEXT_FACTORY, context.getEnvironment().get(Context.INITIAL_CONTEXT_FACTORY)); } if (context.getEnvironment().get(Context.PROVIDER_URL) != null) { initialContextProperties.put(Context.PROVIDER_URL, context.getEnvironment().get(Context.PROVIDER_URL)); } } if (Constants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(destinationType)) { initialContextProperties.put(Constants.TOPIC_PREFIX + destinationName, destinationName); } else { initialContextProperties.put(Constants.QUEUE_PREFIX + destinationName, destinationName); } InitialContext initialContext = new InitialContext(initialContextProperties); try { return lookup(initialContext, Destination.class, destinationName); } catch (NamingException e1) { return lookup(context, Destination.class, (Constants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(destinationType) ? "dynamicTopics/" : "dynamicQueues/") + destinationName); } } }
From source file:org.apache.directory.server.core.jndi.LdapJndiPropertiesTest.java
License:asdf
@Test public void testNoAuthWithNoCredsEnv() throws Exception { Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.SECURITY_PRINCIPAL, ""); env.put(Context.PROVIDER_URL, ""); LdapJndiProperties props = LdapJndiProperties.getLdapJndiProperties(env); assertEquals(AuthenticationLevel.NONE, props.getAuthenticationLevel()); assertTrue(props.getCredentials() == null); }
From source file:org.projectforge.business.ldap.LdapConnector.java
private Hashtable<String, String> createEnv(final String user, final String password) { // Set up the environment for creating the initial context 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, ldapConfig.getCompleteServerUrl()); final String authentication = ldapConfig.getAuthentication(); if (StringUtils.isNotBlank(authentication) == true) { env.put(Context.SECURITY_AUTHENTICATION, ldapConfig.getAuthentication()); if ("none".equals(authentication) == false && user != null && password != null) { env.put(Context.SECURITY_PRINCIPAL, user); env.put(Context.SECURITY_CREDENTIALS, password); }/* ww w . jav a 2 s .com*/ } if (ldapConfig != null && StringUtils.isNotBlank(ldapConfig.getSslCertificateFile()) == true) { env.put("java.naming.ldap.factory.socket", "org.projectforge.business.ldap.MySSLSocketFactory"); } log.info("Trying to connect the LDAP server: url=[" + ldapConfig.getCompleteServerUrl() + "], authentication=[" + ldapConfig.getAuthentication() + "], principal=[" + user + "]"); return env; }