use of com.thoughtworks.go.config.LdapConfig in project gocd by gocd.
the class LdapUserSearchTest method shouldReturnUserFoundInSecondSearchBase.
@Test
public void shouldReturnUserFoundInSecondSearchBase() {
final FilterBasedLdapUserSearch filter1 = mock(FilterBasedLdapUserSearch.class);
final FilterBasedLdapUserSearch filter2 = mock(FilterBasedLdapUserSearch.class);
LdapConfig ldapConfig = setLdapConfig(new BasesConfig(new BaseConfig("base1"), new BaseConfig("base2")));
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."));
DirContextOperations foundUser = mock(DirContextOperations.class);
when(filter2.searchForUser("username")).thenReturn(foundUser);
assertThat(spy.searchForUser("username"), is(foundUser));
verify(filter1).searchForUser("username");
verify(filter2).searchForUser("username");
}
use of com.thoughtworks.go.config.LdapConfig in project gocd by gocd.
the class LdapUserSearchTest method shouldNotLogWhenLastSearchBaseIsInvalidAndUserIsNotFound.
@Test
public void shouldNotLogWhenLastSearchBaseIsInvalidAndUserIsNotFound() {
final FilterBasedLdapUserSearch filter1 = mock(FilterBasedLdapUserSearch.class);
final FilterBasedLdapUserSearch filter2 = mock(FilterBasedLdapUserSearch.class);
LdapConfig ldapConfig = setLdapConfig(new BasesConfig(new BaseConfig("base1"), new BaseConfig("base2")));
doReturn(filter1).when(spy).getFilterBasedLdapUserSearch(ldapConfig.getBasesConfig().get(0).getValue(), ldapConfig.searchFilter());
doReturn(filter2).when(spy).getFilterBasedLdapUserSearch(ldapConfig.getBasesConfig().get(1).getValue(), ldapConfig.searchFilter());
RuntimeException runtimeException = new RuntimeException("Invalid search base");
when(filter1.searchForUser("username")).thenThrow(new UsernameNotFoundException("User not found"));
when(filter2.searchForUser("username")).thenThrow(runtimeException);
thrown.expect(RuntimeException.class);
spy.searchForUser("username");
verify(logger, never()).warn(Matchers.<Object>any(), Matchers.<Throwable>any());
}
use of com.thoughtworks.go.config.LdapConfig in project gocd by gocd.
the class LdapConfigChangedListener method onConfigChange.
public void onConfigChange(CruiseConfig newCruiseConfig) {
LdapConfig newLdapConfig = newCruiseConfig.server().security().ldapConfig();
if (!currentLdapConfig.equals(newLdapConfig)) {
ldapContextFactory.initializeDelegator();
currentLdapConfig = newLdapConfig;
LOGGER.info(String.format("[Configuration Changed] LDAP configuration changed."));
}
}
use of com.thoughtworks.go.config.LdapConfig in project gocd by gocd.
the class FileAuthenticationProviderTest method setupFile.
private void setupFile(String userAndPasswordAndRoles) throws IOException {
final File passwordFile = TestFileUtil.createTempFile("password.properties");
passwordFile.deleteOnExit();
FileUtils.writeStringToFile(passwordFile, userAndPasswordAndRoles);
final SecurityConfig securityConfig = new SecurityConfig(new LdapConfig(new GoCipher()), new PasswordFileConfig(passwordFile.getAbsolutePath()), true, null);
when(goConfigService.security()).thenReturn(securityConfig);
}
use of com.thoughtworks.go.config.LdapConfig in project gocd by gocd.
the class FileAuthenticationProviderTest method shouldThrowExceptionIfFileDoesNotExist.
@Test(expected = UsernameNotFoundException.class)
public void shouldThrowExceptionIfFileDoesNotExist() throws Exception {
when(goConfigService.security()).thenReturn(new SecurityConfig(new LdapConfig(new GoCipher()), new PasswordFileConfig("ueyrweiyri"), true, null));
AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
provider.retrieveUser("blah", null);
}
Aggregations