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.wso2.carbon.automation.extensions.servers.jmsserver.client.JMSTopicMessageConsumer.java
public JMSTopicMessageConsumer(JMSBrokerConfiguration brokerConfiguration) throws NamingException { // Create a ConnectionFactory Properties props = new Properties(); props.setProperty(Context.INITIAL_CONTEXT_FACTORY, brokerConfiguration.getInitialNamingFactory()); if (brokerConfiguration.getProviderURL().startsWith("amqp://")) { //setting property for Qpid running on WSO2 MB props.put("connectionfactory.TopicConnectionFactory", brokerConfiguration.getProviderURL()); } else {// www . j ava2 s . c o m //setting property for ActiveMQ props.setProperty(Context.PROVIDER_URL, brokerConfiguration.getProviderURL()); } Context ctx = new InitialContext(props); connectionFactory = (TopicConnectionFactory) ctx.lookup("TopicConnectionFactory"); }
From source file:it.infn.ct.security.utilities.LDAPUtils.java
private static DirContext getAuthContext(String userCN, String password, boolean dedicatedAdminUser) throws NamingException { ResourceBundle rb = ResourceBundle.getBundle("ldap"); Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, rb.getString("url")); env.put(Context.SECURITY_AUTHENTICATION, "simple"); if (dedicatedAdminUser) { env.put(Context.SECURITY_PRINCIPAL, rb.getString("bindDN")); env.put(Context.SECURITY_CREDENTIALS, rb.getString("bindPass")); } else {/* ww w. j a v a 2 s . c o m*/ env.put(Context.SECURITY_PRINCIPAL, "cn=" + userCN + "," + rb.getString("peopleRoot")); env.put(Context.SECURITY_CREDENTIALS, password); } return new InitialDirContext(env); }
From source file:org.dhatim.routing.jms.activemq.ActiveMQProvider.java
public ActiveMQProvider(final String providerUrl) { this();/*w ww . j a v a 2 s. c o m*/ jndiProperties.setProperty(Context.PROVIDER_URL, providerUrl); this.providerUrl = providerUrl; }
From source file:com.constellio.model.services.users.sync.FastBindConnectionControl.java
@SuppressWarnings("unchecked") public LDAPFastBind(String ldapurl, Boolean followReferences, boolean activeDirectory) { env = new Hashtable(); //This can make LDAP search slow : http://stackoverflow.com/questions/16412236/how-to-resolve-javax-naming-partialresultexception //env.put(Context.REFERRAL, "follow"); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.PROVIDER_URL, ldapurl); env.put("java.naming.ldap.attributes.binary", "tokenGroups objectSid"); if (followReferences) { env.put(Context.REFERRAL, "follow"); }/*from ww w. j a va 2 s . c o m*/ if (StringUtils.startsWith(ldapurl, "ldaps")) { //env.put(Context.SECURITY_PROTOCOL, "ssl"); env.put("java.naming.ldap.factory.socket", "com.constellio.model.services.users.sync.ldaps.DummySSLSocketFactory"); } if (activeDirectory) { connCtls = new Control[] { new FastBindConnectionControl() }; } else { connCtls = new Control[] {}; } //first time we initialize the context, no credentials are supplied //therefore it is an anonymous bind. /*try { ctx = new InitialLdapContext(env, connCtls); } catch (NamingException e) { throw new RuntimeNamingException(e.getMessage()); }*/ //FIX de Vincent pour o a q try { ctx = new InitialLdapContext(env, connCtls); } catch (NamingException e) { if (activeDirectory) { connCtls = new Control[] {}; try { ctx = new InitialLdapContext(env, connCtls); } catch (NamingException e2) { throw new RuntimeException(e); } } else { throw new RuntimeException(e); } } }
From source file:de.tuttas.util.LDAPUtil.java
/** * Benutzer aus der LDAP Abfragen/*from www . ja v a2 s. c o m*/ * * @param username Benutzername * @param password Kennwort * @return der Benutzer * @throws Exception Wenn etwas schief ging */ public LDAPUser authenticateJndi(String username, String password) throws Exception { // Anbindung ans LDAP Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); props.put(Context.PROVIDER_URL, Config.getInstance().ldaphost); props.put(Context.SECURITY_PRINCIPAL, Config.getInstance().bindUser);//adminuser - User with special priviledge, dn user props.put(Context.SECURITY_CREDENTIALS, Config.getInstance().bindPassword);//dn user password try { context = new InitialDirContext(props); ctrls = new SearchControls(); ctrls.setReturningAttributes(new String[] { "description", "mail", "sn", "initials", "givenName", "memberOf", "userPrincipalName", "distinguishedName" }); ctrls.setSearchScope(SearchControls.SUBTREE_SCOPE); } catch (NamingException ex) { Logger.getLogger(LDAPUtil.class.getName()).log(Level.SEVERE, null, ex); } NamingEnumeration<javax.naming.directory.SearchResult> answers = context .search(Config.getInstance().userContext, "(cn=" + username + ")", ctrls); Log.d("answers=" + answers); Log.d("answers=" + answers.hasMore()); if (!answers.hasMore()) { return null; } javax.naming.directory.SearchResult result = answers.nextElement(); try { for (NamingEnumeration ae = result.getAttributes().getAll(); ae.hasMore();) { Attribute attr = (Attribute) ae.next(); Log.d("attribute: " + attr.getID()); /* print each value */ for (NamingEnumeration e = attr.getAll(); e.hasMore(); System.out.println("value: " + e.next())) ; } } catch (NamingException e) { e.printStackTrace(); } String inititials = ""; if (result.getAttributes().get("initials") != null) { inititials = result.getAttributes().get("initials").getAll().next().toString(); } LDAPUser u; if (result.getAttributes().get("mail") == null) { u = new LDAPUser(result.getAttributes().get("sn").getAll().next().toString(), result.getAttributes().get("givenName").getAll().next().toString(), "", inititials); } else { u = new LDAPUser(result.getAttributes().get("sn").getAll().next().toString(), result.getAttributes().get("givenName").getAll().next().toString(), result.getAttributes().get("mail").getAll().next().toString(), inititials); } String dName = result.getAttributes().get("distinguishedName").getAll().next().toString(); Log.d("dName=" + dName); if (dName.contains("OU=Lehrer")) { Log.d("Ich bin ein Lehrer"); u.setRole(Roles.toString(Roles.LEHRER)); } else { Log.d("Ich bin ein Schler"); u.setRole(Roles.toString(Roles.SCHUELER)); if (result.getAttributes().get("memberOf") != null) { String memberOf = result.getAttributes().get("memberOf").getAll().next().toString(); String courseName = memberOf.split(",")[0]; courseName = courseName.substring(courseName.indexOf("=") + 1); Log.d("Name der Klasse ist " + courseName); u.setCourse(courseName); } } String user = result.getNameInNamespace(); try { props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); props.put(Context.PROVIDER_URL, Config.getInstance().ldaphost); props.put(Context.SECURITY_PRINCIPAL, user); props.put(Context.SECURITY_CREDENTIALS, password); context = new InitialDirContext(props); } catch (Exception e) { return null; } return u; }
From source file:io.apiman.gateway.engine.policies.auth.LDAPIdentityValidator.java
/** * @see io.apiman.gateway.engine.policies.auth.IIdentityValidator#validate(java.lang.String, java.lang.String, io.apiman.gateway.engine.beans.ServiceRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.async.IAsyncHandler) *//* w w w .j a v a 2s . c o m*/ @Override public void validate(String username, String password, ServiceRequest request, IPolicyContext context, LDAPIdentitySource config, IAsyncResultHandler<Boolean> handler) { String url = config.getUrl(); String dn = formatDn(config.getDnPattern(), username, request); Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); //$NON-NLS-1$ env.put(Context.PROVIDER_URL, url); env.put(Context.SECURITY_AUTHENTICATION, "simple"); //$NON-NLS-1$ env.put(Context.SECURITY_PRINCIPAL, dn); env.put(Context.SECURITY_CREDENTIALS, password); try { new InitialDirContext(env); handler.handle(AsyncResultImpl.create(Boolean.TRUE)); } catch (AuthenticationException e) { handler.handle(AsyncResultImpl.create(Boolean.FALSE)); } catch (NamingException e) { throw new RuntimeException(e); } }
From source file:org.mule.transport.jms.jndi.AbstractJndiNameResolver.java
protected Hashtable getContextProperties() { if ((jndiInitialFactory == null) && (jndiProviderProperties == null || !jndiProviderProperties.containsKey(Context.INITIAL_CONTEXT_FACTORY))) { throw new IllegalArgumentException("Undefined value for jndiInitialFactory property"); }// w ww.ja v a 2 s . c om Hashtable<String, Object> props = new Hashtable<String, Object>(); if (jndiInitialFactory != null) { props.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialFactory); } if (jndiProviderUrl != null) { props.put(Context.PROVIDER_URL, jndiProviderUrl); } if (jndiProviderProperties != null) { props.putAll(jndiProviderProperties); } return props; }
From source file:org.wso2.carbon.registry.caching.invalidator.connection.JMSNotification.java
@Override public void createConnection(Properties config) { try {// w ww . j a v a2 s . co m Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, config.getProperty("initialContextFactory")); props.put(Context.PROVIDER_URL, config.getProperty("providerUrl")); props.put(Context.SECURITY_PRINCIPAL, config.getProperty("securityPrincipal")); props.put(Context.SECURITY_CREDENTIALS, config.getProperty("securityCredentials")); props.put("topic.cacheInvalidateTopic", config.getProperty("cacheInvalidateTopic")); InitialContext jndi = new InitialContext(props); ConnectionFactory connectionFactory = (ConnectionFactory) jndi.lookup("ConnectionFactory"); destination = (Destination) jndi.lookup("cacheInvalidateTopic"); connection = connectionFactory.createConnection(config.getProperty("securityPrincipal"), config.getProperty("securityCredentials")); connection.start(); } catch (NamingException | JMSException e) { log.error("Global cache invalidation: Error message broker initialization", e); } }
From source file:org.apache.directory.server.core.jndi.LdapJndiPropertiesTest.java
License:asdf
@Test public void testNoAuthWithCredsEnv() throws Exception { Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system"); env.put(Context.SECURITY_CREDENTIALS, "asdf"); env.put(Context.PROVIDER_URL, ""); LdapJndiProperties props = LdapJndiProperties.getLdapJndiProperties(env); assertEquals(AuthenticationLevel.SIMPLE, props.getAuthenticationLevel()); assertTrue(ArrayUtils.isEquals(Strings.getBytesUtf8("asdf"), props.getCredentials())); }
From source file:org.apache.servicemix.jms.AbstractJmsTestSupport.java
protected void createInitContext() throws Exception { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getName()); System.setProperty(Context.PROVIDER_URL, "vm://localhost"); }