Java Code Examples for org.keycloak.models.RealmModel#removeClient()

The following examples show how to use org.keycloak.models.RealmModel#removeClient() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FineGrainAdminUnitTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public static void invokeDelete(KeycloakSession session)  {
    RealmModel realm = session.realms().getRealmByName(TEST);
    AdminPermissionManagement management = AdminPermissions.management(session, realm);
    List<Resource> byResourceServer = management.authz().getStoreFactory().getResourceStore().findByResourceServer(management.realmResourceServer().getId());
    Assert.assertEquals(5, byResourceServer.size());
    RoleModel removedRole = realm.getRole("removedRole");
    realm.removeRole(removedRole);
    ClientModel client = realm.getClientByClientId("removedClient");
    RoleModel removedClientRole = client.getRole("removedClientRole");
    client.removeRole(removedClientRole);
    GroupModel group = KeycloakModelUtils.findGroupByPath(realm, "removedGroup");
    realm.removeGroup(group);
    byResourceServer = management.authz().getStoreFactory().getResourceStore().findByResourceServer(management.realmResourceServer().getId());
    Assert.assertEquals(2, byResourceServer.size());
    realm.removeClient(client.getId());
    byResourceServer = management.authz().getStoreFactory().getResourceStore().findByResourceServer(management.realmResourceServer().getId());
    Assert.assertEquals(1, byResourceServer.size());
    management.users().setPermissionsEnabled(false);
    Resource userResource = management.authz().getStoreFactory().getResourceStore().findByName("Users", management.realmResourceServer().getId());
    Assert.assertNull(userResource);
    byResourceServer = management.authz().getStoreFactory().getResourceStore().findByResourceServer(management.realmResourceServer().getId());
    Assert.assertEquals(0, byResourceServer.size());
}
 
Example 2
Source File: ClientTokenExchangeTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private static void removeDirectExchanger(KeycloakSession session) {
    RealmModel realm = session.realms().getRealmByName(TEST);
    realm.removeClient(realm.getClientByClientId("direct-exchanger").getId());
    realm.removeClient(realm.getClientByClientId("target").getId());
    realm.removeRole(realm.getRole("example"));
    session.users().removeUser(realm, session.users().getUserByUsername("impersonated-user", realm));
}
 
Example 3
Source File: ClientManager.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public boolean removeClient(RealmModel realm, ClientModel client) {
    if (realm.removeClient(client.getId())) {
        UserSessionProvider sessions = realmManager.getSession().sessions();
        if (sessions != null) {
            sessions.onClientRemoved(realm, client);
        }

        UserSessionPersisterProvider sessionsPersister = realmManager.getSession().getProvider(UserSessionPersisterProvider.class);
        if (sessionsPersister != null) {
            sessionsPersister.onClientRemoved(realm, client);
        }

        AuthenticationSessionProvider authSessions = realmManager.getSession().authenticationSessions();
        if (authSessions != null) {
            authSessions.onClientRemoved(realm, client);
        }

        UserModel serviceAccountUser = realmManager.getSession().users().getServiceAccount(client);
        if (serviceAccountUser != null) {
            new UserManager(realmManager.getSession()).removeUser(realm, serviceAccountUser);
        }

        return true;
    } else {
        return false;
    }
}
 
Example 4
Source File: ClientsPartialImport.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(RealmModel realm, KeycloakSession session, ClientRepresentation clientRep) {
    ClientModel clientModel = realm.getClientByClientId(getName(clientRep));
    // remove the associated service account if the account exists
    if (clientModel.isServiceAccountsEnabled()) {
        UserModel serviceAccountUser = session.users().getServiceAccount(clientModel);
        if (serviceAccountUser != null) {
            session.users().removeUser(realm, serviceAccountUser);
        }
    }
    // the authorization resource server seems to be removed using the delete event, so it's not needed
    // remove the client itself
    realm.removeClient(clientModel.getId());
}