Fotios
Fotios

Reputation: 79

Keycloak: Can not get attributes of a role

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()));

Upvotes: 2

Views: 2937

Answers (1)

matejko219
matejko219

Reputation: 1751

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

@param briefRepresentation if false, return roles with their attributes

Upvotes: 2

Related Questions