Class IdPPropertiesApplicationContextInitializer

java.lang.Object
net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer
All Implemented Interfaces:
ApplicationContextInitializer<ConfigurableApplicationContext>
Direct Known Subclasses:
MetadataGeneratorTask.Initializer, V4Install.Initializer

public class IdPPropertiesApplicationContextInitializer
extends Object
implements ApplicationContextInitializer<ConfigurableApplicationContext>
An ApplicationContextInitializer which appends properties to the application context's environment. Properties are loaded from IDP_PROPERTIES as well as additional property files specified by IDP_ADDITIONAL_PROPERTY if set, or if absent, by locating all files under idp.home/conf/ that end in ".properties". The IDP_PROPERTIES file is searched for in the well location returned by getSearchLocation(). If not already set, the IDP_HOME_PROPERTY will be set to the first search location in which the IDP_PROPERTIES file is found. A ConstraintViolationException will be thrown if the property files can not be found or loaded and isFailFast(ConfigurableApplicationContext) returns true.
  • Field Details

    • IDP_HOME_PROPERTY

      @Nonnull @NotEmpty public static final String IDP_HOME_PROPERTY
      IdP home property.
      See Also:
      Constant Field Values
    • IDP_ADDITIONAL_PROPERTY

      @Nonnull @NotEmpty public static final String IDP_ADDITIONAL_PROPERTY
      Property that points to more property sources.
      See Also:
      Constant Field Values
    • IDP_AUTOSEARCH_PROPERTY

      @Nonnull @NotEmpty public static final String IDP_AUTOSEARCH_PROPERTY
      Property that controls auto-search for property sources.
      See Also:
      Constant Field Values
    • IDP_PROPERTIES

      @Nonnull public static final String IDP_PROPERTIES
      Target resource to be searched for.
      See Also:
      Constant Field Values
    • SEARCH_LOCATION

      @Nonnull public static final String SEARCH_LOCATION
      Well known search location.
      See Also:
      Constant Field Values
    • FAILFAST_PROPERTY

      @Nonnull public static final String FAILFAST_PROPERTY
      Property controlling whether to fail fast.
      See Also:
      Constant Field Values
    • LOG

      @Nonnull private static final org.slf4j.Logger LOG
      Class logger.
  • Constructor Details

    • IdPPropertiesApplicationContextInitializer

      public IdPPropertiesApplicationContextInitializer()
  • Method Details

    • initialize

      public void initialize​(@Nonnull ConfigurableApplicationContext applicationContext)
      Specified by:
      initialize in interface ApplicationContextInitializer<ConfigurableApplicationContext>
    • getSearchTarget

      @Nonnull public String getSearchTarget()
      Get the target resource to be searched for. Defaults to IDP_PROPERTIES.
      Returns:
      the target resource to be searched for
    • getSearchLocation

      @Nonnull public String getSearchLocation()
      Get the well known search location. Defaults to SEARCH_LOCATION.
      Returns:
      the well known search locations
    • selectSearchLocation

      @Nonnull public String selectSearchLocation​(@Nonnull ConfigurableApplicationContext applicationContext)
      Select the location used to search for the target. Prefers the user-defined search location defined by IDP_HOME_PROPERTY in the application context. Defaults to the well-known search location returned from getSearchLocation().
      Parameters:
      applicationContext - the application context
      Returns:
      the search location used to search for the target
      Throws:
      ConstraintViolationException - if the user-defined search location is empty or ends with '/' and isFailFast(ConfigurableApplicationContext) is true
    • loadProperties

      @Nullable public Properties loadProperties​(@Nullable Properties sink, @Nonnull Resource resource)
      Load properties from the resource.
      Parameters:
      sink - if non-null use this instance as the target
      resource - the resource
      Returns:
      properties loaded from the resource or null if loading failed
    • getAdditionalSources

      public static Collection<String> getAdditionalSources​(@Nonnull String searchLocation, @Nonnull Properties properties)
      Find out all the additional property files we need to load.
      Parameters:
      searchLocation - Where to search from
      properties - the content of idp.properties so far
      Returns:
      a collection of paths
    • loadAdditionalPropertySources

      public void loadAdditionalPropertySources​(@Nonnull ConfigurableApplicationContext applicationContext, @Nonnull String searchLocation, @Nonnull Properties properties)
      Load additional property sources. File names of additional property sources are defined by IDP_ADDITIONAL_PROPERTY, and are resolved relative to the given search location.
      Parameters:
      applicationContext - the application context
      searchLocation - the location from which additional property sources are resolved
      properties - the properties to be filled with additional property sources
      Throws:
      ConstraintViolationException - if an error occurs loading the additional property sources and isFailFast(ConfigurableApplicationContext) is true
    • logProperties

      public void logProperties​(@Nonnull Properties properties)
      Log property names and values at debug level, suppressing properties whose name matches 'password', 'credential', 'secret', or 'salt'.
      Parameters:
      properties - the properties to log
    • appendPropertySource

      public void appendPropertySource​(@Nonnull ConfigurableApplicationContext applicationContext, @Nonnull String name, @Nonnull Properties properties)
      Add property source to the application context environment with lowest precedence.
      Parameters:
      applicationContext - the application context
      name - the name of the property source to be added to the application context
      properties - the properties added to the application context
    • setIdPHomeProperty

      public void setIdPHomeProperty​(@Nonnull String path, @Nonnull Properties properties)
      Set the IDP_HOME_PROPERTY property to the given path if not already set.
      Parameters:
      path - the property value
      properties - the properties
    • isFailFast

      public boolean isFailFast​(@Nonnull ConfigurableApplicationContext applicationContext)
      Whether we fail immediately if the config is bogus. Defaults to true. Controlled by the value of the FAILFAST_PROPERTY. This functionality is reserved for use in tests where is is usually used to allow tests to be run in the presence of partial configuration.
      Parameters:
      applicationContext - the application context
      Returns:
      whether we fail immediately if the config is faulty or incomplete.