Search in sources :

Example 11 with BaseConfig

use of com.thoughtworks.go.config.server.security.ldap.BaseConfig 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();
}
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 12 with BaseConfig

use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.

the class LdapContextSourceConfiguratorTest method shouldSet_ManagerDnAndPassword_OnContextSource.

@Test
public void shouldSet_ManagerDnAndPassword_OnContextSource() {
    LdapContextSourceConfigurator configurator = new LdapContextSourceConfigurator(new LdapConfig("uri", "managerDn", "managerPass", null, true, new BasesConfig(new BaseConfig("searchBase")), "searchFilter"));
    AbstractContextSource ctxSrc = mock(AbstractContextSource.class);
    configurator.configure(ctxSrc);
    verify(ctxSrc).setPassword("managerPass");
    verify(ctxSrc).setUserDn("managerDn");
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) AbstractContextSource(org.springframework.ldap.core.support.AbstractContextSource) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Example 13 with BaseConfig

use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.

the class LdapUserSearchTest method shouldNotLogErrorsIfThereIsOnlyOneSearchBaseWhichIsInvalidWhenAuthenticating.

@Test
public void shouldNotLogErrorsIfThereIsOnlyOneSearchBaseWhichIsInvalidWhenAuthenticating() {
    final FilterBasedLdapUserSearch filter1 = mock(FilterBasedLdapUserSearch.class);
    LdapConfig ldapConfig = setLdapConfig(new BasesConfig(new BaseConfig("base1")));
    doReturn(filter1).when(spy).getFilterBasedLdapUserSearch(ldapConfig.getBasesConfig().get(0).getValue(), ldapConfig.searchFilter());
    RuntimeException runtimeException = new RuntimeException("Invalid search base");
    when(filter1.searchForUser("username")).thenThrow(runtimeException);
    thrown.expect(RuntimeException.class);
    spy.searchForUser("username");
    verify(logger, never()).warn(Matchers.<Object>any(), Matchers.<Throwable>any());
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig) 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 14 with BaseConfig

use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.

the class LdapUserSearchTest method shouldThrowBadCredentialsExceptionWhenNoUserFound_WithMultipleSearchBase.

@Test
public void shouldThrowBadCredentialsExceptionWhenNoUserFound_WithMultipleSearchBase() {
    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."));
    when(filter2.searchForUser("username")).thenThrow(new UsernameNotFoundException("User username not found in directory."));
    thrown.expect(BadCredentialsException.class);
    thrown.expectMessage(is("Bad credentials"));
    spy.searchForUser("username");
    verify(filter1).searchForUser("username");
    verify(filter2).searchForUser("username");
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig) UsernameNotFoundException(org.springframework.security.userdetails.UsernameNotFoundException) 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 15 with BaseConfig

use of com.thoughtworks.go.config.server.security.ldap.BaseConfig in project gocd by gocd.

the class LdapUserSearchTest method shouldLogErrorsDueToInvalidSearchBaseWhenAuthenticating.

@Test
public void shouldLogErrorsDueToInvalidSearchBaseWhenAuthenticating() {
    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);
    RuntimeException runtimeException = new RuntimeException("Invalid search base");
    when(filter1.searchForUser("username")).thenThrow(runtimeException);
    when(filter2.searchForUser("username")).thenReturn(foundUser);
    assertThat(spy.searchForUser("username"), is(foundUser));
    verify(filter1).searchForUser("username");
    verify(filter2).searchForUser("username");
    verify(logger).warn("The ldap configuration for search base 'base1' is invalid", runtimeException);
}
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

BaseConfig (com.thoughtworks.go.config.server.security.ldap.BaseConfig)33 BasesConfig (com.thoughtworks.go.config.server.security.ldap.BasesConfig)30 Test (org.junit.Test)29 LdapConfig (com.thoughtworks.go.config.LdapConfig)15 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)11 UsernameNotFoundException (org.springframework.security.userdetails.UsernameNotFoundException)7 DirContextOperations (org.springframework.ldap.core.DirContextOperations)6 GoCipher (com.thoughtworks.go.security.GoCipher)4 AdminsConfig (com.thoughtworks.go.config.AdminsConfig)3 PasswordFileConfig (com.thoughtworks.go.config.PasswordFileConfig)3 SearchControls (javax.naming.directory.SearchControls)3 AttributesMapperCallbackHandler (org.springframework.ldap.core.AttributesMapperCallbackHandler)3 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 DefaultSpringSecurityContextSource (org.springframework.security.ldap.DefaultSpringSecurityContextSource)2 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 AbstractContextSource (org.springframework.ldap.core.support.AbstractContextSource)1 LikeFilter (org.springframework.ldap.filter.LikeFilter)1 OrFilter (org.springframework.ldap.filter.OrFilter)1