/** * Returns the retrieved Subjects. * * @return the retrieved Subjects. */ public Subjects getSubjects() { return PoliciesModelFactory.newSubjects(subjects); }
/** * Returns a new {@code Subjects} containing the given subjects. * * @param subjects the {@link Subject}s to be contained in the new Subjects. * @return the new {@code Subjects}. * @throws NullPointerException if {@code subjects} is {@code null}. */ static Subjects newInstance(final Iterable<Subject> subjects) { return PoliciesModelFactory.newSubjects(subjects); }
/** * Returns a new {@code Subjects} containing the given subjects. * * @param subject the {@link Subject} to be contained in the new Subjects. * @param furtherSubjects further {@link Subject}s to be contained in the new Subjects. * @return the new {@code Subjects}. * @throws NullPointerException if any argument is {@code null}. */ static Subjects newInstance(final Subject subject, final Subject... furtherSubjects) { return PoliciesModelFactory.newSubjects(subject, furtherSubjects); }
/** * Returns the retrieved Subjects. * * @return the retrieved Subjects. */ public Subjects getSubjects() { return PoliciesModelFactory.newSubjects(subjects); }
@Nonnull private Subjects getFinalSubjects(final CharSequence label) { return PoliciesModelFactory.newSubjects(retrieveExistingSubjects(label).values()); }
/** * Returns a new {@link Subjects} containing the given subjects. * * @param subject the {@link Subject} to be contained in the new Subjects. * @param furtherSubjects further {@link Subject}s to be contained in the new Subjects. * @return the new {@code Subjects}. */ public static Subjects newSubjects(final Subject subject, final Subject... furtherSubjects) { checkNotNull(subject, "mandatory subject"); checkNotNull(furtherSubjects, "additional subjects"); final Collection<Subject> allSubjects = new ArrayList<>(1 + furtherSubjects.length); allSubjects.add(subject); Collections.addAll(allSubjects, furtherSubjects); return newSubjects(allSubjects); }
/** * Returns a new immutable {@link PolicyEntry} with the given authorization subject and permissions. * * @param label the Label of the PolicyEntry to create. * @param subjects the Subjects contained in the PolicyEntry to create. * @param resources the Resources of the PolicyEntry to create. * @return the new Policy entry. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code label} is empty. */ public static PolicyEntry newPolicyEntry(final CharSequence label, final Iterable<Subject> subjects, final Iterable<Resource> resources) { return ImmutablePolicyEntry.of(Label.of(label), newSubjects(subjects), newResources(resources)); }
private static PolicyEntry createPolicyEntryForPut(final String jsonString, final CharSequence labelString) { final JsonObject jsonObject = wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); final Subjects subjects = PoliciesModelFactory.newSubjects(jsonObject.getValueOrThrow(PolicyEntry.JsonFields.SUBJECTS)); final Resources resources = PoliciesModelFactory.newResources(jsonObject.getValueOrThrow(PolicyEntry.JsonFields.RESOURCES)); return PoliciesModelFactory.newPolicyEntry(Label.of(labelString), subjects, resources); }
/** * Creates a new {@code SubjectsModified} from a JSON object. * * @param jsonObject the JSON object from which a new SubjectsModified instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code SubjectsModified} 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 'SubjectsModified' * format. */ public static SubjectsModified fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<SubjectsModified>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String policyId = jsonObject.getValueOrThrow(JsonFields.POLICY_ID); final Label label = Label.of(jsonObject.getValueOrThrow(JSON_LABEL)); final JsonObject subjectsJsonObject = jsonObject.getValueOrThrow(JSON_SUBJECTS); final Subjects extractedModifiedSubjects = PoliciesModelFactory.newSubjects(subjectsJsonObject); return of(policyId, label, extractedModifiedSubjects, revision, timestamp, dittoHeaders); }); }
/** * Creates a command for modifying {@code Subjects} of a {@code Policy}'s {@code PolicyEntry} from a JSON object. * * @param jsonObject the JSON object of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @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 ModifySubjects fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<ModifySubjects>(TYPE, jsonObject).deserialize(() -> { final String policyId = jsonObject.getValueOrThrow(PolicyModifyCommand.JsonFields.JSON_POLICY_ID); final Label label = PoliciesModelFactory.newLabel(jsonObject.getValueOrThrow(JSON_LABEL)); final Subjects subjects = PoliciesModelFactory.newSubjects(jsonObject.getValueOrThrow(JSON_SUBJECTS)); return of(policyId, label, subjects, dittoHeaders); }); }
/** * Creates a new {@code SubjectsModified} from a JSON object. * * @param jsonObject the JSON object from which a new SubjectsModified instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code SubjectsModified} 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 'SubjectsModified' * format. */ public static SubjectsModified fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<SubjectsModified>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String policyId = jsonObject.getValueOrThrow(JsonFields.POLICY_ID); final Label label = Label.of(jsonObject.getValueOrThrow(JSON_LABEL)); final JsonObject subjectsJsonObject = jsonObject.getValueOrThrow(JSON_SUBJECTS); final Subjects extractedModifiedSubjects = PoliciesModelFactory.newSubjects(subjectsJsonObject); return of(policyId, label, extractedModifiedSubjects, revision, timestamp, dittoHeaders); }); }
/** * Creates a command for modifying {@code Subjects} of a {@code Policy}'s {@code PolicyEntry} from a JSON object. * * @param jsonObject the JSON object of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @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 ModifySubjects fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<ModifySubjects>(TYPE, jsonObject).deserialize(() -> { final String policyId = jsonObject.getValueOrThrow(PolicyModifyCommand.JsonFields.JSON_POLICY_ID); final Label label = PoliciesModelFactory.newLabel(jsonObject.getValueOrThrow(JSON_LABEL)); final Subjects subjects = PoliciesModelFactory.newSubjects(jsonObject.getValueOrThrow(JSON_SUBJECTS)); return of(policyId, label, subjects, dittoHeaders); }); }
/** * Creates a new {@code PolicyEntry} object from the specified JSON object. * * @param label the Label for the PolicyEntry to create. * @param jsonObject a JSON object which provides the data for the Policy entry to be created. If there are more * than one entries in the given JSON object, it'll take the first in the object. * @return a new Policy entry which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code label} or {@code jsonObject} is {@code null}. * @throws IllegalArgumentException if {@code label} is empty. * @throws DittoJsonException if {@code jsonObject} * <ul> * <li>is empty or</li> * <li>contains only a field with the schema version.</li> * </ul> */ public static PolicyEntry fromJson(final CharSequence label, final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object"); final Label lbl = Label.of(label); try { final JsonObject subjectsJsonObject = jsonObject.getValueOrThrow(JsonFields.SUBJECTS); final Subjects subjectsFromJson = PoliciesModelFactory.newSubjects(subjectsJsonObject); final JsonObject resourcesJsonObject = jsonObject.getValueOrThrow(JsonFields.RESOURCES); final Resources resourcesFromJson = PoliciesModelFactory.newResources(resourcesJsonObject); return of(lbl, subjectsFromJson, resourcesFromJson); } catch (final JsonMissingFieldException e) { throw new DittoJsonException(e); } }
private Route thingsEntryPolicyEntrySubjects(final RequestContext ctx, final DittoHeaders dittoHeaders, final String policyId) { return rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment()), label -> rawPathPrefix(mergeDoubleSlashes().concat(PATH_SUFFIX_SUBJECTS), () -> pathEndOrSingleSlash(() -> route( get(() -> // GET /entries/<label>/subjects handlePerRequest(ctx, RetrieveSubjects.of(policyId, Label.of(label), dittoHeaders)) ), put(() -> // PUT /entries/<label>/subjects extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, subjectsJson -> ModifySubjects.of(policyId, Label.of(label), PoliciesModelFactory.newSubjects( JsonFactory.newObject( subjectsJson)), dittoHeaders))) ) ) ) ) ); }