/** * Returns the EntityId represented by the given MetadataEntity. Note: Custom MetadataEntity cannot be converted * into EntityId hence this call is only safe to be called if the MetadataEntity does represent an EntityId and can * actually be converted to an EntityId. * @param metadataEntity the MetadataEntity which needs to be converted to EntityId * @return the EntityId * @throws IllegalArgumentException if the metadataEntity does not represent an EntityId and is a custom * metadataEntity. */ public static <T extends EntityId> T fromMetadataEntity(MetadataEntity metadataEntity) { // check that the type of teh metadata entity is known type EntityType.valueOf(metadataEntity.getType().toUpperCase()); return getSelfOrParentEntityId(metadataEntity); }
/** * Returns the EntityId represented by the given MetadataEntity. Note: Custom MetadataEntity cannot be converted * into EntityId hence this call is only safe to be called if the MetadataEntity does represent an EntityId and can * actually be converted to an EntityId. * @param metadataEntity the MetadataEntity which needs to be converted to EntityId * @return the EntityId * @throws IllegalArgumentException if the metadataEntity does not represent an EntityId and is a custom * metadataEntity. */ public static <T extends EntityId> T fromMetadataEntity(MetadataEntity metadataEntity) { // check that the type of teh metadata entity is known type EntityType.valueOf(metadataEntity.getType().toUpperCase()); return getSelfOrParentEntityId(metadataEntity); }
/** * Filter a list of {@link MetadataSearchResultRecordV2} that ensures the logged-in user has a privilege on * * @param results the {@link MetadataSearchResponseV2} to filter * @return filtered {@link MetadataSearchResponseV2} */ private MetadataSearchResponseV2 filterAuthorizedSearchResult(final MetadataSearchResponseV2 results) throws Exception { //noinspection ConstantConditions return new MetadataSearchResponseV2( results.getSort(), results.getOffset(), results.getLimit(), results.getNumCursors(), results.getTotal(), // For authorization either use the known entity and if it is custom entity do enforcement on the parent. // TODO CDAP-13574 Support authorization for custom entities/resources ImmutableSet.copyOf( AuthorizationUtil.isVisible(results.getResults(), authorizationEnforcer, authenticationContext.getPrincipal(), input -> EntityId.getSelfOrParentEntityId(input.getMetadataEntity()), null)), results.getCursors(), results.isShowHidden(), results.getEntityScope()); }
/** * Filter a list of {@link MetadataSearchResultRecord} that ensures the logged-in user has a privilege on * * @param results the {@link MetadataSearchResponse} to filter * @return filtered {@link MetadataSearchResponse} */ private MetadataSearchResponse filterAuthorizedSearchResult(final MetadataSearchResponse results) throws Exception { //noinspection ConstantConditions return new MetadataSearchResponse( results.getSort(), results.getOffset(), results.getLimit(), results.getNumCursors(), results.getTotal(), // For authorization either use the known entity and if it is custom entity do enforcement on the parent. // TODO CDAP-13574 Support authorization for custom entities/resources ImmutableSet.copyOf( AuthorizationUtil.isVisible(results.getResults(), authorizationEnforcer, authenticationContext.getPrincipal(), input -> EntityId.getSelfOrParentEntityId(input.getMetadataEntity()), null)), results.getCursors(), results.isShowHidden(), results.getEntityScope()); } }