3 Replies Latest reply on Dec 18, 2014 5:30 AM by bharadwaj

    Jasypt + Fuse + Camel

    wesssel

      Hello 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. ;-)

        • 1. Re: Jasypt + Fuse + Camel
          wesssel

          If anyone knows how to properly use Jasypt in Spring and the Camel context in a different way, that's also welcome. ;-)

          • 2. Re: Re: Jasypt + Fuse + Camel
            vladimir_v

            Hi,

             

            I use jasypt with camel in blueprint.

            In my pom.xml for dependencies I have:

             

             

            <!-- snip --> 
            <dependency>
              <groupId>org.apache.camel</groupId>
              <artifactId>camel-core</artifactId>
              <version>2.12.0.redhat-610379</version>
              </dependency>
              <dependency>
              <groupId>org.apache.camel</groupId>
              <artifactId>camel-blueprint</artifactId>
              <version>2.12.0.redhat-610379</version>
              </dependency>
            <!-- snip -->
            <Import-Package>org.jasypt.encryption.pbe,*</Import-Package>
            <!-- snip -->
            

             

             

            Then in src/main/resources/OSGI-INF/blueprint/blueprint.xml I have:

            <?xml version="1.0" encoding="UTF-8"?>
            <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/blueprint"
              xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
              xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
              xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0"
              xsi:schemaLocation="
              http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
              http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
            
              <reference id="curator" interface="org.apache.curator.framework.CuratorFramework"/>
            
              <ext:property-placeholder>
              <ext:location>file:etc/encrypted.passwords</ext:location>
              </ext:property-placeholder>
              <enc:property-placeholder>
              <enc:encryptor class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
              <property name="config">
              <bean class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
              <property name="algorithm" value="PBEWithMD5AndDES"/>
              <property name="passwordEnvName" value="FUSE_ENC_PASSWD"/>
              </bean>
              </property>
              </enc:encryptor>
              </enc:property-placeholder>
            

             

            Then calling the passwords with ${something}

            You can export FUSE_ENC_PASSWD in the init script for example.

             

            Also I'm assigning a new profile to my container which has features jasypt-encryption, fabric-camel, mq-fabric-camel

            • 3. Re: Jasypt + Fuse + Camel
              bharadwaj

              <dependency>

                  <groupId>org.apache.camel</groupId>

                  <artifactId>camel-jasypt</artifactId>

                  <version>x.x.x</version>

                  <!-- use the same version as your Camel core version -->

              </dependency>

               

              <!-- define the jasypt properties parser with the given password to be used -->

               

              <bean id="jasypt" class="org.apache.camel.component.jasypt.JasyptPropertiesParser">

                  <!-- password is mandatory, you can prefix it with sysenv: or sys: to indicate it should use

                       an OS environment or JVM system property value, so you dont have the master password defined here -->

                  <property name="password" value="secret"/>

              </bean>

              <camelContext xmlns="http://camel.apache.org/schema/spring">

                  <!-- define the camel properties placeholder, and let it leverage jasypt -->

                  <propertyPlaceholder id="properties"

                                       location="classpath:org/apache/camel/component/jasypt/myproperties.properties"

                                       propertiesParserRef="jasypt"/>

                  <route>

                      <from uri="direct:start"/>

                      <to uri="{{cool.result}}"/>

                  </route>

              </camelContext>