use of com.webauthn4j.springframework.security.WebAuthnAuthenticationRequest in project webauthn4j-spring-security by webauthn4j.
the class FidoServerAssertionResultEndpointFilter method attemptAuthentication.
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) {
InputStream inputStream;
try {
inputStream = request.getInputStream();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
try {
ServerPublicKeyCredential<ServerAuthenticatorAssertionResponse> credential = jsonConverter.readValue(inputStream, credentialTypeRef);
serverPublicKeyCredentialValidator.validate(credential);
ServerAuthenticatorAssertionResponse assertionResponse = credential.getResponse();
ServerProperty serverProperty = serverPropertyProvider.provide(request);
CollectedClientData collectedClientData = collectedClientDataConverter.convert(assertionResponse.getClientDataJSON());
UserVerificationRequirement userVerificationRequirement = serverEndpointFilterUtil.decodeUserVerification(collectedClientData.getChallenge());
WebAuthnAuthenticationRequest webAuthnAuthenticationRequest = new WebAuthnAuthenticationRequest(credential.getRawId() == null ? null : Base64UrlUtil.decode(credential.getRawId()), assertionResponse.getClientDataJSON() == null ? null : Base64UrlUtil.decode(assertionResponse.getClientDataJSON()), assertionResponse.getAuthenticatorData() == null ? null : Base64UrlUtil.decode(assertionResponse.getAuthenticatorData()), assertionResponse.getSignature() == null ? null : Base64UrlUtil.decode(assertionResponse.getSignature()), credential.getClientExtensionResults());
WebAuthnAuthenticationParameters webAuthnAuthenticationParameters = new WebAuthnAuthenticationParameters(serverProperty, userVerificationRequirement == UserVerificationRequirement.REQUIRED, false);
WebAuthnAssertionAuthenticationToken webAuthnAssertionAuthenticationToken = new WebAuthnAssertionAuthenticationToken(webAuthnAuthenticationRequest, webAuthnAuthenticationParameters, Collections.emptyList());
setDetails(request, webAuthnAssertionAuthenticationToken);
return this.getAuthenticationManager().authenticate(webAuthnAssertionAuthenticationToken);
} catch (DataConversionException e) {
throw new com.webauthn4j.springframework.security.exception.DataConversionException("Failed to convert data", e);
}
}
use of com.webauthn4j.springframework.security.WebAuthnAuthenticationRequest in project webauthn4j-spring-security by webauthn4j.
the class WithMockWebAuthnUserSecurityContextFactory method createSecurityContext.
/**
* Create a {@link SecurityContext} given an Annotation.
*
* @param user the {@link WithMockWebAuthnUser} to create the {@link SecurityContext}
* from. Cannot be null.
* @return the {@link SecurityContext} to use. Cannot be null.
*/
@Override
public SecurityContext createSecurityContext(WithMockWebAuthnUser user) {
SecurityContext context = SecurityContextHolder.createEmptyContext();
List<AuthorityEntity> authorities = Arrays.stream(user.authorities()).map((name) -> new AuthorityEntity(null, name)).collect(Collectors.toList());
List<GroupEntity> groups = Arrays.stream(user.groups()).map(GroupEntity::new).collect(Collectors.toList());
List<AuthenticatorEntity> authenticatorEntities = Arrays.stream(user.authenticators()).map((name) -> {
AuthenticatorEntity authenticatorEntity = new AuthenticatorEntity();
authenticatorEntity.setName(name);
return authenticatorEntity;
}).collect(Collectors.toList());
UserEntity principal = new UserEntity();
principal.setId(user.id());
principal.setUserHandle(Base64UrlUtil.decode(user.userHandleBase64Url()));
principal.setFirstName(user.firstName());
principal.setLastName(user.lastName());
principal.setEmailAddress(user.emailAddress());
principal.setGroups(groups);
principal.setAuthorities(authorities);
principal.setAuthenticators(authenticatorEntities);
principal.setLocked(user.locked());
WebAuthnAuthenticationRequest request = mock(WebAuthnAuthenticationRequest.class);
Authentication auth = new WebAuthnAuthenticationToken(principal, request, principal.getAuthorities());
context.setAuthentication(auth);
return context;
}
Aggregations