Class ConfigPropertiesCascadeBase
- java.lang.Object
-
- org.owasp.csrfguard.config.overlay.ConfigPropertiesCascadeBase
-
- Direct Known Subclasses:
ConfigurationOverlayProvider
public abstract class ConfigPropertiesCascadeBase extends Object
Base class for a cascaded config. Extend this class to have a config based on a certain file. This code is copied from the Grouper project see https://github.com/Internet2/grouper/blob/master/grouper-misc/grouperActivemq/dist/bin/edu/internet2/middleware/grouperActivemq/config/ConfigPropertiesCascadeBase.java- Author:
- mchyzer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classConfigPropertiesCascadeBase.ConfigFileprotected static classConfigPropertiesCascadeBase.ConfigFileTypeconfig file type
-
Constructor Summary
Constructors Constructor Description ConfigPropertiesCascadeBase()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleanfilesNeedReloadingBasedOnContents()protected Class<?>getClassInSiblingJar()if it's ok to put the config file in the same directory as a jar, then return a class in the jar hereprotected abstract StringgetHierarchyConfigKey()config key of the hierarchy valueprotected abstract StringgetMainConfigClasspath()get the main config classpath, e.g.protected abstract StringgetMainExampleConfigClasspath()get the example config classpath, e.g.protected abstract StringgetSecondsToCheckConfigKey()config key of the time in seconds to check config.protected IntegergetTimeToCheckConfigSeconds()when we build the config object, get the time to check config in secondsprotected booleanneedToCheckIfFilesNeedReloading()Propertiesproperties()get the properties object for this config fileprotected static PropertiespropertiesFromResourceName(String resourceName, boolean exceptionIfNotExist)read properties from a resource, don't modify the properties returned since they are cachedprotected PropertiespropertiesHelper(boolean setValues)get the properties object for this config fileMap<String,String>propertiesOverrideMap()override map for properties for testingMap<String,String>propertiesThreadLocalOverrideMap()override map for properties in thread local to be used in a web server or the like, based on property class this is static since the properties class can get reloaded, but these shouldn'tprotected static <T extends ConfigPropertiesCascadeBase>
TretrieveConfig(Class<T> configClass)retrieve a config from the config file or from cacheprotected ConfigPropertiesCascadeBaseretrieveFromConfigFileOrCache()see if there is one in cache, if so, use it, if not, get from config filesprotected ConfigPropertiesCascadeBaseretrieveFromConfigFiles()get the config object from config files
-
-
-
Method Detail
-
retrieveConfig
protected static <T extends ConfigPropertiesCascadeBase> T retrieveConfig(Class<T> configClass)
retrieve a config from the config file or from cache- Type Parameters:
T- class which is the return type of config class- Parameters:
configClass- The configuration object- Returns:
- the config object never null
-
getClassInSiblingJar
protected Class<?> getClassInSiblingJar()
if it's ok to put the config file in the same directory as a jar, then return a class in the jar here- Returns:
- the class or null if not available
-
getSecondsToCheckConfigKey
protected abstract String getSecondsToCheckConfigKey()
config key of the time in seconds to check config. -1 means dont check again- Returns:
- config key
-
propertiesThreadLocalOverrideMap
public Map<String,String> propertiesThreadLocalOverrideMap()
override map for properties in thread local to be used in a web server or the like, based on property class this is static since the properties class can get reloaded, but these shouldn't- Returns:
- the override map
-
propertiesOverrideMap
public Map<String,String> propertiesOverrideMap()
override map for properties for testing- Returns:
- the override map
-
properties
public Properties properties()
get the properties object for this config file- Returns:
- the properties
-
propertiesHelper
protected Properties propertiesHelper(boolean setValues)
get the properties object for this config file- Parameters:
setValues- if we should set the values for the properties. if not, the values might not be correct, but this will be more performant depending on how many EL properties there are- Returns:
- the properties
-
getTimeToCheckConfigSeconds
protected Integer getTimeToCheckConfigSeconds()
when we build the config object, get the time to check config in seconds- Returns:
- the time to check config foe changes (in seconds)
-
retrieveFromConfigFiles
protected ConfigPropertiesCascadeBase retrieveFromConfigFiles()
get the config object from config files- Returns:
- the config object
-
retrieveFromConfigFileOrCache
protected ConfigPropertiesCascadeBase retrieveFromConfigFileOrCache()
see if there is one in cache, if so, use it, if not, get from config files- Returns:
- the config from file or cache
-
needToCheckIfFilesNeedReloading
protected boolean needToCheckIfFilesNeedReloading()
- Returns:
- true if need to reload this config, false if not
-
filesNeedReloadingBasedOnContents
protected boolean filesNeedReloadingBasedOnContents()
- Returns:
- true if need to reload this config, false if not
-
getMainConfigClasspath
protected abstract String getMainConfigClasspath()
get the main config classpath, e.g. csrf guard properties- Returns:
- the classpath of the main config file
-
getHierarchyConfigKey
protected abstract String getHierarchyConfigKey()
config key of the hierarchy value- Returns:
- the classpath of the main config file
-
getMainExampleConfigClasspath
protected abstract String getMainExampleConfigClasspath()
get the example config classpath, e.g. csrf guard base properties- Returns:
- the classpath of the example config file
-
propertiesFromResourceName
protected static Properties propertiesFromResourceName(String resourceName, boolean exceptionIfNotExist)
read properties from a resource, don't modify the properties returned since they are cached- Parameters:
resourceName- Name of properties resourceexceptionIfNotExist- When true, throw an exception if an URL for the resource name cannot be constructued- Returns:
- the properties or null if not exist
-
-