forked from apache/camel-spring-boot-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Croway
- Loading branch information
Showing
24 changed files
with
974 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ssl | ||
*.jks | ||
*.pem |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
== Spring Boot Example with HTTP and SSL | ||
|
||
=== Introduction | ||
|
||
This example shows how to configure SSL in different scenarios: | ||
|
||
1. one way SSL, the server exposes REST API using SSL and the client trusts the server certificate. The SSL server configuration is managed by Spring Boot and the Camel inherit it, the SSL client configuration is managed by Camel in HTTP component | ||
2. two ways SSL, the server and the client check both certificates in a mutual trusted handshake | ||
3. same scenario as point 1 but the server configuration is managed directly in Camel (undertow component) instead of Spring Boot | ||
|
||
=== Prerequisites | ||
|
||
keytool installed and available on PATH | ||
|
||
Generate certificates and keystores | ||
|
||
$ ./generate-certificates.sh | ||
|
||
=== Run using one way ssl (server validation on client side) | ||
|
||
Start ssl-server in a separate terminal: | ||
|
||
$ mvn spring-boot:run -f ssl-server/pom.xml | ||
|
||
Start ssl-client in a separate terminal: | ||
|
||
$ mvn spring-boot:run -f ssl-client/pom.xml | ||
|
||
=== Run using two ways ssl (mutual validation) | ||
|
||
Start ssl-server in a separate terminal: | ||
|
||
$ mvn spring-boot:run -f ssl-server/pom.xml -Ptwoways | ||
|
||
Start ssl-client in a separate terminal: | ||
|
||
$ mvn spring-boot:run -f ssl-client/pom.xml -Ptwoways | ||
|
||
=== Run using Camel component as server | ||
|
||
Start ssl-camel-server in a separate terminal: | ||
|
||
$ mvn spring-boot:run -f ssl-camel-server/pom.xml | ||
|
||
Start ssl-client in a separate terminal: | ||
|
||
$ mvn spring-boot:run -f ssl-client/pom.xml | ||
|
||
=== Call service to start handshake | ||
|
||
$ curl http://localhost:8080/ping | ||
|
||
==== Tip | ||
|
||
to show the full handshake it is possible to add `-Dspring-boot.run.jvmArguments="-Djavax.net.debug=all"` in the start command line | ||
|
||
|
||
=== Help and contributions | ||
|
||
If you hit any problem using Camel or have some feedback, then please | ||
https://camel.apache.org/community/support/[let us know]. | ||
|
||
We also love contributors, so | ||
https://camel.apache.org/community/contributing/[get involved] :-) | ||
|
||
The Camel riders! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
GEN_DIR="ssl" | ||
|
||
K_PASS=pass123 | ||
SERVER_JKS=$GEN_DIR/server.jks | ||
SERVER_CERT=$GEN_DIR/server.pem | ||
SERVER_TRUST=$GEN_DIR/server-truststore.jks | ||
CLIENT_JKS=$GEN_DIR/client.jks | ||
CLIENT_CERT=$GEN_DIR/client.pem | ||
CLIENT_TRUST=$GEN_DIR/client-truststore.jks | ||
|
||
echo remove directory $GEN_DIR if exists | ||
[ -e $GEN_DIR ] && rm -rf $GEN_DIR | ||
|
||
echo create directory $GEN_DIR | ||
mkdir -p $GEN_DIR | ||
|
||
echo generate server certificates | ||
keytool -alias server -dname "cn=localhost, ou=ssl-server, o=csb-http-ssl, c=US" -genkeypair -storepass $K_PASS -keyalg RSA -keystore $SERVER_JKS | ||
|
||
echo generate client certificates | ||
keytool -alias client -dname "cn=localhost, ou=ssl-client, o=csb-http-ssl, c=US" -genkeypair -storepass $K_PASS -keyalg RSA -keystore $CLIENT_JKS | ||
|
||
echo export server certificates | ||
keytool -exportcert -alias server -storepass $K_PASS -keystore $SERVER_JKS -rfc -file $SERVER_CERT | ||
|
||
echo export client certificates | ||
keytool -exportcert -alias client -storepass $K_PASS -keystore $CLIENT_JKS -rfc -file $CLIENT_CERT | ||
|
||
echo import server in client truststore | ||
keytool -import -keystore $CLIENT_TRUST -storepass $K_PASS -file $SERVER_CERT -alias server -noprompt -trustcacerts | ||
|
||
echo import client in server truststore | ||
keytool -import -keystore $SERVER_TRUST -storepass $K_PASS -file $CLIENT_CERT -alias client -noprompt -trustcacerts | ||
|
||
echo copy $SERVER_JKS in ssl-server/src/main/resources | ||
[ -e ssl-server/src/main/resources/server.jks ] && rm ssl-server/src/main/resources/server.jks | ||
cp $SERVER_JKS ssl-server/src/main/resources/server.jks | ||
|
||
echo copy $SERVER_TRUST in ssl-server/src/main/resources | ||
[ -e ssl-server/src/main/resources/server-truststore.jks ] && rm ssl-server/src/main/resources/server-truststore.jks | ||
cp $SERVER_TRUST ssl-server/src/main/resources/server-truststore.jks | ||
|
||
echo copy $CLIENT_JKS in ssl-client/src/main/resources | ||
[ -e ssl-client/src/main/resources/client.jks ] && rm ssl-client/src/main/resources/client.jks | ||
cp $CLIENT_JKS ssl-client/src/main/resources/client.jks | ||
|
||
echo copy $CLIENT_TRUST in ssl-client/src/main/resources | ||
[ -e ssl-client/src/main/resources/client-truststore.jks ] && rm ssl-client/src/main/resources/client-truststore.jks | ||
cp $CLIENT_TRUST ssl-client/src/main/resources/client-truststore.jks | ||
|
||
echo copy $SERVER_JKS in ssl-camel-server/src/main/resources | ||
[ -e ssl-camel-server/src/main/resources/server.jks ] && rm ssl-camel-server/src/main/resources/server.jks | ||
cp $SERVER_JKS ssl-camel-server/src/main/resources/server.jks |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.camel.springboot.example</groupId> | ||
<artifactId>examples</artifactId> | ||
<version>4.4.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>camel-example-spring-boot-http-ssl</artifactId> | ||
<name>Camel SB Examples :: HTTP SSL</name> | ||
<description>An example showing the Camel HTTP component with Spring Boot and SSL</description> | ||
<packaging>pom</packaging> | ||
|
||
<properties> | ||
<category>Rest</category> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.redhat.camel.springboot.platform</groupId> | ||
<artifactId>camel-spring-boot-bom</artifactId> | ||
<version>${camel-spring-boot-version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<modules> | ||
<module>ssl-server</module> | ||
<module>ssl-client</module> | ||
<module>ssl-camel-server</module> | ||
</modules> | ||
|
||
</project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.camel.springboot.example</groupId> | ||
<artifactId>camel-example-spring-boot-http-ssl</artifactId> | ||
<version>4.4.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>camel-example-spring-boot-http-ssl-camel-server</artifactId> | ||
<name>Camel SB Examples :: HTTP SSL :: SSL Camel server</name> | ||
<description>SSL Server using undertow component</description> | ||
|
||
<properties> | ||
<category>Rest</category> | ||
|
||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<!-- Camel --> | ||
<dependency> | ||
<groupId>org.apache.camel.springboot</groupId> | ||
<artifactId>camel-spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel.springboot</groupId> | ||
<artifactId>camel-undertow-starter</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>${spring-boot-version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
28 changes: 28 additions & 0 deletions
28
.../main/java/org/apache/camel/springboot/example/httpssl/HttpSslCamelServerApplication.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.springboot.example.httpssl; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class HttpSslCamelServerApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(HttpSslCamelServerApplication.class, args); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...r/src/main/java/org/apache/camel/springboot/example/httpssl/HttpSslCamelServerRouter.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.springboot.example.httpssl; | ||
|
||
import org.apache.camel.builder.RouteBuilder; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class HttpSslCamelServerRouter extends RouteBuilder { | ||
@Override | ||
public void configure() throws Exception { | ||
from("undertow:{{exposed.server.url}}/ping") | ||
.setBody().constant("pong"); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...el-server/src/main/java/org/apache/camel/springboot/example/httpssl/SSLConfiguration.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.springboot.example.httpssl; | ||
|
||
import org.apache.camel.support.jsse.KeyManagersParameters; | ||
import org.apache.camel.support.jsse.KeyStoreParameters; | ||
import org.apache.camel.support.jsse.SSLContextParameters; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class SSLConfiguration { | ||
|
||
@Bean("serverConfig") | ||
public SSLContextParameters sslContextParameters(@Value("${keystore-password}") final String password | ||
, @Value("${keystore-resource}") final String keystore) { | ||
final SSLContextParameters sslContextParameters = new SSLContextParameters(); | ||
|
||
final KeyStoreParameters ksp = new KeyStoreParameters(); | ||
ksp.setResource(keystore); | ||
ksp.setPassword(password); | ||
ksp.setType("PKCS12"); | ||
|
||
KeyManagersParameters kmp = new KeyManagersParameters(); | ||
kmp.setKeyPassword(password); | ||
kmp.setKeyStore(ksp); | ||
|
||
sslContextParameters.setKeyManagers(kmp); | ||
|
||
return sslContextParameters; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
http-ssl/ssl-camel-server/src/main/resources/application.properties
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
camel.springboot.name=ssl-camel-server | ||
camel.component.undertow.ssl-context-parameters=#serverConfig | ||
camel.component.undertow.use-global-ssl-context-parameters=true | ||
keystore-password=pass123 | ||
keystore-resource=classpath:server.jks | ||
exposed.server.url=https://localhost:8443 | ||
logging.level.org.apache.camel.support.jsse=TRACE |
Oops, something went wrong.