@Override public ClientModel getClientById(String id) { return model.getClientById(id, this); }
@Override public ClientModel getClientById(String id) { return session.realms().getClientById(id, this); }
@Override public ClientModel getClientByClientId(String clientId, RealmModel realm) { TypedQuery<String> query = em.createNamedQuery("findClientIdByClientId", String.class); query.setParameter("clientId", clientId); query.setParameter("realm", realm.getId()); List<String> results = query.getResultList(); if (results.isEmpty()) return null; String id = results.get(0); return session.realms().getClientById(id, realm); }
@Override public List<ClientModel> getClients(RealmModel realm) { TypedQuery<String> query = em.createNamedQuery("getClientIdsByRealm", String.class); query.setParameter("realm", realm.getId()); List<String> clients = query.getResultList(); if (clients.isEmpty()) return Collections.EMPTY_LIST; List<ClientModel> list = new LinkedList<>(); for (String id : clients) { ClientModel client = session.realms().getClientById(id, realm); if (client != null) list.add(client); } return Collections.unmodifiableList(list); }
protected boolean isUpdated() { if (updated != null) return true; if (!invalidated) return false; updated = cacheSession.getRealmDelegate().getClientById(cached.getId(), cachedRealm); if (updated == null) throw new IllegalStateException("Not found in database"); return true; }
private void getDelegateForUpdate() { if (updated == null) { cacheSession.registerApplicationInvalidation(getId()); updated = cacheSession.getDelegate().getClientById(getId(), cachedRealm); if (updated == null) throw new IllegalStateException("Not found in database"); } }
@Override public ClientModel getClientById(String id, RealmModel realm) { if (!cache.isEnabled()) return getDelegate().getClientById(id, realm); CachedClient cached = cache.getApplication(id); if (cached != null && !cached.getRealm().equals(realm.getId())) { cached = null; } if (cached == null) { ClientModel model = getDelegate().getClientById(id, realm); if (model == null) return null; if (appInvalidations.contains(id)) return model; cached = new CachedClient(cache, getDelegate(), realm, model); cache.addCachedClient(cached); } else if (appInvalidations.contains(id)) { return getDelegate().getClientById(id, realm); } else if (managedApplications.containsKey(id)) { return managedApplications.get(id); } ClientAdapter adapter = new ClientAdapter(realm, cached, this, cache); managedApplications.put(id, adapter); return adapter; } @Override
@Override public List<ClientModel> getClients(RealmModel realm) { DBObject query = new QueryBuilder() .and("realmId").is(realm.getId()) .get(); List<MongoClientEntity> clientEntities = getMongoStore().loadEntities(MongoClientEntity.class, query, invocationContext); if (clientEntities.isEmpty()) return Collections.EMPTY_LIST; List<ClientModel> result = new ArrayList<ClientModel>(); for (MongoClientEntity clientEntity : clientEntities) { result.add(session.realms().getClientById(clientEntity.getId(), realm)); } return Collections.unmodifiableList(result); }
private void getDelegateForUpdate() { if (updated == null) { cacheSession.registerClientInvalidation(cached.getId(), cached.getClientId(), cachedRealm.getId()); updated = cacheSession.getRealmDelegate().getClientById(cached.getId(), cachedRealm); if (updated == null) throw new IllegalStateException("Not found in database"); } } protected boolean invalidated;
@Override public ClientModel getClientById(String id, RealmModel realm) { CachedClient cached = cache.get(id, CachedClient.class); if (cached != null && !cached.getRealm().equals(realm.getId())) { cached = null; } if (cached != null) { logger.tracev("client by id cache hit: {0}", cached.getClientId()); } if (cached == null) { Long loaded = cache.getCurrentRevision(id); ClientModel model = getClientDelegate().getClientById(id, realm); if (model == null) return null; ClientModel adapter = cacheClient(realm, model, loaded); managedApplications.put(id, adapter); return adapter; } else if (invalidations.contains(id)) { return getRealmDelegate().getClientById(id, realm); } else if (managedApplications.containsKey(id)) { return managedApplications.get(id); } ClientModel adapter = validateCache(realm, cached); managedApplications.put(id, adapter); return adapter; }
@Override public ClientModel getMasterAdminClient() { ClientEntity masterAdminClient = realm.getMasterAdminClient(); if (masterAdminClient == null) { return null; } RealmModel masterRealm = null; String masterAdminClientRealmId = masterAdminClient.getRealm().getId(); if (masterAdminClientRealmId.equals(getId())) { masterRealm = this; } else { masterRealm = session.realms().getRealm(masterAdminClientRealmId); } return session.realms().getClientById(masterAdminClient.getId(), masterRealm); }
ClientModel client = session.realms().getClientById(id, realm); if (client == null) {
@Override public ClientModel getClientByClientId(String clientId, RealmModel realm) { DBObject query = new QueryBuilder() .and("realmId").is(realm.getId()) .and("clientId").is(clientId) .get(); MongoClientEntity appEntity = getMongoStore().loadSingleEntity(MongoClientEntity.class, query, invocationContext); if (appEntity == null) return null; return session.realms().getClientById(appEntity.getId(), realm); }
private UserConsentModel toConsentModel(RealmModel realm, CachedUserConsent cachedConsent) { ClientModel client = session.realms().getClientById(cachedConsent.getClientDbId(), realm); if (client == null) { return null; } UserConsentModel consentModel = new UserConsentModel(client); consentModel.setCreatedDate(cachedConsent.getCreatedDate()); consentModel.setLastUpdatedDate(cachedConsent.getLastUpdatedDate()); for (String clientScopeId : cachedConsent.getClientScopeIds()) { ClientScopeModel clientScope = KeycloakModelUtils.findClientScopeById(realm, client, clientScopeId); if (clientScope != null) { consentModel.addGrantedClientScope(clientScope); } } return consentModel; }