@Override public String apply(NamespacedEntityId input) { return input.getEntityName(); } };
@Override public String apply(NamespacedEntityId input) { return input.getEntityName(); } };
/** * Validates the given {@link NamespacedEntityId} to be supported by the {@link OwnerStore} * i.e. the entity can be associated with an owner. * * @param entityId {@link NamespacedEntityId} to be validated */ protected final void validate(NamespacedEntityId entityId) { if (!SUPPORTED_ENTITY_TYPES.contains(entityId.getEntityType())) { throw new IllegalArgumentException(String.format("The given entity '%s' is of unsupported types '%s'. " + "Entity ownership is only supported for '%s'.", entityId.getEntityName(), entityId.getEntityType(), SUPPORTED_ENTITY_TYPES)); } }
/** * <p>Verifies the owner principal of an entity is same as the owner specified during entity creation. If an owner * was not specified during entity creation but is being specified later (i.e. during updating properties etc) the * specified owner principal is same as the effective impersonating principal.</p> * <p>Note: This method should not be called for an non-existing entity for example while the entity is being * created.</p> * @param existingEntity the existing entity whose owner principal is being verified * @param specifiedOwnerPrincipal the specified principal * @param ownerAdmin {@link OwnerAdmin} * @throws IOException if failed to query the given ownerAdmin * @throws UnauthorizedException if the specified owner information is not valid with the existing * impersonation principal */ public static void verifyOwnerPrincipal(NamespacedEntityId existingEntity, @Nullable String specifiedOwnerPrincipal, OwnerAdmin ownerAdmin) throws IOException, UnauthorizedException { // if an owner principal was not specified then ensure that a direct owner doesn't exist. Although, if an owner // principal was specified then it must be equal to the effective impersonating principal of this entity if (!((specifiedOwnerPrincipal == null && ownerAdmin.getOwnerPrincipal(existingEntity) == null) || Objects.equals(specifiedOwnerPrincipal, ownerAdmin.getImpersonationPrincipal(existingEntity)))) { // Not giving existing owner information as it might be unacceptable under some security scenarios throw new UnauthorizedException(String.format("%s '%s' already exists and the specified %s '%s' is not the " + "same as the existing one. The %s of an entity cannot be " + "changed.", existingEntity.getEntityType(), existingEntity.getEntityName(), Constants.Security.PRINCIPAL, specifiedOwnerPrincipal, Constants.Security.PRINCIPAL)); } }
private Optional<MetadataEntry> parseRow(Row rowToProcess, String indexColumn, Set<EntityTypeSimpleName> entityFilter, boolean showHidden) { String rowValue = rowToProcess.getString(indexColumn); if (rowValue == null) { return Optional.empty(); } final byte[] rowKey = rowToProcess.getRow(); String targetType = MetadataKey.extractTargetType(rowKey); // Filter on target type if not set to include all types boolean includeAllTypes = entityFilter.isEmpty() || entityFilter.contains(EntityTypeSimpleName.ALL); if (!includeAllTypes && !entityFilter.contains(EntityTypeSimpleName.valueOfSerializedForm(targetType))) { return Optional.empty(); } MetadataEntity metadataEntity = MetadataKey.extractMetadataEntityFromKey(rowKey); try { NamespacedEntityId namespacedEntityId = EntityId.fromMetadataEntity(metadataEntity); // if the entity starts with _ then skip it unless the caller choose to showHidden. if (!showHidden && namespacedEntityId != null && namespacedEntityId.getEntityName().startsWith("_")) { return Optional.empty(); } } catch (IllegalArgumentException e) { // ignore. For custom entities we don't really want to hide them if they start with _ } String key = MetadataKey.extractMetadataKey(rowKey); MetadataEntry entry = getMetadata(metadataEntity, key); return Optional.ofNullable(entry); }
private Optional<MetadataEntry> parseRow(Row rowToProcess, String indexColumn, Set<EntityTypeSimpleName> entityFilter, boolean showHidden) { String rowValue = rowToProcess.getString(indexColumn); if (rowValue == null) { return Optional.empty(); } final byte[] rowKey = rowToProcess.getRow(); String targetType = MetadataKey.extractTargetType(rowKey); // Filter on target type if not set to include all types boolean includeAllTypes = entityFilter.isEmpty() || entityFilter.contains(EntityTypeSimpleName.ALL); if (!includeAllTypes && !entityFilter.contains(EntityTypeSimpleName.valueOfSerializedForm(targetType))) { return Optional.empty(); } MetadataEntity metadataEntity = MetadataKey.extractMetadataEntityFromKey(rowKey); try { NamespacedEntityId namespacedEntityId = EntityId.fromMetadataEntity(metadataEntity); // if the entity starts with _ then skip it unless the caller choose to showHidden. if (!showHidden && namespacedEntityId != null && namespacedEntityId.getEntityName().startsWith("_")) { return Optional.empty(); } } catch (IllegalArgumentException e) { // ignore. For custom entities we don't really want to hide them if they start with _ } String key = MetadataKey.extractMetadataKey(rowKey); MetadataEntry entry = getMetadata(metadataEntity, key); return Optional.ofNullable(entry); }