Class ConfigurationUtils
java.lang.Object
com.bonitasoft.processbuilder.extension.ConfigurationUtils
Utility class for safely retrieving and handling configuration values.
This class provides methods to lookup configuration values with proper logging, error handling, and support for sensitive data masking (e.g., passwords).
The configuration retrieval is decoupled from the data source through functional interfaces, allowing integration with any DAO or configuration provider.
Usage Example:
// Example 1: Basic configuration lookup
String smtpHost = ConfigurationUtils.lookupConfigurationValue(
SmtpType.SMTP_HOST.getKey(),
ConfigurationType.SMTP.getKey(),
() -> pBConfigurationDAO.findByFullNameAndRefEntityTypeName(
SmtpType.SMTP_HOST.getKey(),
ConfigurationType.SMTP.getKey()
).getConfigValue(),
"localhost",
false // not sensitive
);
// Example 2: Sensitive value lookup (password - value will be masked in logs)
String password = ConfigurationUtils.lookupConfigurationValue(
SmtpType.PASSWORD.getKey(),
ConfigurationType.SMTP.getKey(),
() -> pBConfigurationDAO.findByFullNameAndRefEntityTypeName(
SmtpType.PASSWORD.getKey(),
ConfigurationType.SMTP.getKey()
).getConfigValue(),
"",
true // sensitive - will be masked in logs
);
- Since:
- 1.0
- Author:
- Bonitasoft
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringMask used to hide sensitive values in log output. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringlookupConfigurationValue(String fullNameKey, String entityTypeKey, Supplier<String> configValueSupplier, String defaultValue, boolean isSensitive) Looks up a configuration value using a provided supplier, with support for sensitive data masking.static StringlookupConfigurationValue(String fullNameKey, Supplier<String> configValueSupplier, String defaultValue, boolean isSensitive) Looks up a configuration value without entity type context.static StringmaskIfSensitive(String value, boolean isSensitive) Masks a value if it is marked as sensitive.
-
Field Details
-
MASKED_VALUE
Mask used to hide sensitive values in log output.- See Also:
-
-
Method Details
-
lookupConfigurationValue
public static String lookupConfigurationValue(String fullNameKey, String entityTypeKey, Supplier<String> configValueSupplier, String defaultValue, boolean isSensitive) Looks up a configuration value using a provided supplier, with support for sensitive data masking.This method encapsulates the common pattern of:
- Logging the start of the lookup operation
- Executing the configuration retrieval via the supplier
- Validating the retrieved value
- Returning the value or a default if not found/empty
- Masking sensitive values in log output
- Logging the completion of the operation
- Parameters:
fullNameKey- the configuration key name (e.g., "SmtpHost", "Password")entityTypeKey- the entity type for logging context (e.g., "SMTP", "DATABASE")configValueSupplier- a supplier that retrieves the configuration value; may return null if configuration not founddefaultValue- the default value to return if configuration is not found or emptyisSensitive- if true, the actual value will be masked in log output- Returns:
- the configuration value if found and not empty, otherwise the default value
- Throws:
RuntimeException- if the supplier throws an exception during retrieval
-
lookupConfigurationValue
public static String lookupConfigurationValue(String fullNameKey, Supplier<String> configValueSupplier, String defaultValue, boolean isSensitive) Looks up a configuration value without entity type context.This is a convenience overload for cases where entity type logging is not needed.
- Parameters:
fullNameKey- the configuration key nameconfigValueSupplier- a supplier that retrieves the configuration valuedefaultValue- the default value to return if configuration is not foundisSensitive- if true, the actual value will be masked in log output- Returns:
- the configuration value if found and not empty, otherwise the default value
- Throws:
RuntimeException- if the supplier throws an exception during retrieval
-
maskIfSensitive
Masks a value if it is marked as sensitive.- Parameters:
value- the value to potentially maskisSensitive- whether the value should be masked- Returns:
- the masked value if sensitive, otherwise the original value
-