[java-oidc-common] branch main updated: JCOMOIDC-102 - Implement metadata cache loading strategy for generic resources
Henri Mikkonen
henri.mikkonen at iki.fi
Fri Mar 8 11:10:01 UTC 2024
This is an automated email from the git hooks/post-receive script.
hjmikkon 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=0163085b7ba27de0f1ef5dcd9310f7c8e42365d6
The following commit(s) were added to refs/heads/main by this push:
new 0163085 JCOMOIDC-102 - Implement metadata cache loading strategy for generic resources
0163085 is described below
commit 0163085b7ba27de0f1ef5dcd9310f7c8e42365d6
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Fri Mar 8 13:09:40 2024 +0200
JCOMOIDC-102 - Implement metadata cache loading strategy for generic resources
https://shibboleth.atlassian.net/browse/JCOMOIDC-102
Added a new version of buildFileLoadingMetadataPolicyResolver that
allows injection of default contents if the resource is null. The
default contents are injected via ByteArrayResource wrapped inside
ConditionalResource. The latter was needed as thr former doesn't
provide proper lastModified() implementation required for the
resources by our code.
---
.../impl/MetadataPolicyLookupStrategyFactory.java | 52 ++++++++++++++++++++--
1 file changed, 49 insertions(+), 3 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 a7f6b98..46d1425 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
@@ -23,6 +23,7 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import org.opensaml.profile.context.ProfileRequestContext;
+import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
@@ -35,6 +36,7 @@ import net.shibboleth.oidc.profile.config.navigate.ResolverBasedRegistrationMeta
import net.shibboleth.shared.annotation.ParameterName;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.resolver.CriteriaSet;
+import net.shibboleth.shared.spring.resource.ConditionalResource;
import net.shibboleth.shared.spring.resource.PreferFileSystemResourceLoader;
/**
@@ -70,14 +72,58 @@ public class MetadataPolicyLookupStrategyFactory {
final Function<ProfileRequestContext, CriteriaSet> criteriaSetLookupStrategy,
@ParameterName(name="id") @Nonnull final String id) throws ComponentInitializationException, IOException{
+ return buildFileLoadingMetadataPolicyResolver(resource, cacheSpec, criteriaSetLookupStrategy, id, null);
+ }
+
+ /**
+ * Build a Function that maps a profile request context to a map of metadata policies. The map is resolved
+ * 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 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 id the identifier/name for the back-end cache created
+ * @param defaultContents the default contents for the resource if resource was null or empty.
+ *
+ * @return the function
+ *
+ * @throws ComponentInitializationException on error.
+ * @throws IOException on error.
+ *
+ * @since 3.1.0
+ */
+ @Nonnull public Function<ProfileRequestContext,Map<String,MetadataPolicy>> buildFileLoadingMetadataPolicyResolver(
+ @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,
+ @ParameterName(name="defaultContents") @Nullable final String defaultContents)
+ throws ComponentInitializationException, IOException{
+
Resource fileResource = null;
+ final LoadingStrategy loadingStrategy;
if (resource != null && !resource.isEmpty()) {
final ResourceLoader resourceLoader = new PreferFileSystemResourceLoader();
fileResource = resourceLoader.getResource(resource);
+ loadingStrategy = new DefaultFileLoadingStrategy(fileResource);
+ } else {
+ if (defaultContents == null) {
+ loadingStrategy = new DefaultFileLoadingStrategy(fileResource);
+ } else {
+ final byte[] contents = defaultContents.getBytes("UTF-8");
+ assert contents != null;
+ final ByteArrayResource staticResource = new ByteArrayResource(contents);
+ final ConditionalResource conditionalResource = new ConditionalResource(staticResource);
+ conditionalResource.setDefaultContent(defaultContents);
+ conditionalResource.setId("Static conditional resource");
+ conditionalResource.initialize();
+ loadingStrategy = new DefaultResourceLoadingStrategy(conditionalResource);
+ }
}
- @Nonnull final DefaultFileLoadingStrategy fileStrategy = new DefaultFileLoadingStrategy(fileResource);
- return buildMetadataPolicyResolver(fileStrategy, cacheSpec, criteriaSetLookupStrategy, id);
-
+ return buildMetadataPolicyResolver(loadingStrategy, cacheSpec, criteriaSetLookupStrategy, id);
}
/**
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list