Skip to content

Commit 8d2d4a8

Browse files
authored
JCL-363: Rework verification response object (#477)
1 parent b188909 commit 8d2d4a8

File tree

3 files changed

+101
-20
lines changed

3 files changed

+101
-20
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2023 Inrupt Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to use,
7+
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8+
* Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
package com.inrupt.client.accessgrant;
22+
23+
import java.util.Collections;
24+
import java.util.List;
25+
26+
/**
27+
* The response from a verification operation.
28+
*/
29+
public class AccessCredentialVerification {
30+
31+
private final List<String> checks;
32+
private final List<String> warnings;
33+
private final List<String> errors;
34+
35+
/**
36+
* Create a verification response.
37+
*
38+
* @param checks the checks that were performed
39+
* @param warnings any warnings from the verification operation
40+
* @param errors any errors from the verification operation
41+
*/
42+
public AccessCredentialVerification(final List<String> checks, final List<String> warnings,
43+
final List<String> errors) {
44+
this.checks = makeImmutable(checks);
45+
this.warnings = makeImmutable(warnings);
46+
this.errors = makeImmutable(errors);
47+
}
48+
49+
/**
50+
* The verification checks that were performed.
51+
*
52+
* @return an unmodifiable list of any verification checks performed, never {@code null}
53+
*/
54+
public List<String> getChecks() {
55+
return checks;
56+
}
57+
58+
/**
59+
* The verification warnings that were discovered.
60+
*
61+
* @return an unmodifiable list of any verification warnings, never {@code null}
62+
*/
63+
public List<String> getWarnings() {
64+
return warnings;
65+
}
66+
67+
/**
68+
* The verification errors that were discovered.
69+
*
70+
* @return an unmodifiable list of any verification errors, never {@code null}
71+
*/
72+
public List<String> getErrors() {
73+
return errors;
74+
}
75+
76+
static List<String> makeImmutable(final List<String> list) {
77+
if (list != null) {
78+
return Collections.unmodifiableList(list);
79+
}
80+
return Collections.emptyList();
81+
}
82+
}
83+

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public CompletionStage<AccessGrant> issue(final URI type, final URI agent, final
289289
* @param credential the credential to verify
290290
* @return the next stage of completion containing the verification result
291291
*/
292-
public CompletionStage<VerificationResponse> verify(final AccessCredential credential) {
292+
public CompletionStage<AccessCredentialVerification> verify(final AccessCredential credential) {
293293
return v1Metadata().thenCompose(metadata -> {
294294

295295
final Map<String, Object> presentation = new HashMap<>();
@@ -312,7 +312,9 @@ public CompletionStage<VerificationResponse> verify(final AccessCredential crede
312312
try (final InputStream input = res.body()) {
313313
final int status = res.statusCode();
314314
if (isSuccess(status)) {
315-
return processVerificationResult(input);
315+
final VerificationResponseData data = jsonService.fromJson(input,
316+
VerificationResponseData.class);
317+
return new AccessCredentialVerification(data.checks, data.warnings, data.errors);
316318
}
317319
throw new AccessGrantException("Unable to perform Access Grant verify: HTTP error " + status,
318320
status);
@@ -544,10 +546,6 @@ <T extends AccessCredential> T processVerifiableCredential(final InputStream inp
544546
throw new AccessGrantException("Invalid Access Grant: missing supported type");
545547
}
546548

547-
VerificationResponse processVerificationResult(final InputStream input) throws IOException {
548-
return jsonService.fromJson(input, VerificationResponse.class);
549-
}
550-
551549
<T extends AccessCredential> List<T> processQueryResponse(final InputStream input, final Set<String> validTypes,
552550
final Class<T> clazz) throws IOException {
553551
final Map<String, Object> data = jsonService.fromJson(input,
@@ -778,9 +776,9 @@ static boolean isAccessRequest(final URI type) {
778776
}
779777

780778
/**
781-
* A data objects for verification responses.
779+
* A data object for verification responses.
782780
*/
783-
public static class VerificationResponse {
781+
static class VerificationResponseData {
784782
/**
785783
* The verification checks that were performed.
786784
*/

access-grant/src/test/java/com/inrupt/client/accessgrant/AccessGrantClientTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ void testFetch1() {
101101
assertEquals(uri, grant.getIdentifier());
102102
assertEquals(baseUri, grant.getIssuer());
103103

104-
final AccessGrantClient.VerificationResponse response = client.verify(grant).toCompletableFuture().join();
105-
assertTrue(response.checks.contains("expirationDate"));
106-
assertTrue(response.warnings.isEmpty());
107-
assertTrue(response.errors.isEmpty());
104+
final AccessCredentialVerification response = client.verify(grant).toCompletableFuture().join();
105+
assertTrue(response.getChecks().contains("expirationDate"));
106+
assertTrue(response.getWarnings().isEmpty());
107+
assertTrue(response.getErrors().isEmpty());
108108

109109
// Revoke
110110
assertDoesNotThrow(client.revoke(grant).toCompletableFuture()::join);
@@ -144,10 +144,10 @@ void testFetchDeprecated() {
144144
assertEquals(uri, grant.getIdentifier());
145145
assertEquals(baseUri, grant.getIssuer());
146146

147-
final AccessGrantClient.VerificationResponse response = client.verify(grant).toCompletableFuture().join();
148-
assertTrue(response.checks.contains("expirationDate"));
149-
assertTrue(response.warnings.isEmpty());
150-
assertTrue(response.errors.isEmpty());
147+
final AccessCredentialVerification response = client.verify(grant).toCompletableFuture().join();
148+
assertTrue(response.getChecks().contains("expirationDate"));
149+
assertTrue(response.getWarnings().isEmpty());
150+
assertTrue(response.getErrors().isEmpty());
151151

152152
// Revoke
153153
assertDoesNotThrow(client.revoke(grant).toCompletableFuture()::join);
@@ -197,10 +197,10 @@ void testFetch5() {
197197
assertEquals(uri, request.getIdentifier());
198198
assertEquals(baseUri, request.getIssuer());
199199

200-
final AccessGrantClient.VerificationResponse response = client.verify(request).toCompletableFuture().join();
201-
assertTrue(response.checks.contains("expirationDate"));
202-
assertTrue(response.warnings.isEmpty());
203-
assertTrue(response.errors.isEmpty());
200+
final AccessCredentialVerification response = client.verify(request).toCompletableFuture().join();
201+
assertTrue(response.getChecks().contains("expirationDate"));
202+
assertTrue(response.getWarnings().isEmpty());
203+
assertTrue(response.getErrors().isEmpty());
204204

205205
// Revoke
206206
final CompletionException err1 = assertThrows(CompletionException.class, () ->

0 commit comments

Comments
 (0)