List of usage examples for javax.naming Context INITIAL_CONTEXT_FACTORY
String INITIAL_CONTEXT_FACTORY
To view the source code for javax.naming Context INITIAL_CONTEXT_FACTORY.
Click Source Link
From source file:org.eclipselabs.etrack.util.security.ldap.impl.LdapService.java
@Override public boolean authenticate(String id, char[] password) { if (id == null || id.isEmpty()) return false; if (idSuffix != null) id = id + idSuffix;//from ww w . ja v a 2 s . c o m String cachedPassword = credentialCache.get(id); String encodedPassword = null; try { encodedPassword = codec.encode(new String(password)); } catch (EncoderException e1) { } if (cachedPassword != null && encodedPassword != null && cachedPassword.equals(encodedPassword)) return true; Hashtable<String, String> environment = new Hashtable<String, String>(); environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); environment.put(Context.PROVIDER_URL, url); environment.put(Context.SECURITY_AUTHENTICATION, "simple"); environment.put(Context.SECURITY_PRINCIPAL, id); environment.put(Context.SECURITY_CREDENTIALS, new String(password)); try { InitialDirContext context = new InitialDirContext(environment); context.close(); if (encodedPassword != null) credentialCache.put(id, encodedPassword); return true; } catch (NamingException e) { return false; } }
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 w w .j a v a 2 s . co m 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.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfigurationTests.java
@Before public void setupJndi() { this.initialContextFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY); System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TestableInitialContextFactory.class.getName()); }
From source file:org.openhie.openempi.ejb.util.ServiceLocator.java
/** * Get the initial naming context//from w ww . j a v a 2 s . c o m */ protected static Context getInitialContext() throws NamingException { if (context == null) { Hashtable<String, String> props = new Hashtable<String, String>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); props.put(Context.PROVIDER_URL, "localhost:1099"); context = new InitialContext(props); } return context; }
From source file:br.com.upic.camel.ldap.LdapEndpoint.java
@Override protected void onExchange(final Exchange exchange) throws Exception { LOG.info("Setting up the context"); final Hashtable<String, String> conf = new Hashtable<String, String>(); LOG.debug("Initial Context Factory = " + initialContextFactory); conf.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory); LOG.debug("Provider URL = " + providerUrl); conf.put(Context.PROVIDER_URL, providerUrl); LOG.debug("Security Authentication = " + securityAuthentication); conf.put(Context.SECURITY_AUTHENTICATION, securityAuthentication); final Message in = exchange.getIn(); final String user = in.getHeader(HEADER_USER, String.class); LOG.debug("User = " + user); conf.put(Context.SECURITY_PRINCIPAL, user); final String password = in.getHeader(HEADER_PASSWORD, String.class); LOG.debug("Password = " + password); conf.put(Context.SECURITY_CREDENTIALS, password); LOG.info("Authenticating in directory"); final Message out = exchange.getOut(); try {/* w w w . ja va 2 s. co m*/ new InitialContext(conf); out.setBody(true); } catch (final AuthenticationException e) { LOG.error(e.getMessage(), e); out.setBody(false); } }
From source file:com.clican.pluto.common.util.JndiUtils.java
/** * Bind the resource manager instance to the JNDI directory. * <p>/* w ww . ja v a 2s .com*/ * This method will use the full JNDI path provided for the resource * manager, and will create if necessary the individual segments of that * path. * * @param jndiName * The full JNDI path at which the resource manager instance will * be bound in the JNDI directory. JNDI clients can use that path * to obtain the resource manager instance. * @param obj * The object to be bound. * @return <b>true</b> if the resource manager was successfully bound to * JNDI using the provided path; otherwise <b>false</b>. * * @see #unbind(String) */ public static boolean bind(String jndiName, Object obj) { if (log.isDebugEnabled()) { log.debug("Binding object [" + obj + "] in JNDI at path [" + jndiName + "]."); } Context ctx = null; try { // Create a binding that is local to this host only. Hashtable<String, String> ht = new Hashtable<String, String>(); // If a special JNDI initial context factory was specified in the // constructor, then use it. if (jndiInitialContextFactory != null) { ht.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialContextFactory); } // Turn off binding replication . // ht.put(WLContext.REPLICATE_BINDINGS, "false"); ctx = new InitialContext(ht); String[] arrJndiNames = jndiName.split("/"); String subContext = ""; for (int i = 0; i < arrJndiNames.length - 1; i++) { subContext = subContext + "/" + arrJndiNames[i]; try { ctx.lookup(subContext); } catch (NameNotFoundException e) { ctx.createSubcontext(subContext); } } if (obj instanceof Serializable || jndiInitialContextFactory != null) { ctx.bind(jndiName, obj); } else { NonSerializableFactory.bind(jndiName, obj); } } catch (NamingException ex) { log.error("An error occured while binding [" + jndiName + "] to JNDI:", ex); return false; } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException ne) { log.error("Close context error:", ne); } } } return true; }
From source file:org.wso2.carbon.custom.connector.EJBConnector.java
/** * Creates the initial context to be used. * TODO: In order to improve the performance, you might need to cache this properly * * @return context to be used for service lookup * @throws NamingException//www. j ava 2s . c om */ private static InitialContext getInitialContext() throws NamingException { log.info("Initializing EJBConnector InitialContext"); Properties prop = new Properties(); prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory"); prop.setProperty("org.omg.CORBA.ORBInitialHost", "localhost"); prop.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); prop.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl"); prop.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming"); return new InitialContext(prop); }
From source file:com.microsoft.azure.servicebus.samples.jmstopicquickstart.JmsTopicQuickstart.java
public void run(String connectionString) throws Exception { // The connection string builder is the only part of the azure-servicebus SDK library // we use in this JMS sample and for the purpose of robustly parsing the Service Bus // connection string. ConnectionStringBuilder csb = new ConnectionStringBuilder(connectionString); // set up the JNDI context Hashtable<String, String> hashtable = new Hashtable<>(); hashtable.put("connectionfactory.SBCF", "amqps://" + csb.getEndpoint().getHost() + "?amqp.idleTimeout=120000&amqp.traceFrames=true"); hashtable.put("topic.TOPIC", "BasicTopic"); hashtable.put("queue.SUBSCRIPTION1", "BasicTopic/Subscriptions/Subscription1"); hashtable.put("queue.SUBSCRIPTION2", "BasicTopic/Subscriptions/Subscription2"); hashtable.put("queue.SUBSCRIPTION3", "BasicTopic/Subscriptions/Subscription3"); hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); Context context = new InitialContext(hashtable); ConnectionFactory cf = (ConnectionFactory) context.lookup("SBCF"); // Look up the topic Destination topic = (Destination) context.lookup("TOPIC"); // we create a scope here so we can use the same set of local variables cleanly // again to show the receive side seperately with minimal clutter {/*from w ww .ja va 2 s . c o m*/ // Create Connection Connection connection = cf.createConnection(csb.getSasKeyName(), csb.getSasKey()); connection.start(); // Create Session, no transaction, client ack Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); // Create producer MessageProducer producer = session.createProducer(topic); // Send messaGES for (int i = 0; i < totalSend; i++) { BytesMessage message = session.createBytesMessage(); message.writeBytes(String.valueOf(i).getBytes()); producer.send(message); System.out.printf("Sent message %d.\n", i + 1); } producer.close(); session.close(); connection.stop(); connection.close(); } // Look up the subscription (pretending it's a queue) receiveFromSubscription(csb, context, cf, "SUBSCRIPTION1"); receiveFromSubscription(csb, context, cf, "SUBSCRIPTION2"); receiveFromSubscription(csb, context, cf, "SUBSCRIPTION3"); System.out.printf("Received all messages, exiting the sample.\n"); System.out.printf("Closing queue client.\n"); }
From source file:org.sample.jms.SampleQueueReceiver.java
public MessageConsumer registerSubscriber() throws NamingException, JMSException { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF); properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(userName, password)); properties.put("queue." + queueName, queueName); InitialContext ctx = new InitialContext(properties); // Lookup connection factory QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME); queueConnection = connFactory.createQueueConnection(); queueConnection.start();// w w w . jav a 2 s . c o m queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); Queue queue = (Queue) ctx.lookup(queueName); MessageConsumer consumer = queueSession.createConsumer(queue); return consumer; }
From source file:org.pepstock.jem.junit.test.springbatch.java.RestToBeExecutedAndContext.java
/** * // w w w. j a va 2 s . com * @param stepContribution * @param chunkContext */ @ToBeExecuted public void exec(StepContribution stepContribution, ChunkContext chunkContext) { if (stepContribution == null || chunkContext == null) { throw new RuntimeException("StepContribution or ChuckContext is null"); } try { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.pepstock.jem.node.tasks.jndi.JemContextFactory"); InitialContext context = new InitialContext(env); RestClient rest = (RestClient) context.lookup("JUNIT-REST-RESOURCE"); System.err.println(); System.err.println("*** REST XML"); get(rest, MediaType.APPLICATION_XML); get(rest, MediaType.APPLICATION_JSON); get(rest, MediaType.APPLICATION_XML); get(rest, MediaType.APPLICATION_JSON); } catch (NamingException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } try { System.err.println(); System.err.println("*** REST XML"); get(restC, MediaType.APPLICATION_XML); get(restC, MediaType.APPLICATION_JSON); get(restC, MediaType.APPLICATION_XML); get(restC, MediaType.APPLICATION_JSON); } catch (IOException e) { throw new RuntimeException(e); } }