use of com.thoughtworks.go.config.SecurityConfig 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.SecurityConfig 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.SecurityConfig in project gocd by gocd.
the class OauthTokenSweeper method securityChanged.
private boolean securityChanged(CruiseConfig newConfig) {
SecurityConfig currentSecurity = currentConfig.server().security();
SecurityConfig newSecurity = newConfig.server().security();
return (currentSecurity == null && newSecurity != null) || (currentSecurity != null && currentSecurity.hasSecurityMethodChanged(newSecurity));
}
use of com.thoughtworks.go.config.SecurityConfig in project gocd by gocd.
the class LdapContextFactoryTest method shouldNotInitializeDelegatorWhenAnLDAPConfigurationIsRemovedFromOurConfig.
@Test
public void shouldNotInitializeDelegatorWhenAnLDAPConfigurationIsRemovedFromOurConfig() {
LdapContextFactory factory = new LdapContextFactory(goConfigService);
when(goConfigService.security()).thenReturn(new SecurityConfig(new LdapConfig(goCipher), new PasswordFileConfig(), true));
try {
factory.initializeDelegator();
} catch (Exception e) {
e.printStackTrace();
fail("should not have thrown an execption");
}
verify(goConfigService).security();
}
use of com.thoughtworks.go.config.SecurityConfig in project gocd by gocd.
the class LdapUserSearchTest method setUp.
@Before
public void setUp() {
goConfigService = mock(GoConfigService.class);
contextFactory = mock(SpringSecurityContextSource.class);
securityConfig = mock(SecurityConfig.class);
ldapTemplate = mock(LdapTemplate.class);
logger = mock(Logger.class);
ldapUserSearch = new LdapUserSearch(goConfigService, contextFactory, ldapTemplate, logger);
when(goConfigService.security()).thenReturn(securityConfig);
spy = spy(ldapUserSearch);
}
Aggregations