Jasypt + Fuse + Camel
wesssel Dec 11, 2014 4:03 AMHello everyone,
We have a Camel route defined with Spring XML and we are trying to use Jasypt for encrypting passwords in properties files. Since we would like to use the properties in both Spring and in the Camel route itself, we started off with a BridgePropertyPlaceholderConfigurer, but this does not work with the Jasypt propertiesParser.
After doing some Googling I came up with this solution:
<bean id="environmentVariablesConfiguration" class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
<property name="algorithm" value="PBEWithMD5AndDES" />
<property name="password" value="secret" />
</bean>
<bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config" ref="environmentVariablesConfiguration" />
</bean>
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="ignoreMissingLocation" value="true" />
<property name="locations">
<list>
<value>classpath:file.properties</value>
<value>file:/etc/jboss/otherfile.conf</value>
</list>
</property>
<property name="propertiesParser" ref="jasypt" />
</bean>
<bean id="propertyConfigurer" class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="configurationEncryptor"/>
<property name="placeholderPrefix" value="?{" />
<property name="placeholderSuffix" value="}" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:file.properties</value>
<value>file:/etc/jboss/otherfile.conf</value>
</list>
</property>
</bean>
<bean id="jasypt" class="org.apache.camel.component.jasypt.JasyptPropertiesParser">
<property name="password" value="secret" />
</bean>
Which works fine when running as mvn camel:run, but when deploying to Fuse I am getting an exception:
09:42:44,311 | ERROR | ExtenderThread-6 | ContextLoaderListener | 147 - org.springframework.osgi.extender - 1.2.1 | Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=com.onior.justid.datahandler, config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'propertyConfigurer' defined in URL [bundle://337.1:0/META-INF/spring/camel-context-dev.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.jasypt.encryption.StringEncryptor]: Could not convert constructor argument value of type [org.jasypt.encryption.pbe.StandardPBEStringEncryptor] to required type [org.jasypt.encryption.StringEncryptor]: Failed to convert value of type 'org.jasypt.encryption.pbe.StandardPBEStringEncryptor' to required type 'org.jasypt.encryption.StringEncryptor'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.jasypt.encryption.pbe.StandardPBEStringEncryptor] to required type [org.jasypt.encryption.StringEncryptor]: no matching editors or conversion strategy found
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'propertyConfigurer' defined in URL [bundle://337.1:0/META-INF/spring/camel-context-dev.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.jasypt.util.text.TextEncryptor]: Could not convert constructor argument value of type [org.jasypt.encryption.pbe.StandardPBEStringEncryptor] to required type [org.jasypt.util.text.TextEncryptor]: Failed to convert value of type 'org.jasypt.encryption.pbe.StandardPBEStringEncryptor' to required type 'org.jasypt.util.text.TextEncryptor'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.jasypt.encryption.pbe.StandardPBEStringEncryptor] to required type [org.jasypt.util.text.TextEncryptor]: no matching editors or conversion strategy found
The pom looks like this:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jasypt</artifactId>
<version>${camel.version}</version>
</dependency>
<!-- Jasypt Password encryption -->
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt-spring31</artifactId>
<version>1.9.1</version>
</dependency>
The Camel version is 2.12.0.redhat-610379, which uses the same version 1.9.1 for jasypt. I have the jasypt-spring31 and jasypt in Fuse, so osgi dependencies are met AFAIK.
I have been Googling and found someone with the same issue, stating the properties file was wrapping lines incorrectly, this is not the case for us.
If anyone knows what's up, I would love to hear. Thanks in advance. ;-)