- camel-jetty: A test-case for the Camel Jetty component, TLS, the REST DSL + Jasypt.
1) The Apache Camel REST DSL
Apache Camel offers a REST DSL which makes it really easy to create a simple REST service.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<rest path="/data"> | |
<get produces="application/xml"> | |
<to uri="direct:get"/> | |
</get> | |
</rest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<route> | |
<from uri="direct:get" /> | |
<pollEnrich> | |
<constant>file:target/test-classes/data?noop=true</constant> | |
</pollEnrich> | |
</route> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<restConfiguration scheme="https" component="jetty" port="{{https.port}}"> | |
<endpointProperty key="sslContextParameters" value="#serverSSLParameters"/> | |
</restConfiguration> |
2) Getting TLS to work with the Camel REST DSL
To support TLS with the Camel REST DSL, we need to set the scheme to "https" as above in the "restConfiguration". The REST configuration also refers to a property called "sslContextParameters", which is where we obtain the keys required to support TLS. See the Camel JSSE documentation for more information on this property.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<sslContextParameters id="serverSSLParameters" xmlns="http://camel.apache.org/schema/spring"> | |
<keyManagers keyPassword="{{service.key.password}}"> | |
<keyStore resource="servicestore.jks" password="{{service.keystore.password}}"/> | |
</keyManagers> | |
<trustManagers> | |
<keyStore resource="truststore.jks" password="{{ca.keystore.password}}"/> | |
</trustManagers> | |
</sslContextParameters> |
3) Using Jasypt to decrypt keystore passwords for use in TLS
Note above that we have not hard-coded the TLS keystore passwords in our Camel spring configuration, but are instead retrieving them from a property. Camel offers the ability to store the passwords in encrypted form, by using the Camel Jasypt component to decrypt them given a master password. The encrypted passwords themselves are stored in a passwords.properties file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service.keystore.password=ENC(JQD869NUF1pHbAu+653J2Q==) | |
service.key.password=ENC(uL17JPAMXUHzzRacEjSXAQ==) | |
ca.keystore.password=ENC(IX/BDgPKyRbRyQgKK0u+4cjmjFLPHyxw) |
- java -jar camel-jasypt-2.23.1.jar -c encrypt -p master-secret -i storepass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean id="jasypt" class="org.apache.camel.component.jasypt.JasyptPropertiesParser"> | |
<property name="password" value="sys:PASSWORD"/> | |
</bean> |
4) Invoking on our secured REST service using the Camel HTTP4 component
The demo also includes a client route which invokes on the secured REST service we have created. We use the Camel HTTP4 component for this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<route> | |
<from uri="timer:start?repeatCount=1"/> | |
<to uri="http4:localhost:{{https.port}}/data?sslContextParameters=#clientSSLParameters&x509HostnameVerifier=#noopHostnameVerifier" /> | |
<log message="Data received: ${body}" /> | |
</route> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<sslContextParameters id="clientSSLParameters" xmlns="http://camel.apache.org/schema/spring"> | |
<trustManagers> | |
<keyStore resource="truststore.jks" password="{{ca.keystore.password}}"/> | |
</trustManagers> | |
</sslContextParameters> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean id="noopHostnameVerifier" class="org.apache.http.conn.ssl.NoopHostnameVerifier" /> |