public CachedUserConsents(Long revision, String id, RealmModel realm, List<UserConsentModel> consents) { super(revision, id); this.realmId = realm.getId(); if (consents != null) { for (UserConsentModel consent : consents) { this.consents.put(consent.getClient().getId(), new CachedUserConsent(consent)); } } }
public CachedUserConsent(UserConsentModel consentModel) { this.clientDbId = consentModel.getClient().getId(); for (ClientScopeModel clientScope : consentModel.getGrantedClientScopes()) { this.clientScopeIds.add(clientScope.getId()); } this.createdDate = consentModel.getCreatedDate(); this.lastUpdatedDate = consentModel.getLastUpdatedDate(); }
@Override public void updateConsent(RealmModel realm, String userId, UserConsentModel consent) { String clientId = consent.getClient().getId(); UserConsentEntity consentEntity = getGrantedConsentEntity(userId, clientId); if (consentEntity == null) { throw new ModelException("Consent not found for client [" + clientId + "] and user [" + userId + "]"); } updateGrantedConsentEntity(consentEntity, consent); }
public static UserConsentRepresentation toRepresentation(UserConsentModel model) { String clientId = model.getClient().getClientId();
@Override public void updateConsent(RealmModel realm, String userId, UserConsentModel consent) { createIndex(realm, userId); String clientId = consent.getClient().getId(); FederatedUserConsentEntity consentEntity = getGrantedConsentEntity(userId, clientId); if (consentEntity == null) { throw new ModelException("Consent not found for client [" + clientId + "] and user [" + userId + "]"); } updateGrantedConsentEntity(consentEntity, consent); }
@Override public void updateConsent(RealmModel realm, String userId, UserConsentModel consent) { String clientId = consent.getClient().getId(); MongoUserConsentEntity consentEntity = getConsentEntityByClientId(userId, clientId); if (consentEntity == null) { throw new ModelException("Consent not found for client [" + clientId + "] and user [" + userId + "]"); } else { fillEntityFromModel(consent, consentEntity); getMongoStore().updateEntity(consentEntity, invocationContext); } }
@Override public void addConsent(RealmModel realm, String userId, UserConsentModel consent) { String clientId = consent.getClient().getId(); if (getConsentEntityByClientId(userId, clientId) != null) { throw new ModelDuplicateException("Consent already exists for client [" + clientId + "] and user [" + userId + "]"); } long currentTime = Time.currentTimeMillis(); MongoUserConsentEntity consentEntity = new MongoUserConsentEntity(); consentEntity.setUserId(userId); consentEntity.setClientId(clientId); consentEntity.setCreatedDate(currentTime); consentEntity.setLastUpdatedDate(currentTime); fillEntityFromModel(consent, consentEntity); getMongoStore().insertEntity(consentEntity, invocationContext); }
@Override public void addConsent(RealmModel realm, String userId, UserConsentModel consent) { String clientId = consent.getClient().getId(); UserConsentEntity consentEntity = getGrantedConsentEntity(userId, clientId); if (consentEntity != null) { throw new ModelDuplicateException("Consent already exists for client [" + clientId + "] and user [" + userId + "]"); } long currentTime = Time.currentTimeMillis(); consentEntity = new UserConsentEntity(); consentEntity.setId(KeycloakModelUtils.generateId()); consentEntity.setUser(em.getReference(UserEntity.class, userId)); StorageId clientStorageId = new StorageId(clientId); if (clientStorageId.isLocal()) { consentEntity.setClientId(clientId); } else { consentEntity.setClientStorageProvider(clientStorageId.getProviderId()); consentEntity.setExternalClientId(clientStorageId.getExternalId()); } consentEntity.setCreatedDate(currentTime); consentEntity.setLastUpdatedDate(currentTime); em.persist(consentEntity); em.flush(); updateGrantedConsentEntity(consentEntity, consent); }
@Override public void addConsent(RealmModel realm, String userId, UserConsentModel consent) { createIndex(realm, userId); String clientId = consent.getClient().getId(); FederatedUserConsentEntity consentEntity = getGrantedConsentEntity(userId, clientId); if (consentEntity != null) { throw new ModelDuplicateException("Consent already exists for client [" + clientId + "] and user [" + userId + "]"); } consentEntity = new FederatedUserConsentEntity(); consentEntity.setId(KeycloakModelUtils.generateId()); consentEntity.setUserId(userId); StorageId clientStorageId = new StorageId(clientId); if (clientStorageId.isLocal()) { consentEntity.setClientId(clientId); } else { consentEntity.setClientStorageProvider(clientStorageId.getProviderId()); consentEntity.setExternalClientId(clientStorageId.getExternalId()); } consentEntity.setRealmId(realm.getId()); consentEntity.setStorageProviderId(new StorageId(userId).getProviderId()); long currentTime = Time.currentTimeMillis(); consentEntity.setCreatedDate(currentTime); consentEntity.setLastUpdatedDate(currentTime); em.persist(consentEntity); em.flush(); updateGrantedConsentEntity(consentEntity, consent); }