Skip to content

Commit 1245a40

Browse files
committed
Fix backupState JSON property name in RegisteredCredential
1 parent 3d52a7e commit 1245a40

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
== Version 2.5.0 (unreleased) ==
22

3+
Breaking changes to experimental features:
4+
5+
* Added Jackson annotation `@JsonProperty` to method
6+
`RegisteredCredential.isBackedUp()`, changing the property name from
7+
`backedUp` to `backupState`. `backedUp` is still accepted during
8+
deserialization but will no longer be emitted during serialization.
9+
310
New features:
411

512
* Added method `.isUserVerified()` to `RegistrationResult` and `AssertionResult`

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package com.yubico.webauthn;
2626

27+
import com.fasterxml.jackson.annotation.JsonAlias;
2728
import com.fasterxml.jackson.annotation.JsonCreator;
2829
import com.fasterxml.jackson.annotation.JsonProperty;
2930
import com.yubico.webauthn.data.AttestedCredentialData;
@@ -153,7 +154,7 @@ private RegisteredCredential(
153154
@NonNull @JsonProperty("publicKeyCose") ByteArray publicKeyCose,
154155
@JsonProperty("signatureCount") long signatureCount,
155156
@JsonProperty("backupEligible") Boolean backupEligible,
156-
@JsonProperty("backupState") Boolean backupState) {
157+
@JsonProperty("backupState") @JsonAlias("backedUp") Boolean backupState) {
157158
this.credentialId = credentialId;
158159
this.userHandle = userHandle;
159160
this.publicKeyCose = publicKeyCose;
@@ -183,6 +184,7 @@ private RegisteredCredential(
183184
* the standard matures.
184185
*/
185186
@Deprecated
187+
@JsonProperty("backupEligible")
186188
public Optional<Boolean> isBackupEligible() {
187189
return Optional.ofNullable(backupEligible);
188190
}
@@ -206,6 +208,7 @@ public Optional<Boolean> isBackupEligible() {
206208
* the standard matures.
207209
*/
208210
@Deprecated
211+
@JsonProperty("backupState")
209212
public Optional<Boolean> isBackedUp() {
210213
return Optional.ofNullable(backupState);
211214
}

webauthn-server-core/src/test/scala/com/yubico/webauthn/data/JsonIoSpec.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ package com.yubico.webauthn.data
2727
import com.fasterxml.jackson.core.`type`.TypeReference
2828
import com.fasterxml.jackson.databind.ObjectMapper
2929
import com.fasterxml.jackson.databind.exc.ValueInstantiationException
30+
import com.fasterxml.jackson.databind.node.BooleanNode
3031
import com.fasterxml.jackson.databind.node.ObjectNode
3132
import com.fasterxml.jackson.databind.node.TextNode
3233
import com.yubico.internal.util.JacksonCodecs
@@ -533,4 +534,23 @@ class JsonIoSpec
533534
}
534535
}
535536

537+
describe("The class RegisteredCredential") {
538+
it("""does not have a "backedUp" property when newly serialized.""") {
539+
forAll { cred: RegisteredCredential =>
540+
val tree = json.valueToTree(cred).asInstanceOf[ObjectNode]
541+
tree.has("backedUp") should be(false)
542+
}
543+
}
544+
545+
it("""can be parsed with the previous "backedUp" property name.""") {
546+
forAll { cred: RegisteredCredential =>
547+
val tree = json.valueToTree(cred).asInstanceOf[ObjectNode]
548+
tree.set[ObjectNode]("backedUp", BooleanNode.TRUE)
549+
tree.remove("backupState")
550+
val cred2 = json.treeToValue(tree, classOf[RegisteredCredential])
551+
cred2.isBackedUp.toScala should equal(Some(true))
552+
}
553+
}
554+
}
555+
536556
}

0 commit comments

Comments
 (0)