use of com.thoughtworks.go.config.server.security.ldap.BasesConfig in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldWriteMultipleSearchBases.
@Test
public void shouldWriteMultipleSearchBases() throws Exception {
BaseConfig base1 = new BaseConfig("base1");
BaseConfig base2 = new BaseConfig("base2");
BasesConfig basesConfig = new BasesConfig(base1, base2);
LdapConfig ldapConfig = new LdapConfig("url", "managerDn", "managerPassword", "managerPassword", false, basesConfig, "filter");
SecurityConfig securityConfig = new SecurityConfig(ldapConfig, new PasswordFileConfig("some_path"), false);
ServerConfig serverConfig = new ServerConfig(securityConfig, new MailHost(new GoCipher()));
CruiseConfig cruiseConfig = new BasicCruiseConfig();
cruiseConfig.setServerConfig(serverConfig);
xmlWriter.write(cruiseConfig, output, false);
GoConfigHolder holder = xmlLoader.loadConfigHolder(output.toString());
BasesConfig actualBasesConfig = holder.config.server().security().ldapConfig().getBasesConfig();
assertThat(actualBasesConfig.size(), is(2));
assertThat(actualBasesConfig, hasItems(base1, base2));
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig in project gocd by gocd.
the class GoConfigMigrationIntegrationTest method shouldMigrateFrom61_MigrateSearchBaseIntoAnElementAndOnlyOtherNecessaryFields.
@Test
public void shouldMigrateFrom61_MigrateSearchBaseIntoAnElementAndOnlyOtherNecessaryFields() throws Exception {
final String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<cruise schemaVersion=\"61\">\n" + " <server artifactsdir=\"artifacts\">\n" + " <security>" + " <ldap uri='some_url' searchBase='ou=Enterprise,ou=Principal,dc=corporate,dc=thoughtworks,dc=com'/>" + " </security>" + " </server>" + " </cruise>";
CruiseConfig config = migrateConfigAndLoadTheNewConfig(content, 61);
LdapConfig ldapConfig = config.server().security().ldapConfig();
BasesConfig basesConfig = ldapConfig.getBasesConfig();
assertThat(basesConfig.size(), is(1));
assertThat(basesConfig.first().getValue(), is("ou=Enterprise,ou=Principal,dc=corporate,dc=thoughtworks,dc=com"));
assertThat(ldapConfig.uri(), is("some_url"));
assertThat(ldapConfig.searchFilter(), isEmptyString());
assertThat(ldapConfig.managerDn(), isEmptyString());
assertThat(ldapConfig.managerPassword(), isEmptyString());
assertThat(ldapConfig.getEncryptedManagerPassword(), is(nullValue()));
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig in project gocd by gocd.
the class GoConfigMigrationIntegrationTest method shouldMigrateFrom61_MigrateSearchBaseIntoAnElement.
@Test
public void shouldMigrateFrom61_MigrateSearchBaseIntoAnElement() throws Exception {
final String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<cruise schemaVersion=\"61\">\n" + " <server artifactsdir=\"artifacts\">\n" + " <security>" + " <ldap uri='some_url' managerDn='some_manager_dn' managerPassword='foo' searchBase='ou=Enterprise,ou=Principal,dc=corporate,dc=thoughtworks,dc=com' searchFilter='(sAMAccountName={0})' />" + " </security>" + " </server>" + " </cruise>";
CruiseConfig config = migrateConfigAndLoadTheNewConfig(content, 61);
LdapConfig ldapConfig = config.server().security().ldapConfig();
BasesConfig basesConfig = ldapConfig.getBasesConfig();
assertThat(basesConfig.size(), is(1));
assertThat(basesConfig.first().getValue(), is("ou=Enterprise,ou=Principal,dc=corporate,dc=thoughtworks,dc=com"));
assertThat(ldapConfig.searchFilter(), is("(sAMAccountName={0})"));
assertThat(ldapConfig.uri(), is("some_url"));
assertThat(ldapConfig.managerDn(), is("some_manager_dn"));
assertThat(ldapConfig.managerPassword(), is("foo"));
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig in project gocd by gocd.
the class GoConfigFileHelper method addLdapSecurityWithAdmin.
public void addLdapSecurityWithAdmin(String uri, String managerDn, String managerPassword, String searchBase, String searchFilter, String adminUser) {
LdapConfig ldapConfig = new LdapConfig(uri, managerDn, managerPassword, null, true, new BasesConfig(new BaseConfig(searchBase)), searchFilter);
addLdapSecurityWith(ldapConfig, true, new PasswordFileConfig(), new AdminsConfig(new AdminUser(new CaseInsensitiveString(adminUser))));
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig in project gocd by gocd.
the class SecurityConfigTest method shouldNotUpdateManagerPasswordForLDAPIfNotChangedOrNull.
@Test
public void shouldNotUpdateManagerPasswordForLDAPIfNotChangedOrNull() throws InvalidCipherTextException {
SecurityConfig securityConfig = new SecurityConfig();
securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "p", null, true, new BasesConfig(new BaseConfig("")), ""));
assertThat(ReflectionUtil.getField(securityConfig.ldapConfig(), "managerPassword"), is(""));
assertThat(securityConfig.ldapConfig().managerPassword(), is("p"));
String encryptedPassword = new GoCipher().encrypt("p");
assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(encryptedPassword));
securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "notP", null, false, new BasesConfig(new BaseConfig("")), ""));
assertThat(ReflectionUtil.getField(securityConfig.ldapConfig(), "managerPassword"), is(""));
assertThat(securityConfig.ldapConfig().managerPassword(), is("p"));
assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(encryptedPassword));
securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "", null, true, new BasesConfig(new BaseConfig("")), ""));
assertThat(securityConfig.ldapConfig().managerPassword(), is(""));
assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(nullValue()));
}
Aggregations