title: Jasypt Encryption not working with Maven profiles
body: <p>I'm trying to get jasypt to decrypt a (previously encrypted) property value, which ultimately will be used to log into a database.  The decryption works fine except for when I introduce Maven profiles.  I have a local/dev/prod set of property files which are environment specific.  </p>
  
  <p>Here's the relevant portion of my spring3 config.  This is the most critical part of the code examples: this is driving how the decryption is setup and what decrypted string is being set to the example dummy bean.</p>
  
  <pre><code>  &lt;bean id="jvmVariablesConfiguration" class="org.jasypt.encryption.pbe.config.EnvironmentPBEConfig"
           p:password="secret_password_here"/&gt;
  
    &lt;bean id="jvmConfigurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor"
          p:config-ref="jvmVariablesConfiguration"/&gt;
  
    &lt;bean id="jvmPropertyConfigurer" class="org.jasypt.spring3.properties.EncryptablePropertyPlaceholderConfigurer"
          p:locations-ref="passwordProps"&gt;
      &lt;constructor-arg ref="jvmConfigurationEncryptor"/&gt;
    &lt;/bean&gt;
  
    &lt;util:list id="passwordProps"&gt;
      &lt;value&gt;classpath:database.properties&lt;/value&gt;    
    &lt;/util:list&gt;
  
    &lt;encryption:encryptable-properties id="dbProps" encryptor="jvmConfigurationEncryptor" location="classpath:database.properties"/&gt;
  
    &lt;bean id="dummy" class="DummyPropertyTest"&gt;
      &lt;property name="prop" value="${database.bar}"/&gt;
    &lt;/bean&gt;
  </code></pre>
  
  <p>In one of my maven poms, here is where I specify the profiles.</p>
  
  <pre><code>  ...
  
    &lt;profiles&gt;
      &lt;profile&gt;
        &lt;id&gt;local&lt;/id&gt;
        &lt;properties&gt;
          &lt;build.profile.id&gt;local&lt;/build.profile.id&gt;
        &lt;/properties&gt;
        &lt;build&gt;
          &lt;filters&gt;
            &lt;filter&gt;src/main/resources/properties/${build.profile.id}/database.properties&lt;/filter&gt;
          &lt;/filters&gt;
          &lt;resources&gt;
            &lt;resource&gt;
              &lt;filtering&gt;true&lt;/filtering&gt;
              &lt;directory&gt;src/main/resources&lt;/directory&gt;
              &lt;includes&gt;
                &lt;include&gt;**/*.properties&lt;/include&gt;
                &lt;include&gt;**/*.xml&lt;/include&gt;
              &lt;/includes&gt;
            &lt;/resource&gt;
          &lt;/resources&gt;
        &lt;/build&gt;
      &lt;/profile&gt;
  
      &lt;!--dev and prod profiles follow this in a similar pattern --&gt;
  
  ....
  </code></pre>
  
  <p>I'm using jasypt version 1.9.1: </p>
  
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.jasypt&lt;/groupId&gt;
    &lt;artifactId&gt;jasypt-spring3&lt;/artifactId&gt;
    &lt;version&gt;1.9.1&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I have a main database property file (database.properties) setup in /src/main/resources, which has these placeholder properties:</p>
  
  <pre><code>database.url=${database.url}
  database.username=${database.username}
  database.password=${database.password}
  database.dialect=${database.dialect}
  database.driver=${database.driver}
  database.show_sql=${database.show_sql}
  database.bar=${database.bar}
  </code></pre>
  
  <p>And then here's my local property file, located at /src/main/resources/properties/local/database.properties :</p>
  
  <pre><code>database.url=jdbc:hsqldb:hsql://localhost/db
  database.username=sa
  database.password=
  database.dialect=MyHSQLDialect
  database.driver=org.hsqldb.jdbcDriver
  database.show_sql=true
  database.bar=ENC(RSuprdBgcpdheiWX0hJ45Q==)
  </code></pre>
  
  <p>Here's my sample spring bean code, simply reading the property that was set to it.  If everything works, the value will be printed to stdout decrypted. </p>
  
  <pre><code>import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  public class DummyPropertyTest {
  
      private String prop;
  
      public String getProp() {
          return prop;
      }
  
      public void setProp(String prop) {
          this.prop = prop;
      }
  
      @Value("#{dbProps['database.bar']}")
      public String otherProp;
  
      public String getOtherProp() {
          return otherProp;
      }
  
      public static void main(String[] args) {
          ApplicationContext ctx = new ClassPathXmlApplicationContext("/META-INF/spring/applicationContext-common.xml");
          DummyPropertyTest dpt = (DummyPropertyTest) ctx.getBean("dummy");
  
          System.out.println("what's my property being set??: "+dpt.getProp());
          System.out.println("otherProp:"+dpt.getOtherProp());
      }
  }
  </code></pre>
  
  <p>If I tweak my spring configuration to read in a property that resides on the main property file which normally just contains just placeholders for the per-property environment override, then the decryption works.  But the decryption does not work trying to read a encrypted property from the local properties file.  I've mucked around quite a bit trying to tweak the spring configurations, hoping that perhaps it was just a classpath issue, but that didn't seem to help either.</p>
  
  <p>Do I need to override how Spring looks at property prefixes and suffixes, if only for perhaps the properties i need to encrypt?  (If I do that, that would seem to be applicable to all properties, not just the encryptable ones, since Jasypt's EncryptablePropertyPlaceholderConfigurer is a drop-in replacement for Spring's PropertyPlaceholderConfigurer).</p>
  
  <p>Here's the output of the program if I have the two properties files set as I've illustrated: 
  <code>what's my property being set??: ENC(RSuprdBgcpdheiWX0hJ45Q==)</code></p>
  
  <p>Here's the output of the program if I have the main property file contain the encrypted property:
  <code>what's my property being set??: sa</code></p>
  
  <p>I'm not sure if the problem is Spring, or Jayspt.  I don't think it's Maven.  I'd rather not ditch the Maven profiles as they stand now, if at all possible.</p>
  
  <p><strong>Edited for clarity, runtime examples.</strong></p>
  
  <p>*<strong><em>Update</em>*</strong>: I can verify that the value is correctly decrypted if I use the Jasypt Spring configuration way 
  <code>&lt;encryption:encryptable-properties id="dbProps" encryptor="jvmConfigurationEncryptor" location="classpath:database.properties"/&gt;</code></p>
  
  <p>Then in my test Bean I can wire up a member to have the property assigned to it:</p>
  
  <pre><code>    @Value("#{dbProps['database.bar']}")
      public String otherProp;
  </code></pre>
  
  <p>This seems to work. But I really need the PropertyOverride thing to work, so that I can properly get the database configuration buttoned up.</p>