use of com.thoughtworks.go.config.server.security.ldap.BasesConfig in project gocd by gocd.
the class ServerConfigServiceIntegrationTest method shouldUseTheEncryptedPasswordWhenPasswordIsNotChanged.
@Test
public void shouldUseTheEncryptedPasswordWhenPasswordIsNotChanged() throws InvalidCipherTextException {
String encryptedPassword = new GoCipher().encrypt("encrypted_password");
LdapConfig ldapConfig = new LdapConfig(LDAP_URL, MANAGER_DN, MANAGER_PASSWORD, encryptedPassword, false, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
DefaultSpringSecurityContextSource source = serverConfigService.ldapContextSource(ldapConfig);
assertThat(source.getAuthenticationSource().getCredentials(), is("encrypted_password"));
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig in project gocd by gocd.
the class LdapUserSearchTest method shouldThrowExceptionWhenSearchingIfBaseSearchIsEmpty.
@Test
public void shouldThrowExceptionWhenSearchingIfBaseSearchIsEmpty() {
setLdapConfig(new BasesConfig());
thrown.expect(RuntimeException.class);
thrown.expectMessage(is("Atleast one Search Base needs to be configured."));
spy.search("username");
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig in project gocd by gocd.
the class LdapUserSearchTest method shouldFilterForMatchingUsernamesInSearchBase.
@Test
public void shouldFilterForMatchingUsernamesInSearchBase() throws Exception {
ldapUserSearch.search("username", ldapConfig(new BasesConfig(new BaseConfig("base1"))));
verify(ldapTemplate).search(argThat(is("base1")), anyString(), any(SearchControls.class), any(AttributesMapperCallbackHandler.class));
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig in project gocd by gocd.
the class LdapConfigChangedListenerTest method shouldTriggerReintializeOfContextFactoryOnChangeOnLdapConfig.
@Test
public void shouldTriggerReintializeOfContextFactoryOnChangeOnLdapConfig() {
LdapConfig oldLdapConfig = new LdapConfig("oldOne", "manager", "pwd", null, true, new BasesConfig(new BaseConfig("foo")), "bar");
LdapConfig newLdapConfig = new LdapConfig("newOne", "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(newLdapConfig, true, new PasswordFileConfig(), new AdminsConfig());
listener.onConfigChange(helper.currentConfig());
verify(mockContextFactory, times(1)).initializeDelegator();
}
use of com.thoughtworks.go.config.server.security.ldap.BasesConfig in project gocd by gocd.
the class LdapUserSearchTest method shouldNotLogWhenUserNameNotFoundExceptionIsThrown.
@Test
public void shouldNotLogWhenUserNameNotFoundExceptionIsThrown() {
final FilterBasedLdapUserSearch filter1 = mock(FilterBasedLdapUserSearch.class);
final FilterBasedLdapUserSearch filter2 = mock(FilterBasedLdapUserSearch.class);
LdapConfig ldapConfig = setLdapConfig(new BasesConfig(new BaseConfig("base1"), new BaseConfig("base2")));
DirContextOperations foundUser = mock(DirContextOperations.class);
doReturn(filter1).when(spy).getFilterBasedLdapUserSearch(ldapConfig.getBasesConfig().get(0).getValue(), ldapConfig.searchFilter());
doReturn(filter2).when(spy).getFilterBasedLdapUserSearch(ldapConfig.getBasesConfig().get(1).getValue(), ldapConfig.searchFilter());
when(filter1.searchForUser("username")).thenThrow(new UsernameNotFoundException("User username not found in directory."));
when(filter2.searchForUser("username")).thenReturn(foundUser);
spy.searchForUser("username");
verify(logger, never()).warn(Matchers.<Object>any(), Matchers.<Throwable>any());
}
Aggregations