Class AbstractPropertiesApplicationContextInitializer
- All Implemented Interfaces:
ApplicationContextInitializer<ConfigurableApplicationContext>
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendPropertySource(ConfigurableApplicationContext applicationContext, String name, Properties properties) Add property source to the application context environment with lowest precedence.protected abstract StringGet the name of the property identifying the additional property resources to load (e.g., "idp.additionalProperties").protected Collection<String>getAdditionalSources(String searchLocation, Properties properties) Find out all the additional property files we need to load.protected abstract StringGet the name of the property determining whether to enable auto-search (e.g., "idp.searchForProperties").protected abstract StringGet the name of the property to populate with duplicates detected.protected abstract StringGet the name of the property used to control fail-fast behavior (e.g., "idp.initializer.failFast").protected abstract StringGet 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 StringGet the well known search location (e.g., "/opt/shibboleth-idp").protected abstract StringGet the target resource to be searched for (e.g., "/conf/idp.properties").voidinitialize(ConfigurableApplicationContext applicationContext) protected booleanisFailFast(ConfigurableApplicationContext applicationContext) Whether we fail immediately if the config is bogus.protected voidloadAdditionalPropertySources(ConfigurableApplicationContext applicationContext, String searchLocation, Properties properties) Load additional property sources.protected PropertiesloadProperties(Properties sink, Resource resource) Load properties from the resource.protected voidlogProperties(Properties properties) Log property names and values at debug level, suppressing properties whose name matches 'password', 'credential', 'secret', or 'salt'.protected StringselectSearchLocation(ConfigurableApplicationContext applicationContext) Select the location used to search for the target.protected voidsetHomeProperty(String path, Properties properties) Set thegetHomePropertyName()property to the given path if not already set.
-
Field Details
-
LOG
@Nonnull private static final org.slf4j.Logger LOGClass logger.
-
-
Constructor Details
-
AbstractPropertiesApplicationContextInitializer
public AbstractPropertiesApplicationContextInitializer()
-
-
Method Details
-
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
Get the target resource to be searched for (e.g., "/conf/idp.properties").- Returns:
- the target resource to be searched for
-
getSearchLocation
Get the well known search location (e.g., "/opt/shibboleth-idp").- Returns:
- the well known search locations
-
getFailFastPropertyName
Get the name of the property used to control fail-fast behavior (e.g., "idp.initializer.failFast").- Returns:
- failfast property name
-
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
Get the name of the property determining whether to enable auto-search (e.g., "idp.searchForProperties").- Returns:
- name of additional properties property
-
getDuplicateWarningPropertyName
Get the name of the property to populate with duplicates detected.- Returns:
- duplicate warning property name
- Since:
- 9.1.0
-
initialize
- Specified by:
initializein interfaceApplicationContextInitializer<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 bygetHomePropertyName()in the application context. Defaults to the well-known search location returned fromgetSearchLocation().- 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 '/' andisFailFast(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 targetresource- the resource- Returns:
- properties loaded from the resource or
nullif loading failed
-
getAdditionalSources
@Nonnull @Unmodifiable @NotLive protected 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 fromproperties- 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 contextsearchLocation- the location from which additional property sources are resolvedproperties- the properties to be filled with additional property sources- Throws:
ConstraintViolationException- if an error occurs loading the additional property sources andisFailFast(ConfigurableApplicationContext)is true
-
logProperties
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 contextname- the name of the property source to be added to the application contextproperties- the properties added to the application context
-
setHomeProperty
Set thegetHomePropertyName()property to the given path if not already set.- Parameters:
path- the property valueproperties- the properties
-
isFailFast
Whether we fail immediately if the config is bogus. Defaults to true. Controlled by the value of thegetFailFastPropertyName(). 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.
-