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:
66 `RegistrationResult` and `RegisteredCredential`.
77 ** Thanks to Jakob Heher (A-SIT) for the contribution, see
88 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>`
915* (Experimental) Added option `isSecurePaymentConfirmation(boolean)` to
1016 `FinishAssertionOptions`. When set, `RelyingParty.finishAssertion()` will
1117 adapt the validation logic for a Secure Payment Confirmation (SPC) response
Original file line number Diff line number Diff line change 2626
2727import com .fasterxml .jackson .annotation .JsonCreator ;
2828import com .fasterxml .jackson .annotation .JsonValue ;
29+ import java .util .Optional ;
2930import java .util .stream .Stream ;
3031import lombok .AllArgsConstructor ;
3132import lombok .Getter ;
@@ -72,8 +73,23 @@ public enum AuthenticatorAttachment {
7273
7374 @ JsonValue @ Getter @ NonNull private final String value ;
7475
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+
7591 @ JsonCreator
7692 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 );
7894 }
7995}
Original file line number Diff line number Diff line change @@ -51,13 +51,24 @@ public enum PublicKeyCredentialType {
5151
5252 @ JsonValue @ Getter @ NonNull private final String id ;
5353
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 ) {
5566 return Stream .of (values ()).filter (v -> v .id .equals (id )).findAny ();
5667 }
5768
5869 @ JsonCreator
5970 private static PublicKeyCredentialType fromJsonString (@ NonNull String id ) {
60- return fromString (id )
71+ return fromId (id )
6172 .orElseThrow (
6273 () ->
6374 new IllegalArgumentException (
Original file line number Diff line number Diff line change @@ -105,13 +105,24 @@ public enum ResidentKeyRequirement {
105105
106106 @ JsonValue @ Getter @ NonNull private final String value ;
107107
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 ) {
109120 return Stream .of (values ()).filter (v -> v .value .equals (value )).findAny ();
110121 }
111122
112123 @ JsonCreator
113124 private static ResidentKeyRequirement fromJsonString (@ NonNull String value ) {
114- return fromString (value )
125+ return fromValue (value )
115126 .orElseThrow (
116127 () ->
117128 new IllegalArgumentException (
Original file line number Diff line number Diff line change @@ -58,13 +58,24 @@ public enum TokenBindingStatus {
5858
5959 @ JsonValue @ Getter @ NonNull private final String value ;
6060
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 ) {
6273 return Arrays .stream (values ()).filter (v -> v .value .equals (value )).findAny ();
6374 }
6475
6576 @ JsonCreator
6677 static TokenBindingStatus fromJsonString (@ NonNull String value ) {
67- return fromString (value )
78+ return fromValue (value )
6879 .orElseThrow (
6980 () ->
7081 new IllegalArgumentException (
Original file line number Diff line number Diff line change @@ -66,13 +66,24 @@ public enum UserVerificationRequirement {
6666
6767 @ JsonValue @ Getter @ NonNull private final String value ;
6868
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 ) {
7081 return Stream .of (values ()).filter (v -> v .value .equals (value )).findAny ();
7182 }
7283
7384 @ JsonCreator
7485 private static UserVerificationRequirement fromJsonString (@ NonNull String value ) {
75- return fromString (value )
86+ return fromValue (value )
7687 .orElseThrow (
7788 () ->
7889 new IllegalArgumentException (
You can’t perform that action at this time.
0 commit comments