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);
}
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;
}
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;
}
Aggregations