@Override public List<ClientScopeModel> getDefaultClientScopes(boolean defaultScope) { TypedQuery<String> query = em.createNamedQuery("defaultClientScopeRealmMappingIdsByRealm", String.class); query.setParameter("realm", getEntity()); query.setParameter("defaultScope", defaultScope); List<String> ids = query.getResultList(); List<ClientScopeModel> clientScopes = new LinkedList<>(); for (String clientScopeId : ids) { ClientScopeModel clientScope = getClientScopeById(clientScopeId); if (clientScope == null) continue; clientScopes.add(clientScope); } return clientScopes; }
@Override public boolean removeClientScope(String id) { if (id == null) return false; ClientScopeModel clientScope = getClientScopeById(id); if (clientScope == null) return false; if (KeycloakModelUtils.isClientScopeUsed(this, clientScope)) { throw new ModelException("Cannot remove client scope, it is currently in use"); } ClientScopeEntity clientScopeEntity = null; Iterator<ClientScopeEntity> it = realm.getClientScopes().iterator(); while (it.hasNext()) { ClientScopeEntity ae = it.next(); if (ae.getId().equals(id)) { clientScopeEntity = ae; it.remove(); break; } } if (clientScope == null) { return false; } session.users().preRemove(clientScope); em.createNamedQuery("deleteClientScopeRoleMappingByClientScope").setParameter("clientScope", clientScopeEntity).executeUpdate(); em.flush(); em.remove(clientScopeEntity); em.flush(); return true; }