Search in sources :

Example 26 with BasesConfig

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

Example 27 with BasesConfig

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

Example 28 with BasesConfig

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));
}
Also used : SearchControls(javax.naming.directory.SearchControls) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) AttributesMapperCallbackHandler(org.springframework.ldap.core.AttributesMapperCallbackHandler) Test(org.junit.Test)

Example 29 with BasesConfig

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();
}
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)

Example 30 with BasesConfig

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());
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig) UsernameNotFoundException(org.springframework.security.userdetails.UsernameNotFoundException) DirContextOperations(org.springframework.ldap.core.DirContextOperations) FilterBasedLdapUserSearch(org.springframework.security.ldap.search.FilterBasedLdapUserSearch) 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