ThingResourceKey(final CharSequence path) { resourceKey = ResourceKey.newInstance(PoliciesResourceType.THING, path); }
private static JsonPointer createAbsoluteResourcePointer(final ResourceKey resourceKey) { return JsonFactory.newPointer(resourceKey.getResourceType()).append(resourceKey.getResourcePath()); }
@Override public char charAt(final int index) { return resourceKey.charAt(index); }
buildJsonView(resourceKey, jsonFields, authorizationContext, permissions); final ResourceKey rootResourceKey = ResourceKey.newInstance(resourceKey.getResourceType(), JsonFactory.emptyPointer()); final boolean isAuthorizationSubjectRelevant =
@Override public String getResourceType() { return resourceKey.getResourceType(); }
@Override public JsonPointer getResourcePath() { return resourceKey.getResourcePath(); }
@Override public int length() { return resourceKey.length(); }
@Override public String getResourceType() { return resourceKey.getResourceType(); }
@Override public JsonPointer getPath() { return resourceKey.getResourcePath(); }
@Override public int length() { return resourceKey.length(); }
ThingResourceKey(final CharSequence path) { resourceKey = ResourceKey.newInstance(PoliciesResourceType.THING, path); }
/** * Converts a {@link ResourceKey} to an iterator of JSON keys by prepending the resource type to the resource path. * * @param resourceKey The resource key to convert. * @return The converted JSON key iterator. * @throws NullPointerException if {@code resourceKey} is {@code null}. */ static Iterator<JsonKey> getJsonKeyIterator(final ResourceKey resourceKey) { checkNotNull(resourceKey, "resource key to convert"); return JsonFactory.newPointer(resourceKey.getResourceType()).append(resourceKey.getResourcePath()).iterator(); }
@Override public String getType() { return resourceKey.getResourceType(); }
@Override public JsonPointer getResourcePath() { return resourceKey.getResourcePath(); }
@Override public char charAt(final int index) { return resourceKey.charAt(index); }
private static ResourceKey resourceKeyFromUnmatchedPath(final String resource) { // cut off leading "/" if there is one: return resource.startsWith("/") ? ResourceKey.newInstance(resource.substring(1)) : ResourceKey.newInstance(resource); }
@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 Collection<String> authorizationSubjectIds = getAuthorizationSubjectIds(authorizationContext); final EffectedResources effectedResources = getGrantedAndRevokedSubResource( JsonFactory.newPointer(ROOT_RESOURCE), resourceKey.getResourceType(), authorizationSubjectIds, permissions); if (jsonFields instanceof JsonObject && ((JsonObject) jsonFields).isNull()) { return JsonFactory.nullObject(); } final List<PointerAndValue> flatPointers = new ArrayList<>(); jsonFields.forEach(jsonField -> collectFlatPointers(jsonField.getKey().asPointer(), jsonField, flatPointers)); final Set<JsonPointer> grantedResources = extractJsonPointers(effectedResources.getGrantedResources()); final Set<JsonPointer> revokedResources = extractJsonPointers(effectedResources.getRevokedResources()); final JsonPointer resourcePath = resourceKey.getResourcePath(); final List<PointerAndValue> prefixedPointers = flatPointers.stream() .map(pv -> new PointerAndValue(resourcePath.append(pv.pointer), pv.value)) .collect(Collectors.toList()); return filterEntries(prefixedPointers, grantedResources, revokedResources, resourcePath); }
@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(); } }
/** * Removes the Resource with the given {@code resourceType} and {@code resourcePath} from a copy of this Resources. * * @param resourceType the type of the Resource to be removed. * @param resourcePath the path of the Resource to be removed. * @return a copy of this Resources with {@code resource} removed. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code resourceType} is empty. */ default Resources removeResource(final String resourceType, final CharSequence resourcePath) { return removeResource(ResourceKey.newInstance(resourceType, resourcePath)); }
/** * Returns the Resource with the given {@code resourceType} and {@code resourcePath} or an empty optional. * * @param resourceType the type of the Resource to be retrieved. * @param resourcePath the path of the Resource to be retrieved. * @return the Resource or an empty optional. * @throws NullPointerException if {@code resourcePath} is {@code null}. * @throws IllegalArgumentException if {@code resourceType} is empty. */ default Optional<Resource> getResource(final String resourceType, final CharSequence resourcePath) { return getResource(ResourceKey.newInstance(resourceType, resourcePath)); }