use of org.keycloak.models.jpa.entities.RealmEntity in project keycloak by keycloak.
the class JpaRealmProvider method getRealm.
@Override
public RealmModel getRealm(String id) {
RealmEntity realm = em.find(RealmEntity.class, id);
if (realm == null)
return null;
RealmAdapter adapter = new RealmAdapter(session, em, realm);
return adapter;
}
use of org.keycloak.models.jpa.entities.RealmEntity in project keycloak by keycloak.
the class JpaRealmProvider method createRealm.
@Override
public RealmModel createRealm(String id, String name) {
RealmEntity realm = new RealmEntity();
realm.setName(name);
realm.setId(id);
em.persist(realm);
em.flush();
final RealmModel adapter = new RealmAdapter(session, em, realm);
session.getKeycloakSessionFactory().publish(new RealmModel.RealmCreationEvent() {
@Override
public RealmModel getCreatedRealm() {
return adapter;
}
@Override
public KeycloakSession getKeycloakSession() {
return session;
}
});
return adapter;
}
use of org.keycloak.models.jpa.entities.RealmEntity in project keycloak by keycloak.
the class JpaRealmProvider method removeRealm.
@Override
public boolean removeRealm(String id) {
RealmEntity realm = em.find(RealmEntity.class, id, LockModeType.PESSIMISTIC_WRITE);
if (realm == null) {
return false;
}
em.refresh(realm);
final RealmAdapter adapter = new RealmAdapter(session, em, realm);
session.users().preRemove(adapter);
realm.getDefaultGroupIds().clear();
em.flush();
int num = em.createNamedQuery("deleteGroupRoleMappingsByRealm").setParameter("realm", realm.getId()).executeUpdate();
session.clients().removeClients(adapter);
num = em.createNamedQuery("deleteDefaultClientScopeRealmMappingByRealm").setParameter("realm", realm).executeUpdate();
session.clientScopes().removeClientScopes(adapter);
session.roles().removeRoles(adapter);
adapter.getTopLevelGroupsStream().forEach(adapter::removeGroup);
num = em.createNamedQuery("removeClientInitialAccessByRealm").setParameter("realm", realm).executeUpdate();
em.remove(realm);
em.flush();
em.clear();
session.getKeycloakSessionFactory().publish(new RealmModel.RealmRemovedEvent() {
@Override
public RealmModel getRealm() {
return adapter;
}
@Override
public KeycloakSession getKeycloakSession() {
return session;
}
});
return true;
}
Aggregations