Skip to content

Commit cf0dc37

Browse files
committed
Add JSON deserialization definitions to RegisteredCredential
1 parent 3ea09ae commit cf0dc37

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Changes:
77
attestation statements will now pass as untrusted attestations, instead of
88
throwing an IllegalArgumentException.
99

10+
New features:
11+
12+
* Class `RegisteredCredential` can now be serialized to and deserialized from
13+
JSON.
14+
1015

1116
== Version 1.6.4 ==
1217

webauthn-server-core/src/main/java/com/yubico/webauthn/RegisteredCredential.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525
package com.yubico.webauthn;
2626

27+
import com.fasterxml.jackson.annotation.JsonCreator;
28+
import com.fasterxml.jackson.annotation.JsonProperty;
2729
import com.yubico.webauthn.data.AttestedCredentialData;
2830
import com.yubico.webauthn.data.AuthenticatorAssertionResponse;
2931
import com.yubico.webauthn.data.AuthenticatorData;
3032
import com.yubico.webauthn.data.ByteArray;
3133
import com.yubico.webauthn.data.PublicKeyCredentialDescriptor;
3234
import com.yubico.webauthn.data.UserIdentity;
33-
import lombok.AccessLevel;
34-
import lombok.AllArgsConstructor;
3535
import lombok.Builder;
3636
import lombok.NonNull;
3737
import lombok.Value;
@@ -46,9 +46,8 @@
4646
* </p>
4747
*/
4848
@Value
49-
@AllArgsConstructor(access = AccessLevel.PRIVATE)
5049
@Builder(toBuilder = true)
51-
public class RegisteredCredential {
50+
public final class RegisteredCredential {
5251

5352
/**
5453
* The <a href="https://www.w3.org/TR/2019/PR-webauthn-20190117/#credential-id">credential ID</a> of the
@@ -103,6 +102,19 @@ public class RegisteredCredential {
103102
@Builder.Default
104103
private final long signatureCount = 0;
105104

105+
@JsonCreator
106+
private RegisteredCredential(
107+
@NonNull @JsonProperty("credentialId") ByteArray credentialId,
108+
@NonNull @JsonProperty("userHandle") ByteArray userHandle,
109+
@NonNull @JsonProperty("publicKeyCose") ByteArray publicKeyCose,
110+
@JsonProperty("signatureCount") long signatureCount
111+
) {
112+
this.credentialId = credentialId;
113+
this.userHandle = userHandle;
114+
this.publicKeyCose = publicKeyCose;
115+
this.signatureCount = signatureCount;
116+
}
117+
106118
public static RegisteredCredentialBuilder.MandatoryStages builder() {
107119
return new RegisteredCredentialBuilder.MandatoryStages();
108120
}

0 commit comments

Comments
 (0)