Why does WebAuthn authentication persist authenticated users and anonymousUser in PublicKeyCredentialUserEntityRepository.java / MapPublicKeyCredentialUserEntityRepository.java?
Design intent is unclear. Also, because I use a single JPA entity for traditional and WebAuthn login, persisting anonymousUser causes problems in my application.
Official docs and debugging doesn't help me understand how to design for anonymousUser persistence, or workaround it.
Unauthenticated / anonymous users are never persisted. Authentication works by looking up the credential first, and using the credential to lookup the user second.
Also, credential registration works for authenticated or unauthenticated users. During credential registration, if user doesn't exist then the user is created, as mentioned in the Registration section of the WebAuthn L1 (2019) and WebAuthn L2 (2021) specs.
Quote
Or the user may be in the process of creating a new account.
N.B. MyPublicKeyCredentialUserEntityRepository.java wraps MapPublicKeyCredentialUserEntityRepository.java for logging.
Register to go to https://localhost:8443/webauthn/register page.aaa and click register button.findByUsername failed, id: u
save, id: Bytes[nF5bm4qc-cztclmzyi-vbvz7ruzS7VOULT8aS9C0kWw], name: u, displayName: u
findByUsername succeeded, id: u, name: Bytes[nF5bm4qc-cztclmzyi-vbvz7ruzS7VOULT8aS9C0kWw], displayName: u
Logout to go to https://localhost:8443/logout page.findByUsername failed, id: anonymousUser
save, id: Bytes[fL8lr_HE0Yfe5DgPYAXOJfcj4OQdWRT8GhNwjHYvnQA], name: anonymousUser, displayName: anonymousUser
findById succeeded, id: Bytes[nF5bm4qc-cztclmzyi-vbvz7ruzS7VOULT8aS9C0kWw], name: u, displayName: u
From official docs and debugging the code, it is unclear what is design intent of storing anonymousUsers in PublicKeyCredentialUserEntityRepository.java / MapPublicKeyCredentialUserEntityRepository.java.
I am not sure if I am on the right track with my services, particularly my choice of reusing the same JPA entity for users.
I am also not sure if MyWebauthnUserService needs to detect and handle all of the anonymousUsers separately from all of the authenticated users.
authenticated users versus anonymousUsers in separate JPA entities?anonymousUsers in Redis myself?Lastly, it is unclear why the default MapPublicKeyCredentialUserEntityRepository.java puts authenticated users and anonymousUsers into the same two HashMaps.
public class MapPublicKeyCredentialUserEntityRepository implements PublicKeyCredentialUserEntityRepository {
    private final Map<String, PublicKeyCredentialUserEntity> usernameToUserEntity = new HashMap<>();
    private final Map<Bytes, PublicKeyCredentialUserEntity> idToUserEntity = new HashMap<>();
And, if there are two overlapping anonymousUser authentication attempts, it seems like the two HashMaps mentioned above will get out of sync. I think idToUserEntity would have 2 entries, but usernameToUserEntity would only have 1 entry, because anonymousUser #2 would clobber anonymousUser #1?

