Package com.randomnoun.common.webapp
Class AppConfigBase
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<Object,
Object>
An attempt to standardise config objects across the handful of webapps in this
workspace.
Holds configuration data for this web application. Is used to look up resources for use by other application components, including:
- database connections (JdbcTemplates)
- security contexts (for authentication / authorisation)
- Author:
- Greg
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map
<String, DataSource> Datasource underlying the jdbcTemplatesprotected Throwable
If set to non-null, indicates an exception that occurred during initialisation.static AppConfigBase
Global instanceJdbcTemplates for this AppConfigstatic org.apache.log4j.Logger
Logger instance for this classprotected SecurityContext
Security context used for authentication and authorisationFields inherited from class java.util.Properties
defaults
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
checkPermission
(User user, String permission) Determines whether a user 'may have' a permission on the application.Returns a bundle to be used for internationalisation.abstract String
The name of the file which configures this application; e.g.Provides direct access to the datasource for this application.getDataSource
(String connectionName) Provides direct access to a named datasource for this application.org.springframework.jdbc.core.JdbcTemplate
Return a jdbcTemplate object that can be used to query the databaseorg.springframework.jdbc.core.JdbcTemplate
getJdbcTemplate
(String connectionName) Returns a named jdbcTemplate object that can be used to query the databaseReturn the security context for this applicationabstract String
The name of the -D directive which, if present, specifies the folder containing the configuration file; e.g.boolean
hasPermission
(User user, String permission) Determines whether a user 'may have' a permission on the application.boolean
Determines whether a user has a permission on the application.protected void
Ensure that the database drivers are accessible, for simple and dbcp connection typesprotected void
Sets the hostname application property.protected void
Initialises log4jprotected void
protected void
Load the configuration from both the classpath and the filesystem.Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
Field Details
-
logger
Logger instance for this class -
instance
Global instance -
jdbcTemplates
JdbcTemplates for this AppConfig -
dataSources
Datasource underlying the jdbcTemplates -
securityContext
Security context used for authentication and authorisation -
initialisationFailure
If set to non-null, indicates an exception that occurred during initialisation.
-
-
Constructor Details
-
AppConfigBase
public AppConfigBase()
-
-
Method Details
-
getSystemPropertyKeyConfigPath
The name of the -D directive which, if present, specifies the folder containing the configuration file; e.g. "com.randomnoun.appName.configPath" -
getConfigResourceLocation
The name of the file which configures this application; e.g. "/appName-web.properties" -
initDatabase
Ensure that the database drivers are accessible, for simple and dbcp connection types -
initLogger
Initialises log4j -
initSecurityContext
-
initHostname
Sets the hostname application property. Should be called beforeloadProperties()
, which may have ENVIRONMENT settings that rely on the hostname. -
getBundle
Returns a bundle to be used for internationalisation. The bundle will initially be searched for using the standard ResourceBundle.getBundle(name) method (i.e. in the server's classpath); and, if this fails, will return ResourceBundle("resources.i18n." + name); which will search the i18n tree of the eomail project.- Parameters:
i18nBundleName
- The bundle name to search for (e.g. "user")user
- The user for whom we are retrieving i18ned messages for (the locale of this user will be used to determine which resource bundle to use)- Returns:
- The ResourceBundle requested.
-
loadProperties
Load the configuration from both the classpath and the filesystem. Properties defined on the filesystem will override any contained within the web application.Multiple environments can be specified in properties files using the STARTENVIRONMENT/ENDENVIRONMENT tags. The tags use the machine's hostname as an environment specifier.
-
getJdbcTemplate
Return a jdbcTemplate object that can be used to query the database- Returns:
- a jdbcTemplate to the database
-
getJdbcTemplate
Returns a named jdbcTemplate object that can be used to query the database- Parameters:
connectionName
- The name of the connection- Returns:
- a jdbcTemplate to the database
-
getSecurityContext
Return the security context for this application- Returns:
- the security context for this application
-
hasPermission
Determines whether a user 'may have' a permission on the application. See the hasPermission method in SecurityContext for more details.- Parameters:
user
- The user we are checking permissions for.permission
- The permission we are checking.- Returns:
- 'true' if the user may be authorised to perform the permission, false otherwise
-
checkPermission
Determines whether a user 'may have' a permission on the application. See the hasPermission method in SecurityContext for more details. If the user does not have the permission, then a SecurityException is thrown- Parameters:
user
- The user we are checking permissions for.permission
- The permission we are checking.- Throws:
SecurityException
- if the user does not have the supplied permission- See Also:
-
hasPermission
Determines whether a user has a permission on the application. See the hasPermission method in SecurityContext for more details.- Parameters:
user
- The user we are checking permissions for.permission
- The permission we are checking.resourceContext
- Fine-grained resource context- Returns:
- 'true' if the user is authorised to perform the permission, false otherwise
-
getDataSource
Provides direct access to the datasource for this application. Most applications should use thegetJdbcTemplate()
method instead.- Returns:
- the dataSource underlying the jdbcTemplate to the database
-
getDataSource
Provides direct access to a named datasource for this application. Most applications should use thegetJdbcTemplate(String)
method instead.- Parameters:
connectionName
- the name of the connection- Returns:
- the dataSource underlying the named jdbcTemplate to the database
-