use of org.springframework.security.ldap.DefaultSpringSecurityContextSource 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 org.springframework.security.ldap.DefaultSpringSecurityContextSource in project gocd by gocd.
the class ServerConfigServiceIntegrationTest method shouldUseTheNewPasswordIfItIsChanged.
@Test
public void shouldUseTheNewPasswordIfItIsChanged() {
LdapConfig ldapConfig = new LdapConfig(LDAP_URL, MANAGER_DN, "changed_password", "encrypted_password", true, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
DefaultSpringSecurityContextSource source = serverConfigService.ldapContextSource(ldapConfig);
assertThat(source.getAuthenticationSource().getCredentials(), is("changed_password"));
}
use of org.springframework.security.ldap.DefaultSpringSecurityContextSource in project atlas by apache.
the class AtlasADAuthenticationProvider method getADBindAuthentication.
private Authentication getADBindAuthentication(Authentication authentication) {
try {
String userName = authentication.getName();
String userPassword = "";
if (authentication.getCredentials() != null) {
userPassword = authentication.getCredentials().toString();
}
LdapContextSource ldapContextSource = new DefaultSpringSecurityContextSource(adURL);
ldapContextSource.setUserDn(adBindDN);
ldapContextSource.setPassword(adBindPassword);
ldapContextSource.setReferral(adReferral);
ldapContextSource.setCacheEnvironmentProperties(true);
ldapContextSource.setAnonymousReadOnly(false);
ldapContextSource.setPooled(true);
ldapContextSource.afterPropertiesSet();
FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(adBase, adUserSearchFilter, ldapContextSource);
userSearch.setSearchSubtree(true);
BindAuthenticator bindAuthenticator = new BindAuthenticator(ldapContextSource);
bindAuthenticator.setUserSearch(userSearch);
bindAuthenticator.afterPropertiesSet();
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator);
if (userName != null && userPassword != null && !userName.trim().isEmpty() && !userPassword.trim().isEmpty()) {
final List<GrantedAuthority> grantedAuths = getAuthorities(userName);
final UserDetails principal = new User(userName, userPassword, grantedAuths);
final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal, userPassword, grantedAuths);
authentication = ldapAuthenticationProvider.authenticate(finalAuthentication);
if (groupsFromUGI) {
authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
}
return authentication;
} else {
LOG.error("AD Authentication Failed userName or userPassword is null or empty");
return null;
}
} catch (Exception e) {
LOG.error("AD Authentication Failed:", e);
return null;
}
}
use of org.springframework.security.ldap.DefaultSpringSecurityContextSource in project spring-security by spring-projects.
the class LdapServerBeanDefinitionParserTests method loadingSpecificLdifFileIsSuccessful.
@Test
public void loadingSpecificLdifFileIsSuccessful() {
this.appCtx = new InMemoryXmlApplicationContext("<ldap-server ldif='classpath*:test-server2.xldif' root='dc=monkeymachine,dc=co,dc=uk' port='0'/>");
DefaultSpringSecurityContextSource contextSource = (DefaultSpringSecurityContextSource) this.appCtx.getBean(BeanIds.CONTEXT_SOURCE);
LdapTemplate template = new LdapTemplate(contextSource);
template.lookup("uid=pg,ou=gorillas");
}
use of org.springframework.security.ldap.DefaultSpringSecurityContextSource in project spring-security by spring-projects.
the class LdapServerBeanDefinitionParserTests method useOfUrlAttributeCreatesCorrectContextSource.
@Test
public void useOfUrlAttributeCreatesCorrectContextSource() throws Exception {
int port = getDefaultPort();
// Create second "server" with a url pointing at embedded one
this.appCtx = new InMemoryXmlApplicationContext("<ldap-server ldif='classpath:test-server.ldif' port='" + port + "'/>" + "<ldap-server ldif='classpath:test-server.ldif' id='blah' url='ldap://127.0.0.1:" + port + "/dc=springframework,dc=org' />");
// Check the default context source is still there.
this.appCtx.getBean(BeanIds.CONTEXT_SOURCE);
DefaultSpringSecurityContextSource contextSource = (DefaultSpringSecurityContextSource) this.appCtx.getBean("blah");
// Check data is loaded as before
LdapTemplate template = new LdapTemplate(contextSource);
template.lookup("uid=ben,ou=people");
}
Aggregations