List of usage examples for org.springframework.security.core.authority.mapping GrantedAuthoritiesMapper mapAuthorities
Collection<? extends GrantedAuthority> mapAuthorities(Collection<? extends GrantedAuthority> authorities);
From source file:org.keycloak.adapters.springsecurity.support.KeycloakSpringAdapterUtils.java
/** * Creates a {@link GrantedAuthority} collection from the given {@link KeycloakSecurityContext}. * * @param context the current <code>RefreshableKeycloakSecurityContext</code> (required) * @param mapper an optional {@link GrantedAuthoritiesMapper} to convert the * authorities loaded the given <code>context</code> which will be used in the * {@code Authentication} object/*from ww w.ja v a2s .co m*/ * * @return a {@link GrantedAuthority} collection if any; an empty list otherwise */ public static Collection<? extends GrantedAuthority> createGrantedAuthorities( RefreshableKeycloakSecurityContext context, GrantedAuthoritiesMapper mapper) { Assert.notNull(context, "RefreshableKeycloakSecurityContext cannot be null"); List<KeycloakRole> grantedAuthorities = new ArrayList<>(); for (String role : AdapterUtils.getRolesFromSecurityContext(context)) { grantedAuthorities.add(new KeycloakRole(role)); } return mapper != null ? mapper.mapAuthorities(grantedAuthorities) : Collections.unmodifiableList(grantedAuthorities); }