/** * 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()); } }
/** * 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()); } }
@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); }
@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); }
@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); }
@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); }
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 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(); }
policyTreeNode.getChildren() .forEach((s, child) -> traverseSubtreeForPermissionAccess(permission, resource.addLeaf(JsonKey.of(s)), type, child, grantedResources, revokedResources, level + 1, false));
@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(); } }