@Override public ImmutablePolicyBuilder removeSubjectFor(final CharSequence label, final CharSequence subjectIssuerWithId) { final Map<SubjectId, Subject> existingSubject = retrieveExistingSubjects(label); existingSubject.remove(SubjectId.newInstance(subjectIssuerWithId)); return this; }
/** * Returns a new {@code Subject} with the specified {@code subjectIssuerWithId} and {@code subjectType}. * * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}") of the Subject to create. * @param subjectType the SubjectType of the new Subject to create. * @return the new {@code Subject}. * @throws NullPointerException if any argument is {@code null}. */ static Subject newInstance(final CharSequence subjectIssuerWithId, final SubjectType subjectType) { return PoliciesModelFactory.newSubject(SubjectId.newInstance(subjectIssuerWithId), subjectType); }
/** * Returns a new {@code Subject} with the specified {@code issuer}, {@code subject} and {@code subjectType}. * * @param issuer the character sequence for the SubjectId's {@code issuer}. * @param subject the character sequence for the SubjectId's {@code subject}. * @param subjectType the SubjectType of the new Subject to create. * @return the new {@code Subject}. * @throws NullPointerException if any argument is {@code null}. */ static Subject newInstance(final SubjectIssuer issuer, final CharSequence subject, final SubjectType subjectType) { return PoliciesModelFactory.newSubject(SubjectId.newInstance(issuer, subject), subjectType); }
/** * 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)); }
/** * Removes the Subject with the given identifier from a copy of this Subjects. * * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}") of the Subject to be removed. * @return a copy of this Subjects with {@code subject} removed. * @throws NullPointerException if {@code subjectIssuerWithId} is {@code null}. * @throws IllegalArgumentException if {@code subjectIssuerWithId} is empty. */ default Subjects removeSubject(final CharSequence subjectIssuerWithId) { return removeSubject(SubjectId.newInstance(subjectIssuerWithId)); }
/** * Removes the Subject with the given {@code issuer} and {@code subject} from a copy of this Subjects. * * @param issuer the SubjectId's {@code issuer} of the Subject to be removed. * @param subject the character sequence for the SubjectId's {@code subject} of the Subject to be removed. * @return a copy of this Subjects with {@code subject} removed. * @throws NullPointerException if {@code subjectId} is {@code null}. * @throws IllegalArgumentException if {@code subject} is empty. */ default Subjects removeSubject(final SubjectIssuer issuer, final CharSequence subject) { return removeSubject(SubjectId.newInstance(issuer, subject)); }
/** * Returns a new {@code Subject} with the specified {@code issuer}, {@code subject} and * subject type {@link SubjectType#GENERATED}. * * @param issuer the character sequence for the SubjectId's {@code issuer}. * @param subject the character sequence for the SubjectId's {@code subject}. * @return the new {@code Subject}. * @throws NullPointerException if any argument is {@code null}. */ static Subject newInstance(final SubjectIssuer issuer, final CharSequence subject) { return PoliciesModelFactory.newSubject(SubjectId.newInstance(issuer, subject)); }
/** * 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)); }
/** * Removes the subject identified by the specified {@code issuer} and {@code subject} from this builder. * * @param label the label identifying the PolicyEntry to modify. * @param issuer the SubjectId's {@code issuer} to remove from the PolicyEntry identified by the {@code label}. * @param subject the character sequence for the SubjectId's {@code subject} to remove from the PolicyEntry * identified by the {@code label}. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code label} is empty. */ default PolicyBuilder removeSubjectFor(final CharSequence label, final SubjectIssuer issuer, final CharSequence subject) { return removeSubjectFor(label, SubjectId.newInstance(issuer, subject)); }
/** * Removes the subject identified by the specified {@code subjectIssuerWithId} from this builder. * * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}") of the Subject to remove from the PolicyEntry identified by the {@code label}. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. */ default LabelScoped removeSubject(final CharSequence subjectIssuerWithId) { removeSubjectFor(getLabel(), SubjectId.newInstance(subjectIssuerWithId)); return this; }
/** * Removes the subject identified by the specified {@code issuer} and {@code subject} from this builder. * * @param issuer the SubjectId's {@code issuer} to remove from the PolicyEntry identified by the {@code label}. * @param subject the character sequence for the SubjectId's {@code subject} to remove from the PolicyEntry * identified by the {@code label}. * @return this builder to allow method chaining. * @throws NullPointerException if any argument is {@code null}. */ default LabelScoped removeSubject(final SubjectIssuer issuer, final CharSequence subject) { removeSubjectFor(getLabel(), SubjectId.newInstance(issuer, subject)); return this; }
@Override public List<AuthorizationSubject> getAuthorizationSubjects(final JsonWebToken jsonWebToken) { checkNotNull(jsonWebToken); final String issuer = jsonWebToken.getIssuer(); final JwtSubjectIssuerConfig jwtSubjectIssuerConfig = jwtSubjectIssuersConfig.getConfigItem(issuer) .orElseThrow(() -> GatewayJwtIssuerNotSupportedException.newBuilder(issuer).build()); return jsonWebToken.getSubjects().stream() .map(subject -> SubjectId.newInstance(jwtSubjectIssuerConfig.getSubjectIssuer(), subject)) .map(AuthorizationSubject::newInstance) .collect(Collectors.toList()); }
private static Subject createSubjectForPut(final String jsonString, final CharSequence subjectId) { final JsonObject jsonObject = wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); final String subjectTypeString = jsonObject.getValueOrThrow(Subject.JsonFields.TYPE); final SubjectType subjectType = PoliciesModelFactory.newSubjectType(subjectTypeString); return PoliciesModelFactory.newSubject(SubjectId.newInstance(subjectId), subjectType); }
/** * Creates a new {@code RetrieveSubject} from a JSON object. * * @param jsonObject the JSON object of which a new RetrieveSubject instance is to be created. * @param dittoHeaders the optional command headers of the request. * @return the {@code RetrieveSubjects} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static RetrieveSubject fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveSubject>(TYPE, jsonObject).deserialize(() -> { final String policyId = jsonObject.getValueOrThrow(PolicyQueryCommand.JsonFields.JSON_POLICY_ID); final Label extractedLabel = Label.of(jsonObject.getValueOrThrow(JSON_LABEL)); final String subjectIdValue = jsonObject.getValueOrThrow(JSON_SUBJECT_ID); final SubjectId extractedSubjectId = SubjectId.newInstance(subjectIdValue); return of(policyId, extractedLabel, extractedSubjectId, dittoHeaders); }); }
/** * Creates a new {@code RetrieveSubject} from a JSON object. * * @param jsonObject the JSON object of which a new RetrieveSubject instance is to be created. * @param dittoHeaders the optional command headers of the request. * @return the {@code RetrieveSubjects} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static RetrieveSubject fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<RetrieveSubject>(TYPE, jsonObject).deserialize(() -> { final String policyId = jsonObject.getValueOrThrow(PolicyQueryCommand.JsonFields.JSON_POLICY_ID); final Label extractedLabel = Label.of(jsonObject.getValueOrThrow(JSON_LABEL)); final String subjectIdValue = jsonObject.getValueOrThrow(JSON_SUBJECT_ID); final SubjectId extractedSubjectId = SubjectId.newInstance(subjectIdValue); return of(policyId, extractedLabel, extractedSubjectId, dittoHeaders); }); }
/** * Creates a new {@code SubjectDeleted} from a JSON object. * * @param jsonObject the JSON object from which a new SubjectDeleted instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code SubjectDeleted} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected 'SubjectDeleted' format. */ public static SubjectDeleted fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<SubjectDeleted>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String policyId = jsonObject.getValueOrThrow(JsonFields.POLICY_ID); final Label label = Label.of(jsonObject.getValueOrThrow(JSON_LABEL)); final SubjectId extractedDeletedSubjectId = SubjectId.newInstance(jsonObject.getValueOrThrow(JSON_SUBJECT_ID)); return of(policyId, label, extractedDeletedSubjectId, revision, timestamp, dittoHeaders); }); }
/** * Creates a new {@code SubjectDeleted} from a JSON object. * * @param jsonObject the JSON object from which a new SubjectDeleted instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code SubjectDeleted} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected 'SubjectDeleted' format. */ public static SubjectDeleted fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<SubjectDeleted>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String policyId = jsonObject.getValueOrThrow(JsonFields.POLICY_ID); final Label label = Label.of(jsonObject.getValueOrThrow(JSON_LABEL)); final SubjectId extractedDeletedSubjectId = SubjectId.newInstance(jsonObject.getValueOrThrow(JSON_SUBJECT_ID)); return of(policyId, label, extractedDeletedSubjectId, revision, timestamp, dittoHeaders); }); }
/** * Creates a new {@code Subject} object from the specified JSON object. * * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}" of the Subject to be created. * @param jsonObject a JSON object which provides the data for the Subject to be created. * @return a new Subject which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws DittoJsonException if {@code jsonObject} * <ul> * <li>is empty,</li> * <li>contains only a field with the schema version</li> * <li>or it contains more than two fields.</li> * </ul> */ public static Subject fromJson(final CharSequence subjectIssuerWithId, final JsonObject jsonObject) { checkNotNull(subjectIssuerWithId, "Subject ID"); checkNotNull(jsonObject, "JSON object"); final String subjectTypeValue = jsonObject.getValue(JsonFields.TYPE) .orElseThrow(() -> new DittoJsonException(JsonMissingFieldException.newBuilder() .message("The 'type' for the 'subject' is missing.") .build())); return of(SubjectId.newInstance(subjectIssuerWithId), ImmutableSubjectType.of(subjectTypeValue)); }
SubjectId.newInstance(subjectId), dittoHeaders)) ), SubjectId.newInstance(subjectId), dittoHeaders))