Class DecryptingPropertySource

java.lang.Object
io.fluxzero.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 through the default Fluxzero property source using the ENCRYPTION_KEY or encryption_key property. This includes environment variables, system properties, configured additional locations, application property files, and Fluxzero defaults according to DefaultPropertySource precedence. If no key is found, a no-op fallback is used, meaning decryption will be skipped.

To enable encrypted property support in a Fluxzero 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 with the specified delegate property source. By default, the encryption key is fetched from the DefaultPropertySource using the keys ENCRYPTION_KEY or encryption_key.
      Parameters:
      delegate - the property source to wrap and decrypt values from
    • 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