Search in sources :

Example 21 with BasesConfig

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));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Example 22 with BasesConfig

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()));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) Test(org.junit.Test)

Example 23 with BasesConfig

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"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) Test(org.junit.Test)

Example 24 with BasesConfig

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))));
}
Also used : BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig)

Example 25 with BasesConfig

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()));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Aggregations

BasesConfig (com.thoughtworks.go.config.server.security.ldap.BasesConfig)35 Test (org.junit.Test)33 BaseConfig (com.thoughtworks.go.config.server.security.ldap.BaseConfig)30 LdapConfig (com.thoughtworks.go.config.LdapConfig)14 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)10 DirContextOperations (org.springframework.ldap.core.DirContextOperations)6 UsernameNotFoundException (org.springframework.security.userdetails.UsernameNotFoundException)6 GoCipher (com.thoughtworks.go.security.GoCipher)4 AdminsConfig (com.thoughtworks.go.config.AdminsConfig)3 PasswordFileConfig (com.thoughtworks.go.config.PasswordFileConfig)3 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 SearchControls (javax.naming.directory.SearchControls)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 AttributesMapperCallbackHandler (org.springframework.ldap.core.AttributesMapperCallbackHandler)2 DefaultSpringSecurityContextSource (org.springframework.security.ldap.DefaultSpringSecurityContextSource)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 AbstractContextSource (org.springframework.ldap.core.support.AbstractContextSource)1