@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources/" + resourceCreated.getResourceKey(); return JsonPointer.of(path); }
@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources/" + resource.getResourceKey(); return JsonPointer.of(path); }
@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources/" + resource.getResourceKey(); return JsonPointer.of(path); }
@Override public JsonPointer getResourcePath() { final String path = "/entries/" + label + "/resources/" + resourceCreated.getResourceKey(); return JsonPointer.of(path); }
@Override public Resources setResource(final Resource resource) { checkNotNull(resource, "resource to set"); Resources result = this; final Resource existingResource = resources.get(resource.getResourceKey()); if (!Objects.equals(existingResource, resource)) { result = createNewResourcesWithNewResource(resource); } return result; }
private Resources createNewResourcesWithNewResource(final Resource newResource) { final Map<ResourceKey, Resource> resourcesCopy = copyResources(); resourcesCopy.put(newResource.getResourceKey(), newResource); return new ImmutableResources(resourcesCopy); }
@Override protected Optional<Resource> determineETagEntity(final ModifyResource command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getResources) .flatMap(r -> r.getResource(command.getResource().getResourceKey())); } }
/** * Removes the specified Resource from this Policy. * * @param label the label identifying the PolicyEntry to modify. * @param resource the Resource to remove from the PolicyEntry identified by the {@code label}. * @return a copy of this Policy with the removed subject. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code label} is empty. */ default Policy removeResourceFor(final CharSequence label, final Resource resource) { return removeResourceFor(label, checkNotNull(resource, "resource").getResourceKey()); }
@Override public ImmutablePolicyBuilder removeResourceFor(final CharSequence label, final Resource resource) { checkNotNull(resource, "the resource to be removed"); return removeResourceFor(label, resource.getResourceKey()); }
@Override protected Optional<Resource> determineETagEntity(final ModifyResource command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getResources) .flatMap(r -> r.getResource(command.getResource().getResourceKey())); } }
/** * 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); }
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; }); }
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; }); }
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; }); }
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 public ImmutablePolicyBuilder setResourcesFor(final CharSequence label, final Resources resources) { checkNotNull(resources, "Resources to be set"); final Map<ResourceKey, Permissions> grantedMap = retrieveGrantedPermissions(label); final Map<ResourceKey, Permissions> revokedMap = retrieveRevokedPermissions(label); resources.forEach(resource -> { final ResourceKey resourceKey = resource.getResourceKey(); final EffectedPermissions effectedPermissions = resource.getEffectedPermissions(); grantedMap.put(resourceKey, effectedPermissions.getGrantedPermissions()); revokedMap.put(resourceKey, effectedPermissions.getRevokedPermissions()); }); return this; }
/** * 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); }
/** * 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); }
final ModifyResourceResponse response; if (policyEntry.getResources().getResource(resource.getResourceKey()).isPresent()) { response = ModifyResourceResponse.modified(policyId, label, dittoHeaders); eventToPersist =
private void addPolicyEntry(final PolicyEntry policyEntry) { final Collection<String> subjectIds = getSubjectIds(policyEntry.getSubjects()); policyEntry.getResources().forEach(resource -> { final PolicyTrie target = seekOrCreate(getJsonKeyIterator(resource.getResourceKey())); final EffectedPermissions effectedPermissions = resource.getEffectedPermissions(); target.grant(subjectIds, effectedPermissions.getGrantedPermissions()); target.revoke(subjectIds, effectedPermissions.getRevokedPermissions()); }); }