List of usage examples for javax.naming Context SECURITY_PROTOCOL
String SECURITY_PROTOCOL
To view the source code for javax.naming Context SECURITY_PROTOCOL.
Click Source Link
From source file:org.rhq.enterprise.server.core.CustomJaasDeploymentService.java
private void validateLdapOptions(Map<String, String> options) throws NamingException { Properties env = new Properties(); String factory = options.get(Context.INITIAL_CONTEXT_FACTORY); if (factory == null) { throw new NamingException("No initial context factory"); }/*from w w w. j av a 2s . c o m*/ String url = options.get(Context.PROVIDER_URL); if (url == null) { throw new NamingException("Naming provider url not set"); } String protocol = options.get(Context.SECURITY_PROTOCOL); if ("ssl".equals(protocol)) { String ldapSocketFactory = env.getProperty("java.naming.ldap.factory.socket"); if (ldapSocketFactory == null) { env.put("java.naming.ldap.factory.socket", UntrustedSSLSocketFactory.class.getName()); } env.put(Context.SECURITY_PROTOCOL, "ssl"); } env.setProperty(Context.INITIAL_CONTEXT_FACTORY, factory); env.setProperty(Context.PROVIDER_URL, url); // Load any information we may need to bind String bindDN = options.get("BindDN"); String bindPW = options.get("BindPW"); if ((bindDN != null) && (bindDN.length() != 0) && (bindPW != null) && (bindPW.length() != 0)) { env.setProperty(Context.SECURITY_PRINCIPAL, bindDN); env.setProperty(Context.SECURITY_CREDENTIALS, bindPW); env.setProperty(Context.SECURITY_AUTHENTICATION, "simple"); } log.debug("Validating LDAP properties. Initializing context..."); new InitialLdapContext(env, null).close(); return; }
From source file:org.rhq.enterprise.server.core.jaas.LdapLoginModule.java
/** * Load a default set of properties to use when connecting to the LDAP server. If basic authentication is needed, * the caller must set Context.SECURITY_PRINCIPAL, Context.SECURITY_CREDENTIALS and Context.SECURITY_AUTHENTICATION * appropriately./* w w w . j ava 2s. c o m*/ * * @return properties that are to be used when connecting to LDAP server */ private Properties getProperties() { Properties env = new Properties(); // Map all user options into into our environment Iterator iter = options.entrySet().iterator(); while (iter.hasNext()) { Entry entry = (Entry) iter.next(); if ((entry.getKey() != null) && (entry.getValue() != null)) { env.put(entry.getKey(), entry.getValue()); } } // Set our default factory name if one is not given String factoryName = env.getProperty(Context.INITIAL_CONTEXT_FACTORY); if (factoryName == null) { env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); } // Setup SSL if requested String protocol = env.getProperty(Context.SECURITY_PROTOCOL); if ("ssl".equals(protocol)) { String ldapSocketFactory = env.getProperty("java.naming.ldap.factory.socket"); if (ldapSocketFactory == null) { env.put("java.naming.ldap.factory.socket", UntrustedSSLSocketFactory.class.getName()); } env.put(Context.SECURITY_PROTOCOL, "ssl"); } // Set the LDAP url String providerUrl = env.getProperty(Context.PROVIDER_URL); if (providerUrl == null) { providerUrl = "ldap://localhost:" + (((protocol != null) && protocol.equals("ssl")) ? "636" : "389"); } env.setProperty(Context.PROVIDER_URL, providerUrl); // Follow referrals automatically env.setProperty(Context.REFERRAL, "ignore");//BZ:582471- active directory query change return env; }
From source file:org.rhq.enterprise.server.resource.group.LdapGroupManagerBean.java
/** * Load a default set of properties to use when connecting to the LDAP server. If basic authentication is needed, * the caller must set Context.SECURITY_PRINCIPAL, Context.SECURITY_CREDENTIALS and Context.SECURITY_AUTHENTICATION * appropriately.//from ww w.j a v a2 s . c o m * * @return properties that are to be used when connecting to LDAP server */ private Properties getProperties(Properties systemConfig) { Properties env = new Properties(systemConfig); // Set our default factory name if one is not given String factoryName = env.getProperty(RHQConstants.LDAPFactory); env.setProperty(Context.INITIAL_CONTEXT_FACTORY, factoryName); // Setup SSL if requested String value = env.getProperty(SystemSetting.USE_SSL_FOR_LDAP.getInternalName()); boolean ldapSsl = "ssl".equalsIgnoreCase(value); if (ldapSsl) { String ldapSocketFactory = env.getProperty("java.naming.ldap.factory.socket"); if (ldapSocketFactory == null) { env.put("java.naming.ldap.factory.socket", UntrustedSSLSocketFactory.class.getName()); } env.put(Context.SECURITY_PROTOCOL, "ssl"); } // Set the LDAP url String providerUrl = env.getProperty(RHQConstants.LDAPUrl); if (providerUrl == null) { int port = (ldapSsl) ? 636 : 389; providerUrl = "ldap://localhost:" + port; } env.setProperty(Context.PROVIDER_URL, providerUrl); // Follow referrals automatically env.setProperty(Context.REFERRAL, "ignore"); //BZ:582471- active directory query change return env; }
From source file:org.wso2.carbon.connector.ldap.LDAPUtils.java
protected static DirContext getDirectoryContext(MessageContext messageContext) throws NamingException { String providerUrl = LDAPUtils.lookupContextParams(messageContext, LDAPConstants.PROVIDER_URL); String securityPrincipal = LDAPUtils.lookupContextParams(messageContext, LDAPConstants.SECURITY_PRINCIPAL); String securityCredentials = LDAPUtils.lookupContextParams(messageContext, LDAPConstants.SECURITY_CREDENTIALS); boolean secureConnection = Boolean .valueOf(LDAPUtils.lookupContextParams(messageContext, LDAPConstants.SECURE_CONNECTION)); boolean disableSSLCertificateChecking = Boolean .valueOf(LDAPUtils.lookupContextParams(messageContext, LDAPConstants.DISABLE_SSL_CERT_CHECKING)); Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, LDAPConstants.COM_SUN_JNDI_LDAP_LDAPCTXFACTORY); env.put(Context.PROVIDER_URL, providerUrl); env.put(Context.SECURITY_PRINCIPAL, securityPrincipal); env.put(Context.SECURITY_CREDENTIALS, securityCredentials); if (secureConnection) { env.put(Context.SECURITY_PROTOCOL, LDAPConstants.SSL); }/*w w w . ja va 2 s .c o m*/ if (disableSSLCertificateChecking) { env.put(LDAPConstants.JAVA_NAMING_LDAP_FACTORY_SOCKET, LDAPConstants.ORG_WSO2_CARBON_CONNECTOR_SECURITY_MYSSLSOCKETFACTORY); } DirContext ctx = null; ctx = new InitialDirContext(env); return ctx; }