[java-oidc-common] branch main updated: Fix method parameter name injection in metadata policy strategy
Phil Smart
philip.smart at jisc.ac.uk
Wed Mar 9 12:16:24 UTC 2022
This is an automated email from the git hooks/post-receive script.
philsmart pushed a commit to branch main
in repository java-oidc-common.
View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=f7a42ef9adb3a335eb10053d05eeb7620be06af3
The following commit(s) were added to refs/heads/main by this push:
new f7a42ef Fix method parameter name injection in metadata policy strategy
f7a42ef is described below
commit f7a42ef9adb3a335eb10053d05eeb7620be06af3
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Wed Mar 9 12:16:19 2022 +0000
Fix method parameter name injection in metadata policy strategy
---
.../impl/MetadataPolicyLookupStrategyFactory.java | 26 ++++++++++++++--------
.../MetadataPolicyLookupStrategyFactoryTest.java | 6 ++---
...etadata-policy-lookup-strategy-factory-test.xml | 9 ++++----
3 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactory.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactory.java
index 4f4a852..6752267 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactory.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactory.java
@@ -10,7 +10,9 @@ import javax.annotation.concurrent.ThreadSafe;
import org.opensaml.profile.context.ProfileRequestContext;
import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import net.shibboleth.ext.spring.resource.PreferFileSystemResourceLoader;
import net.shibboleth.oidc.metadata.policy.MetadataPolicy;
import net.shibboleth.oidc.metadata.policy.MetadataPolicyResolver;
import net.shibboleth.oidc.metadata.policy.impl.OIDCMetadataPolicyResolver;
@@ -34,10 +36,10 @@ public class MetadataPolicyLookupStrategyFactory {
* from a newly instantiated {@link MetadataPolicyResolver}. The Resolver calls a new {@link BatchMetadataCache}
* which is hard-wired to use a default file loading strategy with the file resource supplied.
*
- * @param file the file to inject into the loading strategy
- * @param spec the metadata cache specification
+ * @param resource the file to inject into the loading strategy. Can be null or empty.
+ * @param cacheSpec the metadata cache specification
* @param criteriaSetLookupStrategy the lookup strategy for the criteria set used for the metadata policy resolver.
- * @param cacheId the identifier/name for the back-end cache created
+ * @param id the identifier/name for the back-end cache created
*
* @return the function
*
@@ -45,19 +47,25 @@ public class MetadataPolicyLookupStrategyFactory {
* @throws IOException on error.
*/
public Function<ProfileRequestContext,Map<String,MetadataPolicy>> buildFileLoadingMetadataPolicyResolver(
- @ParameterName(name="resource") @Nonnull final Resource file,
- @ParameterName(name="cacheSpec") @Nonnull final BatchMetadataCacheBuilderSpec<String, Map<String, MetadataPolicy>> spec,
+ @ParameterName(name="resource") @Nullable final String resource,
+ @ParameterName(name="cacheSpec") @Nonnull final BatchMetadataCacheBuilderSpec<String, Map<String, MetadataPolicy>> cacheSpec,
@ParameterName(name="criteriaSetLookupStrategy") @Nullable final Function<ProfileRequestContext, CriteriaSet> criteriaSetLookupStrategy,
@ParameterName(name="id") @Nonnull final String id) throws ComponentInitializationException, IOException{
final BatchMetadataCacheBuilder.Builder<String, Map<String, MetadataPolicy>> builder =
new BatchMetadataCacheBuilder.Builder<>();
- final DefaultFileLoadingStrategy fileStrategy = new DefaultFileLoadingStrategy(file);
- spec.setLoadingStrategy(fileStrategy);
- spec.setCacheId(id + "-cache");
+ Resource fileResource = null;
+ if (resource != null && !resource.isEmpty()) {
+ final ResourceLoader resourceLoader = new PreferFileSystemResourceLoader();
+ fileResource = resourceLoader.getResource(resource);
+ }
+
+ final DefaultFileLoadingStrategy fileStrategy = new DefaultFileLoadingStrategy(fileResource);
+ cacheSpec.setLoadingStrategy(fileStrategy);
+ cacheSpec.setCacheId(id + "-cache");
- final BatchMetadataCache<String, Map<String, MetadataPolicy>> cache = builder.build(spec);
+ final BatchMetadataCache<String, Map<String, MetadataPolicy>> cache = builder.build(cacheSpec);
final OIDCMetadataPolicyResolver resolver = new OIDCMetadataPolicyResolver(cache);
resolver.setId(id + "-resolver");
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactoryTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactoryTest.java
index 87093dc..2311e18 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactoryTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/cache/impl/MetadataPolicyLookupStrategyFactoryTest.java
@@ -8,10 +8,7 @@ import java.time.Instant;
import java.util.Collections;
import java.util.Map;
-import org.mockito.Mockito;
-import org.springframework.context.support.AbstractRefreshableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
-import org.springframework.core.io.Resource;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -60,7 +57,8 @@ public class MetadataPolicyLookupStrategyFactoryTest {
/* Test the factory creates the function correctly. Not throwing an exception is likely enough to test this.*/
@Test
public void testFactoryBuild_FileBased_Success() throws ComponentInitializationException, IOException {
- final var createdFunction = factory.buildFileLoadingMetadataPolicyResolver(Mockito.mock(Resource.class),spec, null, "Mock");
+ final var createdFunction =
+ factory.buildFileLoadingMetadataPolicyResolver(null,spec, null, "Mock");
assertNotNull(createdFunction);
}
diff --git a/oidc-common-metadata-impl/src/test/resources/net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test.xml b/oidc-common-metadata-impl/src/test/resources/net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test.xml
index f9d8e43..b9dd1d9 100644
--- a/oidc-common-metadata-impl/src/test/resources/net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test.xml
+++ b/oidc-common-metadata-impl/src/test/resources/net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test.xml
@@ -44,18 +44,19 @@
<bean id="shibboleth.oidc.test.MetadataPolicyLookupStrategy" abstract="true"
factory-bean="shibboleth.oidc.test.MetadataPolicyLookupStrategyFactory"
factory-method="buildFileLoadingMetadataPolicyResolver"
- c:_1-ref="shibboleth.oidc.test.BatchMetadataCacheBuilderSpec"
- c:_2="#{null}"/>
+ c:cacheSpec-ref="shibboleth.oidc.test.BatchMetadataCacheBuilderSpec"
+ c:criteriaSetLookupStrategy="#{null}"
+ />
<bean id="shibboleth.oidc.test.MetadataPolicyLookupStrategyOne"
parent="shibboleth.oidc.test.MetadataPolicyLookupStrategy"
- c:_0="classpath:net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test-dummy-file.txt"
+ c:resource="classpath:net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test-dummy-file.txt"
c:id="PolicyOne" />
<bean id="shibboleth.oidc.test.MetadataPolicyLookupStrategyTwo"
parent="shibboleth.oidc.test.MetadataPolicyLookupStrategy"
- c:_0="classpath:net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test-dummy-file.txt"
+ c:resource="classpath:net/shibboleth/oidc/metadata/impl/metadata-policy-lookup-strategy-factory-test-dummy-file.txt"
c:id="PolicyTwo" />
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list