/** * Substitutes all placeholders contained in the {@code input} based on the {@link DittoHeaders} contained in * {@code withDittoHeaders}. * * @param input the input. * @param withDittoHeaders the instance of {@link WithDittoHeaders}, from which the headers are extracted * (normally a command). * @return the replaced input, if the input contains placeholders; the (same) input object, if no placeholders * were contained in the input. */ public String substitute(final String input, final WithDittoHeaders withDittoHeaders) { requireNonNull(input); requireNonNull(withDittoHeaders); return substitute(input, withDittoHeaders.getDittoHeaders()); }
static AclEntry substituteAclEntry(final AclEntry existingAclEntry, final HeaderBasedPlaceholderSubstitutionAlgorithm substitutionAlgorithm, final DittoHeaders dittoHeaders) { final String subjectId = existingAclEntry.getAuthorizationSubject().getId(); final String substitutedSubjectId = substitutionAlgorithm.substitute(subjectId, dittoHeaders); final AclEntry resultAclEntry; if (subjectId.equals(substitutedSubjectId)) { resultAclEntry = existingAclEntry; } else { resultAclEntry = AclEntry.newInstance(AuthorizationSubject.newInstance(substitutedSubjectId), existingAclEntry.getPermissions()); } return resultAclEntry; }
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()); } } }