File tree Expand file tree Collapse file tree 6 files changed +75
-9
lines changed
webauthn-server-core/src/main/java/com/yubico/webauthn/data Expand file tree Collapse file tree 6 files changed +75
-9
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ New features:
6
6
`RegistrationResult` and `RegisteredCredential`.
7
7
** Thanks to Jakob Heher (A-SIT) for the contribution, see
8
8
https://github.com/Yubico/java-webauthn-server/pull/299
9
+ * Added enum parsing functions:
10
+ ** `AuthenticatorAttachment.fromValue(String): Optional<AuthenticatorAttachment>`
11
+ ** `PublicKeyCredentialType.fromId(String): Optional<PublicKeyCredentialType>`
12
+ ** `ResidentKeyRequirement.fromValue(String): Optional<ResidentKeyRequirement>`
13
+ ** `TokenBindingStatus.fromValue(String): Optional<TokenBindingStatus>`
14
+ ** `UserVerificationRequirement.fromValue(String): Optional<UserVerificationRequirement>`
9
15
* (Experimental) Added option `isSecurePaymentConfirmation(boolean)` to
10
16
`FinishAssertionOptions`. When set, `RelyingParty.finishAssertion()` will
11
17
adapt the validation logic for a Secure Payment Confirmation (SPC) response
Original file line number Diff line number Diff line change 26
26
27
27
import com .fasterxml .jackson .annotation .JsonCreator ;
28
28
import com .fasterxml .jackson .annotation .JsonValue ;
29
+ import java .util .Optional ;
29
30
import java .util .stream .Stream ;
30
31
import lombok .AllArgsConstructor ;
31
32
import lombok .Getter ;
@@ -72,8 +73,23 @@ public enum AuthenticatorAttachment {
72
73
73
74
@ JsonValue @ Getter @ NonNull private final String value ;
74
75
76
+ /**
77
+ * Attempt to parse a string as an {@link AuthenticatorAttachment}.
78
+ *
79
+ * @param value a {@link String} equal to the {@link #getValue() value} of a constant in {@link
80
+ * AuthenticatorAttachment}
81
+ * @return The {@link AuthenticatorAttachment} instance whose {@link #getValue() value} equals
82
+ * <code>value</code>, if any.
83
+ * @see <a
84
+ * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enumdef-authenticatorattachment">§5.4.5.
85
+ * Authenticator Attachment Enumeration (enum AuthenticatorAttachment) </a>
86
+ */
87
+ public static Optional <AuthenticatorAttachment > fromValue (@ NonNull String value ) {
88
+ return Stream .of (values ()).filter (v -> v .value .equals (value )).findAny ();
89
+ }
90
+
75
91
@ JsonCreator
76
92
private static AuthenticatorAttachment fromJsonString (@ NonNull String value ) {
77
- return Stream . of ( values ()). filter ( v -> v . value . equals ( value )). findAny ( ).orElse (null );
93
+ return fromValue ( value ).orElse (null );
78
94
}
79
95
}
Original file line number Diff line number Diff line change @@ -51,13 +51,24 @@ public enum PublicKeyCredentialType {
51
51
52
52
@ JsonValue @ Getter @ NonNull private final String id ;
53
53
54
- private static Optional <PublicKeyCredentialType > fromString (@ NonNull String id ) {
54
+ /**
55
+ * Attempt to parse a string as a {@link PublicKeyCredentialType}.
56
+ *
57
+ * @param id a {@link String} equal to the {@link #getId() id} of a constant in {@link
58
+ * PublicKeyCredentialType}
59
+ * @return The {@link AuthenticatorAttachment} instance whose {@link #getId() id} equals <code>id
60
+ * </code>, if any.
61
+ * @see <a
62
+ * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enumdef-publickeycredentialtype">§5.10.2.
63
+ * Credential Type Enumeration (enum PublicKeyCredentialType)</a>
64
+ */
65
+ public static Optional <PublicKeyCredentialType > fromId (@ NonNull String id ) {
55
66
return Stream .of (values ()).filter (v -> v .id .equals (id )).findAny ();
56
67
}
57
68
58
69
@ JsonCreator
59
70
private static PublicKeyCredentialType fromJsonString (@ NonNull String id ) {
60
- return fromString (id )
71
+ return fromId (id )
61
72
.orElseThrow (
62
73
() ->
63
74
new IllegalArgumentException (
Original file line number Diff line number Diff line change @@ -105,13 +105,24 @@ public enum ResidentKeyRequirement {
105
105
106
106
@ JsonValue @ Getter @ NonNull private final String value ;
107
107
108
- private static Optional <ResidentKeyRequirement > fromString (@ NonNull String value ) {
108
+ /**
109
+ * Attempt to parse a string as a {@link ResidentKeyRequirement}.
110
+ *
111
+ * @param value a {@link String} equal to the {@link #getValue() value} of a constant in {@link
112
+ * ResidentKeyRequirement}
113
+ * @return The {@link ResidentKeyRequirement} instance whose {@link #getValue() value} equals
114
+ * <code>value</code>, if any.
115
+ * @see <a
116
+ * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enum-residentKeyRequirement">§5.4.6.
117
+ * Resident Key Requirement Enumeration (enum ResidentKeyRequirement)</a>
118
+ */
119
+ public static Optional <ResidentKeyRequirement > fromValue (@ NonNull String value ) {
109
120
return Stream .of (values ()).filter (v -> v .value .equals (value )).findAny ();
110
121
}
111
122
112
123
@ JsonCreator
113
124
private static ResidentKeyRequirement fromJsonString (@ NonNull String value ) {
114
- return fromString (value )
125
+ return fromValue (value )
115
126
.orElseThrow (
116
127
() ->
117
128
new IllegalArgumentException (
Original file line number Diff line number Diff line change @@ -58,13 +58,24 @@ public enum TokenBindingStatus {
58
58
59
59
@ JsonValue @ Getter @ NonNull private final String value ;
60
60
61
- private static Optional <TokenBindingStatus > fromString (@ NonNull String value ) {
61
+ /**
62
+ * Attempt to parse a string as a {@link TokenBindingStatus}.
63
+ *
64
+ * @param value a {@link String} equal to the {@link #getValue() value} of a constant in {@link
65
+ * TokenBindingStatus}
66
+ * @return The {@link TokenBindingStatus} instance whose {@link #getValue() value} equals <code>
67
+ * value</code>, if any.
68
+ * @see <a
69
+ * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enumdef-tokenbindingstatus">enum
70
+ * TokenBindingStatus</a>
71
+ */
72
+ public static Optional <TokenBindingStatus > fromValue (@ NonNull String value ) {
62
73
return Arrays .stream (values ()).filter (v -> v .value .equals (value )).findAny ();
63
74
}
64
75
65
76
@ JsonCreator
66
77
static TokenBindingStatus fromJsonString (@ NonNull String value ) {
67
- return fromString (value )
78
+ return fromValue (value )
68
79
.orElseThrow (
69
80
() ->
70
81
new IllegalArgumentException (
Original file line number Diff line number Diff line change @@ -66,13 +66,24 @@ public enum UserVerificationRequirement {
66
66
67
67
@ JsonValue @ Getter @ NonNull private final String value ;
68
68
69
- private static Optional <UserVerificationRequirement > fromString (@ NonNull String value ) {
69
+ /**
70
+ * Attempt to parse a string as a {@link UserVerificationRequirement}.
71
+ *
72
+ * @param value a {@link String} equal to the {@link #getValue() value} of a constant in {@link
73
+ * UserVerificationRequirement}
74
+ * @return The {@link UserVerificationRequirement} instance whose {@link #getValue() value} equals
75
+ * <code>value</code>, if any.
76
+ * @see <a
77
+ * href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#enumdef-userverificationrequirement">§5.10.6.
78
+ * User Verification Requirement Enumeration (enum UserVerificationRequirement)</a>
79
+ */
80
+ public static Optional <UserVerificationRequirement > fromValue (@ NonNull String value ) {
70
81
return Stream .of (values ()).filter (v -> v .value .equals (value )).findAny ();
71
82
}
72
83
73
84
@ JsonCreator
74
85
private static UserVerificationRequirement fromJsonString (@ NonNull String value ) {
75
- return fromString (value )
86
+ return fromValue (value )
76
87
.orElseThrow (
77
88
() ->
78
89
new IllegalArgumentException (
You can’t perform that action at this time.
0 commit comments