Class DecryptingPropertySource

java.lang.Object
io.fluxcapacitor.common.application.DecryptingPropertySource
All Implemented Interfaces:
PropertySource

public class DecryptingPropertySource extends Object implements PropertySource
A PropertySource decorator that transparently decrypts encrypted property values.

This implementation wraps a delegate PropertySource and attempts to decrypt any retrieved property value using a configured Encryption strategy.

Decryption is only applied to values identified as encrypted via Encryption.isEncrypted(String). Values that are not encrypted are returned as-is.

The encryption strategy is determined using the ENCRYPTION_KEY environment variable or system property. If no key is found, a no-op fallback is used, meaning decryption will be skipped.

To enable encrypted property support in a Flux application, ensure the appropriate key is present, e.g.:


   export ENCRYPTION_KEY=ChaCha20|mYbAse64ENcodedKeY==
 
See Also:
  • Constructor Details

    • DecryptingPropertySource

      public DecryptingPropertySource(PropertySource delegate)
      Constructs a DecryptingPropertySource using a delegate and automatically resolves the encryption key from system or environment variables.

      It looks for the ENCRYPTION_KEY or encryption_key in the following order:

      • Environment variable ENCRYPTION_KEY
      • Environment variable encryption_key
      • System property ENCRYPTION_KEY
      • System property encryption_key

      If no key is found, a no-op encryption fallback is used.

      Parameters:
      delegate - the property source to wrap
    • DecryptingPropertySource

      public DecryptingPropertySource(PropertySource delegate, String encryptionKey)
      Constructs a DecryptingPropertySource using the given encryption key.

      If the provided key is invalid or unrecognized, a no-op encryption fallback is used.

      Parameters:
      delegate - the property source to wrap
      encryptionKey - the Base64-encoded encryption key in the form algorithm|key
    • DecryptingPropertySource

      public DecryptingPropertySource(PropertySource delegate, Encryption encryption)
      Constructs a DecryptingPropertySource using an explicit Encryption strategy.
      Parameters:
      delegate - the property source to wrap
      encryption - the encryption strategy to apply to values
  • Method Details

    • get

      public String get(String name)
      Returns the decrypted value of the given property name.

      If the underlying property is encrypted (i.e., Encryption.isEncrypted(String) is true), it is decrypted using the configured Encryption implementation. Otherwise, the raw value is returned unchanged.

      Values are cached after the first decryption attempt for efficiency.

      Specified by:
      get in interface PropertySource
      Parameters:
      name - the property key
      Returns:
      the decrypted or original property value, or null if not found