Skip to content

Support plain text decryption for XML file extension #2767

@cselagea

Description

@cselagea

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:

  1. There were an easier way to plug in custom ResourceEncryptor implementations, e.g. by simply defining ResourceEncryptor beans
  2. AbstractCipherResourceEncryptor were open for extension

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions