Keycloak: 无法获取角色的属性

huangapple go评论102阅读模式
英文:

Keycloak: Can not get attributes of a role

问题

我已经将属性设置给了一个角色。前往 角色->编辑角色->转到“属性”选项卡,然后添加一个键和一个值。
然后,使用以下代码尝试检索属性。我成功检索到了所有角色(role.getName() 有一个值),但属性为 null。我是不是忘记在 Keycloak 中做一些设置?

  1. Keycloak keycloak = KeycloakBuilder.builder()
  2. .serverUrl("http://host.docker.internal:8080/auth")
  3. .realm("test")
  4. .username("admin")
  5. .password("admin")
  6. .clientId("testId")
  7. .authorization(kp.getKeycloakSecurityContext().getTokenString())
  8. .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(20).build())
  9. .build();
  10. RealmResource realm = keycloak.realm("test");
  11. realm.roles().list().forEach(role->System.out.println(role.getName() + " " +role.getAttributes()));
英文:

I have set an attribute to a role.Go to Roles->Edit a role->go to tab Attributes and then add a key and a value.
Then with the below code I try to retrieve the attribute. I manage to retrieve all roles (role.getName() has a value) but the attributes are null. Did I forget to set something to keycloak?

  1. Keycloak keycloak = KeycloakBuilder.builder()
  2. .serverUrl("http://host.docker.internal:8080/auth")
  3. .realm("test")
  4. .username("admin")
  5. .password("admin")
  6. .clientId("testId")
  7. .authorization(kp.getKeycloakSecurityContext().getTokenString())
  8. .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(20).build())
  9. .build();
  10. RealmResource realm = keycloak.realm("test");
  11. realm.roles().list().forEach(role->System.out.println(role.getName() + " " +role.getAttributes()));

答案1

得分: 2

你需要使用 realm.roles().list(false) 来获取所有数据。

  1. @param briefRepresentation 如果为false则返回带有其属性的角色
英文:

You need to use realm.roles().list(false) to get all data.

  1. @param briefRepresentation if false, return roles with their attributes

huangapple
  • 本文由 发表于 2020年7月27日 21:41:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/63116643.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定