From 535345f583e2b53dfe09d38023755cddde6719d0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Jan 2025 06:50:42 +0000 Subject: [PATCH 1/2] chore(deps): bump webauthn4jVersion Bumps `webauthn4jVersion` from 0.28.3.RELEASE to 0.28.4.RELEASE. Updates `com.webauthn4j:webauthn4j-util` from 0.28.3.RELEASE to 0.28.4.RELEASE - [Release notes](https://github.com/webauthn4j/webauthn4j/releases) - [Changelog](https://github.com/webauthn4j/webauthn4j/blob/master/github-release-notes-generator.yml) - [Commits](https://github.com/webauthn4j/webauthn4j/compare/0.28.3.RELEASE...0.28.4.RELEASE) Updates `com.webauthn4j:webauthn4j-core` from 0.28.3.RELEASE to 0.28.4.RELEASE - [Release notes](https://github.com/webauthn4j/webauthn4j/releases) - [Changelog](https://github.com/webauthn4j/webauthn4j/blob/master/github-release-notes-generator.yml) - [Commits](https://github.com/webauthn4j/webauthn4j/compare/0.28.3.RELEASE...0.28.4.RELEASE) Updates `com.webauthn4j:webauthn4j-metadata` from 0.28.3.RELEASE to 0.28.4.RELEASE - [Release notes](https://github.com/webauthn4j/webauthn4j/releases) - [Changelog](https://github.com/webauthn4j/webauthn4j/blob/master/github-release-notes-generator.yml) - [Commits](https://github.com/webauthn4j/webauthn4j/compare/0.28.3.RELEASE...0.28.4.RELEASE) Updates `com.webauthn4j:webauthn4j-test` from 0.28.3.RELEASE to 0.28.4.RELEASE - [Release notes](https://github.com/webauthn4j/webauthn4j/releases) - [Changelog](https://github.com/webauthn4j/webauthn4j/blob/master/github-release-notes-generator.yml) - [Commits](https://github.com/webauthn4j/webauthn4j/compare/0.28.3.RELEASE...0.28.4.RELEASE) --- updated-dependencies: - dependency-name: com.webauthn4j:webauthn4j-util dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: com.webauthn4j:webauthn4j-core dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: com.webauthn4j:webauthn4j-metadata dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: com.webauthn4j:webauthn4j-test dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7ce8239f7..fb0faf374 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ buildscript { asciidoctorGradleVersion = "4.0.4" //Libraries - webauthn4jVersion = '0.28.3.RELEASE' + webauthn4jVersion = '0.28.4.RELEASE' springSecurityVersion = '6.0.2' } From 58a47b186a35cb2b143a3d5f00644b189d24c584 Mon Sep 17 00:00:00 2001 From: Yoshikazu Nojima Date: Wed, 1 Jan 2025 17:43:31 +0900 Subject: [PATCH 2/2] Address WebAuthn4J HttpClient interface design change --- .../RestTemplateAdaptorHttpClient.java | 18 ++++++- .../RestTemplateAdaptorHttpClientTest.java | 47 ++++++++++++++++--- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/webauthn4j-spring-security-metadata/src/main/java/com/webauthn4j/springframework/security/metadata/RestTemplateAdaptorHttpClient.java b/webauthn4j-spring-security-metadata/src/main/java/com/webauthn4j/springframework/security/metadata/RestTemplateAdaptorHttpClient.java index 39f0b0e5d..42cd5ca36 100644 --- a/webauthn4j-spring-security-metadata/src/main/java/com/webauthn4j/springframework/security/metadata/RestTemplateAdaptorHttpClient.java +++ b/webauthn4j-spring-security-metadata/src/main/java/com/webauthn4j/springframework/security/metadata/RestTemplateAdaptorHttpClient.java @@ -17,9 +17,17 @@ package com.webauthn4j.springframework.security.metadata; import com.webauthn4j.metadata.HttpClient; +import com.webauthn4j.metadata.exception.MDSException; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; +import java.io.IOException; +import java.util.Objects; + /** * An {@link HttpClient} implementation with Spring {@link RestTemplate} */ @@ -36,7 +44,13 @@ public RestTemplateAdaptorHttpClient(RestTemplate restTemplate) { * {@inheritDoc} */ @Override - public String fetch(String url) { - return restTemplate.getForObject(url, String.class); + public Response fetch(String url) { + ResponseEntity entity = restTemplate.getForEntity(url, Resource.class); + Resource resource = Objects.requireNonNull(entity.getBody()); + try { + return new Response(entity.getStatusCode().value(), resource.getInputStream()); + } catch (IOException e) { + throw new MDSException("Failed to fetch " + url, e); + } } } diff --git a/webauthn4j-spring-security-metadata/src/test/java/com/webauthn4j/springframework/security/metadata/RestTemplateAdaptorHttpClientTest.java b/webauthn4j-spring-security-metadata/src/test/java/com/webauthn4j/springframework/security/metadata/RestTemplateAdaptorHttpClientTest.java index 171d88a1b..14f050aaf 100644 --- a/webauthn4j-spring-security-metadata/src/test/java/com/webauthn4j/springframework/security/metadata/RestTemplateAdaptorHttpClientTest.java +++ b/webauthn4j-spring-security-metadata/src/test/java/com/webauthn4j/springframework/security/metadata/RestTemplateAdaptorHttpClientTest.java @@ -18,20 +18,55 @@ import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; +import org.springframework.boot.test.context.TestComponent; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; +import java.io.IOException; + +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; +@RunWith(MockitoJUnitRunner.class) public class RestTemplateAdaptorHttpClientTest { + @Mock + private RestTemplate restTemplate; + + @Mock + ResponseEntity entity; + + @Mock + Resource resource; + @Test - public void fetch_test() { + public void fetch_test() throws IOException { String url = "https://example.com/webauthn/options"; - RestTemplate restTemplate = mock(RestTemplate.class); - when(restTemplate.getForObject(eq(url), eq(String.class))).thenReturn("response"); + when(restTemplate.getForEntity(eq(url), eq(Resource.class))).thenReturn(entity); + when(entity.getBody()).thenReturn(resource); + when(entity.getStatusCode()).thenReturn(HttpStatusCode.valueOf(200)); + when(resource.getInputStream()).thenReturn(null); RestTemplateAdaptorHttpClient httpClient = new RestTemplateAdaptorHttpClient(restTemplate); httpClient.fetch(url); - verify(restTemplate).getForObject(eq(url), eq(String.class)); + verify(restTemplate).getForEntity(eq(url), eq(Resource.class)); } - -} \ No newline at end of file +}