2

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?

  Keycloak keycloak = KeycloakBuilder.builder()
            .serverUrl("http://host.docker.internal:8080/auth")
            .realm("test")
            .username("admin")
            .password("admin")
            .clientId("testId")
            .authorization(kp.getKeycloakSecurityContext().getTokenString())
            .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(20).build())
            .build();    
    
  RealmResource realm = keycloak.realm("test");
  realm.roles().list().forEach(role->System.out.println(role.getName() +  " " +role.getAttributes()));
Fotios
  • 79
  • 8

1 Answers1

2

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

@param briefRepresentation if false, return roles with their attributes
matejko219
  • 1,601
  • 10
  • 14
  • I downgraded to keycloak 8.0.1 and I do not have the option of realm.roles().list(false). I have only option realm.roles().list() and now unfortunately I do not retrieve attributes again. Any suggestion? – Fotios Jul 28 '20 at 15:17
  • I managed to find a solution. realm.roles().get("Admins").toRepresentation().getAttributes() – Fotios Jul 28 '20 at 15:43
  • It is good, if you are looking for specific role, but if you are looking for roles having specific argument, you must get them all and filter them out. – matejko219 Jul 28 '20 at 16:45