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.bonitasoft.engine.LocalServerTestsInitializer.java
public void prepareEnvironment() throws IOException, ClassNotFoundException, NoSuchMethodException, BonitaHomeNotSetException, IllegalAccessException, InvocationTargetException { System.out.println("========= PREPARE ENVIRONMENT ======="); String bonitaHome = setSystemPropertyIfNotSet(BONITA_HOME_PROPERTY, BONITA_HOME_DEFAULT_PATH); final String dbVendor = setSystemPropertyIfNotSet("sysprop.bonita.db.vendor", "h2"); // paste the default local server properties // TODO do not handle the default local server like this File platformInit = new File(bonitaHome, "engine-server/conf/platform-init"); FileUtils.copyInputStreamToFile(this.getClass().getResourceAsStream("/local-server.xml"), new File(platformInit, "local-server.xml")); FileUtils.copyInputStreamToFile(this.getClass().getResourceAsStream("/local-server.properties"), new File(platformInit, "local-server.properties")); // Force these system properties System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.bonitasoft.engine.local.SimpleMemoryContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.bonitasoft.engine.local"); if ("h2".equals(dbVendor)) { this.h2Server = startH2Server(); }//w ww .ja v a 2 s. co m }
From source file:gda.jython.authenticator.LdapAuthenticator.java
private boolean checkAuthenticatedUsingServer(String ldapURL, String fedId, String password) throws NamingException { InitialLdapContext ctx = null; try {/* w w w.ja v a2 s . c o m*/ Hashtable<String, String> env = new Hashtable<String, String>(); String principal = "CN=" + fedId + adminName; env.put(Context.INITIAL_CONTEXT_FACTORY, ldapContext); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, principal); env.put(Context.SECURITY_CREDENTIALS, password); env.put(Context.PROVIDER_URL, ldapURL); ctx = new InitialLdapContext(env, null); //if no exception then password is OK return true; } catch (AuthenticationException ae) { logger.error("LDAP AuthenticationException: " + StringEscapeUtils.escapeJava(ae.getMessage())); } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { } } } return false; }
From source file:com.adaptris.core.runtime.AdapterRegistryTest.java
@Override public void setUp() throws Exception { super.setUp(); contextEnv.put(Context.INITIAL_CONTEXT_FACTORY, JndiContextFactory.class.getName()); spyPreProcessorLoader = new DefaultPreProcessorLoader(); MockitoAnnotations.initMocks(this); }
From source file:security.AuthenticationManager.java
private static Hashtable<String, String> buildEnvContext(String username, String password, String contextFactory, String ldapUrl, String principalDomain) { Hashtable<String, String> env = new Hashtable<>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory); env.put(Context.PROVIDER_URL, ldapUrl); env.put(Context.SECURITY_PRINCIPAL, username + principalDomain); env.put(Context.SECURITY_CREDENTIALS, password); return env;/*from w ww. j a v a2s .co m*/ }
From source file:org.rhq.plugins.jbossas5.connection.RemoteProfileServiceConnectionProvider.java
protected AbstractProfileServiceConnection doConnect() { Properties env = new Properties(); env.setProperty(Context.PROVIDER_URL, this.providerURL); // Always use the non-login context factory, since we'll use JAAS for authentication if a username/password was // provided.//from w w w . ja va 2 s . c o m env.setProperty(Context.INITIAL_CONTEXT_FACTORY, NAMING_CONTEXT_FACTORY); env.setProperty(JNP_TIMEOUT_JNP_INIT_PROP, String.valueOf(JNP_TIMEOUT)); env.setProperty(JNP_SOTIMEOUT_JNP_INIT_PROP, String.valueOf(JNP_SO_TIMEOUT)); env.setProperty(JNP_DISABLE_DISCOVERY_JNP_INIT_PROP, String.valueOf(JNP_DISABLE_DISCOVERY)); log.debug("Connecting to Profile Service via remote JNDI using env [" + env + "]..."); this.initialContext = createInitialContext(env); ProfileService profileService = (ProfileService) lookup(this.initialContext, PROFILE_SERVICE_JNDI_NAME); ManagementView managementView = (ManagementView) lookup(this.initialContext, MANAGEMENT_VIEW_JNDI_NAME); DeploymentManager deploymentManager = (DeploymentManager) lookup(this.initialContext, DEPLOYMENT_MANAGER_JNDI_NAME); AbstractProfileServiceConnection profileServiceConnection; if (this.principal != null) { // Use a connection that will perform a JAAS login prior to all invocations. profileServiceConnection = new JaasAuthenticationProxyProfileServiceConnection(this, profileService, managementView, deploymentManager); } else { profileServiceConnection = new BasicProfileServiceConnection(this, profileService, managementView, deploymentManager); } return profileServiceConnection; }
From source file:org.imirsel.plugins.JndiInitializeServlet.java
/**Called when the servlet starts -called only once. * //from w w w .j a v a 2 s. c o m */ @Override @SuppressWarnings("unchecked") public void init(ServletConfig config) throws ServletException { super.init(config); // initialize the ArtifactManagerImpl ArtifactManagerImpl.init(this.coreConfiguration.getPublicResourcesDirectory()); logger.info("Starting the JNDIInitialize Servlet: -loading various database contexts"); Properties nemaFlowServiceProperties = new Properties(); try { nemaFlowServiceProperties.load( JndiInitializeServlet.class.getClassLoader().getResourceAsStream("nemaflowservice.properties")); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); logger.severe(e1.getMessage()); throw new RuntimeException(e1); } try { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.mortbay.naming.InitialContextFactory"); env.put(Context.PROVIDER_URL, "localhost:1099"); ctx = new InitialContext(env); } catch (Exception e) { logger.severe("Error configuring initial context " + e); throw new ServletException(e); } try { dataSourceFlowResults = getDataSource(nemaFlowServiceProperties); dataSourceJob = getDataSource(nemaFlowServiceProperties); } catch (Exception e) { e.printStackTrace(); logger.severe("Error getting properites " + e); } logger.info("binding flowresults datasource"); bindObject(PluginConstants.JOBRESULT_JNDI_SERVICE, dataSourceFlowResults); bindObject(PluginConstants.JOB_JNDI_SERVICE, dataSourceJob); createDataTablesIfNotExist(); this.inited(true); }
From source file:org.kie.server.integrationtests.shared.KieServerBaseIntegrationTest.java
@BeforeClass public static void setupClass() throws Exception { if (TestConfig.isLocalServer()) { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "bitronix.tm.jndi.BitronixInitialContextFactory"); startKieController();/*from w ww . ja v a2s .com*/ startKieServer(); } setupCustomSettingsXml(); warmUpServer(); }
From source file:com.mirth.connect.connectors.jms.JmsDispatcherTests.java
private static ConnectionFactory lookupConnectionFactoryWithJndi(JmsConnectorProperties connectorProperties) throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.PROVIDER_URL, connectorProperties.getJndiProviderUrl()); env.put(Context.INITIAL_CONTEXT_FACTORY, connectorProperties.getJndiInitialContextFactory()); env.put(Context.SECURITY_PRINCIPAL, connectorProperties.getUsername()); env.put(Context.SECURITY_CREDENTIALS, connectorProperties.getPassword()); initialContext = new InitialContext(env); String connectionFactoryName = connectorProperties.getJndiConnectionFactoryName(); return (ConnectionFactory) initialContext.lookup(connectionFactoryName); }
From source file:org.modeshape.connector.meta.jdbc.DatasourceHelper.java
public static void bindInJNDI(String name) throws NamingException { // Create initial context System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.commons.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); InitialContext ic = new InitialContext(); ic.createSubcontext("java:"); ic.bind("java:/" + name, dataSource); }
From source file:org.wso2.mb.integration.common.clients.operations.topic.TopicMessageReceiver.java
public TopicMessageReceiver(String connectionString, String hostName, String port, String userName, String password, String topicName, boolean isDurable, String subscriptionID, int ackMode, boolean useMessageListener, AtomicInteger messageCounter, int delayBetweenMessages, int printNumberOfMessagesPer, boolean isToPrintEachMessage, String fileToWriteReceivedMessages, int stopAfter, int unsubscrbeAfter, int ackAfterEach, int commitAfterEach, int rollbackAfterEach) { this.hostName = hostName; this.port = port; this.connectionString = connectionString; this.useMessageListener = useMessageListener; this.delayBetweenMessages = delayBetweenMessages; this.messageCounter = messageCounter; this.topicName = topicName; this.printNumberOfMessagesPer = printNumberOfMessagesPer; this.isToPrintEachMessage = isToPrintEachMessage; this.fileToWriteReceivedMessages = fileToWriteReceivedMessages; this.stopAfter = stopAfter; this.unSubscribeAfter = unsubscrbeAfter; this.ackAfterEach = ackAfterEach; this.commitAfterEach = commitAfterEach; this.rollbackAfterEach = rollbackAfterEach; this.subscriptionId = subscriptionID; Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF); properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(userName, password)); properties.put("topic." + topicName, topicName); log.info("getTCPConnectionURL(userName,password) = " + getTCPConnectionURL(userName, password)); try {//w w w .j a va2 s .c om InitialContext ctx = new InitialContext(properties); // Lookup connection factory TopicConnectionFactory connFactory = (TopicConnectionFactory) ctx.lookup(CF_NAME); topicConnection = connFactory.createTopicConnection(); topicConnection.setClientID(subscriptionId); topicConnection.start(); if (ackMode == TopicSession.SESSION_TRANSACTED) { topicSession = topicConnection.createTopicSession(true, QueueSession.SESSION_TRANSACTED); } else { topicSession = topicConnection.createTopicSession(false, QueueSession.AUTO_ACKNOWLEDGE); } // Send message Topic topic = (Topic) ctx.lookup(topicName); log.info("Starting listening on topic: " + topic); if (isDurable) { topicSubscriber = topicSession.createDurableSubscriber(topic, subscriptionId); } else { topicSubscriber = topicSession.createSubscriber(topic); } } catch (NamingException e) { log.error("Error while looking up for topic", e); } catch (JMSException e) { log.error("Error while initializing topic connection", e); } }