Skip to content

Commit 3060a0d

Browse files
[bugfix] mdoc credential request without the 'claims' property
1 parent 69af94d commit 3060a0d

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

src/main/java/com/authlete/jaxrs/server/vc/MdocOrderProcessor.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,45 @@ private static boolean matchDocType(
116116
@SuppressWarnings("unchecked")
117117
private static boolean includeClaims(
118118
Map<String, Object> issuableCredential,
119-
Map<String, Object> requestedCredential)
119+
Map<String, Object> requestedCredential) throws InvalidCredentialRequestException
120120
{
121121
// The claims in the issuable credential.
122122
Object issuableCredentialClaims = issuableCredential.get(KEY_CLAIMS);
123123

124124
// The claims in the requested credential.
125125
Object requestedCredentialClaims = requestedCredential.get(KEY_CLAIMS);
126126

127-
// If either or both are not maps.
128-
if (!(issuableCredentialClaims instanceof Map) ||
129-
!(requestedCredentialClaims instanceof Map))
127+
// If the credential request does not include the "claims" property.
128+
if (requestedCredentialClaims == null)
129+
{
130+
// Conceptually, any issuable credential includes an empty claim set.
131+
// But note that the issued verifiable credential will include no claim.
132+
return true;
133+
}
134+
135+
// If the credential request includes the "claims" property but its
136+
// value is not a JSON object.
137+
if (!(requestedCredentialClaims instanceof Map))
138+
{
139+
throw new InvalidCredentialRequestException(
140+
"The value of the 'claims' property in the credential request is not a JSON object.");
141+
}
142+
143+
// If the content of the "claims" property in the credential request is empty.
144+
if (((Map<String, Object>)requestedCredentialClaims).isEmpty())
130145
{
146+
// Conceptually, any issuable credential includes an empty claim set.
147+
// But note that the issued verifiable credential will include no claim.
148+
return true;
149+
}
150+
151+
// If the code flow reaches here, requestedCredentialClaims contains
152+
// at least one claim.
153+
154+
// If the issuable credential does include any claims.
155+
if (!(issuableCredentialClaims instanceof Map))
156+
{
157+
// No claim can be requested.
131158
return false;
132159
}
133160

@@ -271,6 +298,13 @@ private static Map<String, Object> buildClaims(
271298

272299
Map<String, Object> claims = new LinkedHashMap<>();
273300

301+
// If the credential request does not include the "claims" property.
302+
if (requestedClaims == null)
303+
{
304+
// The verifiable credential will include no claim.
305+
return claims;
306+
}
307+
274308
for (Map.Entry<String, Object> requestedNameSpace : requestedClaims.entrySet())
275309
{
276310
// The name space

0 commit comments

Comments
 (0)