[java-identity-provider COMMIT] /trunk/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationConte...

noreply at shibboleth.net noreply at shibboleth.net
Tue May 26 22:24:43 EDT 2015


Author: scantor
Date: Tue May 26 22:24:43 2015
New Revision: 7536

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=7536&view=rev
Log:
IDP-715 - Allow idp.home to be any kind of Spring property (e.g. servlet init-param)

Modified:
    trunk/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java

Modified: trunk/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java?rev=7536&r1=7535&r2=7536&view=diff
==============================================================================
--- trunk/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java	(original)
+++ trunk/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java	Tue May 26 22:24:43 2015
@@ -19,6 +19,8 @@
 
 import java.io.IOException;
 import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Properties;
 import java.util.TreeSet;
 import java.util.regex.Pattern;
@@ -60,19 +62,28 @@
     /** Well known search locations. */
     @Nonnull public static final String[] SEARCH_LOCATIONS =
         {
-            System.getProperty("idp.home", "/opt/shibboleth-idp"),
+            "/opt/shibboleth-idp",
         };
 
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(IdPPropertiesApplicationContextInitializer.class);
 
-// Checkstyle: CyclomaticComplexity OFF
+// Checkstyle: CyclomaticComplexity|MethodLength OFF
     /** {@inheritDoc} */
     @Override public void initialize(@Nonnull final ConfigurableApplicationContext applicationContext) {
         log.debug("Initializing application context '{}'", applicationContext);
 
-        log.debug("Attempting to find '{}' at well known locations '{}'", getSearchTarget(), getSearchLocations());
-        for (String searchLocation : getSearchLocations()) {
+        final ArrayList<String> searchLocations = new ArrayList<>();
+        final String homeProperty = applicationContext.getEnvironment().getProperty(IDP_HOME_PROPERTY);
+        if (homeProperty != null) {
+            log.debug("Prepending idp.home property value '{}' to well-known search locations", homeProperty);
+            searchLocations.add(homeProperty);
+        }
+        
+        searchLocations.addAll(Arrays.asList(getSearchLocations()));
+        
+        log.debug("Attempting to find '{}' at search locations '{}'", getSearchTarget(), searchLocations);
+        for (final String searchLocation : searchLocations) {
 
             final String searchPath = searchLocation + getSearchTarget();
 
@@ -88,11 +99,14 @@
                     return;
                 }
 
-                if ("classpath:".equals(searchLocation) || (resource instanceof ClassPathResource)) {
-                    setIdPHomeProperty(searchLocation, properties);
-                } else {
-                    final String searchLocationAbsolutePath = Paths.get(searchLocation).toAbsolutePath().toString();
-                    setIdPHomeProperty(searchLocationAbsolutePath, properties);
+                // See if we need to set idp.home as a property ourselves...
+                if (homeProperty == null) {
+                    if ("classpath:".equals(searchLocation) || (resource instanceof ClassPathResource)) {
+                        setIdPHomeProperty(searchLocation, properties);
+                    } else {
+                        final String searchLocationAbsolutePath = Paths.get(searchLocation).toAbsolutePath().toString();
+                        setIdPHomeProperty(searchLocationAbsolutePath, properties);
+                    }
                 }
                 
                 // Load any additional property sources.
@@ -131,7 +145,7 @@
 
         log.warn("Unable to find '{}' at well known locations '{}'", getSearchTarget(), getSearchLocations());
     }
-// Checkstyle: CyclomaticComplexity ON
+// Checkstyle: CyclomaticComplexity|MethodLength ON
 
     /**
      * Get the target resource to be searched for {@link #IDP_PROPERTIES}.
@@ -206,8 +220,7 @@
 
     /**
      * 
-     * Set the {@link #IDP_HOME_PROPERTY} property to the given path if not already set and if not set as a system
-     * property.
+     * Set the {@link #IDP_HOME_PROPERTY} property to the given path if not already set.
      * 
      * The property value will be normalized by calling {@link #normalizePath(String)}.
      * 
@@ -223,12 +236,6 @@
             return;
         }
 
-        if (System.getProperty(IDP_HOME_PROPERTY) != null) {
-            log.debug("Will not set '{}' property because it is already set as a system property '{}'",
-                    IDP_HOME_PROPERTY, System.getProperty(IDP_HOME_PROPERTY));
-            return;
-        }
-
         final String normalizedPath = normalizePath(path);
 

[... 2 lines stripped ...]


More information about the commits mailing list