/** * Returns the Subject with the given {@code issuer} and {@code subject} or an empty optional. * * @param issuer the SubjectId's {@code issuer} of the Subject to be retrieved. * @param subject the character sequence for the SubjectId's {@code subject} of the Subject to be retrieved. * @return the Subject with the given subjectId or an empty optional. * @throws NullPointerException if {@code subjectId} is {@code null}. * @throws IllegalArgumentException if {@code subject} is empty. */ default Optional<Subject> getSubject(final SubjectIssuer issuer, final CharSequence subject) { return getSubject(SubjectId.newInstance(issuer, subject)); }
/** * Returns the Subject with the given subjectIssuerWithId or an empty optional. * * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}") of the Subject to be retrieved. * @return the Subject with the given subjectIssuerWithId or an empty optional. * @throws NullPointerException if {@code subjectIssuerWithId} is {@code null}. * @throws IllegalArgumentException if {@code subjectIssuerWithId} is empty. */ default Optional<Subject> getSubject(final CharSequence subjectIssuerWithId) { return getSubject(SubjectId.newInstance(subjectIssuerWithId)); }
@Override protected Optional<Subject> determineETagEntity(final RetrieveSubject command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getSubjects) .flatMap(s -> s.getSubject(command.getSubjectId())); } }
@Override protected Optional<Subject> determineETagEntity(final DeleteSubject command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getSubjects) .flatMap(s -> s.getSubject(command.getSubjectId())); } }
@Override protected Optional<Subject> determineETagEntity(final RetrieveSubject command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getSubjects) .flatMap(s -> s.getSubject(command.getSubjectId())); } }
@Override protected Optional<Subject> determineETagEntity(final DeleteSubject command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getSubjects) .flatMap(s -> s.getSubject(command.getSubjectId())); } }
@Override protected Optional<Subject> determineETagEntity(final ModifySubject command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getSubjects) .flatMap(s -> s.getSubject(command.getSubject().getId())); } }
@Override protected Optional<Subject> determineETagEntity(final ModifySubject command) { return Optional.ofNullable(policy) .flatMap(p -> p.getEntryFor(command.getLabel())) .map(PolicyEntry::getSubjects) .flatMap(s -> s.getSubject(command.getSubject().getId())); } }
@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 RetrieveSubject command) { final Optional<PolicyEntry> optionalEntry = policy.getEntryFor(command.getLabel()); if (optionalEntry.isPresent()) { final PolicyEntry policyEntry = optionalEntry.get(); final Optional<Subject> optionalSubject = policyEntry.getSubjects().getSubject(command.getSubjectId()); if (optionalSubject.isPresent()) { final RetrieveSubjectResponse response = RetrieveSubjectResponse.of(policyId, command.getLabel(), optionalSubject.get(), command.getDittoHeaders()); sendSuccessResponse(command, response); } else { subjectNotFound(command.getLabel(), command.getSubjectId(), command.getDittoHeaders()); } } else { policyEntryNotFound(command.getLabel(), command.getDittoHeaders()); } }
@Override protected void doApply(final RetrieveSubject command) { final Optional<PolicyEntry> optionalEntry = policy.getEntryFor(command.getLabel()); if (optionalEntry.isPresent()) { final PolicyEntry policyEntry = optionalEntry.get(); final Optional<Subject> optionalSubject = policyEntry.getSubjects().getSubject(command.getSubjectId()); if (optionalSubject.isPresent()) { final RetrieveSubjectResponse response = RetrieveSubjectResponse.of(policyId, command.getLabel(), optionalSubject.get(), command.getDittoHeaders()); sendSuccessResponse(command, response); } else { subjectNotFound(command.getLabel(), command.getSubjectId(), command.getDittoHeaders()); } } else { policyEntryNotFound(command.getLabel(), command.getDittoHeaders()); } }
public PolicyAssert hasSubjectTypeFor(final Label label, final SubjectId subjectId, final SubjectType expectedSubjectType) { isNotNull(); hasSubjectFor(label, subjectId); final Subject subject = actual.getEntryFor(label).get().getSubjects().getSubject(subjectId).get(); assertThat(subject.getType()).isEqualTo(expectedSubjectType) // .overridingErrorMessage( "Expected Label <%s> to contain for SubjectId <%s> SubjectType " + "\n<%s> but did not: \n<%s>", label, subjectId, expectedSubjectType, subject.getType()); return this; }
if (optionalEntry.isPresent()) { final PolicyEntry policyEntry = optionalEntry.get(); if (policyEntry.getSubjects().getSubject(subjectId).isPresent()) { final PoliciesValidator validator = PoliciesValidator.newInstance(policy.removeSubjectFor(label, subjectId));
if (optionalEntry.isPresent()) { final PolicyEntry policyEntry = optionalEntry.get(); if (policyEntry.getSubjects().getSubject(subjectId).isPresent()) { final PoliciesValidator validator = PoliciesValidator.newInstance(policy.removeSubjectFor(label, subjectId));
public PolicyAssert doesNotHaveSubjectFor(final Label label, final SubjectId subjectId) { isNotNull(); hasLabel(label); final PolicyEntry policyEntry = actual.getEntryFor(label).get(); assertThat(policyEntry.getSubjects().getSubject(subjectId)).isEmpty() // .overridingErrorMessage( "Expected Label <%s> to NOT contain Subject for SubjectId \n<%s> " + "but it did: \n<%s>", label, subjectId, policyEntry.getSubjects()); return this; }
public PolicyAssert hasSubjectFor(final Label label, final SubjectId subjectId) { isNotNull(); hasLabel(label); final PolicyEntry policyEntry = actual.getEntryFor(label).get(); assertThat(policyEntry.getSubjects().getSubject(subjectId)).isPresent() // .overridingErrorMessage( "Expected Label <%s> to contain Subject for SubjectId \n<%s> " + "but did not: \n<%s>", label, subjectId, policyEntry.getSubjects()); return this; }
final ModifySubjectResponse response; if (policyEntry.getSubjects().getSubject(subject.getId()).isPresent()) { response = ModifySubjectResponse.modified(policyId, label, dittoHeaders); eventToPersist =
final ModifySubjectResponse response; if (policyEntry.getSubjects().getSubject(subject.getId()).isPresent()) { response = ModifySubjectResponse.modified(policyId, label, dittoHeaders); eventToPersist =