private static WithDittoHeaders checkForHarmfulEntity(final WithDittoHeaders withDittoHeaders) { if (withDittoHeaders instanceof Command && withDittoHeaders instanceof WithOptionalEntity) { final Optional<JsonValue> optionalEntity = ((WithOptionalEntity) withDittoHeaders).getEntity(); if (optionalEntity.isPresent() && isJsonValueIllegal(optionalEntity.get())) { throw buildError(withDittoHeaders); } } return withDittoHeaders; }
@Override public WithDittoHeaders apply(final WithDittoHeaders withDittoHeaders) { return checkForHarmfulEntity(withDittoHeaders); }
private static boolean isJsonFieldIllegal(final JsonField jsonField) { return isStringIllegal(jsonField.getKeyName()) || isJsonValueIllegal(jsonField.getValue()); }
private static Function<WithDittoHeaders, CompletionStage<WithDittoHeaders>> newPreEnforcer( final BlockedNamespaces blockedNamespaces, final PlaceholderSubstitution placeholderSubstitution) { return withDittoHeaders -> BlockNamespaceBehavior.of(blockedNamespaces) .block(withDittoHeaders) .thenApply(CommandWithOptionalEntityValidator.getInstance()) .thenCompose(placeholderSubstitution); }
private static boolean isJsonValueIllegal(final JsonValue entity) { final boolean result; if (entity.isArray()) { result = entity.asArray().stream().anyMatch(CommandWithOptionalEntityValidator::isJsonValueIllegal); } else if (entity.isObject()) { result = entity.asObject().stream().anyMatch(CommandWithOptionalEntityValidator::isJsonFieldIllegal); } else if (entity.isString()) { result = isStringIllegal(entity.asString()); } else { result = false; } return result; }