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.jboss.test.security.test.SubjectContextUnitTestCase.java
public void testUserMethod() throws Exception { log.debug("+++ testUserMethod()"); Properties env = new Properties(); env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory"); env.setProperty(Context.SECURITY_PRINCIPAL, "jduke"); env.setProperty(Context.SECURITY_CREDENTIALS, "theduke"); InitialContext ctx = new InitialContext(env); Object obj = ctx.lookup("jacc/Secured"); obj = PortableRemoteObject.narrow(obj, SecuredServiceRemoteHome.class); SecuredServiceRemoteHome home = (SecuredServiceRemoteHome) obj; log.debug("Found SecuredServiceRemoteHome"); SecuredServiceRemote bean = home.create(); log.debug("Created SecuredServiceRemote"); Principal callerIdentity = new SimplePrincipal("jduke"); Principal runAsIdentity = new SimplePrincipal("runAsUser"); HashSet expectedCallerRoles = new HashSet(); expectedCallerRoles.add("groupMemberCaller"); expectedCallerRoles.add("userCaller"); expectedCallerRoles.add("allAuthCaller"); expectedCallerRoles.add("webUser"); HashSet expectedRunAsRoles = new HashSet(); expectedRunAsRoles.add("identitySubstitutionCaller"); expectedRunAsRoles.add("extraRunAsRole"); CallerInfo info = new CallerInfo(callerIdentity, runAsIdentity, expectedCallerRoles, expectedRunAsRoles); bean.userMethod(info);//from w ww . j av a 2 s.com bean.remove(); }
From source file:com.mirth.connect.connectors.jms.JmsConnector.java
protected void initJndiContext() throws NamingException, InitialisationException { if (jndiContext == null) { Hashtable props = new Hashtable(); if (jndiInitialFactory != null) { props.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialFactory); } else if (jndiProviderProperties == null || !jndiProviderProperties.containsKey(Context.INITIAL_CONTEXT_FACTORY)) { throw new InitialisationException(new Message(Messages.X_IS_NULL, "jndiInitialFactory"), this); }//from w w w. j a va2 s. c o m if (jndiProviderUrl != null) { props.put(Context.PROVIDER_URL, replacer.replaceValues(jndiProviderUrl)); } if (jndiProviderProperties != null) { props.putAll(jndiProviderProperties); } jndiContext = new InitialContext(props); } }
From source file:tools.pki.gbay.crypto.keys.validation.CertificateRevocationList.java
/** * Downloads a CRL from given LDAP url, e.g. * ldap://ldap.infonotary.com/dc=identity-ca,dc=infonotary,dc=com * @throws IOException /*www .jav a 2s . c o m*/ */ @SuppressWarnings("rawtypes") private static X509CRL downloadCRLFromLDAP(String ldapURL) throws CertificateException, NamingException, CRLException, CryptoException, IOException { Map<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapURL); DirContext ctx = new InitialDirContext((Hashtable) env); Attributes avals = ctx.getAttributes(""); Attribute aval = avals.get("certificateRevocationList;binary"); byte[] val = (byte[]) aval.get(); if ((val == null) || (val.length == 0)) { throw new CryptoException("Can not download CRL from: " + ldapURL); } else { return fromByteArray(val); } }
From source file:org.wso2.carbon.apimgt.impl.dao.test.APIMgtDAOTest.java
private void initializeDatabase(String configFilePath) { InputStream in = null;//from ww w .ja va 2 s. co m try { in = FileUtils.openInputStream(new File(configFilePath)); StAXOMBuilder builder = new StAXOMBuilder(in); String dataSource = builder.getDocumentElement().getFirstChildWithName(new QName("DataSourceName")) .getText(); OMElement databaseElement = builder.getDocumentElement().getFirstChildWithName(new QName("Database")); String databaseURL = databaseElement.getFirstChildWithName(new QName("URL")).getText(); String databaseUser = databaseElement.getFirstChildWithName(new QName("Username")).getText(); String databasePass = databaseElement.getFirstChildWithName(new QName("Password")).getText(); String databaseDriver = databaseElement.getFirstChildWithName(new QName("Driver")).getText(); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(databaseDriver); basicDataSource.setUrl(databaseURL); basicDataSource.setUsername(databaseUser); basicDataSource.setPassword(databasePass); // Create initial context System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); try { InitialContext.doLookup("java:/comp/env/jdbc/WSO2AM_DB"); } catch (NamingException e) { InitialContext ic = new InitialContext(); ic.createSubcontext("java:"); ic.createSubcontext("java:/comp"); ic.createSubcontext("java:/comp/env"); ic.createSubcontext("java:/comp/env/jdbc"); ic.bind("java:/comp/env/jdbc/WSO2AM_DB", basicDataSource); } } catch (XMLStreamException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:org.apache.openaz.xacml.std.pip.engines.ldap.LDAPEngine.java
@Override public void configure(String id, Properties properties) throws PIPException { /*/*from w w w . j a va 2 s. c o m*/ * Handle the standard properties */ super.configure(id, properties); String propertyPrefix = id + "."; /* * Configure the LDAP environment: I think the only required property is the provider_url */ if (!this.configureStringProperty(propertyPrefix, Context.PROVIDER_URL, properties, null)) { throw new PIPException("Invalid configuration for " + this.getClass().getName() + ": No " + propertyPrefix + Context.PROVIDER_URL); } this.configureStringProperty(propertyPrefix, Context.AUTHORITATIVE, properties, null); this.configureIntegerProperty(propertyPrefix, Context.BATCHSIZE, properties, null); this.configureStringProperty(propertyPrefix, Context.DNS_URL, properties, null); this.configureStringProperty(propertyPrefix, Context.INITIAL_CONTEXT_FACTORY, properties, DEFAULT_CONTEXT_FACTORY); this.configureStringProperty(propertyPrefix, Context.LANGUAGE, properties, null); this.configureStringProperty(propertyPrefix, Context.OBJECT_FACTORIES, properties, null); this.configureStringProperty(propertyPrefix, Context.REFERRAL, properties, null); this.configureStringProperty(propertyPrefix, Context.SECURITY_AUTHENTICATION, properties, null); this.configureStringProperty(propertyPrefix, Context.SECURITY_CREDENTIALS, properties, null); this.configureStringProperty(propertyPrefix, Context.SECURITY_PRINCIPAL, properties, null); this.configureStringProperty(propertyPrefix, Context.SECURITY_PROTOCOL, properties, null); this.configureStringProperty(propertyPrefix, Context.STATE_FACTORIES, properties, null); this.configureStringProperty(propertyPrefix, Context.URL_PKG_PREFIXES, properties, null); String ldapScopeValue = properties.getProperty(propertyPrefix + PROP_LDAP_SCOPE, DEFAULT_SCOPE); if (LDAP_SCOPE_SUBTREE.equals(ldapScopeValue)) { this.ldapScope = SearchControls.SUBTREE_SCOPE; } else if (LDAP_SCOPE_OBJECT.equals(ldapScopeValue)) { this.ldapScope = SearchControls.OBJECT_SCOPE; } else if (LDAP_SCOPE_ONELEVEL.equals(ldapScopeValue)) { this.ldapScope = SearchControls.ONELEVEL_SCOPE; } else { this.logger.warn("Invalid LDAP Scope value '" + ldapScopeValue + "'; using " + DEFAULT_SCOPE); this.ldapScope = SearchControls.SUBTREE_SCOPE; } /* * Get list of resolvers defined for this LDAP Engine */ String resolversList = properties.getProperty(propertyPrefix + PROP_RESOLVERS); if (resolversList == null || resolversList.isEmpty()) { throw new PIPException("Invalid configuration for " + this.getClass().getName() + ": No " + propertyPrefix + PROP_RESOLVERS); } /* * Iterate the resolvers */ for (String resolver : Splitter.on(',').trimResults().omitEmptyStrings().split(resolversList)) { /* * Get the LDAPResolver for this LDAPEngine */ String resolverClassName = properties .getProperty(propertyPrefix + PROP_RESOLVER + "." + resolver + ".classname"); if (resolverClassName == null) { throw new PIPException("Invalid configuration for " + this.getClass().getName() + ": No " + propertyPrefix + PROP_RESOLVER + "." + resolver + ".classname"); } LDAPResolver ldapResolverNew = null; try { Class<?> classResolver = Class.forName(resolverClassName); if (!LDAPResolver.class.isAssignableFrom(classResolver)) { this.logger.error("LDAPResolver class " + resolverClassName + " does not implement " + LDAPResolver.class.getCanonicalName()); throw new PIPException("LDAPResolver class " + resolverClassName + " does not implement " + LDAPResolver.class.getCanonicalName()); } ldapResolverNew = LDAPResolver.class.cast(classResolver.newInstance()); } catch (Exception ex) { this.logger.error("Exception instantiating LDAPResolver for class '" + resolverClassName + "': " + ex.getMessage(), ex); throw new PIPException("Exception instantiating LDAPResolver for class '" + resolverClassName + "'", ex); } assert ldapResolverNew != null; ldapResolverNew.configure(propertyPrefix + PROP_RESOLVER + "." + resolver, properties, this.getIssuer()); this.ldapResolvers.add(ldapResolverNew); } }
From source file:org.apache.juddi.v3.auth.LdapSimpleAuthenticator.java
public String authenticate(String authorizedName, String cred) throws AuthenticationException, FatalErrorException { if (authorizedName == null || "".equals(authorizedName)) { throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName)); }//from w w w . ja v a 2 s. c o m int MaxBindingsPerService = -1; int MaxServicesPerBusiness = -1; int MaxTmodels = -1; int MaxBusinesses = -1; try { MaxBindingsPerService = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_BINDINGS_PER_SERVICE, -1); MaxServicesPerBusiness = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_SERVICES_PER_BUSINESS, -1); MaxTmodels = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_TMODELS_PER_PUBLISHER, -1); MaxBusinesses = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_BUSINESSES_PER_PUBLISHER, -1); } catch (Exception ex) { MaxBindingsPerService = -1; MaxServicesPerBusiness = -1; MaxTmodels = -1; MaxBusinesses = -1; logger.error("config exception! " + authorizedName, ex); } boolean isLdapUser = false; try { env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, AppConfig.getConfiguration() .getString(Property.JUDDI_AUTHENTICATOR_INITIAL_CONTEXT, "com.sun.jndi.ldap.LdapCtxFactory")); env.put(Context.SECURITY_AUTHENTICATION, AppConfig.getConfiguration().getString(Property.JUDDI_AUTHENTICATOR_STYLE, "simple")); env.put(Context.PROVIDER_URL, url); // organization ldap url, example ldap://localhost:389 env.put(Context.SECURITY_PRINCIPAL, authorizedName); env.put(Context.SECURITY_CREDENTIALS, cred); ctx = new InitialLdapContext(env, null); isLdapUser = true; logger.info(authorizedName + " is authenticated"); } catch (ConfigurationException e) { logger.error(authorizedName + " is not authenticated", e); throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName)); } catch (NamingException e) { logger.error(authorizedName + " is not authenticated"); throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName)); } finally { try { ctx.close(); } catch (NamingException e) { logger.error("Context close failure " + e); } } if (isLdapUser) { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); Publisher publisher = em.find(Publisher.class, authorizedName); if (publisher == null) { logger.warn("Publisher was not found, adding the publisher in on the fly."); publisher = new Publisher(); publisher.setAuthorizedName(authorizedName); publisher.setIsAdmin("false"); publisher.setIsEnabled("true"); publisher.setMaxBindingsPerService(MaxBindingsPerService); publisher.setMaxBusinesses(MaxBusinesses); publisher.setMaxServicesPerBusiness(MaxServicesPerBusiness); publisher.setMaxTmodels(MaxTmodels); publisher.setPublisherName("Unknown"); em.persist(publisher); tx.commit(); } } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } } else { throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName)); } return authorizedName; }
From source file:org.kie.server.integrationtests.shared.KieServerBaseIntegrationTest.java
@AfterClass public static void tearDown() { if (TestConfig.isLocalServer()) { stopKieServer();//from w w w .ja va2 s .co m stopKieController(); System.clearProperty(Context.INITIAL_CONTEXT_FACTORY); } }
From source file:org.qucosa.indexfeeder.Main.java
private static void initializeProperties() { properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, ACTIVEMQ_CONTEXT_FACTORY_NAME); properties.setProperty(JMSManager.CONNECTION_FACTORY_NAME, "ConnectionFactory"); properties.setProperty(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, DEFAULT_PROVIDER_URL)); properties.setProperty("topic.fedora", System.getProperty("topic.fedora", DEFAULT_TOPIC_FILTER)); properties.setProperty(FEDORA_PARAM_BASE_URL, System.getProperty(FEDORA_PARAM_BASE_URL, "http://localhost:8080/fedora")); properties.setProperty(FEDORA_PARAM_USER, System.getProperty(FEDORA_PARAM_USER, "fedoraAdmin")); properties.setProperty(FEDORA_PARAM_PASSWORD, System.getProperty(FEDORA_PARAM_PASSWORD, "fedoraAdmin")); properties.setProperty(ELASTICSEARCH_PARAM_HOST, System.getProperty(ELASTICSEARCH_PARAM_HOST, "http://localhost:9300")); log.info("ActiveMQ URL: " + properties.getProperty(Context.PROVIDER_URL)); log.info("ActiveMQ Topic: " + properties.getProperty("topic.fedora")); log.info("Fedora URL: " + properties.getProperty(FEDORA_PARAM_BASE_URL)); log.info("Fedora User: " + properties.getProperty(FEDORA_PARAM_USER)); log.info("ElasticSearch Host: " + properties.getProperty(ELASTICSEARCH_PARAM_HOST)); }
From source file:CreateJavaSchema.java
/** * Signs on to directory server using parameters supplied to program. * @return The initial context to the server. *///ww w. j a va 2 s . c om private DirContext signOn() throws NamingException { if (dn != null && auth == null) { auth = "simple"; // use simple for Netscape } Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.REFERRAL, "follow"); if (auth != null) { env.put(Context.SECURITY_AUTHENTICATION, auth); env.put(Context.SECURITY_PRINCIPAL, dn); env.put(Context.SECURITY_CREDENTIALS, passwd); } // Workaround for Netscape schema bugs if (netscapebug) { env.put("com.sun.naming.netscape.schemaBugs", "true"); } // LDAP protocol tracing if (traceLdap) { env.put("com.sun.jndi.ldap.trace.ber", System.err); } return new InitialDirContext(env); }
From source file:com.jkoolcloud.tnt4j.streams.inputs.JMSStream.java
@Override protected void initialize() throws Exception { super.initialize(); if (StringUtils.isEmpty(serverURL)) { throw new IllegalStateException( StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME, "TNTInputStream.property.undefined", StreamProperties.PROP_SERVER_URI)); }/*from ww w . j a v a2s.com*/ if (StringUtils.isEmpty(queueName) && StringUtils.isEmpty(topicName)) { throw new IllegalStateException(StreamsResources.getStringFormatted( StreamsResources.RESOURCE_BUNDLE_NAME, "TNTInputStream.property.undefined.one.of", StreamProperties.PROP_QUEUE_NAME, StreamProperties.PROP_TOPIC_NAME)); } jmsDataReceiver = new JMSDataReceiver(); Hashtable<String, String> env = new Hashtable<>(2); env.put(Context.INITIAL_CONTEXT_FACTORY, jndiFactory); env.put(Context.PROVIDER_URL, serverURL); Context ic = new InitialContext(env); jmsDataReceiver.initialize(ic, StringUtils.isEmpty(queueName) ? topicName : queueName, jmsConnFactory); }