Search in sources :

Example 16 with LdapConfig

use of com.thoughtworks.go.config.LdapConfig 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 17 with LdapConfig

use of com.thoughtworks.go.config.LdapConfig in project gocd by gocd.

the class LdapContextSourceConfiguratorTest method shouldNotSet_EitherManagerDn_OrPassword_OnContextSource_WhenNoManagerDnConfigured.

@Test
public void shouldNotSet_EitherManagerDn_OrPassword_OnContextSource_WhenNoManagerDnConfigured() {
    GoCipher goCipher = new GoCipher();
    LdapContextSourceConfigurator configurator = new LdapContextSourceConfigurator(new LdapConfig(goCipher));
    AbstractContextSource ctxSrc = mock(AbstractContextSource.class);
    configurator.configure(ctxSrc);
    verify(ctxSrc, never()).setPassword(any(String.class));
    verify(ctxSrc, never()).setUserDn(any(String.class));
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig) GoCipher(com.thoughtworks.go.security.GoCipher) AbstractContextSource(org.springframework.ldap.core.support.AbstractContextSource) Test(org.junit.Test)

Example 18 with LdapConfig

use of com.thoughtworks.go.config.LdapConfig 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)

Example 19 with LdapConfig

use of com.thoughtworks.go.config.LdapConfig in project gocd by gocd.

the class LdapUserSearchTest method setLdapConfig.

private LdapConfig setLdapConfig(final BasesConfig basesConfig) {
    when(securityConfig.isSecurityEnabled()).thenReturn(true);
    LdapConfig ldapConfig = ldapConfig(basesConfig);
    when(securityConfig.ldapConfig()).thenReturn(ldapConfig);
    return ldapConfig;
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig)

Example 20 with LdapConfig

use of com.thoughtworks.go.config.LdapConfig in project gocd by gocd.

the class LdapUserSearchTest method shouldSkipInvalidSearchBaseWhenAuthenticating.

@Test
public void shouldSkipInvalidSearchBaseWhenAuthenticating() {
    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());
    DirContextOperations foundUser = mock(DirContextOperations.class);
    when(filter1.searchForUser("username")).thenThrow(new RuntimeException("Invalid search base"));
    when(filter2.searchForUser("username")).thenReturn(foundUser);
    assertThat(spy.searchForUser("username"), is(foundUser));
    verify(filter1).searchForUser("username");
    verify(filter2).searchForUser("username");
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig) 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

LdapConfig (com.thoughtworks.go.config.LdapConfig)23 Test (org.junit.Test)17 BaseConfig (com.thoughtworks.go.config.server.security.ldap.BaseConfig)15 BasesConfig (com.thoughtworks.go.config.server.security.ldap.BasesConfig)14 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)11 PasswordFileConfig (com.thoughtworks.go.config.PasswordFileConfig)7 UsernameNotFoundException (org.springframework.security.userdetails.UsernameNotFoundException)7 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)6 DirContextOperations (org.springframework.ldap.core.DirContextOperations)6 GoCipher (com.thoughtworks.go.security.GoCipher)4 AdminsConfig (com.thoughtworks.go.config.AdminsConfig)3 AbstractContextSource (org.springframework.ldap.core.support.AbstractContextSource)2 AdminUser (com.thoughtworks.go.config.AdminUser)1 Authorization (com.thoughtworks.go.config.Authorization)1 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 MingleConfig (com.thoughtworks.go.config.MingleConfig)1 PipelineConfigs (com.thoughtworks.go.config.PipelineConfigs)1 ViewConfig (com.thoughtworks.go.config.ViewConfig)1 AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)1