Search in sources :

Example 46 with RealmManager

use of org.keycloak.services.managers.RealmManager in project keycloak by keycloak.

the class UserConsentWithUserStorageModelTest method after.

@After
public void after() {
    testingClient.server().run(session -> {
        RealmManager realmManager = new RealmManager(session);
        RealmModel realm = realmManager.getRealmByName("original");
        if (realm != null) {
            session.sessions().removeUserSessions(realm);
            UserModel user = session.users().getUserByUsername(realm, "user");
            UserModel user1 = session.users().getUserByUsername(realm, "user1");
            UserModel user2 = session.users().getUserByUsername(realm, "user2");
            UserModel user3 = session.users().getUserByUsername(realm, "user3");
            UserManager um = new UserManager(session);
            if (user != null) {
                um.removeUser(realm, user);
            }
            if (user1 != null) {
                um.removeUser(realm, user1);
            }
            if (user2 != null) {
                um.removeUser(realm, user2);
            }
            if (user3 != null) {
                um.removeUser(realm, user3);
            }
            realmManager.removeRealm(realm);
        }
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) UserModel(org.keycloak.models.UserModel) UserManager(org.keycloak.models.UserManager) RealmManager(org.keycloak.services.managers.RealmManager) After(org.junit.After)

Example 47 with RealmManager

use of org.keycloak.services.managers.RealmManager in project keycloak by keycloak.

the class AbstractClientRegistrationProvider method delete.

public void delete(String clientId) {
    event.event(EventType.CLIENT_DELETE).client(clientId);
    ClientModel client = session.getContext().getRealm().getClientByClientId(clientId);
    auth.requireDelete(client);
    if (new ClientManager(new RealmManager(session)).removeClient(session.getContext().getRealm(), client)) {
        event.client(client.getClientId()).success();
    } else {
        throw new ForbiddenException();
    }
}
Also used : ClientModel(org.keycloak.models.ClientModel) ForbiddenException(org.keycloak.services.ForbiddenException) ClientManager(org.keycloak.services.managers.ClientManager) RealmManager(org.keycloak.services.managers.RealmManager)

Aggregations

RealmManager (org.keycloak.services.managers.RealmManager)47 RealmModel (org.keycloak.models.RealmModel)34 Test (org.junit.Test)19 UserModel (org.keycloak.models.UserModel)17 KeycloakSession (org.keycloak.models.KeycloakSession)16 ClientModel (org.keycloak.models.ClientModel)13 ClientManager (org.keycloak.services.managers.ClientManager)11 ModelTest (org.keycloak.testsuite.arquillian.annotation.ModelTest)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)8 Path (javax.ws.rs.Path)6 UserSessionModel (org.keycloak.models.UserSessionModel)6 UserManager (org.keycloak.models.UserManager)5 AbstractAuthTest (org.keycloak.testsuite.AbstractAuthTest)4 LinkedList (java.util.LinkedList)3 GET (javax.ws.rs.GET)3 NotFoundException (javax.ws.rs.NotFoundException)3 Produces (javax.ws.rs.Produces)3 UserConsentModel (org.keycloak.models.UserConsentModel)3 ClientPolicyException (org.keycloak.services.clientpolicy.ClientPolicyException)3