Skip to content

Commit

Permalink
fix: keycloak roles retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolife999 committed Mar 4, 2024
1 parent a41f12a commit f04ccaa
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -65,12 +66,11 @@ protected GrantedAuthoritiesMapper userAuthoritiesMapper() {
OidcUserAuthority oidcUserAuthority = (OidcUserAuthority) authority;
OidcUserInfo userInfo = oidcUserAuthority.getUserInfo();

StaticLoggerDispatcher.custom(LOGGER, userInfo.getClaims());

List<String> roles = userInfo.getClaimAsStringList("roles");
if (roles == null) {
roles = userInfo.getClaimAsStringList("groups");
}
@SuppressWarnings("unchecked")
List<String> roles = (List<String>) ObjectUtils.firstNonNull(
userInfo.getClaimAsStringList("roles"),
userInfo.getClaimAsStringList("groups"),
userInfo.getClaimAsMap("realm_access").get("roles"));

List<SimpleGrantedAuthority> groupAuthorities = roles.stream()
.map(g -> new SimpleGrantedAuthority(g)).toList();
Expand Down

0 comments on commit f04ccaa

Please sign in to comment.