Search in sources :

Example 1 with BaseConfig

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

the class GoConfigFileHelper method addLdapSecurity.

public void addLdapSecurity(String uri, String managerDn, String managerPassword, String searchBase, String searchFilter) {
    LdapConfig ldapConfig = new LdapConfig(uri, managerDn, managerPassword, null, true, new BasesConfig(new BaseConfig(searchBase)), searchFilter);
    addLdapSecurityWith(ldapConfig, true, new PasswordFileConfig(), new AdminsConfig());
}
Also used : BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig)

Example 2 with BaseConfig

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

the class SecurityConfigTest method shouldBeAbleToTellIfSecurityMethodChangedFromNothingToLdap.

@Test
public void shouldBeAbleToTellIfSecurityMethodChangedFromNothingToLdap() {
    SecurityConfig ldapSecurity = new SecurityConfig();
    ldapSecurity.modifyLdap(new LdapConfig("ldap://uri", "dn", "p", null, true, new BasesConfig(new BaseConfig("")), ""));
    assertTrue(new SecurityConfig().hasSecurityMethodChanged(ldapSecurity));
}
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 3 with BaseConfig

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

the class LdapConfigTest method shouldConsiderTwoLdapConfigsWithDifferentPasswordsUnequal.

@Test
public void shouldConsiderTwoLdapConfigsWithDifferentPasswordsUnequal() {
    LdapConfig ldapConfig1 = new LdapConfig("uri", "managerDn", "password-1", null, true, new BasesConfig(new BaseConfig("blah")), "blah");
    LdapConfig ldapConfig2 = new LdapConfig("uri", "managerDn", "password-2", null, true, new BasesConfig(new BaseConfig("blah")), "blah");
    assertThat(ldapConfig1, is(Matchers.not(ldapConfig2)));
    assertThat(ldapConfig1.hashCode(), is(Matchers.not(ldapConfig2.hashCode())));
}
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 4 with BaseConfig

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

the class LdapUserSearch method searchForUser.

public DirContextOperations searchForUser(String username) {
    SecurityConfig securityConfig = goConfigService.security();
    if (!securityConfig.isSecurityEnabled()) {
        return null;
    }
    LdapConfig ldapConfig = securityConfig.ldapConfig();
    RuntimeException lastFoundException = null;
    BaseConfig failedBaseConfig = null;
    for (BaseConfig baseConfig : ldapConfig.getBasesConfig()) {
        if (lastFoundException != null && !(lastFoundException instanceof BadCredentialsException)) {
            logger.warn(String.format("The ldap configuration for search base '%s' is invalid", failedBaseConfig.getValue()), lastFoundException);
        }
        FilterBasedLdapUserSearch search = getFilterBasedLdapUserSearch(baseConfig.getValue(), ldapConfig.searchFilter());
        search.setSearchSubtree(true);
        // timeout after five seconds
        search.setSearchTimeLimit(5000);
        try {
            return search.searchForUser(username);
        } catch (UsernameNotFoundException e) {
            failedBaseConfig = baseConfig;
            lastFoundException = new BadCredentialsException("Bad credentials");
        } catch (RuntimeException e) {
            failedBaseConfig = baseConfig;
            lastFoundException = e;
        }
    }
    if (lastFoundException != null) {
        throw lastFoundException;
    }
    throw new RuntimeException("No LDAP Search Bases are configured.");
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig) UsernameNotFoundException(org.springframework.security.userdetails.UsernameNotFoundException) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) FilterBasedLdapUserSearch(org.springframework.security.ldap.search.FilterBasedLdapUserSearch) BadCredentialsException(org.springframework.security.BadCredentialsException) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig)

Example 5 with BaseConfig

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

the class GoConfigServiceTest method shouldUnderstandIfLdapIsConfigured.

@Test
public void shouldUnderstandIfLdapIsConfigured() throws Exception {
    CruiseConfig config = new BasicCruiseConfig();
    config.setServerConfig(new ServerConfig(null, new SecurityConfig(new LdapConfig("test", "test", "test", null, true, new BasesConfig(new BaseConfig("test")), "test"), null, true, null)));
    expectLoad(config);
    assertThat("Ldap is configured", goConfigService.isLdapConfigured(), is(true));
}
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

BaseConfig (com.thoughtworks.go.config.server.security.ldap.BaseConfig)39 BasesConfig (com.thoughtworks.go.config.server.security.ldap.BasesConfig)36 Test (org.junit.Test)35 LdapConfig (com.thoughtworks.go.config.LdapConfig)15 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)11 GoCipher (com.thoughtworks.go.security.GoCipher)8 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)8 UsernameNotFoundException (org.springframework.security.userdetails.UsernameNotFoundException)7 DirContextOperations (org.springframework.ldap.core.DirContextOperations)6 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 DefaultSpringSecurityContextSource (org.springframework.security.ldap.DefaultSpringSecurityContextSource)2 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1 ServerSiteUrlConfig (com.thoughtworks.go.domain.ServerSiteUrlConfig)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