Class Base64PropertyDecoder

java.lang.Object
de.gustavblass.fsu.fmi.roombooking.configuration.Base64PropertyDecoder
All Implemented Interfaces:
org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>

public class Base64PropertyDecoder extends Object implements org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>
Decodes Base64-encoded properties.
Author:
Daniele Torino on Stack Overflow, Gustav Blaß
  • Field Details

    • BASE64_PROPERTY_PATTERN

      private static final Pattern BASE64_PROPERTY_PATTERN
      Matches all (but also some malformed) Base64-encoded strings that are prepended with the prefix base64:. The actual Base64 content is the base64 group.
  • Constructor Details

    • Base64PropertyDecoder

      public Base64PropertyDecoder()
  • Method Details

    • initialize

      public void initialize(@NonNull @NonNull org.springframework.context.ConfigurableApplicationContext applicationContext)
      Overrides all Base64-encoded properties with their decoded contents.
      Specified by:
      initialize in interface org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>
      Parameters:
      applicationContext - Holds the properties to be decoded.
    • decodeBase64Properties

      @NonNull private @NonNull Map<String,Object> decodeBase64Properties(@NonNull @NonNull org.springframework.core.env.PropertySource<?> source)
      For each entry in the given EnumerablePropertySource, checks if it is a Based64-encoded string and, if so, decodes it.
      Parameters:
      source - Holds the properties to be decoded.
      Returns:
      The decoded equivalents of any Base64-encoded properties. Empty if there are none or if the given PropertySource is not an EnumerablePropertySource.
    • decodeBase64Property

      @Contract(pure=true) @NonNull private @NonNull Optional<String> decodeBase64Property(@NonNull @NonNull String input)
      Converts the given Base64-encoded String back to its original (decoded) form.
      Parameters:
      input - The encoded string that shall be decoded. Will only be decoded if it begins with base64:
      Returns:
      The decoding result. Empty if the input does not start with the specified prefix or if decoding failed.