use of org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator in project hub-alert by blackducksoftware.
the class LdapManager method updateAuthenticationProvider.
private LdapAuthenticationProvider updateAuthenticationProvider(FieldUtility configurationModel, LdapContextSource contextSource) throws AlertConfigurationException {
LdapAuthenticator authenticator = createAuthenticator(configurationModel, contextSource);
LdapAuthoritiesPopulator ldapAuthoritiesPopulator = createAuthoritiesPopulator(configurationModel, contextSource);
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(authenticator, ldapAuthoritiesPopulator);
ldapAuthenticationProvider.setUserDetailsContextMapper(inetOrgPersonContextMapper);
return ldapAuthenticationProvider;
}
use of org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator in project pentaho-platform by pentaho.
the class UnionizingLdapAuthoritiesPopulatorTest method testGetGrantedAuthorities.
@Test
public void testGetGrantedAuthorities() throws Exception {
UnionizingLdapAuthoritiesPopulator populator = new UnionizingLdapAuthoritiesPopulator();
Set<LdapAuthoritiesPopulator> pops = new HashSet<>();
pops.add(authPop1);
pops.add(authPop2);
String username = "admin";
GrantedAuthority g1 = new SimpleGrantedAuthority("power user");
GrantedAuthority g2 = new SimpleGrantedAuthority("administrator");
Collection auths1 = Arrays.asList(new GrantedAuthority[] { g1 });
Collection auths2 = Arrays.asList(new GrantedAuthority[] { g2 });
when(authPop1.getGrantedAuthorities(userData, username)).thenReturn(auths1);
when(authPop2.getGrantedAuthorities(userData, username)).thenReturn(auths2);
populator.setPopulators(pops);
Collection<? extends GrantedAuthority> authorities = populator.getGrantedAuthorities(userData, username);
assertEquals(2, authorities.size());
assertTrue(authorities.contains(g1));
assertTrue(authorities.contains(g2));
}
use of org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator in project spring-security by spring-projects.
the class LdapAuthenticationProviderConfigurer method build.
private LdapAuthenticationProvider build() throws Exception {
BaseLdapPathContextSource contextSource = getContextSource();
LdapAuthenticator ldapAuthenticator = createLdapAuthenticator(contextSource);
LdapAuthoritiesPopulator authoritiesPopulator = getLdapAuthoritiesPopulator();
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(ldapAuthenticator, authoritiesPopulator);
ldapAuthenticationProvider.setAuthoritiesMapper(getAuthoritiesMapper());
if (this.userDetailsContextMapper != null) {
ldapAuthenticationProvider.setUserDetailsContextMapper(this.userDetailsContextMapper);
}
return ldapAuthenticationProvider;
}
use of org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator in project spring-security by spring-projects.
the class LdapAuthenticationProviderBuilderSecurityBuilderTests method defaultConfiguration.
@Test
public void defaultConfiguration() {
this.spring.register(DefaultLdapConfig.class).autowire();
LdapAuthenticationProvider provider = ldapProvider();
LdapAuthoritiesPopulator authoritiesPopulator = getAuthoritiesPopulator(provider);
assertThat(authoritiesPopulator).hasFieldOrPropertyWithValue("groupRoleAttribute", "cn");
assertThat(authoritiesPopulator).hasFieldOrPropertyWithValue("groupSearchBase", "");
assertThat(authoritiesPopulator).hasFieldOrPropertyWithValue("groupSearchFilter", "(uniqueMember={0})");
assertThat(authoritiesPopulator).extracting("searchControls").hasFieldOrPropertyWithValue("searchScope", SearchControls.ONELEVEL_SCOPE);
assertThat(ReflectionTestUtils.getField(getAuthoritiesMapper(provider), "prefix")).isEqualTo("ROLE_");
}
use of org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator in project spring-security by spring-projects.
the class LdapAuthenticationProviderConfigurerTests method configureWhenObjectPostProcessorThenAuthoritiesPopulatorIsPostProcessed.
@Test
public void configureWhenObjectPostProcessorThenAuthoritiesPopulatorIsPostProcessed() {
LdapAuthoritiesPopulator populator = mock(LdapAuthoritiesPopulator.class);
assertThat(ReflectionTestUtils.getField(this.configurer, "ldapAuthoritiesPopulator")).isNull();
this.configurer.contextSource(new DefaultSpringSecurityContextSource("ldap://localhost:389"));
this.configurer.addObjectPostProcessor(new ObjectPostProcessor<LdapAuthoritiesPopulator>() {
@Override
public <O extends LdapAuthoritiesPopulator> O postProcess(O object) {
return (O) populator;
}
});
ReflectionTestUtils.invokeMethod(this.configurer, "getLdapAuthoritiesPopulator");
assertThat(ReflectionTestUtils.getField(this.configurer, "ldapAuthoritiesPopulator")).isSameAs(populator);
}
Aggregations