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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final PatternMatches all (but also some malformed) Base64-encoded strings that are prepended with the prefixbase64:. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecodeBase64Properties(@NonNull org.springframework.core.env.PropertySource<?> source) For each entry in the givenEnumerablePropertySource, checks if it is a Based64-encoded string and, if so, decodes it.decodeBase64Property(@NonNull String input) Converts the given Base64-encodedStringback to its original (decoded) form.voidinitialize(@NonNull org.springframework.context.ConfigurableApplicationContext applicationContext) Overrides all Base64-encoded properties with their decoded contents.
-
Field Details
-
BASE64_PROPERTY_PATTERN
-
-
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:
initializein interfaceorg.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 givenEnumerablePropertySource, 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
PropertySourceis not an EnumerablePropertySource.
-
decodeBase64Property
@Contract(pure=true) @NonNull private @NonNull Optional<String> decodeBase64Property(@NonNull @NonNull String input) Converts the given Base64-encodedStringback to its original (decoded) form.- Parameters:
input- The encoded string that shall be decoded. Will only be decoded if it begins withbase64:- Returns:
- The decoding result. Empty if the input does not start with the specified prefix or if decoding failed.
-