use of com.thoughtworks.go.config.server.security.ldap.BasesConfig 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));
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig 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"));
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig 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));
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig 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();
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig in project gocd by gocd.
the class LdapConfigChangedListenerTest method shouldNotTriggerReintializeOfContextFactoryWhenLdapConfigDoesNotChange.
@Test
public void shouldNotTriggerReintializeOfContextFactoryWhenLdapConfigDoesNotChange() {
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);
helper.addLdapSecurityWith(oldLdapConfig, true, new PasswordFileConfig(), new AdminsConfig());
listener.onConfigChange(helper.currentConfig());
verify(mockContextFactory, never()).initializeDelegator();
}
Aggregations