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; }
private UserConsentModel toConsentModel(RealmModel realm, UserConsentEntity entity) { ClientModel client = realm.getClientById(entity.getClientId()); if (client == null) { throw new ModelException("Client with id " + entity.getClientId() + " is not available"); } UserConsentModel model = new UserConsentModel(client); model.setCreatedDate(entity.getCreatedDate()); model.setLastUpdatedDate(entity.getLastUpdatedDate()); for (String roleId : entity.getGrantedRoles()) { RoleModel roleModel = realm.getRoleById(roleId); if (roleModel != null) { model.addGrantedRole(roleModel); } } for (String protMapperId : entity.getGrantedProtocolMappers()) { ProtocolMapperModel protocolMapper = client.getProtocolMapperById(protMapperId); model.addGrantedProtocolMapper(protocolMapper); } return model; }
private UserConsentModel toConsentModel(RealmModel realm, FederatedUserConsentEntity entity) { if (entity == null) { return null; } StorageId clientStorageId = null; if ( entity.getClientId() == null) { clientStorageId = new StorageId(entity.getClientStorageProvider(), entity.getExternalClientId()); } else { clientStorageId = new StorageId(entity.getClientId()); } ClientModel client = realm.getClientById(clientStorageId.getId()); UserConsentModel model = new UserConsentModel(client); model.setCreatedDate(entity.getCreatedDate()); model.setLastUpdatedDate(entity.getLastUpdatedDate()); Collection<FederatedUserConsentClientScopeEntity> grantedClientScopeEntities = entity.getGrantedClientScopes(); if (grantedClientScopeEntities != null) { for (FederatedUserConsentClientScopeEntity grantedClientScope : grantedClientScopeEntities) { ClientScopeModel grantedClientScopeModel = realm.getClientScopeById(grantedClientScope.getScopeId()); if (grantedClientScopeModel != null) { model.addGrantedClientScope(grantedClientScopeModel); } } } return model; }
private UserConsentModel toConsentModel(RealmModel realm, UserConsentEntity entity) { if (entity == null) { return null; } StorageId clientStorageId = null; if ( entity.getClientId() == null) { clientStorageId = new StorageId(entity.getClientStorageProvider(), entity.getExternalClientId()); } else { clientStorageId = new StorageId(entity.getClientId()); } ClientModel client = realm.getClientById(clientStorageId.getId()); if (client == null) { throw new ModelException("Client with id " + clientStorageId.getId() + " is not available"); } UserConsentModel model = new UserConsentModel(client); model.setCreatedDate(entity.getCreatedDate()); model.setLastUpdatedDate(entity.getLastUpdatedDate()); Collection<UserConsentClientScopeEntity> grantedClientScopeEntities = entity.getGrantedClientScopes(); if (grantedClientScopeEntities != null) { for (UserConsentClientScopeEntity grantedClientScope : grantedClientScopeEntities) { ClientScopeModel grantedClientScopeModel = KeycloakModelUtils.findClientScopeById(realm, client, grantedClientScope.getScopeId()); if (grantedClientScopeModel != null) { model.addGrantedClientScope(grantedClientScopeModel); } } } return model; }