You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2017/04/12 13:45:05 UTC

camel git commit: CAMEL-10650: adding general docs and new condition

Repository: camel
Updated Branches:
  refs/heads/master f34fadb29 -> df1cda698


CAMEL-10650: adding general docs and new condition


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/df1cda69
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/df1cda69
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/df1cda69

Branch: refs/heads/master
Commit: df1cda698d125ab5ca75d9f34e1cb99ac7390b82
Parents: f34fadb
Author: Nicola Ferraro <ni...@gmail.com>
Authored: Wed Apr 12 15:37:40 2017 +0200
Committer: Nicola Ferraro <ni...@gmail.com>
Committed: Wed Apr 12 15:44:02 2017 +0200

----------------------------------------------------------------------
 .../security/CamelSSLAutoConfiguration.java     | 26 +++++++-
 .../CamelSSLConfigurationProperties.java        | 13 ----
 .../security/CamelSSLAutoConfigurationTest.java | 68 ++++++++++++++++++++
 .../boot/security/CamelSSLNoConfigTest.java     | 53 +++++++++++++++
 .../en/camel-configuration-utilities.adoc       | 35 ++++++++++
 .../camel/component/jetty9/Jetty9SSLTest.java   |  3 +-
 .../http/springboot/Netty4HttpSSLTest.java      |  1 -
 .../component/undertow/UndertowSSLTest.java     |  1 -
 8 files changed, 181 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/df1cda69/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfiguration.java
index 7479e82..d69e1a8 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfiguration.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfiguration.java
@@ -16,19 +16,27 @@
  */
 package org.apache.camel.spring.boot.security;
 
+import java.util.Map;
+
 import org.apache.camel.spring.boot.CamelAutoConfiguration;
 import org.apache.camel.util.jsse.GlobalSSLContextParametersSupplier;
 import org.apache.camel.util.jsse.SSLContextParameters;
 import org.springframework.boot.autoconfigure.AutoConfigureBefore;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.condition.ConditionMessage;
+import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
+import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
+import org.springframework.boot.bind.RelaxedPropertyResolver;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.context.annotation.Conditional;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.core.type.AnnotatedTypeMetadata;
 
 @Configuration
 @AutoConfigureBefore(CamelAutoConfiguration.class)
 @EnableConfigurationProperties(CamelSSLConfigurationProperties.class)
