[java-identity-provider] branch main updated: Support for optional resources.

Scott Cantor cantor.2 at osu.edu
Tue Oct 13 19:00:21 UTC 2020


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=12ff1eff53a46beff1905c45b8761badfd9b0b29

The following commit(s) were added to refs/heads/main by this push:
       new  12ff1eff5 Support for optional resources.
12ff1eff5 is described below

commit 12ff1eff53a46beff1905c45b8761badfd9b0b29
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Oct 13 15:00:17 2020 -0400

    Support for optional resources.
---
 .../shibboleth/idp/module/AbstractIdPModule.java    | 21 ++++++++++++++++++---
 .../java/net/shibboleth/idp/module/IdPModule.java   |  9 ++++++++-
 .../idp/module/PropertyDrivenIdPModule.java         |  8 +++++++-
 3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java b/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java
index f58cf1271..b61f39dc5 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java
@@ -101,6 +101,11 @@ public abstract class AbstractIdPModule implements IdPModule {
         }
 
         for (final ModuleResource resource : moduleResources) {
+            
+            if (resource.isOptional()) {
+                continue;
+            }
+
             final Path resolved = moduleContext.getIdPHome().resolve(resource.getDestination());
             log.debug("Module {}: resolved resource destination {}", getId(), resolved);
             if (!resolved.toFile().exists()) {
@@ -190,19 +195,24 @@ public abstract class AbstractIdPModule implements IdPModule {
         
         /** Replacement criteria. */
         private final boolean replace;
-        
+
+        /** Optional criteria. */
+        private final boolean optional;
+
         /**
          * Constructor.
          *
          * @param src source
          * @param dest destination
          * @param shouldReplace whether to replace when enabling
+         * @param isOptional whether the resource is optional
          */
         public BasicModuleResource(@Nonnull @NotEmpty final String src, @Nonnull final Path dest,
-                final boolean shouldReplace) {
+                final boolean shouldReplace, final boolean isOptional) {
             source = Constraint.isNotNull(StringSupport.trimOrNull(src), "Source cannot be null");
             destination = Constraint.isNotNull(dest, "Destination cannot be null");
             replace = shouldReplace;
+            optional = isOptional;
         }
 
         /** {@inheritDoc} */
@@ -233,7 +243,12 @@ public abstract class AbstractIdPModule implements IdPModule {
         public boolean isReplace() {
             return replace;
         }
-        
+
+        /** {@inheritDoc} */
+        public boolean isOptional() {
+            return optional;
+        }
+
         /**
          * Gets whether the resource has been altered at its destination from the source material.
          * 
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/module/IdPModule.java b/idp-admin-api/src/main/java/net/shibboleth/idp/module/IdPModule.java
index 2225eb7a2..20e09ebac 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/module/IdPModule.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/module/IdPModule.java
@@ -148,7 +148,14 @@ public interface IdPModule extends IdentifiedComponent {
          * @return true iff the resource should be replaced with the original preserved
          */
         public boolean isReplace();
-    }
+
+        /**
+         * Gets whether the resource, if missing, should not act as a module-disabled signal.
+         * 
+         * @return true iff the resource may be removed by a deployer without disabling the module
+         */
+        public boolean isOptional();
+}
  
     /** Resource management outcome. */
     public enum ResourceResult {
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/module/PropertyDrivenIdPModule.java b/idp-admin-api/src/main/java/net/shibboleth/idp/module/PropertyDrivenIdPModule.java
index 0c2ff37c0..c2e16ebdf 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/module/PropertyDrivenIdPModule.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/module/PropertyDrivenIdPModule.java
@@ -70,6 +70,9 @@ public class PropertyDrivenIdPModule extends AbstractIdPModule {
     /** Suffix of property for resource replacement. */
     @Nonnull @NotEmpty public static final String MODULE_REPLACE_PROPERTY = ".replace";
 
+    /** Suffix of property for resource optionality. */
+    @Nonnull @NotEmpty public static final String MODULE_OPTIONAL_PROPERTY = ".optional";
+
     /** Suffix of property for module post-enable message. */
     @Nonnull @NotEmpty public static final String MODULE_POSTENABLE_PROPERTY = ".postenable";
 
@@ -171,6 +174,9 @@ public class PropertyDrivenIdPModule extends AbstractIdPModule {
                 final Boolean replace = Boolean.valueOf(
                         moduleProperties.getProperty(getId() + renumstr + MODULE_REPLACE_PROPERTY, "false"));
                 
+                final Boolean optional = Boolean.valueOf(
+                        moduleProperties.getProperty(getId() + renumstr + MODULE_OPTIONAL_PROPERTY, "false"));
+                
                 final Path destPath = Path.of(dest);
                 if (dest.contains("..") || destPath.isAbsolute() || destPath.startsWith("/")) {
                     throw new ModuleException("Module contained a suspect resource destination");
@@ -180,7 +186,7 @@ public class PropertyDrivenIdPModule extends AbstractIdPModule {
                     requireHttpClient = src.startsWith("https://") || src.startsWith("http://");
                 }
                 
-                resources.add(new BasicModuleResource(src, destPath, replace));
+                resources.add(new BasicModuleResource(src, destPath, replace, optional));
             }
             
             setResources(resources);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list