OSGI Configuration Parameters for Spring Components - 7.0

Talend ESB Container Administration Guide

EnrichVersion
7.0
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Administration and Monitoring
Design and Development
Installation and Upgrade
EnrichPlatform
Talend ESB

If you are using a Java client and using OSGi configuration parameters, then follow these steps.

To use jasypt with spring components:

  1. Add the following Maven dependencies:

    <dependency>
      <groupId>org.apache.servicemix.bundles</groupId>
      <artifactId>org.apache.servicemix.bundles.jasypt</artifactId>
      <version>1.9.2_1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.servicemix.bundles</groupId>
      <artifactId>org.apache.servicemix.bundles.jasypt-spring31</artifactId>
      <version>1.9.2_1</version>
    </dependency>
  2. Add the usual properties, but the encrypted property should be wrapped by the ENC() function.

    <osgix:cm-properties id="properties" persistent-id="my">
      <prop key="mydb.password">ENC(fAdXf/ed2k+2uD1LhoOpvw==)</prop>
    </osgix:cm-properties>
  3. Add the password and the algorithm configuration for encryptor.

    <bean id="environmentVariablesConfiguration" class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
       <property name="algorithm" value="PBEWITHSHA256AND128BITAES-CBC-BC"/>
       <property name="password" value="TESB_ENV_PASSWORD"/>
    </bean> 
  4. Create the encryptor and inject configuration to it.

    <bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
       <property name="config" ref="environmentVariablesConfiguration"/>
    </bean>
  5. Add the property configurer and pass the properties to it. The EncryptablePropertyPlaceholderConfigurer will read the .properties files and make their values accessible as ${var}.

    <bean id="propertyConfigurer"
     class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderCon
    figurer">
       <constructor-arg ref="configurationEncryptor"/>
       <property name="properties" ref="properties"/>
    </bean>
  6. Now, you can use the properties as usual:

    <bean id="serviceBean" class="org.company.example.MyServiceImpl">
        <property name="prop" value="${mydb.password}"/>
    </bean>