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>
AnApplicationContextInitializerwhich appends properties to the application context's environment. Properties are loaded fromIDP_PROPERTIESas well as additional property files specified byIDP_ADDITIONAL_PROPERTYif set, or if absent, by locating all files under idp.home/conf/ that end in ".properties". TheIDP_PROPERTIESfile is searched for in the well location returned bygetSearchLocation(). If not already set, theIDP_HOME_PROPERTYwill be set to the first search location in which theIDP_PROPERTIESfile is found. AConstraintViolationExceptionwill be thrown if the property files can not be found or loaded andisFailFast(ConfigurableApplicationContext)returns true.
-
-
Field Summary
Fields Modifier and Type Field Description static StringFAILFAST_PROPERTYProperty controlling whether to fail fast.static StringIDP_ADDITIONAL_PROPERTYProperty that points to more property sources.static StringIDP_AUTOSEARCH_PROPERTYProperty that controls auto-search for property sources.static StringIDP_HOME_PROPERTYIdP home property.static StringIDP_PROPERTIESTarget resource to be searched for.private static org.slf4j.LoggerLOGClass logger.static StringSEARCH_LOCATIONWell known search location.
-
Constructor Summary
Constructors Constructor Description IdPPropertiesApplicationContextInitializer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendPropertySource(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.StringgetSearchLocation()Get the well known search location.StringgetSearchTarget()Get the target resource to be searched for.voidinitialize(ConfigurableApplicationContext applicationContext)booleanisFailFast(ConfigurableApplicationContext applicationContext)Whether we fail immediately if the config is bogus.voidloadAdditionalPropertySources(ConfigurableApplicationContext applicationContext, String searchLocation, Properties properties)Load additional property sources.PropertiesloadProperties(Properties sink, Resource resource)Load properties from the resource.voidlogProperties(Properties properties)Log property names and values at debug level, suppressing properties whose name matches 'password', 'credential', 'secret', or 'salt'.StringselectSearchLocation(ConfigurableApplicationContext applicationContext)Select the location used to search for the target.voidsetIdPHomeProperty(String path, Properties properties)Set theIDP_HOME_PROPERTYproperty to the given path if not already set.
-
-
-
Field Detail
-
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.
-
-
Method Detail
-
initialize
public void initialize(@Nonnull ConfigurableApplicationContext applicationContext)- Specified by:
initializein interfaceApplicationContextInitializer<ConfigurableApplicationContext>
-
getSearchTarget
@Nonnull public String getSearchTarget()
Get the target resource to be searched for. Defaults toIDP_PROPERTIES.- Returns:
- the target resource to be searched for
-
getSearchLocation
@Nonnull public String 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_PROPERTYin 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 public 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
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
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 contextname- the name of the property source to be added to the application contextproperties- the properties added to the application context
-
setIdPHomeProperty
public void setIdPHomeProperty(@Nonnull String path, @Nonnull Properties properties)Set theIDP_HOME_PROPERTYproperty to the given path if not already set.- Parameters:
path- the property valueproperties- 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 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.
-
-