private boolean hasPermissionGranted(final PolicyEntry policyEntry) { return policyEntry.getResources().stream() // .anyMatch(resource -> { final boolean isRootResource = ROOT_RESOURCE.equals(resource.getResourceKey()); final boolean containsGrantedPermissions = resource.getEffectedPermissions() .getGrantedPermissions() .contains(Permission.MIN_REQUIRED_POLICY_PERMISSIONS); return isRootResource && containsGrantedPermissions; }); }
@Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); jsonObjectBuilder.set(JSON_LABEL, label.toString(), predicate); jsonObjectBuilder.set(JSON_RESOURCE_KEY, resource.getFullQualifiedPath(), predicate); jsonObjectBuilder.set(JSON_RESOURCE, resource.toJson(schemaVersion, thePredicate), predicate); }
/** * Returns a new instance of {@code Resources} with the given resources. * * @param resources the {@link Resource}s of the new Resources. * @return the new {@code Resources}. * @throws NullPointerException if {@code resources} is {@code null}. */ public static ImmutableResources of(final Iterable<Resource> resources) { checkNotNull(resources, "resources"); final Map<ResourceKey, Resource> resourcesMap = new HashMap<>(); resources.forEach(resource -> { final Resource existingResource = resourcesMap.put(resource.getResourceKey(), resource); if (null != existingResource) { final String msgTemplate = "There is more than one Resource with the path <{0}>!"; throw new IllegalArgumentException(MessageFormat.format(msgTemplate, resource.getPath())); } }); return new ImmutableResources(resourcesMap); }
/** * Creates a response to a {@code RetrieveResource} command. * * @param policyId the Policy ID of the retrieved resource. * @param label the Label of the PolicyEntry. * @param resource the retrieved Resource. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveResourceResponse of(final String policyId, final Label label, final Resource resource, final DittoHeaders dittoHeaders) { return new RetrieveResourceResponse(policyId, label, resource.getResourceKey(), checkNotNull(resource, "Resource").toJson( dittoHeaders.getSchemaVersion().orElse(resource.getLatestSchemaVersion())), HttpStatusCode.OK, dittoHeaders); }
@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources/" + resourceCreated.getResourceKey(); return JsonPointer.of(path); }
@Override public Optional<JsonValue> getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(resourceCreated).map(obj -> obj.toJson(schemaVersion, FieldType.notHidden())); }
private static void mergePermissions(final Resource resource, final ResourceNode existingChild) { final EffectedPermissions existingChildPermissions = existingChild.getPermissions(); final Collection<String> mergedGrantedPermissions = new HashSet<>(existingChildPermissions.getGrantedPermissions()); final Collection<String> mergedRevokedPermissions = new HashSet<>(existingChildPermissions.getRevokedPermissions()); if (!resource.getEffectedPermissions().getRevokedPermissions().isEmpty()) { mergedRevokedPermissions.addAll(resource.getEffectedPermissions().getRevokedPermissions()); } if (!resource.getEffectedPermissions().getGrantedPermissions().isEmpty()) { mergedGrantedPermissions.addAll(resource.getEffectedPermissions().getGrantedPermissions()); } existingChild.setPermissions( EffectedPermissions.newInstance(mergedGrantedPermissions, mergedRevokedPermissions)); }
@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources" + resource.getPath(); return JsonPointer.of(path); }
final ResourceNode rootChild = (ResourceNode) parentNode.getChild(resource.getType()) .orElseGet(() -> { final ResourceNode child = ResourceNode.of(parentNode, resource.getType(), EffectedPermissions.newInstance(new ArrayList<>(), new ArrayList<>())); parentNode.addChild(child); return child; }); addResourceSubTree(rootChild, resource, resource.getPath());
@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources/" + resourceCreated.getResourceKey(); return JsonPointer.of(path); }
/** * Creates a response to a {@code RetrieveResource} command. * * @param policyId the Policy ID of the retrieved resource. * @param label the Label of the PolicyEntry. * @param resource the retrieved Resource. * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveResourceResponse of(final String policyId, final Label label, final Resource resource, final DittoHeaders dittoHeaders) { return new RetrieveResourceResponse(policyId, label, resource.getResourceKey(), checkNotNull(resource, "Resource").toJson( dittoHeaders.getSchemaVersion().orElse(resource.getLatestSchemaVersion())), HttpStatusCode.OK, dittoHeaders); }
@Override public Optional<JsonValue> getEntity(final JsonSchemaVersion schemaVersion) { return Optional.ofNullable(resource.toJson(schemaVersion, FieldType.regularOrSpecial())); }
public PolicyAssert hasResourceEffectedPermissionsFor(final Label label, final ResourceKey resourceKey, final EffectedPermissions expectedEffectedPermissions) { isNotNull(); hasResourceFor(label, resourceKey); final Resource resource = actual.getEntryFor(label).get().getResources().getResource(resourceKey).get(); assertThat(resource.getEffectedPermissions()).isEqualTo(expectedEffectedPermissions) // .overridingErrorMessage( "Expected Label <%s> to contain for Resource path <%s> EffectedPermissions " + "\n<%s> but did not: \n<%s>", label, resourceKey, expectedEffectedPermissions, resource.getEffectedPermissions()); return this; }
@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources" + resource.getPath(); return JsonPointer.of(path); }
private boolean hasPermissionRevoked(final PolicyEntry policyEntry) { return policyEntry.getResources().stream() // .anyMatch(resource -> { final boolean isRootResource = ROOT_RESOURCE.equals(resource.getResourceKey()); final boolean containsRevokedPermissions = resource.getEffectedPermissions() .getRevokedPermissions() .contains(Permission.MIN_REQUIRED_POLICY_PERMISSIONS); return isRootResource && containsRevokedPermissions; }); }
@Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); jsonObjectBuilder.set(JSON_LABEL, label.toString(), predicate); jsonObjectBuilder.set(JSON_RESOURCE_KEY, resource.getFullQualifiedPath(), predicate); jsonObjectBuilder.set(JSON_RESOURCE, resource.toJson(schemaVersion, thePredicate), predicate); }
@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources/" + resource.getResourceKey(); return JsonPointer.of(path); }
@Override public Optional<JsonValue> getEntity(final JsonSchemaVersion schemaVersion) { return Optional.of(resource.toJson(schemaVersion, FieldType.regularOrSpecial())); }
parentNode.getParent().ifPresent(p -> mergePermissions(resource, parentNode)); } else if (!parentNode.getChild(usedPath).isPresent()) { parentNode.addChild(ResourceNode.of(parentNode, usedPath, resource.getEffectedPermissions())); } else { final ResourceNode existingChild = parentNode.getChild(usedPath)
@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources" + resource.getPath(); return JsonPointer.of(path); }