LdapContextSource buildLdapContextSource(LdapServerInventory inv, Map<String, Object> baseEnvironmentProperties) { LdapContextSource ldapContextSource; ldapContextSource = new LdapContextSource(); ldapContextSource.setUrl(inv.getUrl()); ldapContextSource.setBase(inv.getBase()); ldapContextSource.setUserDn(inv.getUsername()); ldapContextSource.setPassword(inv.getPassword()); ldapContextSource.setDirObjectFactory(DefaultDirObjectFactory.class); if (inv.getEncryption().equals(LdapEncryptionType.TLS.toString())) { setTls(ldapContextSource); } ldapContextSource.setCacheEnvironmentProperties(false); ldapContextSource.setPooled(false); ldapContextSource.setReferral("follow"); if (baseEnvironmentProperties != null && !baseEnvironmentProperties.isEmpty()) { ldapContextSource.setBaseEnvironmentProperties(baseEnvironmentProperties); } try { ldapContextSource.afterPropertiesSet(); logger.info("Test LDAP Context Source loaded "); } catch (Exception e) { logger.error("Test LDAP Context Source not loaded ", e); throw new CloudRuntimeException("Test LDAP Context Source not loaded", e); } return ldapContextSource; }
ldapURL); ldapContextSource.setCacheEnvironmentProperties(false); ldapContextSource.setAnonymousReadOnly(true);
private LdapContextSource getLdapContextSource() throws Exception { LdapContextSource ldapContextSource = new DefaultSpringSecurityContextSource( ldapURL); ldapContextSource.setUserDn(ldapBindDN); ldapContextSource.setPassword(ldapBindPassword); ldapContextSource.setReferral(ldapReferral); ldapContextSource.setCacheEnvironmentProperties(false); ldapContextSource.setAnonymousReadOnly(false); ldapContextSource.setPooled(true); ldapContextSource.afterPropertiesSet(); return ldapContextSource; }
@Test public void testGetAnonymousEnvWhenCacheIsOff() throws Exception { tested.setBase("dc=example,dc=se"); tested.setUrl("ldap://ldap.example.com:389"); tested.setPooled(true); tested.setUserDn("cn=Some User"); tested.setPassword("secret"); tested.setCacheEnvironmentProperties(false); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=example,dc=se"); assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true"); assertThat(env.get(Context.SECURITY_PRINCIPAL)).isNull(); assertThat(env.get(Context.SECURITY_CREDENTIALS)).isNull(); tested.setUrl("ldap://ldap2.example.com:389"); env = tested.getAnonymousEnv(); assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap2.example.com:389/dc=example,dc=se"); } }
ldapContextSource.setPassword(adBindPassword); ldapContextSource.setReferral(adReferral); ldapContextSource.setCacheEnvironmentProperties(true); ldapContextSource.setAnonymousReadOnly(false); ldapContextSource.setPooled(true);
/** * Creates an LdapContext from a configuration object. * * @param ldapConfig */ public static LdapContextSource createLdapContext(LDAPBaseSecurityServiceConfig ldapConfig) { LdapContextSource ldapContext = new DefaultSpringSecurityContextSource(ldapConfig.getServerURL()); ldapContext.setCacheEnvironmentProperties(false); ldapContext.setAuthenticationSource(new SpringSecurityAuthenticationSource()); if (ldapConfig.isUseTLS()) { // TLS does not play nicely with pooled connections ldapContext.setPooled(false); DefaultTlsDirContextAuthenticationStrategy tls = new DefaultTlsDirContextAuthenticationStrategy(); tls.setHostnameVerifier( new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); ldapContext.setAuthenticationStrategy(tls); } return ldapContext; }
ctxSource.setCacheEnvironmentProperties(config.isCacheEnvironmentProperties());
ctxSource.setCacheEnvironmentProperties(config.isCacheEnvironmentProperties());