Search in sources :

Example 1 with SimpleAuthorityMapper

use of org.springframework.security.core.authority.mapping.SimpleAuthorityMapper in project keycloak by keycloak.

the class KeycloakAuthenticationProviderTest method testGrantedAuthoritiesMapper.

@Test
public void testGrantedAuthoritiesMapper() throws Exception {
    SimpleAuthorityMapper grantedAuthorityMapper = new SimpleAuthorityMapper();
    grantedAuthorityMapper.setPrefix("ROLE_");
    grantedAuthorityMapper.setConvertToUpperCase(true);
    provider.setGrantedAuthoritiesMapper(grantedAuthorityMapper);
    Authentication result = provider.authenticate(token);
    assertEquals(Sets.newSet("ROLE_USER", "ROLE_ADMIN"), AuthorityUtils.authorityListToSet(result.getAuthorities()));
}
Also used : SimpleAuthorityMapper(org.springframework.security.core.authority.mapping.SimpleAuthorityMapper) Authentication(org.springframework.security.core.Authentication) Test(org.junit.Test)

Example 2 with SimpleAuthorityMapper

use of org.springframework.security.core.authority.mapping.SimpleAuthorityMapper in project gravitee-management-rest-api by gravitee-io.

the class LdapAuthenticationProviderConfigurer method build.

private LdapAuthenticationProvider build() throws Exception {
    BaseLdapPathContextSource contextSource = getContextSource();
    LdapAuthenticator ldapAuthenticator = createLdapAuthenticator(contextSource);
    LdapAuthoritiesPopulator authoritiesPopulator = getLdapAuthoritiesPopulator();
    LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProviderProxy(ldapAuthenticator, authoritiesPopulator);
    SimpleAuthorityMapper simpleAuthorityMapper = new SimpleAuthorityMapper();
    simpleAuthorityMapper.setPrefix(rolePrefix);
    simpleAuthorityMapper.afterPropertiesSet();
    ldapAuthenticationProvider.setAuthoritiesMapper(simpleAuthorityMapper);
    if (userDetailsContextMapper != null) {
        ldapAuthenticationProvider.setUserDetailsContextMapper(userDetailsContextMapper);
    }
    return ldapAuthenticationProvider;
}
Also used : BaseLdapPathContextSource(org.springframework.ldap.core.support.BaseLdapPathContextSource) SimpleAuthorityMapper(org.springframework.security.core.authority.mapping.SimpleAuthorityMapper) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider)

Example 3 with SimpleAuthorityMapper

use of org.springframework.security.core.authority.mapping.SimpleAuthorityMapper in project tutorials by eugenp.

the class SecurityConfig method configureGlobal.

// Submits the KeycloakAuthenticationProvider to the AuthenticationManager
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
    keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
    auth.authenticationProvider(keycloakAuthenticationProvider);
}
Also used : SimpleAuthorityMapper(org.springframework.security.core.authority.mapping.SimpleAuthorityMapper) KeycloakAuthenticationProvider(org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider) Autowired(org.springframework.beans.factory.annotation.Autowired)

Example 4 with SimpleAuthorityMapper

use of org.springframework.security.core.authority.mapping.SimpleAuthorityMapper in project spring-security by spring-projects.

the class LdapAuthenticationProviderConfigurer method getAuthoritiesMapper.

/**
 * Gets the {@link GrantedAuthoritiesMapper} and defaults to
 * {@link SimpleAuthorityMapper}.
 * @return the {@link GrantedAuthoritiesMapper}
 * @throws Exception if errors in {@link SimpleAuthorityMapper#afterPropertiesSet()}
 */
protected GrantedAuthoritiesMapper getAuthoritiesMapper() throws Exception {
    if (this.authoritiesMapper != null) {
        return this.authoritiesMapper;
    }
    SimpleAuthorityMapper simpleAuthorityMapper = new SimpleAuthorityMapper();
    simpleAuthorityMapper.setPrefix(this.rolePrefix);
    simpleAuthorityMapper.afterPropertiesSet();
    this.authoritiesMapper = simpleAuthorityMapper;
    return simpleAuthorityMapper;
}
Also used : SimpleAuthorityMapper(org.springframework.security.core.authority.mapping.SimpleAuthorityMapper)

Aggregations

SimpleAuthorityMapper (org.springframework.security.core.authority.mapping.SimpleAuthorityMapper)4 Test (org.junit.Test)1 KeycloakAuthenticationProvider (org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 BaseLdapPathContextSource (org.springframework.ldap.core.support.BaseLdapPathContextSource)1 Authentication (org.springframework.security.core.Authentication)1 LdapAuthenticationProvider (org.springframework.security.ldap.authentication.LdapAuthenticationProvider)1