Skip to content

Commit

Permalink
Merge pull request #885 from terrestris/update-keycloak-util
Browse files Browse the repository at this point in the history
Add methods to the `KeycloakUtil`
  • Loading branch information
dnlkoch committed Jun 24, 2024
2 parents c442312 + 5c1e94e commit 51b9238
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public class KeycloakUtil {
@Autowired
protected RealmResource keycloakRealm;

public List<UserRepresentation> getRealmUsers() {
return this.keycloakRealm.users().list();
}

public List<GroupRepresentation> getRealmGroups() {
return this.keycloakRealm.groups().groups();
}

public UserResource getUserResource(User<UserRepresentation> user) {
UsersResource kcUsers = this.keycloakRealm.users();
return kcUsers.get(user.getAuthProviderId());
Expand Down Expand Up @@ -263,6 +271,22 @@ public ClientRepresentation getClientRepresentationFromClientId() {
return clientRepresentations.getFirst();
}

/**
* Returns the list of (client) roles for the client the shogun instance is configured with
* (see keycloak.clientId in properties).
*
* @return
*/
public List<RoleRepresentation> getClientRoles() {
ClientRepresentation clientRepresentation = getClientRepresentationFromClientId();

if (clientRepresentation == null) {
return null;
}

return keycloakRealm.clients().get(clientRepresentation.getId()).roles().list();
}

public RoleRepresentation getRoleByName(String roleName) {
ClientRepresentation clientRepresentation = getClientRepresentationFromClientId();

Expand Down

0 comments on commit 51b9238

Please sign in to comment.