Search in sources :

Example 6 with BaseConfig

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

Example 7 with BaseConfig

use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.

the class ServerConfigServiceIntegrationTest method shouldUpdateOnlyLdapConfiguration.

@Test
public void shouldUpdateOnlyLdapConfiguration() {
    CruiseConfig cruiseConfig = goConfigDao.loadForEditing();
    LdapConfig newLdapConfig = new LdapConfig("url", "managerDN", "managerPassword", "encrypted", true, new BasesConfig(new BaseConfig("base1"), new BaseConfig("base2")), "filter");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ServerConfig serverConfig = cruiseConfig.server();
    serverConfigService.updateServerConfig(cruiseConfig.mailHost(), newLdapConfig, serverConfig.security().passwordFileConfig(), serverConfig.artifactsDir(), serverConfig.getPurgeStart(), serverConfig.getPurgeUpto(), serverConfig.getJobTimeout(), true, serverConfig.getSiteUrl().getUrl(), serverConfig.getSecureSiteUrl().getUrl(), serverConfig.getCommandRepositoryLocation(), result, cruiseConfig.getMd5());
    goConfigDao.forceReload();
    CruiseConfig updatedCruiseConfig = goConfigDao.loadForEditing();
    assertThat(result.isSuccessful(), is(true));
    assertThat(updatedCruiseConfig.server().security().ldapConfig().isEnabled(), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Example 8 with BaseConfig

use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.

the class ServerConfigServiceIntegrationTest method shouldUseTheNewPasswordIfItIsChanged.

@Test
public void shouldUseTheNewPasswordIfItIsChanged() {
    LdapConfig ldapConfig = new LdapConfig(LDAP_URL, MANAGER_DN, "changed_password", "encrypted_password", true, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
    DefaultSpringSecurityContextSource source = serverConfigService.ldapContextSource(ldapConfig);
    assertThat(source.getAuthenticationSource().getCredentials(), is("changed_password"));
}
Also used : DefaultSpringSecurityContextSource(org.springframework.security.ldap.DefaultSpringSecurityContextSource) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Example 9 with BaseConfig

use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.

the class ServerConfigServiceIntegrationTest method shouldReturnErrorResultWhenLdapSearchFails.

@Test
public void shouldReturnErrorResultWhenLdapSearchFails() throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    LdapConfig invalidLdapConfig = new LdapConfig(new GoCipher());
    serverConfigService.validateLdapSettings(invalidLdapConfig, result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("Cannot connect to ldap, please check the settings. Reason: An LDAP connection URL must be supplied."));
    result = new HttpLocalizedOperationResult();
    invalidLdapConfig = new LdapConfig("ldap://some_loser_url", MANAGER_DN, MANAGER_PASSWORD, null, true, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
    serverConfigService.validateLdapSettings(invalidLdapConfig, result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("Cannot connect to ldap, please check the settings. Reason: some_loser_url:389; nested exception is javax.naming.CommunicationException: some_loser_url:389 [Root exception is java.net.UnknownHostException: some_loser_url]"));
    result = new HttpLocalizedOperationResult();
    invalidLdapConfig = new LdapConfig(LDAP_URL, "invalidDN=1", MANAGER_PASSWORD, null, true, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
    serverConfigService.validateLdapSettings(invalidLdapConfig, result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("Cannot connect to ldap, please check the settings." + " Reason: [LDAP: error code 49 - Unable to bind as user 'invalidDN=1' because no such entry" + " exists in the server.]; nested exception is javax.naming.AuthenticationException:" + " [LDAP: error code 49 - Unable to bind as user 'invalidDN=1' because no such entry exists in the server.]"));
    result = new HttpLocalizedOperationResult();
    invalidLdapConfig = new LdapConfig(LDAP_URL, MANAGER_DN, "wrong_password", null, true, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
    serverConfigService.validateLdapSettings(invalidLdapConfig, result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("Cannot connect to ldap, please check the settings." + " Reason: [LDAP: error code 49 - Unable to bind as user 'cn=Active Directory Ldap User," + "ou=SomeSystems,ou=Accounts,ou=Principal,dc=corp,dc=somecompany,dc=com' because the provided" + " password was incorrect.]; nested exception is javax.naming.AuthenticationException:" + " [LDAP: error code 49 - Unable to bind as user 'cn=Active Directory Ldap User," + "ou=SomeSystems,ou=Accounts,ou=Principal,dc=corp,dc=somecompany,dc=com' because the provided" + " password was incorrect.]"));
    result = new HttpLocalizedOperationResult();
    LdapConfig validConfig = new LdapConfig(LDAP_URL, MANAGER_DN, MANAGER_PASSWORD, null, true, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
    serverConfigService.validateLdapSettings(validConfig, result);
    assertThat("Expected no message. Got: " + result.message(localizer), result.isSuccessful(), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) 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 10 with BaseConfig

use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.

the class LdapConfigChangedListenerTest method shouldReinitializeDelegator_whenLdapManagerPasswordChanges.

@Test
public void shouldReinitializeDelegator_whenLdapManagerPasswordChanges() {
    LdapConfig oldLdapConfig = new LdapConfig("oldOne", "manager", "pwd", null, true, new BasesConfig(new BaseConfig("foo")), "bar");
    helper.addLdapSecurityWith(oldLdapConfig, true, new PasswordFileConfig(), new AdminsConfig());
    LdapContextFactory mockContextFactory = mock(LdapContextFactory.class);
    LdapConfigChangedListener listener = new LdapConfigChangedListener(oldLdapConfig, mockContextFactory);
    LdapConfig newLdapConfig = new LdapConfig("oldOne", "manager", "new_pwd", null, true, new BasesConfig(new BaseConfig("foo")), "bar");
    helper.addLdapSecurityWith(newLdapConfig, true, new PasswordFileConfig(), new AdminsConfig());
    listener.onConfigChange(helper.currentConfig());
    verify(mockContextFactory).initializeDelegator();
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) PasswordFileConfig(com.thoughtworks.go.config.PasswordFileConfig) AdminsConfig(com.thoughtworks.go.config.AdminsConfig) Test(org.junit.Test)

Aggregations

BaseConfig (com.thoughtworks.go.config.server.security.ldap.BaseConfig)33 BasesConfig (com.thoughtworks.go.config.server.security.ldap.BasesConfig)30 Test (org.junit.Test)29 LdapConfig (com.thoughtworks.go.config.LdapConfig)15 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)11 UsernameNotFoundException (org.springframework.security.userdetails.UsernameNotFoundException)7 DirContextOperations (org.springframework.ldap.core.DirContextOperations)6 GoCipher (com.thoughtworks.go.security.GoCipher)4 AdminsConfig (com.thoughtworks.go.config.AdminsConfig)3 PasswordFileConfig (com.thoughtworks.go.config.PasswordFileConfig)3 SearchControls (javax.naming.directory.SearchControls)3 AttributesMapperCallbackHandler (org.springframework.ldap.core.AttributesMapperCallbackHandler)3 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 DefaultSpringSecurityContextSource (org.springframework.security.ldap.DefaultSpringSecurityContextSource)2 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 AbstractContextSource (org.springframework.ldap.core.support.AbstractContextSource)1 LikeFilter (org.springframework.ldap.filter.LikeFilter)1 OrFilter (org.springframework.ldap.filter.OrFilter)1