Search in sources :

Example 21 with BaseConfig

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

the class MagicalGoConfigXmlWriterTest method shouldWriteMultipleSearchBases.

@Test
public void shouldWriteMultipleSearchBases() throws Exception {
    BaseConfig base1 = new BaseConfig("base1");
    BaseConfig base2 = new BaseConfig("base2");
    BasesConfig basesConfig = new BasesConfig(base1, base2);
    LdapConfig ldapConfig = new LdapConfig("url", "managerDn", "managerPassword", "managerPassword", false, basesConfig, "filter");
    SecurityConfig securityConfig = new SecurityConfig(ldapConfig, new PasswordFileConfig("some_path"), false);
    ServerConfig serverConfig = new ServerConfig(securityConfig, new MailHost(new GoCipher()));
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.setServerConfig(serverConfig);
    xmlWriter.write(cruiseConfig, output, false);
    GoConfigHolder holder = xmlLoader.loadConfigHolder(output.toString());
    BasesConfig actualBasesConfig = holder.config.server().security().ldapConfig().getBasesConfig();
    assertThat(actualBasesConfig.size(), is(2));
    assertThat(actualBasesConfig, hasItems(base1, base2));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Example 22 with BaseConfig

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

the class GoConfigFileHelper method addLdapSecurityWithAdmin.

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

Example 23 with BaseConfig

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

the class SecurityConfigTest method shouldNotUpdateManagerPasswordForLDAPIfNotChangedOrNull.

@Test
public void shouldNotUpdateManagerPasswordForLDAPIfNotChangedOrNull() throws InvalidCipherTextException {
    SecurityConfig securityConfig = new SecurityConfig();
    securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "p", null, true, new BasesConfig(new BaseConfig("")), ""));
    assertThat(ReflectionUtil.getField(securityConfig.ldapConfig(), "managerPassword"), is(""));
    assertThat(securityConfig.ldapConfig().managerPassword(), is("p"));
    String encryptedPassword = new GoCipher().encrypt("p");
    assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(encryptedPassword));
    securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "notP", null, false, new BasesConfig(new BaseConfig("")), ""));
    assertThat(ReflectionUtil.getField(securityConfig.ldapConfig(), "managerPassword"), is(""));
    assertThat(securityConfig.ldapConfig().managerPassword(), is("p"));
    assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(encryptedPassword));
    securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "", null, true, new BasesConfig(new BaseConfig("")), ""));
    assertThat(securityConfig.ldapConfig().managerPassword(), is(""));
    assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(nullValue()));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Example 24 with BaseConfig

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

the class LdapUserSearch method search.

public List<User> search(String username, LdapConfig ldapConfig) {
    if (ldapConfig.getBasesConfig().isEmpty()) {
        throw new RuntimeException("Atleast one Search Base needs to be configured.");
    }
    OrFilter filter = new OrFilter();
    String searchString = MessageFormat.format("*{0}*", username);
    filter.or(new LikeFilter(SAM_ACCOUNT_NAME, searchString));
    filter.or(new LikeFilter(UID, searchString));
    filter.or(new LikeFilter(COMMON_NAME, searchString));
    filter.or(new LikeFilter(MAIL_ID, searchString));
    // This field is optional to search based on. Only for alias emails.
    filter.or(new LikeFilter(ALIAS_EMAIL_ID, searchString));
    //List ldapUserList = template.search(ldapConfig.searchBase(), filter.encode(), attributes);
    SearchControls controls = new SearchControls();
    controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    controls.setCountLimit(MAX_RESULTS);
    AttributesMapperCallbackHandler handler = getAttributesMapperCallbackHandler();
    for (BaseConfig baseConfig : ldapConfig.getBasesConfig()) {
        try {
            ldapTemplate.search(baseConfig.getValue(), filter.encode(), controls, handler);
        } catch (org.springframework.ldap.LimitExceededException e) {
            throw new NotAllResultsShownException(buildUserList(handler.getList()));
        }
    }
    return buildUserList(handler.getList());
}
Also used : LikeFilter(org.springframework.ldap.filter.LikeFilter) SearchControls(javax.naming.directory.SearchControls) OrFilter(org.springframework.ldap.filter.OrFilter) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) AttributesMapperCallbackHandler(org.springframework.ldap.core.AttributesMapperCallbackHandler)

Example 25 with BaseConfig

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

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