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: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 // w w w . j a va 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.apache.juddi.v3.auth.LdapExpandedAuthenticator.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 www . j a va2s .c om boolean isLdapUser = false; 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); } 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 String format = String.format( AppConfig.getConfiguration().getString(Property.JUDDI_AUTHENTICATOR_LDAP_EXPANDED_STR), authorizedName); env.put(Context.SECURITY_PRINCIPAL, format); 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: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)); }/*w w w .ja v a 2 s.c o m*/ 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); }
From source file:com.googlecode.fascinator.authentication.custom.ldap.CustomLdapAuthenticationHandler.java
/** * Creates an LDAP authenticator for the specified server, base DN and given * identifier attribute/*from ww w . ja v a2s.c om*/ * * @param baseUrl * LDAP server URL * @param baseDn * LDAP base DN * @param ldapSecurityPrincipal * LDAP Security Principal * @param ldapSecurityCredentials * Credentials for Security Principal * @param ldapRoleAttr * Name of the LDAP attribute that defines the role * @param idAttr * LDAP user identifier attribute */ public CustomLdapAuthenticationHandler(String baseUrl, String baseDn, String ldapSecurityPrincipal, String ldapSecurityCredentials, String ldapRoleAttr, String idAttr) { // Set public variables this.baseDn = baseDn; this.idAttr = idAttr; this.ldapRoleAttr = ldapRoleAttr; this.baseUrl = baseUrl; this.ldapSecurityPrincipal = ldapSecurityPrincipal; this.ldapSecurityCredentials = ldapSecurityCredentials; if (CustomLdapAuthenticationHandler.credentialCache == null) { CacheManager singletonManager = CacheManager.create(); CustomLdapAuthenticationHandler.credentialCache = new Cache("credentialCache", 500, false, false, 3600, 1800); singletonManager.addCache(CustomLdapAuthenticationHandler.credentialCache); } // Initialise the LDAP environment env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, baseUrl); env.put(Context.SECURITY_AUTHENTICATION, "simple"); if (!ldapSecurityPrincipal.equals("")) { env.put(Context.SECURITY_PRINCIPAL, ldapSecurityPrincipal); env.put(Context.SECURITY_CREDENTIALS, ldapSecurityCredentials); } }
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: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 ww w .j a v a 2 s . c om if (jndiProviderUrl != null) { props.put(Context.PROVIDER_URL, replacer.replaceValues(jndiProviderUrl)); } if (jndiProviderProperties != null) { props.putAll(jndiProviderProperties); } jndiContext = new InitialContext(props); } }
From source file:org.apache.directory.server.operations.bind.MiscBindIT.java
/** * Test to make sure anonymous binds are disabled when going through * the wire protocol./*from w w w. j av a2s .co m*/ * * @throws Exception if anything goes wrong */ @Test public void testDisableAnonymousBinds() throws Exception { getLdapServer().getDirectoryService().setAllowAnonymousAccess(false); // Use the SUN JNDI provider to hit server port and bind as anonymous final Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.PROVIDER_URL, Network.ldapLoopbackUrl(getLdapServer().getPort()) + "/ou=system"); env.put(Context.SECURITY_AUTHENTICATION, "none"); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); try { new InitialDirContext(env); fail(); } catch (Exception e) { // We should get here } try { // Use the netscape API as JNDI cannot be used to do a search without // first binding. LDAPUrl url = new LDAPUrl(Network.LOOPBACK_HOSTNAME, getLdapServer().getPort(), "ou=system", new String[] { "vendorName" }, 0, "(ObjectClass=*)"); LDAPConnection.search(url); fail(); } catch (LDAPException e) { // Expected result } }
From source file:org.squale.jraf.bootstrap.naming.NamingHelper.java
/** * Retourne les proprietes JNDI associees a partir de l'url d'un annuaire et de la factory d'acces * @param jndiUrl url de l'annuaire/*from w w w . ja va 2 s .c o m*/ * @param jndiClass factory d'acces * @return */ public static Properties getJndiProperties(String jndiUrl, String jndiClass) { Properties properties = new Properties(); // context factory if (jndiClass != null) { properties.put(Context.INITIAL_CONTEXT_FACTORY, jndiClass); } // URL if (jndiUrl != null) { properties.put(Context.PROVIDER_URL, jndiUrl); } return properties; }
From source file:org.jkcsoft.java.util.JndiHelper.java
public static DirContext getDirContext(BehavioralContext bctx, Object principal, Object credentials) throws NamingException { DirContext ctx = null;/*w w w. jav a 2 s . co m*/ Configuration tconfig = bctx.getConfig(); String ldapProvider = "ldap" + "://" + tconfig.getString(Constants.KEY_AD_HOST) + ":" + tconfig.getString(Constants.KEY_AD_PORT) + "/" + tconfig.getString(Constants.KEY_AD_ROOT_DN); log.info("Using LDAP url: [" + ldapProvider + "]"); // String url, String contextFactoryName, Hashtable jndiEnv = new Hashtable(); jndiEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); jndiEnv.put(Context.PROVIDER_URL, ldapProvider); jndiEnv.put(Context.REFERRAL, "follow"); if (tconfig.getBoolean(Constants.KEY_AD_SSL)) { log.info("Using SSL for LDAP"); jndiEnv.put(Context.SECURITY_PROTOCOL, "ssl"); } jndiEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); if (principal != null) jndiEnv.put(Context.SECURITY_PRINCIPAL, principal); if (credentials != null) jndiEnv.put(Context.SECURITY_CREDENTIALS, credentials); try { // Creating the JNDI directory context (with LDAP context // factory), performs an LDAP bind to the LDAP provider thereby // authenticating the username/pw. ctx = new InitialDirContext(jndiEnv); } catch (NamingException ex) { log.error("Directory context init failed", ex); throw ex; } return ctx; }
From source file:com.mirth.connect.connectors.jms.JmsReceiverTests.java
private static ConnectionFactory lookupConnectionFactoryWithJndi(JmsConnectorProperties connectorProperties) throws Exception { Hashtable<String, Object> env = new Hashtable<String, Object>(); 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); }