/** * Convert an indexed address metric into a JSON field. * * @param key Key of the address metric; may be empty. * @param metric the address metric to convert. * @return a valid JSON field for the address metric. */ static JsonField toJsonField(final String key, final AddressMetric metric) { final String nonemptyKey = key.isEmpty() ? "<empty>" : key; return JsonFactory.newField(JsonKey.of(nonemptyKey), metric.toJson()); } }
private Set<JsonField> calculateThresholdViolations(final String featureId, final FeatureProperties featureProperties) { return featureProperties.stream() .filter(field -> violatesThreshold( field.getKey().asPointer(), field.getValue(), featurePropertyOverhead(featureId), MAX_INDEX_CONTENT_LENGTH)) .collect(Collectors.toSet()); }
/** * Convert an indexed address metric into a JSON field. * * @param key Key of the address metric; may be empty. * @param metric the address metric to convert. * @return a valid JSON field for the address metric. */ static JsonField toJsonField(final String key, final AddressMetric metric) { final String nonemptyKey = key.isEmpty() ? "<empty>" : key; return JsonFactory.newField(JsonKey.of(nonemptyKey), metric.toJson()); } }
private Set<JsonField> calculateThresholdViolations(final Attributes attributes) { return attributes .stream() .filter(field -> violatesThreshold(field.getKey().asPointer(), field.getValue(), attributeOverhead(), MAX_INDEX_CONTENT_LENGTH)) .collect(Collectors.toSet()); }
@Override default JsonPointer getResourcePath() { final Message<?> message = getMessage(); final String box = message.getDirection() == MessageDirection.TO ? MessageCommand.INBOX_PREFIX : MessageCommand.OUTBOX_PREFIX; final JsonPointer pathSuffix = JsonFactory.newPointer(JsonKey.of(box), JsonKey.of(MessageCommand.MESSAGES_PREFIX), JsonKey.of(message.getSubject())); final JsonPointer path = message.getFeatureId() .map(fId -> JsonFactory.newPointer(JsonKey.of(MessageCommand.FEATURES_PREFIX), JsonKey.of(fId))) .orElse(JsonPointer.empty()); return path.append(pathSuffix); }
private Set<JsonField> calculateThresholdViolations(final String featureId, final FeatureProperties featureProperties) { return featureProperties.stream() .filter(field -> violatesThreshold( field.getKey().asPointer(), field.getValue(), featurePropertyOverhead(featureId), MAX_INDEX_CONTENT_LENGTH)) .collect(Collectors.toSet()); }
@Override default JsonPointer getResourcePath() { final Message<?> message = getMessage(); final String box = message.getDirection() == MessageDirection.TO ? MessageCommand.INBOX_PREFIX : MessageCommand.OUTBOX_PREFIX; final JsonPointer pathSuffix = JsonFactory.newPointer(JsonKey.of(box), JsonKey.of(MessageCommand.MESSAGES_PREFIX), JsonKey.of(message.getSubject())); final JsonPointer path = message.getFeatureId() .map(fId -> JsonFactory.newPointer(JsonKey.of(MessageCommand.FEATURES_PREFIX), JsonKey.of(fId))) .orElse(JsonPointer.empty()); return path.append(pathSuffix); }
private Set<JsonField> calculateThresholdViolations(final Attributes attributes) { return attributes .stream() .filter(field -> violatesThreshold(field.getKey().asPointer(), field.getValue(), attributeOverhead(), MAX_INDEX_CONTENT_LENGTH)) .collect(Collectors.toSet()); }
@Override default JsonPointer getResourcePath() { final Message<?> message = getMessage(); final String box = message.getDirection() == MessageDirection.TO ? INBOX_PREFIX : OUTBOX_PREFIX; final JsonPointer pathSuffix = JsonPointer.empty() .addLeaf(JsonKey.of(box)) .addLeaf(JsonKey.of(MESSAGES_PREFIX)) .addLeaf(JsonKey.of(message.getSubject())); final JsonPointer path = message.getFeatureId().map(fId -> JsonPointer.empty() .addLeaf(JsonKey.of(FEATURES_PREFIX)) .addLeaf(JsonKey.of(fId))) .orElse(JsonPointer.empty()); return path.append(pathSuffix); }
/** * Converts the specified char sequence to a {@link JsonPointer} which is guaranteed to be not empty. * * @param keyOrPointer a string representation of a JSON pointer or a JsonKey. * @return the pointer. * @throws NullPointerException if {@code keyOrPointer} is {@code null}. * @throws IllegalArgumentException if {@code keyOrPointer} would lead to an empty JsonPointer. */ static JsonPointer getNonEmptyPointer(final CharSequence keyOrPointer) { requireNonNull(keyOrPointer, "The key or pointer char sequence must not be null!"); final JsonPointer result; if (isPointer(keyOrPointer)) { result = JsonFactory.newPointer(keyOrPointer); } else { final JsonKey jsonKey = JsonFactory.newKey(keyOrPointer); result = jsonKey.asPointer(); } if (result.isEmpty()) { throw new IllegalArgumentException("The key or pointer must not be empty!"); } return result; }
@Override default JsonPointer getResourcePath() { final Message<?> message = getMessage(); final String box = message.getDirection() == MessageDirection.TO ? INBOX_PREFIX : OUTBOX_PREFIX; final JsonPointer pathSuffix = JsonPointer.empty() .addLeaf(JsonKey.of(box)) .addLeaf(JsonKey.of(MESSAGES_PREFIX)) .addLeaf(JsonKey.of(message.getSubject())); final JsonPointer path = message.getFeatureId().map(fId -> JsonPointer.empty() .addLeaf(JsonKey.of(FEATURES_PREFIX)) .addLeaf(JsonKey.of(fId))) .orElse(JsonPointer.empty()); return path.append(pathSuffix); }
/** * Converts the specified char sequence to a {@link JsonPointer} which is guaranteed to be not empty. * * @param keyOrPointer a string representation of a JSON pointer or a JsonKey. * @return the pointer. * @throws NullPointerException if {@code keyOrPointer} is {@code null}. * @throws IllegalArgumentException if {@code keyOrPointer} would lead to an empty JsonPointer. */ static JsonPointer getNonEmptyPointer(final CharSequence keyOrPointer) { requireNonNull(keyOrPointer, "The key or pointer char sequence must not be null!"); final JsonPointer result; if (isPointer(keyOrPointer)) { result = newPointer(keyOrPointer); } else { final JsonKey jsonKey = newKey(keyOrPointer); result = jsonKey.asPointer(); } if (result.isEmpty()) { throw new IllegalArgumentException("The key or pointer must not be empty!"); } return result; }
private JsonObject subjectsToJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); subjects.values().forEach(subject -> { final JsonKey key = JsonKey.of(subject.getId()); final JsonValue value = subject.toJson(schemaVersion, thePredicate); final JsonFieldDefinition<JsonObject> fieldDefinition = JsonFactory.newJsonObjectFieldDefinition(key, FieldType.REGULAR, JsonSchemaVersion.V_2); final JsonField field = JsonFactory.newField(key, value, fieldDefinition); jsonObjectBuilder.set(field, predicate); }); return jsonObjectBuilder.build(); }
private FeatureProperties fixViolations(final String featureId, final Set<JsonField> exceededProps, final FeatureProperties featureProperties) { final FeaturePropertiesBuilder featurePropertiesBuilder = featureProperties.toBuilder(); exceededProps.forEach( jsonField -> { final JsonValue restrictedValue = fixViolation( jsonField.getKey().asPointer(), jsonField.getValue(), featurePropertyOverhead(featureId), MAX_INDEX_CONTENT_LENGTH); featurePropertiesBuilder.set(jsonField.getKey().asPointer(), restrictedValue); }); return featurePropertiesBuilder.build(); }
private JsonObject resourcesToJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); resources.values().forEach(resource -> { final JsonKey key = JsonKey.of(resource.getFullQualifiedPath()); final JsonValue value = resource.toJson(schemaVersion, thePredicate); final JsonFieldDefinition<JsonObject> fieldDefinition = JsonFactory.newJsonObjectFieldDefinition(key, FieldType.REGULAR, JsonSchemaVersion.V_2); final JsonField field = JsonFactory.newField(key, value, fieldDefinition); jsonObjectBuilder.set(field, predicate); }); return jsonObjectBuilder.build(); }
private FeatureProperties fixViolations(final String featureId, final Set<JsonField> exceededProps, final FeatureProperties featureProperties) { final FeaturePropertiesBuilder featurePropertiesBuilder = featureProperties.toBuilder(); exceededProps.forEach( jsonField -> { final JsonValue restrictedValue = fixViolation( jsonField.getKey().asPointer(), jsonField.getValue(), featurePropertyOverhead(featureId), MAX_INDEX_CONTENT_LENGTH); featurePropertiesBuilder.set(jsonField.getKey().asPointer(), restrictedValue); }); return featurePropertiesBuilder.build(); }
policyTreeNode.getChildren() .forEach((s, child) -> traverseSubtreeForPermissionAccess(permission, resource.addLeaf(JsonKey.of(s)), type, child, grantedResources, revokedResources, level + 1, false));
private Attributes fixViolations(final Set<JsonField> exceededAttributes, final Attributes attributes) { final AttributesBuilder builder = attributes.toBuilder(); exceededAttributes.forEach(field -> builder.set( field.getKey().toString(), fixViolation(field.getKey().asPointer(), field.getValue(), attributeOverhead(), MAX_INDEX_CONTENT_LENGTH))); return builder.build(); }
@Override public JsonObject buildJsonView(final ResourceKey resourceKey, final Iterable<JsonField> jsonFields, final AuthorizationContext authorizationContext, final Permissions permissions) { checkResourceKey(resourceKey); checkNotNull(jsonFields, "JSON fields"); checkPermissions(permissions); final Set<String> subjectIds = getSubjectIds(authorizationContext); final JsonKey typeKey = JsonKey.of(resourceKey.getResourceType()); if (inheritedTrie.hasChild(typeKey)) { final PolicyTrie start = inheritedTrie.seekToLeastAncestor(PolicyTrie.getJsonKeyIterator(resourceKey)); return start.buildJsonView(jsonFields, subjectIds, permissions); } else { return JsonFactory.newObject(); } }
private Attributes fixViolations(final Set<JsonField> exceededAttributes, final Attributes attributes) { final AttributesBuilder builder = attributes.toBuilder(); exceededAttributes.forEach(field -> builder.set( field.getKey().toString(), fixViolation(field.getKey().asPointer(), field.getValue(), attributeOverhead(), MAX_INDEX_CONTENT_LENGTH))); return builder.build(); }