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));
}
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))));
}
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()));
}
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());
}
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"));
}
Aggregations