use of org.keycloak.admin.client.resource.UserResource in project openremote by openremote.
the class KeycloakCleanSetup method onStart.
@Override
public void onStart() throws Exception {
super.onStart();
// Delete all realms that are not the master realm
LOG.info("Deleting all non-master realms");
RealmsResource realmsResource = keycloakProvider.getRealms(accessToken);
List<RealmRepresentation> realms = realmsResource.findAll();
for (RealmRepresentation realmRepresentation : realms) {
if (!realmRepresentation.getRealm().equals(MASTER_REALM)) {
keycloakProvider.getRealms(accessToken).realm(realmRepresentation.getRealm()).remove();
}
}
// Find out if there is a client already present for this application, if so, delete it
masterClientsResource.findAll().stream().filter(clientRepresentation -> clientRepresentation.getClientId().equals(KEYCLOAK_CLIENT_ID)).map(ClientRepresentation::getId).forEach(clientObjectId -> {
LOG.info("Deleting client: " + clientObjectId);
masterClientsResource.get(clientObjectId).remove();
});
// Find out if there are any users except the admin, delete them
masterUsersResource.search(null, null, null).stream().filter(userRepresentation -> !userRepresentation.getUsername().equals(MASTER_REALM_ADMIN_USER)).map(userRepresentation -> {
LOG.info("Deleting user: " + userRepresentation);
return masterUsersResource.get(userRepresentation.getId());
}).forEach(UserResource::remove);
}
Aggregations