Package org.opensaml.core.config

# Class ConfigurationService

java.lang.Object
org.opensaml.core.config.ConfigurationService

public class ConfigurationService extends Object
A service which provides for the registration, retrieval and deregistration of objects related to library module configuration.

The service uses an internally-managed instance of `Configuration` to handle the registration, retrieval and deregistration of the configuration objects under its management.

The service first attempts to use the Java Services API to resolve the instance of Configuration to use. If multiple implementations of Configuration are registered via the Services API mechanism, the first one returned by the `ServiceLoader` iterator is used. If no Configuration implementation is declared or resolvable using the Services API, then it uses the default implementation `MapBasedConfiguration`.

The Configuration instance to use may also be set externally via `setConfiguration(Configuration)`. This may be useful where an application-specific means such as Spring is used to configure the environment. This overrides the resolution process described above.

## Field Summary

Fields
Modifier and Type
Field
Description
`private static ServiceLoader<ConfigurationPropertiesSource>`
`configPropertiesLoader`
The service loader used to locate registered implementations of ConfigurationPropertiesSource.
`private static Configuration`
`configuration`
The configuration instance to use.
`static final String`
`DEFAULT_PARTITION_NAME`
The default storage partition name, if none is specified using configuration properties.
`private static ConfigurationPropertiesSource`
`defaultConfigurationPropertiesSource`
A default configuration properties source to use.
`private static final org.slf4j.Logger`
`LOG`
Logger.
`static final String`
`PROPERTY_PARTITION_NAME`
The configuration property name for the storage partition name to use.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`ConfigurationService()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`static <T> T`
`deregister(Class<T> configClass)`
Deregister a configuration instance.
`static <T> T`
`ensure(Class<T> configClass)`
Obtain the registered configuration instance, raising an exception if absent.
`static <T> T`
`get(Class<T> configClass)`
Obtain the registered configuration instance.
`protected static Configuration`
`getConfiguration()`
Get the `Configuration` instance to use.
`static ConfigurationProperties`
`getConfigurationProperties()`
Get the set of configuration meta-properties, which determines the configuration of the configuration service itself.
`static ConfigurationPropertiesSource`
`getDefaultConfigurationPropertiesSource()`
Get the default `ConfigurationPropertiesSource` instance to use.
`protected static String`
`getPartitionName()`
Return the partition name which will be used for storage of configuration objects.
`static <T, I extends T>
void`
`register(Class<T> configClass, I configInstance)`
Register a configuration instance.
`static void`
`setConfiguration(Configuration newConfiguration)`
Set the `Configuration` instance to use.
`static void`
`setDefaultConfigurationPropertiesSource(ConfigurationPropertiesSource source)`
Set the default `ConfigurationPropertiesSource` instance to use.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### DEFAULT_PARTITION_NAME

@Nonnull @NotEmpty public static final String DEFAULT_PARTITION_NAME
The default storage partition name, if none is specified using configuration properties.

See Also:
  - Constant Field Values

### PROPERTY_PARTITION_NAME

@Nonnull @NotEmpty public static final String PROPERTY_PARTITION_NAME
The configuration property name for the storage partition name to use.

See Also:
  - Constant Field Values

### LOG

@Nonnull private static final org.slf4j.Logger LOG
Logger.

### configPropertiesLoader

@Nonnull private static ServiceLoader<ConfigurationPropertiesSource> configPropertiesLoader
The service loader used to locate registered implementations of ConfigurationPropertiesSource.

### configuration

@Nullable private static Configuration configuration
The configuration instance to use.

### defaultConfigurationPropertiesSource

@Nullable private static ConfigurationPropertiesSource defaultConfigurationPropertiesSource
A default configuration properties source to use.

## Constructor Details

### ConfigurationService

protected ConfigurationService()
Constructor.

## Method Details

### get

@Nullable public static <T> T get(@Nonnull Class<T> configClass)
Obtain the registered configuration instance.

Type Parameters:
  `T` - the type of configuration being retrieved
Parameters:
  `configClass` - the configuration class identifier
Returns:
  the instance of the registered configuration object, or null

### ensure

@Nonnull public static <T> T ensure(@Nonnull Class<T> configClass)
Obtain the registered configuration instance, raising an exception if absent.

Type Parameters:
  `T` - the type of configuration being retrieved
Parameters:
  `configClass` - the configuration class identifier
Returns:
  the instance of the registered configuration object
Since:
  5.0.0

### register

public static <T, I extends T> void register(@Nonnull Class<T> configClass, @Nonnull I configInstance)
Register a configuration instance.

Type Parameters:
  `T` - the type of configuration being registered
  `I` - the configuration object instance type being registered, which must be an instance of `T`
Parameters:
  `configClass` - the type of configuration being registered
  `configInstance` - the configuration object instance being registered

### deregister

@Nullable public static <T> T deregister(@Nonnull Class<T> configClass)
Deregister a configuration instance.

Type Parameters:
  `T` - the type of configuration being deregistered
Parameters:
  `configClass` - the type of configuration class being deregistered
Returns:
  the configuration object instance which was deregistered, or null

### getConfigurationProperties

@Nonnull public static ConfigurationProperties getConfigurationProperties()
Get the set of configuration meta-properties, which determines the configuration of the configuration service itself.

The properties set is obtained from the first configured instance of `ConfigurationPropertiesSource` which returns a non-null properties set.

The first properties source to evaluate is the instance configured by `setDefaultConfigurationPropertiesSource(ConfigurationPropertiesSource)`.

If that is null or produces a null properties set, and there are no properties sources configured via the Java Services API, then a default implementation which exposes the standard Java system properties from `System.getProperties()` set is used.

If properties sources are configured via the Java Services API, then those are evaluated in order, and the first non-null properties set returned is used.

If no configured sources return a properties set, then an empty properties set is returned.

Properties made available in this meta-properties set may also be used by `Initializer` implementations.

Returns:
  the set of configuration meta-properties

### getDefaultConfigurationPropertiesSource

@Nullable public static ConfigurationPropertiesSource getDefaultConfigurationPropertiesSource()
Get the default `ConfigurationPropertiesSource` instance to use.

The configuration properties source to use is normally resolved via the Java Services API, or is defaulted if none are configured. However, this method is provided to allow the default properties source instance to be supplied externally, perhaps using an application-specific means such as Spring dependency injection.

Returns:
  the default ConfigurationPropertiesSource, possibly null

### setDefaultConfigurationPropertiesSource

public static void setDefaultConfigurationPropertiesSource(@Nullable ConfigurationPropertiesSource source)
Set the default `ConfigurationPropertiesSource` instance to use.

The configuration properties source to use is normally resolved via the Java Services API, or is defaulted if none are configured. However, this method is provided to allow the default properties source instance to be supplied externally, perhaps using an application-specific means such as Spring dependency injection.

Parameters:
  `source` - the default ConfigurationPropertiesSource instance to use

### setConfiguration

public static void setConfiguration(@Nonnull Configuration newConfiguration)
Set the `Configuration` instance to use.

The configuration instance to use is normally resolved via the Java Services API, or is defaulted. However, this method is provided to allow the configuration instance to be supplied externally, perhaps using an application-specific means such as Spring dependency injection.

Parameters:
  `newConfiguration` - the Configuration instance to use

### getPartitionName

@Nonnull @NotEmpty protected static String getPartitionName()
Return the partition name which will be used for storage of configuration objects.

This partition name is obtained from the configuration meta-properties. If a value is not supplied via that mechanism, then an internal default value is used.

Returns:
  the partition name

### getConfiguration

@Nonnull protected static Configuration getConfiguration()
Get the `Configuration` instance to use.

The implementation to return is first resolved using the Java Services API. If this produces no implementation, then an instance of the default implementation of `MapBasedConfiguration` is used.

Returns:
  the Configuration implementation instance