-@ConditionalOnProperty(value = "camel.ssl.enabled")
+@Conditional(CamelSSLAutoConfiguration.Condition.class)
 public class CamelSSLAutoConfiguration {
 
     @Bean
@@ -37,4 +45,18 @@ public class CamelSSLAutoConfiguration {
         return () -> config;
     }
 
+    public static class Condition extends SpringBootCondition {
+        @Override
+        public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata annotatedTypeMetadata) {
+            RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), "camel.ssl.config");
+            Map<String, Object> sslProperties = resolver.getSubProperties(".");
+            ConditionMessage.Builder message = ConditionMessage.forCondition("camel.ssl.config");
+            if (sslProperties.size() > 0) {
+                return ConditionOutcome.match(message.because("enabled"));
+            }
+
+            return ConditionOutcome.noMatch(message.because("not enabled"));
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/df1cda69/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSSLConfigurationProperties.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSSLConfigurationProperties.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSSLConfigurationProperties.java
index 7a5d6b6..2893b82 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSSLConfigurationProperties.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/security/CamelSSLConfigurationProperties.java
@@ -24,11 +24,6 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty;
 public class CamelSSLConfigurationProperties {
 
     /**
-     * Enable the global ssl configuration in Camel.
-     */
-    private boolean enabled;
-
-    /**
      * The Camel global SSL configuration
      */
     @NestedConfigurationProperty
@@ -37,14 +32,6 @@ public class CamelSSLConfigurationProperties {
     public CamelSSLConfigurationProperties() {
     }
 
-    public boolean isEnabled() {
-        return enabled;
-    }
-
-    public void setEnabled(boolean enabled) {
-        this.enabled = enabled;
-    }
-
     public SSLContextParameters getConfig() {
         return config;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/df1cda69/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfigurationTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfigurationTest.java
new file mode 100644
index 0000000..3a6b1ad
--- /dev/null
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfigurationTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.spring.boot.security;
+
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.util.jsse.GlobalSSLContextParametersSupplier;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Testing the ssl configuration
+ */
+@RunWith(SpringRunner.class)
+@SpringBootApplication
+@DirtiesContext
+@ContextConfiguration(classes = {CamelSSLAutoConfiguration.class, CamelAutoConfiguration.class})
+@SpringBootTest(properties = {
+        "camel.ssl.config.cert-alias=web",
+        "camel.ssl.config.key-managers.key-password=changeit",
+        "camel.ssl.config.key-managers.key-store.password=changeit",
+        "camel.ssl.config.key-managers.key-store.type=PKCS12",
+        "camel.ssl.config.trust-managers.key-store.password=changeit",
+        "camel.ssl.config.trust-managers.key-store.type=jks"
+})
+public class CamelSSLAutoConfigurationTest {
+
+    @Autowired
+    private ApplicationContext applicationContext;
+
+    @Test
+    public void checkSSLPropertiesPresent() {
+        GlobalSSLContextParametersSupplier supplier = applicationContext.getBean(GlobalSSLContextParametersSupplier.class);
+        assertNotNull(supplier);
+        assertNotNull(supplier.get());
+        assertEquals("web", supplier.get().getCertAlias());
+        assertNotNull(supplier.get().getKeyManagers());
+        assertEquals("changeit", supplier.get().getKeyManagers().getKeyPassword());
+        assertNotNull(supplier.get().getTrustManagers());
+        assertNotNull(supplier.get().getTrustManagers().getKeyStore());
+        assertEquals("jks", supplier.get().getTrustManagers().getKeyStore().getType());
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/df1cda69/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLNoConfigTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLNoConfigTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLNoConfigTest.java
new file mode 100644
index 0000000..21b8efa
--- /dev/null
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLNoConfigTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.spring.boot.security;
+
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.util.jsse.GlobalSSLContextParametersSupplier;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * Testing that the ssl configuration is not created if a subproperty of "camel.ssl.config." (note the last dot) is not present.
+ */
+@RunWith(SpringRunner.class)
+@SpringBootApplication
+@DirtiesContext
+@ContextConfiguration(classes = {CamelSSLAutoConfiguration.class, CamelAutoConfiguration.class})
+@SpringBootTest(properties = {
+        "camel.ssl.configxxx=true"
+})
+public class CamelSSLNoConfigTest {
+
+    @Autowired
+    private ApplicationContext applicationContext;
+
+    @Test(expected = NoSuchBeanDefinitionException.class)
+    public void checkSSLPropertiesNotPresent() {
+        applicationContext.getBean(GlobalSSLContextParametersSupplier.class);
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/df1cda69/docs/user-manual/en/camel-configuration-utilities.adoc
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/camel-configuration-utilities.adoc b/docs/user-manual/en/camel-configuration-utilities.adoc
index 24ba0de..41979d1 100644
--- a/docs/user-manual/en/camel-configuration-utilities.adoc
+++ b/docs/user-manual/en/camel-configuration-utilities.adoc
@@ -610,3 +610,38 @@ ID example is used to resolve the property placeholders.
 
 </beans>
 ---------------------------------------------------------------------------------------------------------------
+
+[[CamelConfigurationUtilities-UsingSpringBoot.1]]
+Using Spring-Boot
+
+As of *2.19.0*, Camel provides a global SSL configuration that can be customized using the
+spring-boot _application.properties_ or _application.yml_ file.
+
+Components do not use the global SSL configuration by default, but this behavior can
+be changed using component-specific options. A flag named _useGlobalSslContextParameters_ is
+included in all components that support the global SSL configuration.
+
+The following example shows how to configure global SSL parameters (in _application.yml_) and enable their
+usage in the _camel-undertow_ component.
+
+[source,text]
+---------------------------------------------------------------------------------------------------------------
+camel:
+  # To enable global SSL in undertow
+  component:
+    undertow:
+      use-global-ssl-context-parameters: true
+  ssl:
+    config:
+      key-managers:
+        key-password: "changeit"
+        key-store:
+          resource: "/keystore.p12"
+          password: "changeit"
+          type: "PKCS12"
+      trust-managers:
+        key-store:
+          resource: "/cacerts"
+          password: "changeit"
+          type: "jks"
+---------------------------------------------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/camel/blob/df1cda69/platforms/spring-boot/components-starter/camel-jetty9-starter/src/test/java/org/apache/camel/component/jetty9/Jetty9SSLTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-jetty9-starter/src/test/java/org/apache/camel/component/jetty9/Jetty9SSLTest.java b/platforms/spring-boot/components-starter/camel-jetty9-starter/src/test/java/org/apache/camel/component/jetty9/Jetty9SSLTest.java
index 6b40ff6..3c68524 100644
--- a/platforms/spring-boot/components-starter/camel-jetty9-starter/src/test/java/org/apache/camel/component/jetty9/Jetty9SSLTest.java
+++ b/platforms/spring-boot/components-starter/camel-jetty9-starter/src/test/java/org/apache/camel/component/jetty9/Jetty9SSLTest.java
@@ -43,7 +43,6 @@ import static org.junit.Assert.assertEquals;
 @DirtiesContext
 @ContextConfiguration(classes = {JettyHttpComponentAutoConfiguration9.class, CamelAutoConfiguration.class})
 @SpringBootTest(properties = {
-        "camel.ssl.enabled=true",
         "camel.ssl.config.cert-alias=web",
         "camel.ssl.config.key-managers.key-password=changeit",
         "camel.ssl.config.key-managers.key-store.resource=/keystore.p12",
@@ -53,7 +52,7 @@ import static org.junit.Assert.assertEquals;
         "camel.ssl.config.trust-managers.key-store.password=changeit",
         "camel.ssl.config.trust-managers.key-store.type=jks",
         "camel.component.jetty.use-global-ssl-context-parameters=true",
-        "camel.component.http4.use-global-ssl-context-parameters=true",
+        "camel.component.http4.use-global-ssl-context-parameters=true"
 })
 @Ignore("Bug in https4 spring-boot configuration")
 public class Jetty9SSLTest {

http://git-wip-us.apache.org/repos/asf/camel/blob/df1cda69/platforms/spring-boot/components-starter/camel-netty4-http-starter/src/test/java/org/apache/camel/component/netty4/http/springboot/Netty4HttpSSLTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-netty4-http-starter/src/test/java/org/apache/camel/component/netty4/http/springboot/Netty4HttpSSLTest.java b/platforms/spring-boot/components-starter/camel-netty4-http-starter/src/test/java/org/apache/camel/component/netty4/http/springboot/Netty4HttpSSLTest.java
index d8451b7..f61b484 100644
--- a/platforms/spring-boot/components-starter/camel-netty4-http-starter/src/test/java/org/apache/camel/component/netty4/http/springboot/Netty4HttpSSLTest.java
+++ b/platforms/spring-boot/components-starter/camel-netty4-http-starter/src/test/java/org/apache/camel/component/netty4/http/springboot/Netty4HttpSSLTest.java
@@ -43,7 +43,6 @@ import static org.junit.Assert.assertEquals;
 @DirtiesContext
 @ContextConfiguration(classes = {NettyHttpComponentAutoConfiguration.class, CamelAutoConfiguration.class})
 @SpringBootTest(properties = {
-        "camel.ssl.enabled=true",
         "camel.ssl.config.cert-alias=web",
         "camel.ssl.config.key-managers.key-password=changeit",
         "camel.ssl.config.key-managers.key-store.resource=/keystore.p12",

http://git-wip-us.apache.org/repos/asf/camel/blob/df1cda69/platforms/spring-boot/components-starter/camel-undertow-starter/src/test/java/org/apache/camel/component/undertow/UndertowSSLTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-undertow-starter/src/test/java/org/apache/camel/component/undertow/UndertowSSLTest.java b/platforms/spring-boot/components-starter/camel-undertow-starter/src/test/java/org/apache/camel/component/undertow/UndertowSSLTest.java
index adf5a29..7849b88 100644
--- a/platforms/spring-boot/components-starter/camel-undertow-starter/src/test/java/org/apache/camel/component/undertow/UndertowSSLTest.java
+++ b/platforms/spring-boot/components-starter/camel-undertow-starter/src/test/java/org/apache/camel/component/undertow/UndertowSSLTest.java
@@ -42,7 +42,6 @@ import static org.junit.Assert.assertEquals;
 @DirtiesContext
 @ContextConfiguration(classes = {UndertowComponentAutoConfiguration.class, CamelAutoConfiguration.class})
 @SpringBootTest(properties = {
-        "camel.ssl.enabled=true",
         "camel.ssl.config.cert-alias=web",
         "camel.ssl.config.key-managers.key-password=changeit",
         "camel.ssl.config.key-managers.key-store.resource=/keystore.p12",