Search in sources :

Example 1 with ClientScopeEntity

use of org.keycloak.models.jpa.entities.ClientScopeEntity in project keycloak by keycloak.

the class JpaRealmProvider method addClientScope.

@Override
public ClientScopeModel addClientScope(RealmModel realm, String id, String name) {
    if (id == null) {
        id = KeycloakModelUtils.generateId();
    }
    ClientScopeEntity entity = new ClientScopeEntity();
    entity.setId(id);
    name = KeycloakModelUtils.convertClientScopeName(name);
    entity.setName(name);
    entity.setRealmId(realm.getId());
    em.persist(entity);
    em.flush();
    return new ClientScopeAdapter(realm, em, session, entity);
}
Also used : ClientScopeEntity(org.keycloak.models.jpa.entities.ClientScopeEntity)

Example 2 with ClientScopeEntity

use of org.keycloak.models.jpa.entities.ClientScopeEntity in project keycloak by keycloak.

the class JpaRealmProvider method removeClientScope.

@Override
public boolean removeClientScope(RealmModel realm, String id) {
    if (id == null)
        return false;
    ClientScopeModel clientScope = getClientScopeById(realm, id);
    if (clientScope == null)
        return false;
    session.users().preRemove(clientScope);
    realm.removeDefaultClientScope(clientScope);
    ClientScopeEntity clientScopeEntity = em.find(ClientScopeEntity.class, id, LockModeType.PESSIMISTIC_WRITE);
    em.createNamedQuery("deleteClientScopeClientMappingByClientScope").setParameter("clientScopeId", clientScope.getId()).executeUpdate();
    em.createNamedQuery("deleteClientScopeRoleMappingByClientScope").setParameter("clientScope", clientScopeEntity).executeUpdate();
    em.remove(clientScopeEntity);
    session.getKeycloakSessionFactory().publish(new ClientScopeModel.ClientScopeRemovedEvent() {

        @Override
        public KeycloakSession getKeycloakSession() {
            return session;
        }

        @Override
        public ClientScopeModel getClientScope() {
            return clientScope;
        }
    });
    em.flush();
    return true;
}
Also used : ClientScopeEntity(org.keycloak.models.jpa.entities.ClientScopeEntity) KeycloakSession(org.keycloak.models.KeycloakSession) ClientScopeModel(org.keycloak.models.ClientScopeModel)

Example 3 with ClientScopeEntity

use of org.keycloak.models.jpa.entities.ClientScopeEntity in project keycloak by keycloak.

the class JpaRealmProvider method getClientScopeById.

@Override
public ClientScopeModel getClientScopeById(RealmModel realm, String id) {
    ClientScopeEntity clientScope = em.find(ClientScopeEntity.class, id);
    // Check if client scope belongs to this realm
    if (clientScope == null || !realm.getId().equals(clientScope.getRealmId()))
        return null;
    ClientScopeAdapter adapter = new ClientScopeAdapter(realm, em, session, clientScope);
    return adapter;
}
Also used : ClientScopeEntity(org.keycloak.models.jpa.entities.ClientScopeEntity)

Aggregations

ClientScopeEntity (org.keycloak.models.jpa.entities.ClientScopeEntity)3 ClientScopeModel (org.keycloak.models.ClientScopeModel)1 KeycloakSession (org.keycloak.models.KeycloakSession)1