Class AppConfigBase

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public abstract class AppConfigBase extends Properties
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 Details

  • Constructor Details

  • 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

      public abstract String getConfigResourceLocation()
      The name of the file which configures this application; e.g. "/appName-web.properties"
    • initDatabase

      protected void initDatabase()
      Ensure that the database drivers are accessible, for simple and dbcp connection types
    • initLogger

      protected void initLogger()
      Initialises log4j
    • initSecurityContext

      protected void initSecurityContext()
    • initHostname

      protected void initHostname()
      Sets the hostname application property. Should be called before loadProperties(), which may have ENVIRONMENT settings that rely on the hostname.
    • getBundle

      public ResourceBundle getBundle(String i18nBundleName, User user)
      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

      protected void 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

      public org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate()
      Return a jdbcTemplate object that can be used to query the database
      Returns:
      a jdbcTemplate to the database
    • getJdbcTemplate

      public org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate(String connectionName)
      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

      public boolean hasPermission(User user, String permission)
      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

      public void checkPermission(User user, String permission) throws SecurityException
      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

      public boolean hasPermission(User user, String permission, Map<String,Object> resourceContext)
      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 the getJdbcTemplate() method instead.
      Returns:
      the dataSource underlying the jdbcTemplate to the database
    • getDataSource

      public DataSource getDataSource(String connectionName)
      Provides direct access to a named datasource for this application. Most applications should use the getJdbcTemplate(String) method instead.
      Parameters:
      connectionName - the name of the connection
      Returns:
      the dataSource underlying the named jdbcTemplate to the database