Skip to content

Commit ec2a416

Browse files
Add more missing mixins and deserializers
1 parent 61d4792 commit ec2a416

14 files changed

+313
-23
lines changed

.idea/checkstyle-idea.xml

Lines changed: 10 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.web.webauthn.jackson;
18+
19+
import com.fasterxml.jackson.core.JsonParser;
20+
import com.fasterxml.jackson.core.JsonToken;
21+
import com.fasterxml.jackson.databind.DeserializationContext;
22+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
23+
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInput;
24+
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInput;
25+
26+
import java.io.IOException;
27+
28+
/**
29+
* Jackson deserializer for {@link AuthenticationExtensionsClientInput}
30+
*
31+
* @author Justin Cranford
32+
* @since 6.5
33+
*/
34+
@SuppressWarnings("serial")
35+
class AuthenticationExtensionsClientInputDeserializer extends StdDeserializer<AuthenticationExtensionsClientInput> {
36+
37+
AuthenticationExtensionsClientInputDeserializer() {
38+
super(AuthenticationExtensionsClientInput.class);
39+
}
40+
41+
@Override
42+
public AuthenticationExtensionsClientInput deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException {
43+
// if (parser.currentToken() != JsonToken.START_OBJECT) {
44+
// ctxt.reportInputMismatch(this, "Expected START_OBJECT token");
45+
// }
46+
//
47+
while (parser.nextToken() != JsonToken.END_OBJECT) {
48+
String extensionId = parser.currentName();
49+
parser.nextToken();
50+
51+
Object value = parser.readValueAs(Object.class);
52+
return new ImmutableAuthenticationExtensionsClientInput(extensionId, value);
53+
}
54+
55+
return null;
56+
}
57+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616

1717
package org.springframework.security.web.webauthn.jackson;
1818

19+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
1920
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
20-
2121
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs;
2222

2323
/**
2424
* Jackson mixin for {@link AuthenticationExtensionsClientInputs}
2525
*
2626
* @author Rob Winch
27+
* @author Justin Cranford
2728
* @since 6.4
2829
*/
2930
@JsonSerialize(using = AuthenticationExtensionsClientInputSerializer.class)
31+
@JsonDeserialize(using = AuthenticationExtensionsClientInputDeserializer.class)
3032
class AuthenticationExtensionsClientInputMixin {
3133

3234
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.web.webauthn.jackson;
18+
19+
import com.fasterxml.jackson.core.JsonParser;
20+
import com.fasterxml.jackson.core.JsonToken;
21+
import com.fasterxml.jackson.databind.DeserializationContext;
22+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
23+
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInput;
24+
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs;
25+
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInputs;
26+
27+
import java.io.IOException;
28+
import java.util.ArrayList;
29+
import java.util.HashMap;
30+
import java.util.List;
31+
import java.util.Map;
32+
33+
/**
34+
* Jackson deserializer for {@link AuthenticationExtensionsClientInputs}
35+
*
36+
* @author Justin Cranford
37+
* @since 6.5
38+
*/
39+
@SuppressWarnings("serial")
40+
class AuthenticationExtensionsClientInputsDeserializer extends StdDeserializer<AuthenticationExtensionsClientInputs> {
41+
42+
AuthenticationExtensionsClientInputsDeserializer() {
43+
super(AuthenticationExtensionsClientInputs.class);
44+
}
45+
46+
@Override
47+
public AuthenticationExtensionsClientInputs deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
48+
// if (p.currentToken() != JsonToken.START_OBJECT) {
49+
// ctxt.reportInputMismatch(this, "Expected START_OBJECT token for AuthenticationExtensionsClientInputs");
50+
// }
51+
//
52+
final AuthenticationExtensionsClientInputDeserializer authenticationExtensionsClientInputDeserializer = new AuthenticationExtensionsClientInputDeserializer();
53+
54+
final List<AuthenticationExtensionsClientInput> extensions = new ArrayList<>();
55+
while (p.nextToken() != JsonToken.END_OBJECT) {
56+
extensions.add(authenticationExtensionsClientInputDeserializer.deserialize(p, ctxt));
57+
}
58+
return new ImmutableAuthenticationExtensionsClientInputs(extensions);
59+
}
60+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.web.webauthn.jackson;
1818

19+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
1920
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2021

2122
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs;
@@ -27,6 +28,7 @@
2728
* @since 6.4
2829
*/
2930
@JsonSerialize(using = AuthenticationExtensionsClientInputsSerializer.class)
31+
@JsonDeserialize(using = AuthenticationExtensionsClientInputsDeserializer.class)
3032
class AuthenticationExtensionsClientInputsMixin {
3133

3234
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.web.webauthn.jackson;
18+
19+
import com.fasterxml.jackson.core.JacksonException;
20+
import com.fasterxml.jackson.core.JsonParser;
21+
import com.fasterxml.jackson.core.JsonToken;
22+
import com.fasterxml.jackson.databind.DeserializationContext;
23+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
24+
import org.springframework.security.web.webauthn.api.AuthenticatorAttachment;
25+
import org.springframework.security.web.webauthn.api.AuthenticatorSelectionCriteria;
26+
import org.springframework.security.web.webauthn.api.AuthenticatorSelectionCriteria.AuthenticatorSelectionCriteriaBuilder;
27+
import org.springframework.security.web.webauthn.api.ResidentKeyRequirement;
28+
import org.springframework.security.web.webauthn.api.UserVerificationRequirement;
29+
30+
import java.io.IOException;
31+
32+
/**
33+
* Jackson deserializer for {@link AuthenticatorSelectionCriteria}
34+
*
35+
* @author Rob Winch
36+
* @author Justin Cranford
37+
* @since 6.4
38+
*/
39+
@SuppressWarnings("serial")
40+
class AuthenticatorSelectionCriteriaDeserializer extends StdDeserializer<AuthenticatorSelectionCriteria> {
41+
42+
AuthenticatorSelectionCriteriaDeserializer() {
43+
super(AuthenticatorSelectionCriteria.class);
44+
}
45+
46+
@Override
47+
public AuthenticatorSelectionCriteria deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException {
48+
final AuthenticatorSelectionCriteriaBuilder builder = AuthenticatorSelectionCriteria.builder();
49+
while (parser.nextToken() != JsonToken.END_OBJECT) {
50+
final String fieldName = parser.currentName();
51+
if ("authenticatorAttachment".equals(fieldName)) {
52+
parser.nextToken(); // Move to value
53+
builder.authenticatorAttachment(AuthenticatorAttachment.valueOf(parser.getText()));
54+
} else if ("requireResidentKey".equals(fieldName)) {
55+
parser.nextToken(); // Move to value
56+
builder.residentKey(ResidentKeyRequirement.valueOf(parser.getText()));
57+
} else if ("userVerification".equals(fieldName)) {
58+
parser.nextToken(); // Move to value
59+
builder.userVerification(UserVerificationRequirement.valueOf(parser.getText()));
60+
} else {
61+
parser.skipChildren(); // Ignore unknown fields
62+
}
63+
}
64+
return builder.build();
65+
}
66+
67+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@
1818

1919
import com.fasterxml.jackson.annotation.JsonInclude;
2020

21+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
22+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2123
import org.springframework.security.web.webauthn.api.AuthenticatorSelectionCriteria;
2224

2325
/**
2426
* Jackson mixin for {@link AuthenticatorSelectionCriteria}
2527
*
2628
* @author Rob Winch
29+
* @author Justin Cranford
2730
* @since 6.4
2831
*/
32+
@JsonSerialize(using = AuthenticatorSelectionCriteriaSerializer.class)
33+
@JsonDeserialize(using = AuthenticatorSelectionCriteriaDeserializer.class)
2934
@JsonInclude(JsonInclude.Include.NON_NULL)
3035
abstract class AuthenticatorSelectionCriteriaMixin {
3136

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.web.webauthn.jackson;
18+
19+
import com.fasterxml.jackson.core.JsonGenerator;
20+
import com.fasterxml.jackson.databind.SerializerProvider;
21+
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
22+
import org.springframework.security.web.webauthn.api.AuthenticatorSelectionCriteria;
23+
import org.springframework.security.web.webauthn.api.AuthenticatorTransport;
24+
25+
import java.io.IOException;
26+
27+
/**
28+
* Jackson serializer for {@link AuthenticatorSelectionCriteria}
29+
*
30+
* @author Rob Winch
31+
* @author Justin Cranford
32+
* @since 6.5
33+
*/
34+
@SuppressWarnings("serial")
35+
class AuthenticatorSelectionCriteriaSerializer extends StdSerializer<AuthenticatorSelectionCriteria> {
36+
37+
AuthenticatorSelectionCriteriaSerializer() {
38+
super(AuthenticatorSelectionCriteria.class);
39+
}
40+
41+
@Override
42+
public void serialize(AuthenticatorSelectionCriteria value, JsonGenerator gen, SerializerProvider provider)
43+
throws IOException {
44+
gen.writeStartObject();
45+
gen.writeFieldName("authenticatorAttachment");
46+
gen.writeString(value.getAuthenticatorAttachment().getValue());
47+
gen.writeFieldName("residentKey");
48+
gen.writeString(value.getResidentKey().getValue());
49+
gen.writeFieldName("userVerification");
50+
gen.writeString(value.getUserVerification().getValue());
51+
gen.writeEndObject();
52+
}
53+
54+
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@
1616

1717
package org.springframework.security.web.webauthn.jackson;
1818

19-
import java.time.Duration;
20-
import java.util.List;
21-
2219
import com.fasterxml.jackson.annotation.JsonCreator;
23-
import com.fasterxml.jackson.annotation.JsonInclude;
2420
import com.fasterxml.jackson.annotation.JsonProperty;
25-
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
26-
2721
import org.springframework.security.web.webauthn.api.AttestationConveyancePreference;
2822
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs;
2923
import org.springframework.security.web.webauthn.api.AuthenticatorSelectionCriteria;
@@ -34,6 +28,9 @@
3428
import org.springframework.security.web.webauthn.api.PublicKeyCredentialRpEntity;
3529
import org.springframework.security.web.webauthn.api.PublicKeyCredentialUserEntity;
3630

31+
import java.time.Duration;
32+
import java.util.List;
33+
3734
/**
3835
* Jackson mixin for {@link PublicKeyCredentialCreationOptions}
3936
*
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.springframework.security.web.webauthn.jackson;
2+
3+
import com.fasterxml.jackson.core.JsonParser;
4+
import com.fasterxml.jackson.databind.DeserializationContext;
5+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
6+
import org.springframework.security.web.webauthn.api.ResidentKeyRequirement;
7+
8+
import java.io.IOException;
9+
10+
public class ResidentKeyRequirementDeserializer extends StdDeserializer<ResidentKeyRequirement> {
11+
12+
public ResidentKeyRequirementDeserializer() {
13+
super(ResidentKeyRequirement.class);
14+
}
15+
16+
@Override
17+
public ResidentKeyRequirement deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
18+
String type = p.readValueAs(String.class);
19+
return ResidentKeyRequirement.valueOf(type);
20+
}
21+
}

0 commit comments

Comments
 (0)