Search in sources :

Example 16 with BasesConfig

use of com.thoughtworks.go.config.server.security.ldap.BasesConfig 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");
}
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 17 with BasesConfig

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

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

the class LdapConfigTest method shouldNotEquateTwoLdapConfigsWithDifferentSearchBases.

@Test
public void shouldNotEquateTwoLdapConfigsWithDifferentSearchBases() {
    LdapConfig ldapConfig1 = new LdapConfig("uri", "managerDn", "password-1", "", false, new BasesConfig(new BaseConfig("old_base1")), "blah");
    LdapConfig ldapConfig2 = new LdapConfig("uri", "managerDn", "password-1", "", false, new BasesConfig(new BaseConfig("old_base2")), "blah");
    assertThat(ldapConfig1, is(not(ldapConfig2)));
}
Also used : 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 BasesConfig

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

the class LdapConfigTest method shouldUpdateSearchBaseWithNewLdapConfig.

@Test
public void shouldUpdateSearchBaseWithNewLdapConfig() {
    LdapConfig ldapConfig = new LdapConfig("uri", "managerDn", "password-1", "", false, new BasesConfig(new BaseConfig("old_base")), "blah");
    LdapConfig newLdapConfig = new LdapConfig("uri", "managerDn", "password-2", null, false, new BasesConfig(new BaseConfig("new_base")), "blah");
    ldapConfig.updateWithNew(newLdapConfig);
    assertThat(ldapConfig.getBasesConfig().size(), is(1));
    assertThat(ldapConfig.getBasesConfig().first().getValue(), is("new_base"));
}
Also used : BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Example 20 with BasesConfig

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

the class LdapConfigTest method shouldReturnEmptyStringWhenThePasswordIsNotChangedAndTheEncryptedPasswordIsNull.

@Test
public void shouldReturnEmptyStringWhenThePasswordIsNotChangedAndTheEncryptedPasswordIsNull() {
    LdapConfig ldapConfig1 = new LdapConfig("uri", "managerDn", "password-1", "", false, new BasesConfig(new BaseConfig("blah")), "blah");
    LdapConfig ldapConfig2 = new LdapConfig("uri", "managerDn", "password-2", null, false, new BasesConfig(new BaseConfig("blah")), "blah");
    assertThat(ldapConfig2.currentManagerPassword(), is(""));
    assertThat(ldapConfig1.currentManagerPassword(), is(""));
}
Also used : 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