Skip to content

Commit a25dabd

Browse files
acoburntimea-solid
andauthored
JCL-342: Use correct data subject property for access requests (#446)
Co-authored-by: Timea <4144203+timea-solid@users.noreply.github.com>
1 parent 321dac4 commit a25dabd

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

access-grant/src/main/java/com/inrupt/client/accessgrant/AccessGrant.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ protected AccessGrant(final String grant) throws IOException {
103103
final Optional<URI> person = asUri(consent.get("isProvidedToPerson"));
104104
final Optional<URI> controller = asUri(consent.get("isProvidedToController"));
105105
final Optional<URI> other = asUri(consent.get("isProvidedTo"));
106-
this.grantee = person.orElseGet(() -> controller.orElseGet(() -> other.orElse(null)));
106+
final Optional<URI> dataSubject = asUri(consent.get("isConsentForDataSubject"));
107+
if (subject.containsKey("hasConsent")) {
108+
this.grantee = dataSubject.orElse(null);
109+
} else {
110+
this.grantee = person.orElseGet(() -> controller.orElseGet(() -> other.orElse(null)));
111+
}
107112
this.modes = asSet(consent.get("mode")).orElseGet(Collections::emptySet);
108113
this.resources = asSet(consent.get("forPersonalData")).orElseGet(Collections::emptySet)
109114
.stream().map(URI::create).collect(Collectors.toSet());

access-grant/src/main/java/com/inrupt/client/accessgrant/AccessGrantClient.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ public AccessGrantClient session(final Session session) {
175175
*/
176176
public CompletionStage<AccessGrant> issue(final URI type, final URI agent, final Set<URI> resources,
177177
final Set<String> modes, final Set<String> purposes, final Instant expiration) {
178+
Objects.requireNonNull(type, "Access Grant type may not be null!");
179+
Objects.requireNonNull(resources, "Resources may not be null!");
180+
Objects.requireNonNull(modes, "Access modes may not be null!");
178181
return v1Metadata().thenCompose(metadata -> {
179182
final Map<String, Object> data;
180183
if (ACCESS_GRANT.equals(type)) {
@@ -522,6 +525,7 @@ static URI asUri(final Object value) {
522525

523526
static Map<String, Object> buildAccessGrantv1(final URI agent, final Set<URI> resources, final Set<String> modes,
524527
final Instant expiration, final Set<String> purposes) {
528+
Objects.requireNonNull(agent, "Access grant agent may not be null!");
525529
final Map<String, Object> consent = new HashMap<>();
526530
consent.put(MODE, modes);
527531
consent.put(HAS_STATUS, "https://w3id.org/GConsent#ConsentStatusExplicitlyGiven");
@@ -536,7 +540,9 @@ static Map<String, Object> buildAccessGrantv1(final URI agent, final Set<URI> re
536540

537541
final Map<String, Object> credential = new HashMap<>();
538542
credential.put(CONTEXT, Arrays.asList(VC_CONTEXT_URI, INRUPT_CONTEXT_URI));
539-
credential.put("expirationDate", expiration.truncatedTo(ChronoUnit.SECONDS).toString());
543+
if (expiration != null) {
544+
credential.put("expirationDate", expiration.truncatedTo(ChronoUnit.SECONDS).toString());
545+
}
540546
credential.put(CREDENTIAL_SUBJECT, subject);
541547

542548
final Map<String, Object> data = new HashMap<>();
@@ -547,10 +553,12 @@ static Map<String, Object> buildAccessGrantv1(final URI agent, final Set<URI> re
547553
static Map<String, Object> buildAccessRequestv1(final URI agent, final Set<URI> resources, final Set<String> modes,
548554
final Instant expiration, final Set<String> purposes) {
549555
final Map<String, Object> consent = new HashMap<>();
550-
consent.put(MODE, modes);
551556
consent.put(HAS_STATUS, "https://w3id.org/GConsent#ConsentStatusRequested");
557+
consent.put(MODE, modes);
552558
consent.put(FOR_PERSONAL_DATA, resources);
553-
consent.put(IS_PROVIDED_TO_PERSON, agent);
559+
if (agent != null) {
560+
consent.put("isConsentForDataSubject", agent);
561+
}
554562
if (!purposes.isEmpty()) {
555563
consent.put("forPurpose", purposes);
556564
}
@@ -560,7 +568,9 @@ static Map<String, Object> buildAccessRequestv1(final URI agent, final Set<URI>
560568

561569
final Map<String, Object> credential = new HashMap<>();
562570
credential.put(CONTEXT, Arrays.asList(VC_CONTEXT_URI, INRUPT_CONTEXT_URI));
563-
credential.put("expirationDate", expiration.truncatedTo(ChronoUnit.SECONDS).toString());
571+
if (expiration != null) {
572+
credential.put("expirationDate", expiration.truncatedTo(ChronoUnit.SECONDS).toString());
573+
}
564574
credential.put(CREDENTIAL_SUBJECT, subject);
565575

566576
final Map<String, Object> data = new HashMap<>();

access-grant/src/test/resources/vc-5.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"hasConsent":{
2020
"mode":["Read","Append"],
2121
"hasStatus":"https://w3id.org/GConsent#ConsentStatusRequested",
22-
"isProvidedToPerson":"https://id.test/agent",
22+
"isConsentForDataSubject":"https://id.test/agent",
2323
"forPurpose":["https://purpose.test/Purpose1"],
2424
"forPersonalData":["https://storage.test/data/"]}},
2525
"proof":{

0 commit comments

Comments
 (0)