Package net.shibboleth.idp.spring
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Property controlling whether to fail fast.static final String
Property that points to more property sources.static final String
Property that controls auto-search for property sources.static final String
IdP home property.static final String
Target resource to be searched for.private static final org.slf4j.Logger
Class logger.static final String
Well known search location. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendPropertySource
(ConfigurableApplicationContext applicationContext, String name, Properties properties) Add property source to the application context environment with lowest precedence.static Collection<String>
getAdditionalSources
(String searchLocation, Properties properties) Find out all the additional property files we need to load.Get the well known search location.Get the target resource to be searched for.void
initialize
(ConfigurableApplicationContext applicationContext) boolean
isFailFast
(ConfigurableApplicationContext applicationContext) Whether we fail immediately if the config is bogus.void
loadAdditionalPropertySources
(ConfigurableApplicationContext applicationContext, String searchLocation, Properties properties) Load additional property sources.loadProperties
(Properties sink, Resource resource) Load properties from the resource.void
logProperties
(Properties properties) Log property names and values at debug level, suppressing properties whose name matches 'password', 'credential', 'secret', or 'salt'.selectSearchLocation
(ConfigurableApplicationContext applicationContext) Select the location used to search for the target.void
setIdPHomeProperty
(String path, Properties properties) Set theIDP_HOME_PROPERTY
property to the given path if not already set.
-
Field Details
-
IDP_HOME_PROPERTY
IdP home property.- See Also:
-
IDP_ADDITIONAL_PROPERTY
Property that points to more property sources.- See Also:
-
IDP_AUTOSEARCH_PROPERTY
Property that controls auto-search for property sources.- See Also:
-
IDP_PROPERTIES
Target resource to be searched for.- See Also:
-
SEARCH_LOCATION
Well known search location.- See Also:
-
FAILFAST_PROPERTY
Property controlling whether to fail fast.- See Also:
-
LOG
@Nonnull private static final org.slf4j.Logger LOGClass logger.
-
-
Constructor Details
-
IdPPropertiesApplicationContextInitializer
public IdPPropertiesApplicationContextInitializer()
-
-
Method Details
-
initialize
- Specified by:
initialize
in interfaceApplicationContextInitializer<ConfigurableApplicationContext>
-
getSearchTarget
Get the target resource to be searched for. Defaults toIDP_PROPERTIES
.- Returns:
- the target resource to be searched for
-
getSearchLocation
Get the well known search location. Defaults toSEARCH_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 byIDP_HOME_PROPERTY
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
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
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 fromproperties
- 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 byIDP_ADDITIONAL_PROPERTY
, 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
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 contextname
- the name of the property source to be added to the application contextproperties
- the properties added to the application context
-
setIdPHomeProperty
Set theIDP_HOME_PROPERTY
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 theFAILFAST_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.
-