Search in sources :

Example 1 with LdapAuthoritiesPopulator

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;
}
Also used : LdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator) LdapAuthenticator(org.springframework.security.ldap.authentication.LdapAuthenticator) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider)

Example 2 with LdapAuthoritiesPopulator

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));
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) LdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with LdapAuthoritiesPopulator

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;
}
Also used : LdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator) DefaultLdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator) BaseLdapPathContextSource(org.springframework.ldap.core.support.BaseLdapPathContextSource) LdapAuthenticator(org.springframework.security.ldap.authentication.LdapAuthenticator) AbstractLdapAuthenticator(org.springframework.security.ldap.authentication.AbstractLdapAuthenticator) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider)

Example 4 with LdapAuthoritiesPopulator

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_");
}
Also used : LdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider) Test(org.junit.jupiter.api.Test)

Example 5 with LdapAuthoritiesPopulator

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);
}
Also used : NullLdapAuthoritiesPopulator(org.springframework.security.ldap.authentication.NullLdapAuthoritiesPopulator) LdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator) DefaultSpringSecurityContextSource(org.springframework.security.ldap.DefaultSpringSecurityContextSource) Test(org.junit.jupiter.api.Test)

Aggregations

LdapAuthoritiesPopulator (org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator)5 LdapAuthenticationProvider (org.springframework.security.ldap.authentication.LdapAuthenticationProvider)3 Test (org.junit.jupiter.api.Test)2 LdapAuthenticator (org.springframework.security.ldap.authentication.LdapAuthenticator)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 BaseLdapPathContextSource (org.springframework.ldap.core.support.BaseLdapPathContextSource)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 DefaultSpringSecurityContextSource (org.springframework.security.ldap.DefaultSpringSecurityContextSource)1 AbstractLdapAuthenticator (org.springframework.security.ldap.authentication.AbstractLdapAuthenticator)1 NullLdapAuthoritiesPopulator (org.springframework.security.ldap.authentication.NullLdapAuthoritiesPopulator)1 DefaultLdapAuthoritiesPopulator (org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator)1