[java-idp-plugin-webauthn] branch main updated: JWEBAUTHN-21 - IdP does not start with a non-existing fido metadata cache file
Phil Smart
philip.smart at jisc.ac.uk
Mon Sep 16 14:47:50 UTC 2024
This is an automated email from the git hooks/post-receive script.
philsmart pushed a commit to branch main
in repository java-idp-plugin-webauthn.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-webauthn.git;a=commit;h=09d47a3123fea7186276db47d454242c4d318555
The following commit(s) were added to refs/heads/main by this push:
new 09d47a3 JWEBAUTHN-21 - IdP does not start with a non-existing fido metadata cache file
09d47a3 is described below
commit 09d47a3123fea7186276db47d454242c4d318555
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Mon Sep 16 15:47:47 2024 +0100
JWEBAUTHN-21 - IdP does not start with a non-existing fido metadata
cache file
- Update to use indirected Shib Resource over Spring Resource.
https://shibboleth.atlassian.net/browse/JWEBAUTHN-21
---
.../metadata/FidoMetadataServiceFactory.java | 11 +++++++----
.../FidoMetadataServiceResolverFactoryTest.java | 21 +++++++++++++--------
2 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/metadata/FidoMetadataServiceFactory.java b/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/metadata/FidoMetadataServiceFactory.java
index 2d548de..d746e3c 100644
--- a/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/metadata/FidoMetadataServiceFactory.java
+++ b/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/metadata/FidoMetadataServiceFactory.java
@@ -17,6 +17,7 @@ package net.shibboleth.idp.plugin.authn.webauthn.metadata;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.security.cert.CRL;
import java.security.cert.CRLException;
@@ -32,7 +33,7 @@ import org.opensaml.security.x509.X509Support;
import org.slf4j.Logger;
import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.FactoryBean;
-import org.springframework.core.io.Resource;
+import org.springframework.util.FileCopyUtils;
import com.yubico.fido.metadata.FidoMetadataDownloader;
import com.yubico.fido.metadata.FidoMetadataService;
@@ -44,6 +45,7 @@ import net.shibboleth.shared.component.AbstractIdentifiableInitializableComponen
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.resource.Resource;
/**
@@ -90,8 +92,9 @@ public class FidoMetadataServiceFactory extends AbstractIdentifiableInitializabl
final Resource localMetadataBlobFile = getMetadataBlobFile();
final Resource localMetadataCacheFile = getCacheFile();
- if (localMetadataBlobFile != null) {
- log.debug("{}: Loading FIDO metadata blob from local file '{}'",getId(), metadataBlobFile);
+ if (localMetadataBlobFile != null && localMetadataBlobFile.exists() && localMetadataBlobFile.isReadable()) {
+ log.debug("{}: Loading FIDO metadata blob from local file '{}'",getId(),
+ localMetadataBlobFile.getFilename());
downloader = FidoMetadataDownloader.builder()
.expectLegalHeader(getExpectedLegalHeaders())
.useTrustRoot(X509Support.decodeCertificate(getTrustRootFile().getFile()))
@@ -160,7 +163,7 @@ public class FidoMetadataServiceFactory extends AbstractIdentifiableInitializabl
if (!file.exists()) {
throw new FileNotFoundException("Metadata blob file does not exist");
}
- return file.getContentAsString(StandardCharsets.UTF_8);
+ return FileCopyUtils.copyToString(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8));
}
diff --git a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/metadata/FidoMetadataServiceResolverFactoryTest.java b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/metadata/FidoMetadataServiceResolverFactoryTest.java
index 13e0cd7..0371646 100644
--- a/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/metadata/FidoMetadataServiceResolverFactoryTest.java
+++ b/webauthn-impl/src/test/java/net/shibboleth/idp/plugin/authn/webauthn/metadata/FidoMetadataServiceResolverFactoryTest.java
@@ -16,20 +16,23 @@ package net.shibboleth.idp.plugin.authn.webauthn.metadata;
import static org.testng.Assert.assertNotNull;
+import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.nio.charset.StandardCharsets;
import org.springframework.beans.FatalBeanException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
+import org.springframework.util.FileCopyUtils;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.yubico.fido.metadata.FidoMetadataService;
import net.shibboleth.idp.plugin.authn.webauthn.impl.AbstractWebAuthnTest;
+import net.shibboleth.shared.resource.Resource;
+import net.shibboleth.shared.spring.resource.ResourceHelper;
import okhttp3.mockwebserver.MockWebServer;
/**
@@ -51,18 +54,18 @@ public class FidoMetadataServiceResolverFactoryTest extends AbstractWebAuthnTest
System.setProperty("com.sun.security.enableCRLDP", "true");
factory = new FidoMetadataServiceFactory();
- factory.setCacheFile(new FileSystemResource("cache-file.bin"));
- factory.setTrustRootFile(new ClassPathResource("root-r3.crt"));
+ factory.setCacheFile(ResourceHelper.of(new FileSystemResource("cache-file.bin")));
+ factory.setTrustRootFile(ResourceHelper.of(new ClassPathResource("root-r3.crt")));
factory.setExpectedLegalHeaders(new String[]{"headers"});
factory.setId("Test metadata factory");
- httpMetadataBlobResource = new ClassPathResource("fido-metadata.bin");
+ httpMetadataBlobResource = ResourceHelper.of(new ClassPathResource("fido-metadata.bin"));
}
@Test(enabled = false)
public void testSuccessfullMetadataLoadFromFile() throws Exception {
// Setting the local metadata blob file will force the factory to load from the local file
- factory.setMetadataBlobFile(new ClassPathResource("fido-metadata.bin"));
+ factory.setMetadataBlobFile(ResourceHelper.of(new ClassPathResource("fido-metadata.bin")));
factory.initialize();
final FidoMetadataService resolver = factory.getObject();
assertNotNull(resolver);
@@ -72,7 +75,7 @@ public class FidoMetadataServiceResolverFactoryTest extends AbstractWebAuthnTest
@Test(expectedExceptions = FatalBeanException.class, enabled = false)
public void testUnsuccessfull_RequiresCacheFileWhenURLUsed() throws Exception {
// Setting the local metadata blob file will force the factory to load from the local file
- factory.setMetadataBlobUrl(new UrlResource("https://localhost:9918/"));
+ factory.setMetadataBlobUrl(ResourceHelper.of(new UrlResource("https://localhost:9918/")));
factory.setCacheFile(null);
factory.initialize();
final FidoMetadataService resolver = factory.getObject();
@@ -86,12 +89,14 @@ public class FidoMetadataServiceResolverFactoryTest extends AbstractWebAuthnTest
public void testSuccessfullMetadataLoadFromURL() throws Exception {
final MockWebServer mockOPServer = createSimpleServer();
- queueMockServerResponse(mockOPServer, 200, httpMetadataBlobResource.getContentAsString(StandardCharsets.UTF_8),
+ queueMockServerResponse(mockOPServer, 200,
+ FileCopyUtils.copyToString(new InputStreamReader(httpMetadataBlobResource.getInputStream(),
+ StandardCharsets.UTF_8)),
"application/octet-stream");
mockOPServer.start(9918);
- factory.setMetadataBlobUrl(new UrlResource("https://localhost:9918/"));
+ factory.setMetadataBlobUrl(ResourceHelper.of(new UrlResource("https://localhost:9918/")));
factory.initialize();
final FidoMetadataService resolver = factory.getObject();
assertNotNull(resolver);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list