[java-identity-provider COMMIT] in /trunk: idp-conf/src/test/java/net/shibboleth/idp/test/flows/paths/IdPPropertiesAp...

noreply at shibboleth.net noreply at shibboleth.net
Sat Nov 7 14:50:30 EST 2015


Author: tzeller
Date: Sat Nov  7 14:50:30 2015
New Revision: 7968

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=7968&view=rev
Log:
IDP-812 - Add fail fast to app ctx initializer.

Cover additional potential error conditions.
Checkpoint tests.

Added:
    trunk/idp-conf/src/test/java/net/shibboleth/idp/test/flows/paths/IdPPropertiesApplicationContextInitializerTest.java   (with props)
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=7968&r1=7967&r2=7968&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	Sat Nov  7 14:50:30 2015
@@ -28,6 +28,7 @@
 
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 import org.slf4j.Logger;
@@ -44,6 +45,8 @@
  * An {@link ApplicationContextInitializer} which attempts to add a properties file property source to the application
  * context environment. The 'conf/idp.properties' file is searched for in well known locations. The 'idp.home' property
  * will be set to the normalized search location if the properties file is found and the property is not already set.
+ * 
+ * TODO Doc fail fast.
  */
 public class IdPPropertiesApplicationContextInitializer
         implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@@ -59,6 +62,9 @@
 
     /** Well known search locations. */
     @Nonnull public static final String[] SEARCH_LOCATIONS = {"/opt/shibboleth-idp",};
+    
+    /** Property controlling whether to fail fast. */
+    @Nonnull public static final String FAILFAST_PROPERTY = "idp.initializer.failFast";
 
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(IdPPropertiesApplicationContextInitializer.class);
@@ -82,8 +88,13 @@
 
                 final Properties properties = loadProperties(null, resource);
                 if (properties == null) {
-                    log.warn("Unable to load properties from resource '{}'", resource);
-                    return;
+                    if (isFailFast(applicationContext)) {
+                        log.error("Unable to load properties from resource '{}'", resource);
+                        throw new ConstraintViolationException("Unable to load properties from resource");
+                    } else {
+                        log.warn("Unable to load properties from resource '{}'", resource);
+                        return;
+                    }
                 }
 
                 if ("classpath:".equals(searchLocation) || (resource instanceof ClassPathResource)) {
@@ -99,11 +110,18 @@
 
                 appendPropertySource(applicationContext, resource.toString(), properties);
 
+                // Search target was found and initialization was successful, we're done.
                 return;
             }
         }
 
-        log.warn("Unable to find '{}' at well known locations '{}'", getSearchTarget(), getSearchLocations());
+        if (isFailFast(applicationContext)) {
+            log.error("Unable to find '{}' at well known locations '{}'", getSearchTarget(), getSearchLocations());
+            throw new ConstraintViolationException(
+                    "Unable to find '" + getSearchTarget() + "' at well known locations");
+        } else {
+            log.warn("Unable to find '{}' at well known locations '{}'", getSearchTarget(), getSearchLocations());
+        }
     }
 
     /**
@@ -129,15 +147,16 @@
      * {@link IDP_HOME_PROPERTY} in the application context. Defaults to the well-known search locations returned from
      * {@link #getSearchLocations()}.
      * 
+     * TODO Doc fail fast.
+     * 
      * @param applicationContext the application context
      * @return the search locations used to search for the target
-     * @throws net.shibboleth.utilities.java.support.logic.ConstraintViolationException if the user-defined search
-     *             location is empty or ends with '/'
+     * @throws ConstraintViolationException if the user-defined search location is empty or ends with '/'
      */
     @Nonnull public String[] selectSearchLocations(@Nonnull final ConfigurableApplicationContext applicationContext) {
         Constraint.isNotNull(applicationContext, "Application context cannot be null");

[... 50 lines stripped ...]


More information about the commits mailing list