java-webauthn-server icon indicating copy to clipboard operation
java-webauthn-server copied to clipboard

fromString on enums

Open fcorneli opened this issue 1 year ago • 5 comments

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?

fcorneli avatar Oct 13 '23 14:10 fcorneli

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

emlun avatar Oct 13 '23 16:10 emlun

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

fcorneli avatar Oct 17 '23 09:10 fcorneli

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.

emlun avatar Oct 17 '23 15:10 emlun

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

fcorneli avatar Oct 17 '23 19:10 fcorneli

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

emlun avatar Nov 09 '23 19:11 emlun