use of com.webauthn4j.springframework.security.exception.PrincipalNotFoundException in project webauthn4j-spring-security by webauthn4j.
the class AttestationOptionsProviderImplTest method getAttestationOptions_with_non_existing_principal_test.
@Test
public void getAttestationOptions_with_non_existing_principal_test() {
Challenge challenge = new DefaultChallenge();
RpIdProviderImpl rpIdProvider = new RpIdProviderImpl();
WebAuthnAuthenticatorService authenticatorService = mock(WebAuthnAuthenticatorService.class);
ChallengeRepository challengeRepository = mock(ChallengeRepository.class);
MockHttpServletRequest mockRequest = new MockHttpServletRequest();
mockRequest.setServerName("example.com");
when(authenticatorService.loadAuthenticatorsByUserPrincipal(any())).thenThrow(new PrincipalNotFoundException("dummy"));
when(challengeRepository.loadOrGenerateChallenge(mockRequest)).thenReturn(challenge);
AttestationOptionsProviderImpl optionsProvider = new AttestationOptionsProviderImpl(rpIdProvider, authenticatorService, challengeRepository);
optionsProvider.setRpName("rpName");
optionsProvider.setPubKeyCredParams(Collections.singletonList(new PublicKeyCredentialParameters(PublicKeyCredentialType.PUBLIC_KEY, COSEAlgorithmIdentifier.ES256)));
optionsProvider.setRegistrationTimeout(10000L);
optionsProvider.setRegistrationExtensions(new AuthenticationExtensionsClientInputs<>());
AttestationOptions attestationOptions = optionsProvider.getAttestationOptions(mockRequest, new UsernamePasswordAuthenticationToken("username", null));
assertThat(attestationOptions.getRp().getId()).isEqualTo("example.com");
assertThat(attestationOptions.getRp().getName()).isEqualTo("rpName");
assertThat(attestationOptions.getUser()).isEqualTo(new PublicKeyCredentialUserEntity("username".getBytes(), "username", "username"));
assertThat(attestationOptions.getChallenge()).isEqualTo(challenge);
assertThat(attestationOptions.getPubKeyCredParams()).isEqualTo(Collections.singletonList(new PublicKeyCredentialParameters(PublicKeyCredentialType.PUBLIC_KEY, COSEAlgorithmIdentifier.ES256)));
assertThat(attestationOptions.getTimeout()).isEqualTo(10000L);
assertThat(attestationOptions.getExcludeCredentials()).isEmpty();
assertThat(attestationOptions.getExtensions()).isEqualTo(new AuthenticationExtensionsClientInputs<>());
}
use of com.webauthn4j.springframework.security.exception.PrincipalNotFoundException in project webauthn4j-spring-security by webauthn4j.
the class WebAuthnSampleController method getCredentialIds.
private List<String> getCredentialIds() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Object principal = authentication.getPrincipal();
if (principal == null || authenticationTrustResolver.isAnonymous(authentication)) {
return Collections.emptyList();
} else {
try {
List<WebAuthnAuthenticator> webAuthnAuthenticators = webAuthnAuthenticatorManager.loadAuthenticatorsByUserPrincipal(principal);
return webAuthnAuthenticators.stream().map(webAuthnAuthenticator -> Base64UrlUtil.encodeToString(webAuthnAuthenticator.getAttestedCredentialData().getCredentialId())).collect(Collectors.toList());
} catch (PrincipalNotFoundException e) {
return Collections.emptyList();
}
}
}
use of com.webauthn4j.springframework.security.exception.PrincipalNotFoundException in project webauthn4j-spring-security by webauthn4j.
the class UserManagerImpl method deleteUser.
/**
* {@inheritDoc}
*/
@Override
public void deleteUser(String username) {
UserEntity userEntity = userEntityRepository.findOneByEmailAddress(username).orElseThrow(() -> new PrincipalNotFoundException(String.format("UserEntity with username'%s' is not found.", username)));
userEntityRepository.delete(userEntity);
}
Aggregations