Package net.shibboleth.shared.spring.context

# Class AbstractPropertiesApplicationContextInitializer

java.lang.Object
net.shibboleth.shared.spring.context.AbstractPropertiesApplicationContextInitializer

All Implemented Interfaces:
  `ApplicationContextInitializer<ConfigurableApplicationContext>`

public abstract class AbstractPropertiesApplicationContextInitializer extends Object implements ApplicationContextInitializer<ConfigurableApplicationContext>
An `ApplicationContextInitializer` which appends properties to the application context's environment.

Properties are loaded from `getSearchTarget()` as well as additional property files specified by `getAdditionalPropertiesPropertyName()` and/or by locating all files under a designated location that end in ".properties".

The `getSearchTarget()` file is searched for in a well-known location returned by `getSearchLocation()`.

If not already set, `getHomePropertyName()` will be set to the first search location in which the `getSearchTarget()` file is found.

A `ConstraintViolationException` will be thrown if the property files can not be found or loaded and `isFailFast(ConfigurableApplicationContext)` returns true.

Since:
  7.0.0

## Field Summary

Fields
Modifier and Type
Field
Description
`private static final org.slf4j.Logger`
`LOG`
Class logger.

## Constructor Summary

Constructors
Constructor
Description
`AbstractPropertiesApplicationContextInitializer()`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`appendPropertySource(ConfigurableApplicationContext applicationContext, String name, Properties properties)`
Add property source to the application context environment with lowest precedence.
`protected abstract String`
`getAdditionalPropertiesPropertyName()`
Get the name of the property identifying the additional property resources to load (e.g., "idp.additionalProperties").
`protected Collection<String>`
`getAdditionalSources(ConfigurableApplicationContext applicationContext, String searchLocation, Properties properties)`
Find out all the additional property files we need to load.
`protected abstract String`
`getAutoSearchPropertyName()`
Get the name of the property determining whether to enable auto-search (e.g., "idp.searchForProperties").
`protected String`
`getAutoSearchRoot()`
Get the root folder under the search location to search for additional property files.
`protected abstract String`
`getDuplicateWarningPropertyName()`
Get the name of the property to populate with duplicates detected.
`protected Collection<String>`
`getExcludedSearchPaths()`
Get the collection of paths under the search root to exclude when searching for additional property files.
`protected abstract String`
`getFailFastPropertyName()`
Get the name of the property used to control fail-fast behavior (e.g., "idp.initializer.failFast").
`protected abstract String`
`getHomePropertyName()`
Get the name of the property used to identify the "home" of the application's configuration tree (e.g., "idp.home" or "sp.home").
`protected abstract String`
`getSearchLocation()`
Get the well known search location (e.g., "/opt/shibboleth-idp").
`protected abstract String`
`getSearchTarget()`
Get the target resource to be searched for (e.g., "/conf/idp.properties").
`void`
`initialize(ConfigurableApplicationContext applicationContext)`
`protected boolean`
`isFailFast(ConfigurableApplicationContext applicationContext)`
Whether we fail immediately if the config is bogus.
`protected void`
`loadAdditionalPropertySources(ConfigurableApplicationContext applicationContext, String searchLocation, Properties properties)`
Load additional property sources.
`protected Properties`
`loadProperties(Properties sink, Resource resource)`
Load properties from the resource.
`protected void`
`logProperties(Properties properties)`
Log property names and values at debug level, suppressing properties whose name matches 'password', 'credential', 'secret', or 'salt'.
`protected String`
`selectSearchLocation(ConfigurableApplicationContext applicationContext)`
Select the location used to search for the target.
`protected void`
`setHomeProperty(String path, Properties properties)`
Set the `getHomePropertyName()` property to the given path if not already set.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### LOG

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

## Constructor Details

### AbstractPropertiesApplicationContextInitializer

public AbstractPropertiesApplicationContextInitializer()

## Method Details

### getHomePropertyName

@Nonnull @NotEmpty protected abstract String getHomePropertyName()
Get the name of the property used to identify the "home" of the application's configuration tree (e.g., "idp.home" or "sp.home").

Returns:
  home property name

### getSearchTarget

@Nonnull @NotEmpty protected abstract String getSearchTarget()
Get the target resource to be searched for (e.g., "/conf/idp.properties").

Returns:
  the target resource to be searched for

### getSearchLocation

@Nonnull @NotEmpty protected abstract String getSearchLocation()
Get the well known search location (e.g., "/opt/shibboleth-idp").

Returns:
  the well known search locations

### getFailFastPropertyName

@Nonnull @NotEmpty protected abstract String getFailFastPropertyName()
Get the name of the property used to control fail-fast behavior (e.g., "idp.initializer.failFast").

Returns:
  failfast property name

### getAdditionalPropertiesPropertyName

@Nonnull @NotEmpty protected abstract String getAdditionalPropertiesPropertyName()
Get the name of the property identifying the additional property resources to load (e.g., "idp.additionalProperties").

Returns:
  name of additional properties property

### getAutoSearchPropertyName

@Nonnull @NotEmpty protected abstract String getAutoSearchPropertyName()
Get the name of the property determining whether to enable auto-search (e.g., "idp.searchForProperties").

Returns:
  name of additional properties property

### getAutoSearchRoot

@Nonnull @NotEmpty protected String getAutoSearchRoot()
Get the root folder under the search location to search for additional property files. TODO: Make abstract in 6.0.0.

Returns:
  search root folder name
Since:
  5.2.0

### getExcludedSearchPaths

@Nonnull @NotEmpty protected Collection<String> getExcludedSearchPaths()
Get the collection of paths under the search root to exclude when searching for additional property files. TODO: Make abstract in 6.0.0.

Returns:
  excluded folders under the search root
Since:
  5.2.0

### getDuplicateWarningPropertyName

@Nonnull @NotEmpty protected abstract String getDuplicateWarningPropertyName()
Get the name of the property to populate with duplicates detected.

Returns:
  duplicate warning property name
Since:
  9.1.0

### initialize

public void initialize(@Nonnull ConfigurableApplicationContext applicationContext)

Specified by:
  `initialize` in interface `ApplicationContextInitializer<ConfigurableApplicationContext>`

### selectSearchLocation

@Nonnull @NotEmpty protected String selectSearchLocation(@Nonnull ConfigurableApplicationContext applicationContext)
Select the location used to search for the target. Prefers the user-defined search location defined by `getHomePropertyName()` 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 protected 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

@Nonnull @Unmodifiable @NotLive protected Collection<String> getAdditionalSources(@Nonnull ConfigurableApplicationContext applicationContext, @Nonnull String searchLocation, @Nonnull Properties properties)
Find out all the additional property files we need to load.

Parameters:
  `applicationContext` - the application context
  `searchLocation` - Where to search from
  `properties` - the content of idp.properties so far
Returns:
  a collection of paths

### loadAdditionalPropertySources

protected void loadAdditionalPropertySources(@Nonnull ConfigurableApplicationContext applicationContext, @Nonnull String searchLocation, @Nonnull Properties properties)
Load additional property sources.

File names of additional property sources are defined by `getAdditionalPropertiesPropertyName()`, 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

protected 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

protected 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

### setHomeProperty

protected void setHomeProperty(@Nonnull String path, @Nonnull Properties properties)
Set the `getHomePropertyName()` property to the given path if not already set.

Parameters:
  `path` - the property value
  `properties` - the properties

### isFailFast

protected boolean isFailFast(@Nonnull ConfigurableApplicationContext applicationContext)
Whether we fail immediately if the config is bogus. Defaults to true. Controlled by the value of the `getFailFastPropertyName()`. 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.