Java Code Examples for org.springframework.security.core.authority.mapping.SimpleAuthorityMapper#setConvertToUpperCase()

The following examples show how to use org.springframework.security.core.authority.mapping.SimpleAuthorityMapper#setConvertToUpperCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecurityConfig.java    From devconf2019-authz with Apache License 2.0 5 votes vote down vote up
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
    SimpleAuthorityMapper grantedAuthorityMapper = new SimpleAuthorityMapper();
    grantedAuthorityMapper.setPrefix("ROLE_");
    grantedAuthorityMapper.setConvertToUpperCase(true);
    keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(grantedAuthorityMapper);
    auth.authenticationProvider(keycloakAuthenticationProvider);
}
 
Example 2
Source File: OidcUserManagementAutoConfiguration.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return a jwt authorities extractor which interprets the roles of a user
 *         as their authorities.
 */
@Bean
@ConditionalOnMissingBean
public JwtAuthoritiesExtractor jwtAuthoritiesExtractor() {
    final SimpleAuthorityMapper authorityMapper = new SimpleAuthorityMapper();
    authorityMapper.setPrefix("");
    authorityMapper.setConvertToUpperCase(true);

    return new JwtAuthoritiesExtractor(authorityMapper);
}
 
Example 3
Source File: KeycloakSpringAdapterUtilsTest.java    From smartling-keycloak-extras with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

    MockitoAnnotations.initMocks(this);
    SimpleAuthorityMapper roleMapper = new SimpleAuthorityMapper();
    roleMapper.setConvertToUpperCase(true);
    grantedAuthoritiesMapper = roleMapper;

    PowerMockito.mockStatic(AdapterUtils.class);
    when(AdapterUtils.getRolesFromSecurityContext(any(RefreshableKeycloakSecurityContext.class))).thenReturn(AUTHORITIES);
    when(AdapterUtils.createPrincipal(eq(deployment), eq(context))).thenReturn(principal);
}
 
Example 4
Source File: KeycloakAuthenticationProviderTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@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()));
}