/** * 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)); }
@Override protected Optional<Resource> determineETagEntity(final DeleteResource command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getResources) .flatMap(r -> r.getResource(command.getResourceKey())); } }
@Override protected Optional<Resource> determineETagEntity(final RetrieveResource command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getResources) .flatMap(r -> r.getResource(command.getResourceKey())); } }
@Override protected Optional<Resource> determineETagEntity(final RetrieveResource command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getResources) .flatMap(r -> r.getResource(command.getResourceKey())); } }
@Override protected Optional<Resource> determineETagEntity(final DeleteResource command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getResources) .flatMap(r -> r.getResource(command.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())); } }
@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())); } }
@Override public Optional<EffectedPermissions> getEffectedPermissionsFor(final CharSequence label, final SubjectId subjectId, final ResourceKey resourceKey) { final Label lbl = Label.of(label); Optional<EffectedPermissions> result = Optional.empty(); final PolicyEntry policyEntry = entries.get(lbl); if (null != policyEntry) { final Subjects subjects = policyEntry.getSubjects(); final Optional<Subject> subjectOptional = subjects.getSubject(subjectId); if (subjectOptional.isPresent()) { final Resources resources = policyEntry.getResources(); result = resources.getResource(resourceKey).map(Resource::getEffectedPermissions); } } return result; }
@Override protected void doApply(final RetrieveResource command) { final Optional<PolicyEntry> optionalEntry = policy.getEntryFor(command.getLabel()); if (optionalEntry.isPresent()) { final PolicyEntry policyEntry = optionalEntry.get(); final Optional<Resource> optionalResource = policyEntry.getResources().getResource(command.getResourceKey()); if (optionalResource.isPresent()) { final RetrieveResourceResponse response = RetrieveResourceResponse.of(policyId, command.getLabel(), optionalResource.get(), command.getDittoHeaders()); sendSuccessResponse(command, response); } else { resourceNotFound(command.getLabel(), command.getResourceKey(), command.getDittoHeaders()); } } else { policyEntryNotFound(command.getLabel(), command.getDittoHeaders()); } }
@Override protected void doApply(final RetrieveResource command) { final Optional<PolicyEntry> optionalEntry = policy.getEntryFor(command.getLabel()); if (optionalEntry.isPresent()) { final PolicyEntry policyEntry = optionalEntry.get(); final Optional<Resource> optionalResource = policyEntry.getResources().getResource(command.getResourceKey()); if (optionalResource.isPresent()) { final RetrieveResourceResponse response = RetrieveResourceResponse.of(policyId, command.getLabel(), optionalResource.get(), command.getDittoHeaders()); sendSuccessResponse(command, response); } else { resourceNotFound(command.getLabel(), command.getResourceKey(), command.getDittoHeaders()); } } else { policyEntryNotFound(command.getLabel(), command.getDittoHeaders()); } }
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; }
final PolicyEntry policyEntry = optionalEntry.get(); if (policyEntry.getResources().getResource(resourceKey).isPresent()) { final PoliciesValidator validator = PoliciesValidator.newInstance(policy.removeResourceFor(label, resourceKey));
final PolicyEntry policyEntry = optionalEntry.get(); if (policyEntry.getResources().getResource(resourceKey).isPresent()) { final PoliciesValidator validator = PoliciesValidator.newInstance(policy.removeResourceFor(label, resourceKey));
final ModifyResourceResponse response; if (policyEntry.getResources().getResource(resource.getResourceKey()).isPresent()) { response = ModifyResourceResponse.modified(policyId, label, dittoHeaders); eventToPersist =
public PolicyAssert hasResourceFor(final Label label, final ResourceKey resourceKey) { isNotNull(); hasLabel(label); final PolicyEntry policyEntry = actual.getEntryFor(label).get(); assertThat(policyEntry.getResources().getResource(resourceKey)).isPresent() // .overridingErrorMessage( "Expected Label <%s> to contain Resource for path \n<%s> " + "but did not: \n<%s>", label, resourceKey, policyEntry.getResources()); return this; }
final ModifyResourceResponse response; if (policyEntry.getResources().getResource(resource.getResourceKey()).isPresent()) { response = ModifyResourceResponse.modified(policyId, label, dittoHeaders); eventToPersist =
public PolicyAssert doesNotHaveResourceFor(final Label label, final ResourceKey resourceKey) { isNotNull(); hasLabel(label); final PolicyEntry policyEntry = actual.getEntryFor(label).get(); assertThat(policyEntry.getResources().getResource(resourceKey)).isEmpty() // .overridingErrorMessage( "Expected Label <%s> to NOT contain Resource for path \n<%s> " + "but it did: \n<%s>", label, resourceKey, policyEntry.getResources()); return this; }