[java-identity-provider] branch main updated: IDP-1888 - Add duplicate property detection to the context initializer

Scott Cantor cantor.2 at osu.edu
Tue Mar 8 22:14:27 UTC 2022


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=a3aa9b4ccf27233bbac9a5f1c8d1ae40d7488656

The following commit(s) were added to refs/heads/main by this push:
     new a3aa9b4cc IDP-1888 - Add duplicate property detection to the context initializer
a3aa9b4cc is described below

commit a3aa9b4ccf27233bbac9a5f1c8d1ae40d7488656
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Mar 8 17:14:23 2022 -0500

    IDP-1888 - Add duplicate property detection to the context initializer
    
    https://shibboleth.atlassian.net/browse/IDP-1888
---
 ...IdPPropertiesApplicationContextInitializer.java | 31 ++++++++++++++++------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java b/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java
index 6962ef5e7..d84600625 100644
--- a/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java
+++ b/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java
@@ -19,6 +19,7 @@ package net.shibboleth.idp.spring;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.nio.file.FileVisitOption;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -26,6 +27,7 @@ import java.nio.file.Paths;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Map;
 import java.util.Properties;
 import java.util.TreeSet;
 import java.util.function.BiPredicate;
@@ -43,7 +45,6 @@ import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.core.env.PropertiesPropertySource;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PropertiesLoaderUtils;
 
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 import net.shibboleth.utilities.java.support.logic.Constraint;
@@ -198,14 +199,28 @@ public class IdPPropertiesApplicationContextInitializer
     @Nullable public Properties loadProperties(@Nullable final Properties sink, @Nonnull final Resource resource) {
         Constraint.isNotNull(resource, "Resource cannot be null");
         try {
-            final Properties properties;
-            if (sink != null) {
-                properties = sink;
-            } else {
-                properties = new Properties();
+            final Properties holder = new Properties();
+            try (final InputStream is = resource.getInputStream()) {
+                final String filename = resource.getFilename();
+                if (filename != null && filename.endsWith(".xml")) {
+                    holder.loadFromXML(is);
+                } else {
+                    holder.load(is);
+                }
             }
-            PropertiesLoaderUtils.fillProperties(properties, resource);
-            return properties;
+            
+            if (sink == null) {
+                return holder;
+            }
+
+            // Check for duplicates before adding.
+            for (final Map.Entry<Object,Object> entry : holder.entrySet()) {
+                if (sink.putIfAbsent(entry.getKey(), entry.getValue()) != null) {
+                    LOG.warn("Ignoring duplicate property '{}'", entry.getKey());
+                }
+            }
+
+            return sink;
         } catch (final IOException e) {
             LOG.warn("Unable to load properties from resource '{}'", resource, e);
             return null;

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


More information about the commits mailing list