use of com.thoughtworks.go.config.LdapConfig in project gocd by gocd.
the class LdapContextFactory method initializeDelegator.
void initializeDelegator() {
//LdapAuthenticationProvider has checked that LDAP config directoryExists
SecurityConfig securityConfig = goConfigService.security();
LdapConfig ldapConfig = securityConfig.ldapConfig();
if (ldapConfig.isEnabled()) {
try {
delegate = new DefaultSpringSecurityContextSource(ldapConfig.uri());
//so user can define the variable java.naming.referral=follow in the server.sh
delegate.setBaseEnvironmentProperties(System.getProperties());
new LdapContextSourceConfigurator(ldapConfig).configure(delegate);
delegate.afterPropertiesSet();
} catch (Exception e) {
throw bomb("Invalid or empty ldap config, Error creating DefaultSpringSecurityContextSource", e);
}
}
}
use of com.thoughtworks.go.config.LdapConfig 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.");
}
use of com.thoughtworks.go.config.LdapConfig in project gocd by gocd.
the class MingleConfigServiceIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
dbHelper.onSetUp();
configHelper = new GoConfigFileHelper(goConfigDao);
configHelper.onSetUp();
configHelper.addPipeline("bar", "stage", MaterialConfigsMother.defaultMaterialConfigs(), "build");
pipelineConfig = configHelper.addPipeline("foo", "stage", MaterialConfigsMother.defaultMaterialConfigs(), "build");
configHelper.addMingleConfigToPipeline("foo", new MingleConfig("https://some-tracking-tool:8443", "project-super-secret", "hello=world"));
CruiseConfig cruiseConfig = configHelper.load();
PipelineConfigs group = cruiseConfig.findGroup("defaultGroup");
group.setAuthorization(new Authorization(new ViewConfig(new AdminUser(new CaseInsensitiveString("authorized_user")))));
configHelper.writeConfigFile(cruiseConfig);
SecurityConfig securityConfig = new SecurityConfig(new LdapConfig(new GoCipher()), new PasswordFileConfig("/tmp/foo.passwd"), true);
securityConfig.adminsConfig().add(new AdminUser(new CaseInsensitiveString("admin")));
configHelper.addSecurity(securityConfig);
}
use of com.thoughtworks.go.config.LdapConfig in project gocd by gocd.
the class LdapConfigChangedListenerTest method shouldReinitializeDelegator_whenLdapManagerPasswordChanges.
@Test
public void shouldReinitializeDelegator_whenLdapManagerPasswordChanges() {
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);
LdapConfig newLdapConfig = new LdapConfig("oldOne", "manager", "new_pwd", null, true, new BasesConfig(new BaseConfig("foo")), "bar");
helper.addLdapSecurityWith(newLdapConfig, true, new PasswordFileConfig(), new AdminsConfig());
listener.onConfigChange(helper.currentConfig());
verify(mockContextFactory).initializeDelegator();
}
use of com.thoughtworks.go.config.LdapConfig 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();
}
Aggregations