-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Is your feature request related to a problem? Please describe.
I need to serve decrypted XML files as plain text, but only YAML, JSON, and properties file extensions are currently supported.
Describe the solution you'd like
Implement a ResourceEncryptor for the xml file extension.
https://github.com/FasterXML/jackson-dataformat-xml provides an XML extension of JsonFactory, which fits in nicely with AbstractCipherResourceEncryptor#decryptWithJacksonParser and hence could make this a straightforward implementation.
Describe alternatives you've considered
I implemented such a ResourceEncryptor, albeit not using jackson-dataformat-xml, and plugged it in using the following configuration:
@Configuration
public class ResourceEncryptorConfiguration {
@Bean
@Primary
public Map<String, ResourceEncryptor> augmentedResourceEncryptors(Map<String, ResourceEncryptor> existing,
TextEncryptorLocator encryptor) {
var resourceEncryptorMap = new HashMap<>(existing);
registerBySupportedExtensions(resourceEncryptorMap, new CipherResourceXmlEncryptor(encryptor));
return resourceEncryptorMap;
}
private void registerBySupportedExtensions(Map<String, ResourceEncryptor> resourceEncryptorMap,
ResourceEncryptor resourceEncryptor) {
for (String ext : resourceEncryptor.getSupportedExtensions()) {
resourceEncryptorMap.put(ext, resourceEncryptor);
}
}
}Not only is this a carbon copy of org.springframework.cloud.config.server.config.ResourceEncryptorConfiguration, but AbstractCipherResourceEncryptor is package-private so I can't reuse the CIPHER_MARKER constant or decryptValue method in my implementation; the latter is especially important because EnvironmentPrefixHelper is also package-private.
This would be a more workable solution if:
- There were an easier way to plug in custom
ResourceEncryptorimplementations, e.g. by simply definingResourceEncryptorbeans AbstractCipherResourceEncryptorwere open for extension
Additional context
N/A