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:com.clustercontrol.port.protocol.ReachAddressDNS.java
/** * DNS????????/*ww w .j a v a 2 s. c o m*/ * * @param addressText * @return DNS */ /* * (non-Javadoc) * * @see * com.clustercontrol.port.protocol.ReachAddressProtocol#isRunning(java. * lang.String) */ @Override protected boolean isRunning(String addressText) { m_message = ""; m_messageOrg = ""; m_response = -1; boolean isReachable = false; try { long start = 0; // long end = 0; // boolean retry = true; // ????(true:??false:???) StringBuffer bufferOrg = new StringBuffer(); // String result = ""; InetAddress address = InetAddress.getByName(addressText); String addressStr = address.getHostAddress(); if (address instanceof Inet6Address) { addressStr = "[" + addressStr + "]"; } bufferOrg.append("Monitoring the DNS Service of " + address.getHostName() + "[" + address.getHostAddress() + "]:" + m_portNo + ".\n\n"); Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory"); props.put(Context.PROVIDER_URL, "dns://" + addressStr + ":" + m_portNo); props.put("com.sun.jndi.dns.timeout.initial", String.valueOf(m_timeout)); props.put("com.sun.jndi.dns.timeout.retries", "1"); InitialDirContext idctx = null; String hostname = HinemosPropertyUtil.getHinemosPropertyStr("monitor.port.protocol.dns", "localhost"); m_log.debug("The hostname from which to retrieve attributes is " + hostname); for (int i = 0; i < m_sentCount && retry; i++) { try { bufferOrg.append(HinemosTime.getDateString() + " Tried to Connect: "); start = HinemosTime.currentTimeMillis(); idctx = new InitialDirContext(props); Attributes attrs = idctx.getAttributes(hostname); end = HinemosTime.currentTimeMillis(); bufferOrg.append("\n"); NamingEnumeration<? extends Attribute> allAttr = attrs.getAll(); while (allAttr.hasMore()) { Attribute attr = allAttr.next(); bufferOrg.append("Attribute: " + attr.getID() + "\n"); NamingEnumeration<?> values = attr.getAll(); while (values.hasMore()) bufferOrg.append("Value: " + values.next() + "\n"); } bufferOrg.append("\n"); m_response = end - start; if (m_response > 0) { if (m_response < m_timeout) { result = result + ("Response Time = " + m_response + "ms"); } else { m_response = m_timeout; result = result + ("Response Time = " + m_response + "ms"); } } else { result = result + ("Response Time < 1ms"); } retry = false; isReachable = true; } catch (NamingException e) { result = (e.getMessage() + "[NamingException]"); retry = true; isReachable = false; } catch (Exception e) { result = (e.getMessage() + "[Exception]"); retry = true; isReachable = false; } finally { bufferOrg.append(result + "\n"); try { if (idctx != null) { idctx.close(); } } catch (NamingException e) { m_log.warn("isRunning(): " + "socket disconnect failed: " + e.getMessage(), e); } } if (i < m_sentCount - 1 && retry) { try { Thread.sleep(m_sentInterval); } catch (InterruptedException e) { break; } } } m_message = result + "(DNS/" + m_portNo + ")"; m_messageOrg = bufferOrg.toString(); return isReachable; } catch (UnknownHostException e) { m_log.debug("isRunning(): " + MessageConstant.MESSAGE_FAIL_TO_EXECUTE_TO_CONNECT.getMessage() + e.getMessage()); m_message = MessageConstant.MESSAGE_FAIL_TO_EXECUTE_TO_CONNECT.getMessage() + " (" + e.getMessage() + ")"; return false; } }
From source file:org.wso2.extension.siddhi.io.jms.source.client.JMSClient.java
public void sendJMSEvents(String filePath, String topicName, String queueName, String format, String broker, String providerURL) {/* w ww . ja va 2 s . c o m*/ if (format == null || "map".equals(format)) { format = "csv"; } if ("".equalsIgnoreCase(broker)) { broker = "activemq"; } Session session = null; Properties properties = new Properties(); if (!"activemq".equalsIgnoreCase(broker) && !"mb".equalsIgnoreCase(broker) && !"qpid".equalsIgnoreCase(broker)) { log.error("Please enter a valid JMS message broker. (ex: activemq, mb, qpid"); return; } try { if (topicName != null && !"".equalsIgnoreCase(topicName)) { TopicConnection topicConnection; TopicConnectionFactory connFactory = null; if ("activemq".equalsIgnoreCase(broker)) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties")); // to provide custom provider urls if (providerURL != null) { properties.put(Context.PROVIDER_URL, providerURL); } Context context = new InitialContext(properties); connFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory"); } else if ("mb".equalsIgnoreCase(broker)) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("mb.properties")); Context context = new InitialContext(properties); connFactory = (TopicConnectionFactory) context.lookup("qpidConnectionFactory"); } else if ("qpid".equalsIgnoreCase(broker)) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("qpid.properties")); Context context = new InitialContext(properties); connFactory = (TopicConnectionFactory) context.lookup("qpidConnectionFactory"); } if (connFactory != null) { topicConnection = connFactory.createTopicConnection(); topicConnection.start(); session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); if (session != null) { Topic topic = session.createTopic(topicName); MessageProducer producer = session.createProducer(topic); List<String> messagesList = JMSClientUtil.readFile(filePath); try { if ("csv".equalsIgnoreCase(format)) { log.info("Sending Map messages on '" + topicName + "' topic"); JMSClientUtil.publishMapMessage(producer, session, messagesList); } else { log.info("Sending " + format + " messages on '" + topicName + "' topic"); JMSClientUtil.publishTextMessage(producer, session, messagesList); } log.info("All Order Messages sent"); } catch (JMSException e) { log.error("Cannot subscribe." + e.getMessage(), e); } catch (IOException e) { log.error("Error when reading the data file." + e.getMessage(), e); } finally { producer.close(); session.close(); topicConnection.stop(); } } } else { log.error("Error when creating connection factory. Please check necessary jar files"); } } else if (queueName != null && !queueName.equalsIgnoreCase("")) { QueueConnection queueConnection; QueueConnectionFactory connFactory = null; if ("activemq".equalsIgnoreCase(broker)) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties")); Context context = new InitialContext(properties); connFactory = (QueueConnectionFactory) context.lookup("ConnectionFactory"); } else if ("mb".equalsIgnoreCase(broker)) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("mb.properties")); Context context = new InitialContext(properties); connFactory = (QueueConnectionFactory) context.lookup("qpidConnectionFactory"); } else if ("qpid".equalsIgnoreCase(broker)) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("qpid.properties")); Context context = new InitialContext(properties); connFactory = (QueueConnectionFactory) context.lookup("qpidConnectionFactory"); } if (connFactory != null) { queueConnection = connFactory.createQueueConnection(); queueConnection.start(); session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); if (session != null) { Queue queue = session.createQueue(queueName); MessageProducer producer = session.createProducer(queue); List<String> messagesList = JMSClientUtil.readFile(filePath); try { if ("csv".equalsIgnoreCase(format)) { log.info("Sending Map messages on '" + queueName + "' queue"); JMSClientUtil.publishMapMessage(producer, session, messagesList); } else { log.info("Sending " + format + " messages on '" + queueName + "' queue"); JMSClientUtil.publishTextMessage(producer, session, messagesList); } } catch (JMSException e) { log.error("Cannot subscribe." + e.getMessage(), e); } catch (IOException e) { log.error("Error when reading the data file." + e.getMessage(), e); } finally { producer.close(); session.close(); queueConnection.stop(); } } } else { log.error("Error when creating connection factory. Please check necessary jar files"); } } else { log.error("Enter queue name or topic name to be published!"); } } catch (Exception e) { log.error("Error when publishing" + e.getMessage(), e); } }
From source file:org.easy.ldap.LdapContextFactory.java
/** * @param rootDn/*from w w w .j a v a 2 s .com*/ * @return * @throws NamingException */ public DirContext createContext(String rootDn) throws NamingException { Hashtable<String, String> properties = getEnviroment(); properties.put(Context.PROVIDER_URL, createProviderUrl(rootDn)); return createContext(properties); }
From source file:org.eclipselabs.etrack.util.security.ldap.impl.LdapSecurityService.java
void activate(Map<?, ?> configuration) throws NamingException { this.url = (String) configuration.get(CONFIG_URL); this.baseDN = (String) configuration.get(CONFIG_BASE_DN); String managerDN = (String) configuration.get(CONFIG_MANAGER_DN); String managerPassword = (String) configuration.get(CONFIG_MANAGER_PASSWORD); 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); if (managerDN != null) { environment.put(Context.SECURITY_AUTHENTICATION, "simple"); environment.put(Context.SECURITY_PRINCIPAL, managerDN); environment.put(Context.SECURITY_CREDENTIALS, managerPassword); } else/*from w w w. ja v a 2s . c o m*/ environment.put(Context.SECURITY_AUTHENTICATION, "none"); searchContext = new InitialDirContext(environment); }
From source file:org.web4thejob.security.ADAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (authentication.getName() == null || (String) authentication.getCredentials() == null) { throw new BadCredentialsException(""); }//from w w w .ja v a 2 s . c o m String principal = getPrincipal(authentication.getName()); String passwd = (String) authentication.getCredentials(); LdapContext ctx = null; try { Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.INITIAL_CONTEXT_FACTORY, LdapCtxFactory.class.getCanonicalName()); env.put(Context.SECURITY_AUTHENTICATION, "Simple"); env.put(Context.SECURITY_PRINCIPAL, principal); env.put(Context.SECURITY_CREDENTIALS, passwd); env.put(Context.PROVIDER_URL, url); ctx = new InitialLdapContext(env, null); //LDAP Connection Successful UserDetails userDetails = userDetailsService.loadUserByUsername(principal); return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities()); } catch (NamingException nex) { throw new BadCredentialsException("LDAP authentication failed.", nex); } catch (UsernameNotFoundException e) { throw new BadCredentialsException("UserDetails did not find a valid user for name: " + principal, e); } finally { if (ctx != null) { try { ctx.close(); } catch (Exception ignore) { } } } }
From source file:it.doqui.index.ecmengine.client.backoffice.EcmEngineBackofficeDirectDelegateImpl.java
@Override protected EcmEngineBackofficeBusinessInterface createBackofficeService() throws Throwable { Properties properties = new Properties(); this.log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] BEGIN "); rb = ResourceBundle.getBundle(ECMENGINE_BKO_PROPERTIES_FILE); /*//from ww w .j a v a 2 s . com * Caricamento della porta delegata del backoffice. */ try { this.log.debug( "[" + getClass().getSimpleName() + "::createBackofficeService] P-Delegata di backoffice."); this.log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] context factory vale : " + rb.getString(ECMENGINE_BKO_CONTEXT_FACTORY)); properties.put(Context.INITIAL_CONTEXT_FACTORY, rb.getString(ECMENGINE_BKO_CONTEXT_FACTORY)); this.log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] url to connect vale : " + rb.getString(ECMENGINE_BKO_URL_TO_CONNECT)); properties.put(Context.PROVIDER_URL, rb.getString(ECMENGINE_BKO_URL_TO_CONNECT)); /* Controllo che la property cluster partition sia valorizzata per capire se * sto lavorando in una configurazione in cluster oppure no */ String clusterPartition = rb.getString(ECMENGINE_BKO_CLUSTER_PARTITION); this.log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] clusterPartition vale : " + clusterPartition); if (clusterPartition != null && clusterPartition.length() > 0) { properties.put("jnp.partitionName", clusterPartition); this.log.debug( "[" + getClass().getSimpleName() + "::createBackofficeService] disable discovery vale : " + rb.getString(ECMENGINE_BKO_DISABLE_DISCOVERY)); properties.put("jnp.disableDiscovery", rb.getString(ECMENGINE_BKO_DISABLE_DISCOVERY)); } // Get an initial context InitialContext jndiContext = new InitialContext(properties); log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] context istanziato"); // Get a reference to the Bean Object ref = jndiContext.lookup(ECMENGINE_BKO_JNDI_NAME); // Get a reference from this to the Bean's Home interface EcmEngineBackofficeHome home = (EcmEngineBackofficeHome) PortableRemoteObject.narrow(ref, EcmEngineBackofficeHome.class); // Create an Adder object from the Home interface return home.create(); } catch (Throwable e) { this.log.error("[" + getClass().getSimpleName() + "::createBackofficeService] " + "Impossibile istanziare la P-Delegata di backoffice: " + e.getMessage()); throw e; } finally { this.log.debug("[" + getClass().getSimpleName() + "::createBackofficeService] END "); } }
From source file:org.compass.core.jndi.NamingHelper.java
/** * Transform JNDI properties passed in the form * <code>compass.jndi. [vaules]</code> to the format accepted by * <code>InitialContext</code> by triming the leading "<code>compass.jndi</code>". *//* w w w .j av a2 s.c om*/ public static Properties getJndiProperties(CompassSettings settings) { HashSet specialProps = new HashSet(); specialProps.add(CompassEnvironment.Jndi.CLASS); specialProps.add(CompassEnvironment.Jndi.URL); specialProps.add(CompassEnvironment.Jndi.ENABLE); Iterator iter = settings.keySet().iterator(); Properties result = new Properties(); while (iter.hasNext()) { String prop = (String) iter.next(); if (prop.indexOf(CompassEnvironment.Jndi.PREFIX) > -1 && !specialProps.contains(prop)) { result.setProperty(prop.substring(CompassEnvironment.Jndi.PREFIX.length() + 1), settings.getSetting(prop)); } } String jndiClass = settings.getSetting(CompassEnvironment.Jndi.CLASS); String jndiURL = settings.getSetting(CompassEnvironment.Jndi.URL); // we want to be able to just use the defaults, // if JNDI environment properties are not supplied // so don't put null in anywhere if (jndiClass != null) result.put(Context.INITIAL_CONTEXT_FACTORY, jndiClass); if (jndiURL != null) result.put(Context.PROVIDER_URL, jndiURL); return result; }
From source file:net.identio.server.service.authentication.ldap.LdapConnectionFactory.java
private InitialLdapContext createContext(LdapAuthMethod ldapAuthMethod, String userDn, String password) throws NamingException { LOG.debug("Begin creation of an LDAP connection to: {}", ldapAuthMethod.getName()); int currentUrlIndexTs = currentUrlIndex; String currentUrl = ldapAuthMethod.getLdapUrl().get(currentUrlIndexTs); Hashtable<String, String> env = new Hashtable<>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, currentUrl); if (currentUrl.startsWith("ldaps://")) { // Add a custom SSL Socket factory to validate server CA env.put("java.naming.ldap.factory.socket", "net.identio.server.service.authentication.ldap.LdapSslSocketFactory"); }//w w w . j a va 2 s.co m if (userDn != null) { env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, userDn); env.put(Context.SECURITY_CREDENTIALS, password); } InitialLdapContext ctx; try { ctx = new InitialLdapContext(env, null); } catch (CommunicationException e) { LOG.error("Error when contacting LDAP server {}", ldapAuthMethod.getLdapUrl().get(currentUrlIndexTs)); if (ldapAuthMethod.getLdapUrl().size() > 1) { int newCurrentUrlIndex = currentUrlIndexTs < ldapAuthMethod.getLdapUrl().size() - 1 ? currentUrlIndexTs + 1 : 0; LOG.error("Switching to LDAP server {}", ldapAuthMethod.getLdapUrl().get(newCurrentUrlIndex)); currentUrlIndex = newCurrentUrlIndex; env.put(Context.PROVIDER_URL, ldapAuthMethod.getLdapUrl().get(newCurrentUrlIndex)); ctx = new InitialLdapContext(env, null); } else { throw e; } } return ctx; }
From source file:org.jboss.adminclient.connection.RemoteProfileServiceConnectionProvider.java
protected ProfileServiceConnectionImpl doConnect() { Properties env = new Properties(); env.setProperty(Context.PROVIDER_URL, this.providerURL); ProfileService profileService;/*from ww w . j a va 2s. c o m*/ ManagementView managementView; DeploymentManager deploymentManager; ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); if (this.principal != null) { env.setProperty(Context.INITIAL_CONTEXT_FACTORY, JNDI_LOGIN_INITIAL_CONTEXT_FACTORY); env.setProperty(Context.SECURITY_PRINCIPAL, this.principal); env.setProperty(Context.SECURITY_CREDENTIALS, this.credentials); log.debug("Connecting to Profile Service via remote JNDI using env [" + env + "]..."); InitialContext initialContext = createInitialContext(env); profileService = (ProfileService) lookup(initialContext, SECURE_PROFILE_SERVICE_JNDI_NAME); managementView = (ManagementView) lookup(initialContext, SECURE_MANAGEMENT_VIEW_JNDI_NAME); deploymentManager = (DeploymentManager) lookup(initialContext, SECURE_DEPLOYMENT_MANAGER_JNDI_NAME); } else { env.setProperty(Context.INITIAL_CONTEXT_FACTORY, NAMING_CONTEXT_FACTORY); env.setProperty(JNP_DISABLE_DISCOVERY_JNP_INIT_PROP, "true"); // Make sure the timeout always happens, even if the JBoss server is hung. env.setProperty("jnp.timeout", String.valueOf(JNP_TIMEOUT)); env.setProperty("jnp.sotimeout", String.valueOf(JNP_SO_TIMEOUT)); log.debug("Connecting to Profile Service via remote JNDI using env [" + env + "]..."); InitialContext initialContext = createInitialContext(env); profileService = (ProfileService) lookup(initialContext, PROFILE_SERVICE_JNDI_NAME); managementView = profileService.getViewManager(); deploymentManager = profileService.getDeploymentManager(); } } finally { Thread.currentThread().setContextClassLoader(originalContextClassLoader); } return new ProfileServiceConnectionImpl(this, profileService, managementView, deploymentManager); }
From source file:org.easy.ldap.LdapContextFactory.java
/** * @return//from w ww. ja v a 2s . c o m * @throws NamingException */ public DirContext createDomainContext() throws NamingException { Hashtable<String, String> properties = getEnviroment(); properties.put(Context.PROVIDER_URL, createProviderUrl(environment.getProperty(PropertyNames.DOMAIN_DN))); return createContext(properties); }