WebAuthnAuthenticationProvider implements AuthenticationProvider { WebAuthnAuthenticator retrieveAuthenticator(byte[] credentialId) { WebAuthnAuthenticator webAuthnAuthenticator; try { webAuthnAuthenticator = authenticatorService.loadAuthenticatorByCredentialId(credentialId); } catch (CredentialIdNotFoundException notFound) { if (hideCredentialIdNotFoundExceptions) { throw new BadCredentialsException(messages.getMessage( "WebAuthnAuthenticationProvider.badCredentials", "Bad credentials")); } else { throw notFound; } } catch (Exception repositoryProblem) { throw new InternalAuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem); } if (webAuthnAuthenticator == null) { throw new InternalAuthenticationServiceException( "WebAuthnAuthenticatorService returned null, which is an interface contract violation"); } return webAuthnAuthenticator; } WebAuthnAuthenticationProvider(
            WebAuthnAuthenticatorService authenticatorService,
            WebAuthnManager webAuthnManager); @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication); boolean isHideCredentialIdNotFoundExceptions(); void setHideCredentialIdNotFoundExceptions(boolean hideCredentialIdNotFoundExceptions);  }
@Test public void retrieveAuthenticator_test() { byte[] credentialId = new byte[0]; WebAuthnAuthenticator expectedAuthenticator = mock(WebAuthnAuthenticator.class); when(authenticatorService.loadAuthenticatorByCredentialId(credentialId)).thenReturn(expectedAuthenticator); WebAuthnAuthenticator webAuthnAuthenticator = authenticationProvider.retrieveAuthenticator(credentialId); assertThat(webAuthnAuthenticator).isEqualTo(expectedAuthenticator); }
@Test(expected = BadCredentialsException.class) public void retrieveWebAuthnUserDetails_test_with_CredentialIdNotFoundException() { byte[] credentialId = new byte[0]; when(authenticatorService.loadAuthenticatorByCredentialId(credentialId)).thenThrow(CredentialIdNotFoundException.class); authenticationProvider.retrieveAuthenticator(credentialId); }