In some cases you might like to inject configuration properties during engine bootstrap. The GlobalParametersProviderFactory provides the option to implement a provider to meet this requirement.
The
GlobalParametersProviderFactory
allows to contribute configuration properties from different sources, like a
database, other property files from the classpath or even computed values like
random hashes. The most prominent source of configuration properties is the
carnot.properties file. You can also set a priority to guarantee a
relative order of property retrieval.
The GlobalParametersProviderFactory works in the way that while (re-)initializing the engine, all provider factories are discovered and sorted with increasing priority. The resulting list of factories is then traversed to obtain one provider per factory. Each provider, in turn, will be asked for its set of properties, which will all be merged into global parameters.
Providers with higher priority may overwrite values from
previous providers by either yielding a new value for a given key
or by yielding a null value to remove a property.
@SPI(status = Status.Stable, useRestriction = UseRestriction.Public)
public interface GlobalParametersProviderFactory
{
int getPriority();
PropertyProvider getPropertyProvider();
}
getPriority() returns the priority of the associated
provider. Providers are consulted in increasing order, thus a provider with
priority 10 might override values yielded by another provider with priority 1.
Properties from carnot.properties will be fetched with priority
1.getPropertyProvider() returns the associated property provider.
It is up to the factory to decide if it instantiates a new provider instance per
request or uses some kind of caching or singleton.In this example, we like to use properties from a custom provider that should
overwrite properties with the same key in carnot.properties.
In this specific case we like to change the default technical user (motu).
We start by implementing a custom property provider. The PropertyProvider allows to set or even overwrite properties derived from any source you would like to. It also provides the option to pre-process a value, e.g. masking a password, before it is sent to the log file.
Our custom property provider reads the properties from
the custom property file and sets them into the properties map returned by the
method with the property keys known by Stardust.
Function getPropertyDisplayValue is used to pre-process a value,
here by masking a password, before it is sent to the log file.
package org.eclipse.stardust.example;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.stardust.common.config.PropertyProvider;
public class CustomPropertiesProvider implements PropertyProvider {
public Map<String, Object> getProperties() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("Security.ResetPassword.TechnicalUser.Account", "xyz");
properties.put("Security.ResetPassword.TechnicalUser.Password", "xyz");
properties.put("Security.ResetPassword.TechnicalUser.Realm", "carnot");
return properties;
}
public String getPropertyDisplayValue(String key)
{
if (propertyBlacklist.contains(key))
{
return "***";
}
return getProperties().get(key).toString();
}
}
Now implement a GlobalParametersProviderFactory to inject our custom properties. We use a high priority value to guarantee that our custom properties are fetched before any extension.
package org.eclipse.stardust.example;
import org.eclipse.stardust.common.config.GlobalParametersProviderFactory;
import org.eclipse.stardust.common.config.PropertyProvider;
public class CustomParametersProviderFactory implements GlobalParametersProviderFactory {
public int getPriority() {
return 9;
}
public PropertyProvider getPropertyProvider() {
return new CustomPropertiesProvider();
}
}