[java-identity-provider COMMIT] /branches/3.1/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicati...

noreply at shibboleth.net noreply at shibboleth.net
Mon Jun 22 07:28:37 EDT 2015


Author: rdw
Date: Mon Jun 22 07:28:37 2015
New Revision: 7586

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=7586&view=rev
Log:
IDP-722 Allow context-params to be used to set idp.home

As a palliative to https://issues.shibboleth.net/jira/browse/IDP-722 merge http://svn.shibboleth.net/view/java-identity-provider?view=revision&revision=7536 into branch 3.1

This allows <context-param>to be used to set idp.home.  Since this can have a space in it, we thus finesse the issue with spaces being treated specially by spring

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

Modified: branches/3.1/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java
URL: http://svn.shibboleth.net/view/java-identity-provider/branches/3.1/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java?rev=7586&r1=7585&r2=7586&view=diff
==============================================================================
--- branches/3.1/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java	(original)
+++ branches/3.1/idp-core/src/main/java/net/shibboleth/idp/spring/IdPPropertiesApplicationContextInitializer.java	Mon Jun 22 07:28:37 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) {

[... 9 lines stripped ...]


More information about the commits mailing list