use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.
the class GoConfigFileHelper method addLdapSecurity.
public void addLdapSecurity(String uri, String managerDn, String managerPassword, String searchBase, String searchFilter) {
LdapConfig ldapConfig = new LdapConfig(uri, managerDn, managerPassword, null, true, new BasesConfig(new BaseConfig(searchBase)), searchFilter);
addLdapSecurityWith(ldapConfig, true, new PasswordFileConfig(), new AdminsConfig());
}
use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.
the class SecurityConfigTest method shouldBeAbleToTellIfSecurityMethodChangedFromNothingToLdap.
@Test
public void shouldBeAbleToTellIfSecurityMethodChangedFromNothingToLdap() {
SecurityConfig ldapSecurity = new SecurityConfig();
ldapSecurity.modifyLdap(new LdapConfig("ldap://uri", "dn", "p", null, true, new BasesConfig(new BaseConfig("")), ""));
assertTrue(new SecurityConfig().hasSecurityMethodChanged(ldapSecurity));
}
use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.
the class LdapConfigTest method shouldConsiderTwoLdapConfigsWithDifferentPasswordsUnequal.
@Test
public void shouldConsiderTwoLdapConfigsWithDifferentPasswordsUnequal() {
LdapConfig ldapConfig1 = new LdapConfig("uri", "managerDn", "password-1", null, true, new BasesConfig(new BaseConfig("blah")), "blah");
LdapConfig ldapConfig2 = new LdapConfig("uri", "managerDn", "password-2", null, true, new BasesConfig(new BaseConfig("blah")), "blah");
assertThat(ldapConfig1, is(Matchers.not(ldapConfig2)));
assertThat(ldapConfig1.hashCode(), is(Matchers.not(ldapConfig2.hashCode())));
}
use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.
the class LdapUserSearch method searchForUser.
public DirContextOperations searchForUser(String username) {
SecurityConfig securityConfig = goConfigService.security();
if (!securityConfig.isSecurityEnabled()) {
return null;
}
LdapConfig ldapConfig = securityConfig.ldapConfig();
RuntimeException lastFoundException = null;
BaseConfig failedBaseConfig = null;
for (BaseConfig baseConfig : ldapConfig.getBasesConfig()) {
if (lastFoundException != null && !(lastFoundException instanceof BadCredentialsException)) {
logger.warn(String.format("The ldap configuration for search base '%s' is invalid", failedBaseConfig.getValue()), lastFoundException);
}
FilterBasedLdapUserSearch search = getFilterBasedLdapUserSearch(baseConfig.getValue(), ldapConfig.searchFilter());
search.setSearchSubtree(true);
// timeout after five seconds
search.setSearchTimeLimit(5000);
try {
return search.searchForUser(username);
} catch (UsernameNotFoundException e) {
failedBaseConfig = baseConfig;
lastFoundException = new BadCredentialsException("Bad credentials");
} catch (RuntimeException e) {
failedBaseConfig = baseConfig;
lastFoundException = e;
}
}
if (lastFoundException != null) {
throw lastFoundException;
}
throw new RuntimeException("No LDAP Search Bases are configured.");
}
use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.
the class GoConfigServiceTest method shouldUnderstandIfLdapIsConfigured.
@Test
public void shouldUnderstandIfLdapIsConfigured() throws Exception {
CruiseConfig config = new BasicCruiseConfig();
config.setServerConfig(new ServerConfig(null, new SecurityConfig(new LdapConfig("test", "test", "test", null, true, new BasesConfig(new BaseConfig("test")), "test"), null, true, null)));
expectLoad(config);
assertThat("Ldap is configured", goConfigService.isLdapConfigured(), is(true));
}
Aggregations