Tooling
The Jasypt component provides a little command line tooling to encrypt or decrypt values.
The console output the syntax and which options it provides:
Apache Camel Jasypt takes the following options
-h or -help = Displays the help screen
-c or -command <command> = Command either encrypt or decrypt
-p or -password <password> = Password to use
-i or -input <input> = Text to encrypt or decrypt
-a or -algorithm <algorithm> = Optional algorithm to use
For example to encrypt the value tiger you run with the following parameters:
XXX -c encrypt -p secret -i tiger"
Which outputs the following result
Encrypted text: qaEEacuW7BUti8LcMgyjKw==
This means the encrypted representation qaEEacuW7BUti8LcMgyjKw== can be decrypted back to tiger if you know the master password which was secret.
If you run the tool again then the encrypted value will return a different result. But decrypting the value will always return the correct original value.
So you can test it by running the tooling using the following parameters:
XXX -c decrypt -p secret -i qaEEacuW7BUti8LcMgyjKw==
Which outputs the following result:
The idea is then to use those encrypted values in your Properties files. Notice how the password value is encrypted and the value has the tokens surrounding ENC(value here)
# refer to a mock endpoint name by that encrypted password
cool.result=mock:{{cool.password}}
# here is a password which is encrypted
cool.password=ENC(bsW9uV37gQ0QHFu7KO03Ww==)
Tooling dependencies
The tooling requires the following JARs in the classpath
camel-core-2.5.jar commons-logging-api-1.1.jar commons-management-1.0.jar jasypt-1.6.jar commons-lang-2.1.jar commons-codec-1.4.jar icu4j-4.0.1.jar
URI Options
The options below are exclusive for the Jasypt component.
Name |
Default Value |
Type |
Description |
password |
null |
String |
Specifies the master password to use for decrypting. This option is mandatory. See below for more details. |
algorithm |
null |
String |
Name of an optional algorithm to use. |
Protecting the master password
The master password used by Jasypt must be provided, so its capable of decrypting the values. However having this master password out in the opening may not be an ideal solution. Therefore you could for example provided it as a JVM system property or as a OS environment setting. If you decide to do so then the password option supports prefixes which dictates this. sysenv: means to lookup the OS system environment with the given key. sys: means to lookup a JVM system property.
For example you could provided the password before you start the application
$ export CAMEL_ENCRYPTION_PASSWORD=secret
Then start the application, such as running the start script.
When the application is up and running you can unset the environment
$ unset CAMEL_ENCRYPTION_PASSWORD
The password option is then a matter of defining as follows: password=sysenv:CAMEL_ENCRYPTION_PASSWORD.
Example with Java DSL
In Java DSL you need to configure Jasypt as a JasyptPropertiesParser instance and set it on the Properties component as show below:
JasyptPropertiesParser jasypt = new JasyptPropertiesParser();
jasypt.setPassword("secret");
PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:org/apache/camel/component/jasypt/myproperties.properties");
pc.setPropertiesParser(jasypt);
context.addComponent("properties", pc);
The properties file myproperties.properties then contain the encrypted value, such as shown below. Notice how the password value is encrypted and the value has the tokens surrounding ENC(value here)
# refer to a mock endpoint name by that encrypted password
cool.result=mock:{{cool.password}}
# here is a password which is encrypted
cool.password=ENC(bsW9uV37gQ0QHFu7KO03Ww==)
Example with Spring XML
In Spring XML you need to configure the JasyptPropertiesParser which is shown below. Then the Camel Properties component is told to use jasypt as the properties parser, which means Jasypt have its chance to decrypt values looked up in the properties.
<bean id="jasypt" class="org.apache.camel.component.jasypt.JasyptPropertiesParser">
<property name="password" value="secret"/>
</bean>
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:org/apache/camel/component/jasypt/myproperties.properties"/>
<property name="propertiesParser" ref="jasypt"/>
</bean>
The Properties component can also be inlined inside the <camelContext> tag which is shown below. Notice how we use the propertiesParserRef attribute to refer to Jasypt.
<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">
<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>
See Also