Skip to content

PropertySourcesPlaceholderConfigurer never calls "convertProperties" on merged properties [SPR-8928] #13568

Closed

Description

@spring-projects-issues

Daniel Fernández opened SPR-8928 and commented

org.springframework.context.support.PropertySourcesPlaceholderConfigurer is overriding the "postProcessBeanFactory" method defined in org.springframework.beans.factory.config.PropertyResourceConfigurer in order to register the required chain of PropertySource objects that will be use for resolving properties. This makes sense and is OK.

But the problem is that the PropertySource object for the local properties (those coming from the "location" attribute and also from the "properties" property) is being created like this:

PropertySource<?> localPropertySource =
new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, this.mergeProperties());

...whereas in the original "postProcessBeanFactory" method in PropertyResourceConfigurer these merged properties are post-processed by executing the "convertProperties" method:

Properties mergedProps = mergeProperties();
// Convert the merged properties, if necessary.
convertProperties(mergedProps);
// Let the subclass process the properties.
processProperties(beanFactory, mergedProps);

This means that the new PropertySourcesPlaceholderConfigurer class never calls "convertProperties", and so disables one of the extension mechanisms of the old pre-3.1 PropertyPlaceholderConfigurer class: overriding the "convertProperty(...)" and "convertPropertyValue(...)" methods.

I am jasypt's author http://www.jasypt.org and I am creating a Spring3.1-compatible EncryptedPropertySourcesPlaceholderConfigurer, but this bug doesn't allow me to transparently apply property decryption at the "convertProperty" method :-(


Affects: 3.1 GA

Issue Links:

8 votes, 18 watchers

Activity

  1. spring-projects-issues commented on Feb 9, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    Hi Daniel,

    Thanks for the submission. Would you be willing to attach a simple test case that demonstrates the problem? There may still be time to fit this in for 3.1.1.

  2. spring-projects-issues commented on Nov 30, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Scott C. commented

    Chris,

    I have the exact use case as Daniel. I suggest this needs to be implemented ASAP for at least 3 reasons:

    1. This use case above.
    2. In the JavaDoc for the convertPropertyValue method it states "Convert the given property value from the properties source to the value which should be applied. The default implementation simply returns the original value. Can be overridden in subclasses, for example to detect encrypted values and decrypt them accordingly." -- this is an explicit design decision/extension Juergen stated, yet it is not longer viable due to this bug. There are plenty of people (I assume), who read that and assume it will work as written.
    3. Finally, I think it is appropriate design to keep backward compatible (nearly at all costs) when you are intending to replace one (class) component with another in a framework used by millions of developers. Consistency (when viable) between the components makes it easier for all to:
      a) upgrade to new versions of a framework
      b) learning the framework
      c) testing both the actual framework and all the users of it

    I could go on, but I think you get my point. :)

    Overall, this is a great replacement for the old PFPC. I applaud the effort. I just think folks expect it to work within the framework as is.

    Looking forward to hearing the comments.

    Thanks!

    Scott

  3. spring-projects-issues commented on Apr 29, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Patrick Hayden commented

    I have exactly the same issue as Daniel describes. I have created a class that extends PropertySourcesPlaceholderConfigurer and overrides convertProperty() to decrypt a property value that I would prefer not to put on the server in plain text. The problem is that the new convertProperty() implementation never gets called.

  4. spring-projects-issues commented on Mar 25, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Andreas Toom commented

    Hi,

    I would like to add another vote for this issue. We are starting a new project with Spring Boot and we are using the Jasypt library mentioned above. When looking through the source code it seems that Spring 4.x does not allow for conversion of properties that are loaded in the Environment using a PropertySourcesPlaceholderConfigurer.

    Spring should allow for a single point of conversion of values no matter where it is loaded from, i.e. command line, system property, environment etc.

    /Andreas

  5. spring-projects-issues commented on Oct 29, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Michael Gallagher commented

    Here's the workaround I'm using, if anyone finds it helpful:

        protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
                                           final StringValueResolver valueResolver) {
    
            super.doProcessProperties(beanFactoryToProcess,
                    new StringValueResolver() {
                        @Override
                        public String resolveStringValue(String strVal) {
                            return convertPropertyValue(valueResolver.resolveStringValue(strVal));
                        }
                    }
            );
        }
    
  6. spring-projects-issues commented on Feb 29, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Alireza Fattahi commented

    @Michael Gallagher solution worked for me. Thanks!

  7. spring-projects-issues commented on May 17, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sima Salmani commented

    @Michael Gallagher
    Hi
    Thanks. It helped me a lot.

  8. spring-projects-issues commented on Jun 14, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Chethan Bandi commented

    yesterday I just stumbled on this with spring-boot 1.3.5.RELEASE in my project. I confirm this issue exists and mentioned workaround worked for me.

  9. spring-projects-issues commented on Jan 13, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Jeremy Hettenhouser commented

    The work around as written does mess with the

    @Value("${...}")
    

    annotations though. My own workaround is pretty ugly though. I use a method similar to jasypt in overriding merged properties and filtering there.

  10. spring-projects-issues commented on Aug 11, 2018

    @spring-projects-issues
    CollaboratorAuthor

    pushpendra-jain commented

    Written one sample application to do add support for using Encrypted values here

    https://github.com/pushpendra-jain/spring-examples/tree/master/PropertySourcesPlaceholderEncrypter

    Basically instead of trying to invoke its convertProperty method overrided its processProperties method and getting the job done and code surely does not change any existing behavior.

  11. added
    type: bug
    status: waiting-for-triage
    in: core
    and removed
    type: bug
    on Jan 11, 2019
  12. added
    status: bulk-closed
    and removed
    status: waiting-for-triage
    on Jan 11, 2019
  13. spring-projects-issues commented on Jan 12, 2019

    @spring-projects-issues
    CollaboratorAuthor

    Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

  14. added a commit that references this issue on Oct 17, 2019
    2363ce5
  15. raduiacobescu commented on Jun 9, 2020

    @raduiacobescu

    It took me ages to get to your implementation example @spring-issuemaster
    This must be added somewhere in a documentation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: corestatus: bulk-closed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions