@Test(expected = BadAttestationStatementException.class) public void validate_caught_exception_test() { WebAuthnRegistrationRequestValidator target = new WebAuthnRegistrationRequestValidator( webAuthnManager, serverPropertyProvider ); when(webAuthnManager.validate(any(RegistrationRequest.class), any(RegistrationParameters.class))).thenThrow(new com.webauthn4j.validator.exception.BadAttestationStatementException("dummy")); MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); mockHttpServletRequest.setScheme("https"); mockHttpServletRequest.setServerName("example.com"); mockHttpServletRequest.setServerPort(443); String clientDataBase64 = "clientDataBase64"; String attestationObjectBase64 = "attestationObjectBase64"; Set<String> transports = Collections.emptySet(); String clientExtensionsJSON = "clientExtensionsJSON"; target.validate(mockHttpServletRequest, clientDataBase64, attestationObjectBase64, transports, clientExtensionsJSON); }
public WebAuthnRegistrationRequestValidationResponse validate(HttpServletRequest httpServletRequest, String clientDataBase64url, String attestationObjectBase64url, Set<String> transports, String clientExtensionsJSON ) { Assert.notNull(httpServletRequest, "httpServletRequest must not be null"); Assert.hasText(clientDataBase64url, "clientDataBase64url must have text"); Assert.hasText(attestationObjectBase64url, "attestationObjectBase64url must have text"); if (transports != null) { transports.forEach(transport -> Assert.hasText(transport, "each transport must have text")); } RegistrationRequest webAuthnRegistrationRequest = createRegistrationRequest(clientDataBase64url, attestationObjectBase64url, transports, clientExtensionsJSON); RegistrationParameters webAuthnRegistrationParameters = createRegistrationParameters(httpServletRequest); try { RegistrationData response = webAuthnManager.validate(webAuthnRegistrationRequest, webAuthnRegistrationParameters); return new WebAuthnRegistrationRequestValidationResponse( response.getCollectedClientData(), response.getAttestationObject(), response.getClientExtensions(), response.getTransports()); } catch (WebAuthnException e) { throw ExceptionUtil.wrapWithAuthenticationException(e); } }
WebAuthnRegistrationRequestValidator { public WebAuthnRegistrationRequestValidationResponse validate(HttpServletRequest httpServletRequest, String clientDataBase64url, String attestationObjectBase64url, Set<String> transports, String clientExtensionsJSON ) { Assert.notNull(httpServletRequest, "httpServletRequest must not be null"); Assert.hasText(clientDataBase64url, "clientDataBase64url must have text"); Assert.hasText(attestationObjectBase64url, "attestationObjectBase64url must have text"); if (transports != null) { transports.forEach(transport -> Assert.hasText(transport, "each transport must have text")); } RegistrationRequest webAuthnRegistrationRequest = createRegistrationRequest(clientDataBase64url, attestationObjectBase64url, transports, clientExtensionsJSON); RegistrationParameters webAuthnRegistrationParameters = createRegistrationParameters(httpServletRequest); try { RegistrationData response = webAuthnManager.validate(webAuthnRegistrationRequest, webAuthnRegistrationParameters); return new WebAuthnRegistrationRequestValidationResponse( response.getCollectedClientData(), response.getAttestationObject(), response.getClientExtensions(), response.getTransports()); } catch (WebAuthnException e) { throw ExceptionUtil.wrapWithAuthenticationException(e); } } }
WebAuthnRegistrationRequestValidator { public WebAuthnRegistrationRequestValidationResponse validate(HttpServletRequest httpServletRequest, String clientDataBase64url, String attestationObjectBase64url, Set<String> transports, String clientExtensionsJSON ) { Assert.notNull(httpServletRequest, "httpServletRequest must not be null"); Assert.hasText(clientDataBase64url, "clientDataBase64url must have text"); Assert.hasText(attestationObjectBase64url, "attestationObjectBase64url must have text"); if (transports != null) { transports.forEach(transport -> Assert.hasText(transport, "each transport must have text")); } RegistrationRequest webAuthnRegistrationRequest = createRegistrationRequest(clientDataBase64url, attestationObjectBase64url, transports, clientExtensionsJSON); RegistrationParameters webAuthnRegistrationParameters = createRegistrationParameters(httpServletRequest); try { RegistrationData response = webAuthnManager.validate(webAuthnRegistrationRequest, webAuthnRegistrationParameters); return new WebAuthnRegistrationRequestValidationResponse( response.getCollectedClientData(), response.getAttestationObject(), response.getClientExtensions(), response.getTransports()); } catch (WebAuthnException e) { throw ExceptionUtil.wrapWithAuthenticationException(e); } } WebAuthnRegistrationRequestValidator(WebAuthnManager webAuthnManager, ServerPropertyProvider serverPropertyProvider); }
WebAuthnRegistrationRequestValidator { public WebAuthnRegistrationRequestValidationResponse validate(HttpServletRequest httpServletRequest, String clientDataBase64url, String attestationObjectBase64url, Set<String> transports, String clientExtensionsJSON ) { Assert.notNull(httpServletRequest, "httpServletRequest must not be null"); Assert.hasText(clientDataBase64url, "clientDataBase64url must have text"); Assert.hasText(attestationObjectBase64url, "attestationObjectBase64url must have text"); if (transports != null) { transports.forEach(transport -> Assert.hasText(transport, "each transport must have text")); } RegistrationRequest webAuthnRegistrationRequest = createRegistrationRequest(clientDataBase64url, attestationObjectBase64url, transports, clientExtensionsJSON); RegistrationParameters webAuthnRegistrationParameters = createRegistrationParameters(httpServletRequest); try { RegistrationData response = webAuthnManager.validate(webAuthnRegistrationRequest, webAuthnRegistrationParameters); return new WebAuthnRegistrationRequestValidationResponse( response.getCollectedClientData(), response.getAttestationObject(), response.getClientExtensions(), response.getTransports()); } catch (WebAuthnException e) { throw ExceptionUtil.wrapWithAuthenticationException(e); } } WebAuthnRegistrationRequestValidator(WebAuthnManager webAuthnManager, ServerPropertyProvider serverPropertyProvider); WebAuthnRegistrationRequestValidationResponse validate(HttpServletRequest httpServletRequest,
                                                                  String clientDataBase64url,
                                                                  String attestationObjectBase64url,
                                                                  Set<String> transports,
                                                                  String clientExtensionsJSON
    ); }
WebAuthnRegistrationRequestValidator { public WebAuthnRegistrationRequestValidationResponse validate(HttpServletRequest httpServletRequest, String clientDataBase64url, String attestationObjectBase64url, Set<String> transports, String clientExtensionsJSON ) { Assert.notNull(httpServletRequest, "httpServletRequest must not be null"); Assert.hasText(clientDataBase64url, "clientDataBase64url must have text"); Assert.hasText(attestationObjectBase64url, "attestationObjectBase64url must have text"); if (transports != null) { transports.forEach(transport -> Assert.hasText(transport, "each transport must have text")); } RegistrationRequest webAuthnRegistrationRequest = createRegistrationRequest(clientDataBase64url, attestationObjectBase64url, transports, clientExtensionsJSON); RegistrationParameters webAuthnRegistrationParameters = createRegistrationParameters(httpServletRequest); try { RegistrationData response = webAuthnManager.validate(webAuthnRegistrationRequest, webAuthnRegistrationParameters); return new WebAuthnRegistrationRequestValidationResponse( response.getCollectedClientData(), response.getAttestationObject(), response.getClientExtensions(), response.getTransports()); } catch (WebAuthnException e) { throw ExceptionUtil.wrapWithAuthenticationException(e); } } WebAuthnRegistrationRequestValidator(WebAuthnManager webAuthnManager, ServerPropertyProvider serverPropertyProvider); WebAuthnRegistrationRequestValidationResponse validate(HttpServletRequest httpServletRequest,
                                                                  String clientDataBase64url,
                                                                  String attestationObjectBase64url,
                                                                  Set<String> transports,
                                                                  String clientExtensionsJSON
    );  }