@Override public void updateConsent(UserConsentModel consent) { String clientId = consent.getClient().getId(); UserConsentEntity consentEntity = getGrantedConsentEntity(clientId); if (consentEntity == null) { throw new ModelException( "Consent not found for client [" + clientId + "] and user [" + user.getId() + "]"); } updateGrantedConsentEntity(consentEntity, consent); }
@Override public void addConsent(UserConsentModel consent) { String clientId = consent.getClient().getId(); UserConsentEntity consentEntity = getGrantedConsentEntity(clientId); if (consentEntity != null) { throw new ModelDuplicateException( "Consent already exists for client [" + clientId + "] and user [" + user.getId() + "]"); } consentEntity = new UserConsentEntity(); consentEntity.setId(KeycloakModelUtils.generateId()); consentEntity.setUser(user); consentEntity.setClientId(clientId); em.persist(consentEntity); em.flush(); updateGrantedConsentEntity(consentEntity, consent); }
@Override public String getId() { return user.getId(); }