Skip to content

Commit d174b10

Browse files
authored
Merge Fix Jackson Deserializer for AuthenticationExtensionsClientOutputs
2 parents 81d07c5 + 3950d5d commit d174b10

File tree

4 files changed

+92
-12
lines changed

4 files changed

+92
-12
lines changed

webauthn/src/main/java/org/springframework/security/web/webauthn/jackson/AuthenticationExtensionsClientOutputsDeserializer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,18 @@ public AuthenticationExtensionsClientOutputs deserialize(JsonParser parser, Dese
5555
throws JacksonException {
5656
List<AuthenticationExtensionsClientOutput<?>> outputs = new ArrayList<>();
5757
for (String key = parser.nextName(); key != null; key = parser.nextName()) {
58-
JsonToken startObject = parser.nextValue();
59-
if (startObject != JsonToken.START_OBJECT) {
60-
break;
61-
}
62-
if (CredentialPropertiesOutput.EXTENSION_ID.equals(key)) {
58+
JsonToken next = parser.nextToken();
59+
if (next == JsonToken.START_OBJECT && CredentialPropertiesOutput.EXTENSION_ID.equals(key)) {
6360
CredentialPropertiesOutput output = parser.readValueAs(CredentialPropertiesOutput.class);
6461
outputs.add(output);
6562
}
6663
else {
6764
if (logger.isDebugEnabled()) {
6865
logger.debug("Skipping unknown extension with id " + key);
6966
}
70-
parser.nextValue();
67+
if (next.isStructStart()) {
68+
parser.skipChildren();
69+
}
7170
}
7271
}
7372

webauthn/src/main/java/org/springframework/security/web/webauthn/jackson/AuthenticationExtensionsClientOutputsJackson2Deserializer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,18 @@ public AuthenticationExtensionsClientOutputs deserialize(JsonParser parser, Dese
6262
throws IOException, JacksonException {
6363
List<AuthenticationExtensionsClientOutput<?>> outputs = new ArrayList<>();
6464
for (String key = parser.nextFieldName(); key != null; key = parser.nextFieldName()) {
65-
JsonToken startObject = parser.nextValue();
66-
if (startObject != JsonToken.START_OBJECT) {
67-
break;
68-
}
69-
if (CredentialPropertiesOutput.EXTENSION_ID.equals(key)) {
65+
JsonToken next = parser.nextToken();
66+
if (next == JsonToken.START_OBJECT && CredentialPropertiesOutput.EXTENSION_ID.equals(key)) {
7067
CredentialPropertiesOutput output = parser.readValueAs(CredentialPropertiesOutput.class);
7168
outputs.add(output);
7269
}
7370
else {
7471
if (logger.isDebugEnabled()) {
7572
logger.debug("Skipping unknown extension with id " + key);
7673
}
77-
parser.nextValue();
74+
if (next.isStructStart()) {
75+
parser.skipChildren();
76+
}
7877
}
7978
}
8079

webauthn/src/test/java/org/springframework/security/web/webauthn/jackson/Jackson2Tests.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,47 @@ void readCredPropsWhenAuthenticatorDisplayName() throws Exception {
123123
assertThat(outputs).usingRecursiveComparison().isEqualTo(credProps);
124124
}
125125

126+
@Test
127+
void readAuthenticationExtensionsClientOutputsWhenAppId() throws Exception {
128+
String json = """
129+
{
130+
"appid": false,
131+
"credProps": {
132+
"rk": false
133+
}
134+
}
135+
""";
136+
CredentialPropertiesOutput credProps = new CredentialPropertiesOutput(false);
137+
138+
AuthenticationExtensionsClientOutputs outputs = this.mapper.readValue(json,
139+
AuthenticationExtensionsClientOutputs.class);
140+
assertThat(outputs.getOutputs()).usingRecursiveFieldByFieldElementComparator().contains(credProps);
141+
}
142+
143+
@Test
144+
void readAuthenticationExtensionsClientOutputsWhenUnknownExtension() throws Exception {
145+
String json = """
146+
{
147+
"unknownObject1": {
148+
"key": "value"
149+
},
150+
"unknownArray": [
151+
{ "key": "value1" },
152+
{ "key": "value2" }
153+
],
154+
"credProps": {
155+
"rk": false
156+
},
157+
"unknownObject2": {}
158+
}
159+
""";
160+
CredentialPropertiesOutput credProps = new CredentialPropertiesOutput(false);
161+
162+
AuthenticationExtensionsClientOutputs outputs = this.mapper.readValue(json,
163+
AuthenticationExtensionsClientOutputs.class);
164+
assertThat(outputs.getOutputs()).usingRecursiveFieldByFieldElementComparator().contains(credProps);
165+
}
166+
126167
@Test
127168
void readAuthenticationExtensionsClientOutputsWhenFieldAfter() throws Exception {
128169
String json = """

webauthn/src/test/java/org/springframework/security/web/webauthn/jackson/JacksonTests.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,47 @@ void readCredPropsWhenAuthenticatorDisplayName() throws Exception {
121121
assertThat(outputs).usingRecursiveComparison().isEqualTo(credProps);
122122
}
123123

124+
@Test
125+
void readAuthenticationExtensionsClientOutputsWhenAppId() {
126+
String json = """
127+
{
128+
"appid": false,
129+
"credProps": {
130+
"rk": false
131+
}
132+
}
133+
""";
134+
CredentialPropertiesOutput credProps = new CredentialPropertiesOutput(false);
135+
136+
AuthenticationExtensionsClientOutputs outputs = this.mapper.readValue(json,
137+
AuthenticationExtensionsClientOutputs.class);
138+
assertThat(outputs.getOutputs()).usingRecursiveFieldByFieldElementComparator().contains(credProps);
139+
}
140+
141+
@Test
142+
void readAuthenticationExtensionsClientOutputsWhenUnknownExtension() {
143+
String json = """
144+
{
145+
"unknownObject1": {
146+
"key": "value"
147+
},
148+
"unknownArray": [
149+
{ "key": "value1" },
150+
{ "key": "value2" }
151+
],
152+
"credProps": {
153+
"rk": false
154+
},
155+
"unknownObject2": {}
156+
}
157+
""";
158+
CredentialPropertiesOutput credProps = new CredentialPropertiesOutput(false);
159+
160+
AuthenticationExtensionsClientOutputs outputs = this.mapper.readValue(json,
161+
AuthenticationExtensionsClientOutputs.class);
162+
assertThat(outputs.getOutputs()).usingRecursiveFieldByFieldElementComparator().contains(credProps);
163+
}
164+
124165
@Test
125166
void readAuthenticationExtensionsClientOutputsWhenFieldAfter() throws Exception {
126167
String json = """

0 commit comments

Comments
 (0)