Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support plain text decryption for XML file extension #2767

Open
cselagea opened this issue Feb 27, 2025 · 0 comments
Open

Support plain text decryption for XML file extension #2767

cselagea opened this issue Feb 27, 2025 · 0 comments

Comments

@cselagea
Copy link
Contributor

cselagea commented Feb 27, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant