Yubico / java-webauthn-server

Server-side Web Authentication library for Java https://www.w3.org/TR/webauthn/#rp-operations
Other
439 stars 137 forks source link

fromString on enums #325

Open fcorneli opened 8 months ago

fcorneli commented 8 months ago

Within my code I have the following in several places:

startAssertionOptionsBuilder.userVerification(UserVerificationRequirement.valueOf(userVerification.toUpperCase()));
...
authenticatorSelectionCriteriaBuilder
                            .residentKey(ResidentKeyRequirement.valueOf(residentKey.toUpperCase()));

while all these enums have a private static fromString. Maybe make these methods public?

emlun commented 8 months ago

Hi! Please help me understand the use case. Why do you need to create these values like this?

fcorneli commented 8 months ago

Because my demo allows it: https://demo.e-contract.be/ejsf-demo/webauthn.xhtml

emlun commented 8 months ago

I see, thank you.

There are the functions PublicKeyCredentialCreationOptions.fromJson and AssertionRequest.fromJson that can parse those entire data structures from JSON, does that help?

But yeah, I also don't see much issue in making the fromString(String): Optional<(enum)> functions public. There are even a few that are already public, like the ones in COSEAlgorithmIdentifier and KeyProtectionType, so I guess we might as well make them all public.

fcorneli commented 8 months ago

Well, I guess once an application allows these options to be somehow configurable (via some property file for example), they need such functions anyway.

emlun commented 8 months ago

This is now released in experimental release 2.6.0-alpha4. Thanks!