Class ConfigurationUtils

java.lang.Object
com.bonitasoft.processbuilder.extension.ConfigurationUtils

public final class ConfigurationUtils extends Object
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 Details

    • MASKED_VALUE

      public static final String 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:

      1. Logging the start of the lookup operation
      2. Executing the configuration retrieval via the supplier
      3. Validating the retrieved value
      4. Returning the value or a default if not found/empty
      5. Masking sensitive values in log output
      6. 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 found
      defaultValue - the default value to return if configuration is not found or empty
      isSensitive - 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 name
      configValueSupplier - a supplier that retrieves the configuration value
      defaultValue - the default value to return if configuration is not found
      isSensitive - 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

      public static String maskIfSensitive(String value, boolean isSensitive)
      Masks a value if it is marked as sensitive.
      Parameters:
      value - the value to potentially mask
      isSensitive - whether the value should be masked
      Returns:
      the masked value if sensitive, otherwise the original value