/** * Sets the given {@link Subject} to the specified {@code label} to this builder. A previous entry with the same * {@code subjectIssuerWithId} in the {@link Label} is replaced by the specified one. * * @param label the Label identifying the PolicyEntry to modify. * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}") of the Subject to set. * @param subjectType the type of the subject to set. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code label} is empty. */ default PolicyBuilder setSubjectFor(final CharSequence label, final CharSequence subjectIssuerWithId, final SubjectType subjectType) { return setSubjectFor(label, Subject.newInstance(subjectIssuerWithId, subjectType)); }
/** * Sets the given {@link Subject} to the specified {@code label} to this builder. A previous entry with the same * {@code issuer} and {@code subject} in the {@link Label} is replaced by the specified one. * * @param label the Label identifying the PolicyEntry to modify. * @param issuer the SubjectId's {@code issuer}. * @param subject the character sequence for the SubjectId's {@code subject}. * @param subjectType the type of the subject to set. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code label} is empty. */ default PolicyBuilder setSubjectFor(final CharSequence label, final SubjectIssuer issuer, final CharSequence subject, final SubjectType subjectType) { return setSubjectFor(label, Subject.newInstance(issuer, subject, subjectType)); }
/** * Sets the given {@link Subject} to the specified {@code label} to this builder. A previous entry with the same * {@code subjectIssuerWithId} in the {@link Label} is replaced by the specified one. * * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}") of the Subject to set. * @param subjectType the type of the subject to set. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. */ default LabelScoped setSubject(final CharSequence subjectIssuerWithId, final SubjectType subjectType) { setSubjectFor(getLabel(), Subject.newInstance(subjectIssuerWithId, subjectType)); return this; }
/** * Sets the given {@link Subject} to the specified {@code label} to this builder. A previous entry with the same * {@code subjectId} in the {@link Label} is replaced by the specified one. Sets the subject type * to {@link SubjectType#GENERATED}. * * @param issuer the SubjectId's {@code issuer}. * @param subject the character sequence for the SubjectId's {@code subject}. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. */ default LabelScoped setSubject(final SubjectIssuer issuer, final CharSequence subject) { setSubjectFor(getLabel(), Subject.newInstance(issuer, subject)); return this; }
/** * Sets the given {@link Subject} to the specified {@code label} to this builder. A previous entry with the same * {@code subjectId} in the {@link Label} is replaced by the specified one. * * @param issuer the SubjectId's {@code issuer}. * @param subject the character sequence for the SubjectId's {@code subject}. * @param subjectType the type of the subject to set. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. */ default LabelScoped setSubject(final SubjectIssuer issuer, final CharSequence subject, final SubjectType subjectType) { setSubjectFor(getLabel(), Subject.newInstance(issuer, subject, subjectType)); return this; }
static Subjects substituteSubjects(final Subjects subjects, final HeaderBasedPlaceholderSubstitutionAlgorithm substitutionAlgorithm, final DittoHeaders dittoHeaders) { Subjects newSubjects = subjects; for (final Subject subject : subjects) { final String subjectId = subject.getId().toString(); final String substitutedSubjectId = substitutionAlgorithm.substitute(subjectId, dittoHeaders); if (!subjectId.equals(substitutedSubjectId)) { final Subject newSubject = Subject.newInstance(substitutedSubjectId, subject.getType()); newSubjects = newSubjects.removeSubject(subjectId).setSubject(newSubject); } } return newSubjects; }
@Override public WithDittoHeaders apply(final ModifySubject modifySubject, final HeaderBasedPlaceholderSubstitutionAlgorithm substitutionAlgorithm) { requireNonNull(modifySubject); requireNonNull(substitutionAlgorithm); final String subjectId = modifySubject.getSubject().getId().toString(); final String substitutedSubjectId = substitutionAlgorithm.substitute(subjectId, modifySubject); if (subjectId.equals(substitutedSubjectId)) { return modifySubject; } else { final Subject newSubject = Subject.newInstance(substitutedSubjectId, modifySubject.getSubject().getType()); return ModifySubject.of(modifySubject.getId(), modifySubject.getLabel(), newSubject, modifySubject.getDittoHeaders()); } } }