Repository: camel Updated Branches: refs/heads/camel-2.18.x ee45e2a76 -> f5e627557
CAMEL-10589: ServiceNow: add an option to convigure SSL/TLS (cherry picked from commit 87898bf1be473a1f06c61fbd7fe4ffd459b2323b) Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/67a0fc5a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/67a0fc5a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/67a0fc5a Branch: refs/heads/camel-2.18.x Commit: 67a0fc5ae2b9657545dd099c5c66dcc767221aed Parents: ee45e2a Author: lburgazzoli <lburgazz...@gmail.com> Authored: Mon Dec 12 15:15:09 2016 +0100 Committer: lburgazzoli <lburgazz...@gmail.com> Committed: Mon Dec 12 17:41:38 2016 +0100 ---------------------------------------------------------------------- .../ServiceNowComponentConfiguration.java | 45 ++++++++++++++++++++ .../src/main/docs/servicenow-component.adoc | 5 ++- .../servicenow/AbstractServiceNowProcessor.java | 2 +- .../component/servicenow/ServiceNowClient.java | 44 ++++++++++++++++--- .../servicenow/ServiceNowConfiguration.java | 43 ++++++++++++++++++- 5 files changed, 131 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/67a0fc5a/components-starter/camel-servicenow-starter/src/main/java/org/apache/camel/component/servicenow/springboot/ServiceNowComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/components-starter/camel-servicenow-starter/src/main/java/org/apache/camel/component/servicenow/springboot/ServiceNowComponentConfiguration.java b/components-starter/camel-servicenow-starter/src/main/java/org/apache/camel/component/servicenow/springboot/ServiceNowComponentConfiguration.java index 1a41297..24caf73 100644 --- a/components-starter/camel-servicenow-starter/src/main/java/org/apache/camel/component/servicenow/springboot/ServiceNowComponentConfiguration.java +++ b/components-starter/camel-servicenow-starter/src/main/java/org/apache/camel/component/servicenow/springboot/ServiceNowComponentConfiguration.java @@ -20,6 +20,9 @@ import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.camel.component.servicenow.ServiceNowComponent; import org.apache.camel.component.servicenow.ServiceNowRelease; +import org.apache.camel.util.jsse.SSLContextParameters; +import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy; +import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; @@ -268,6 +271,22 @@ public class ServiceNowComponentConfiguration { * Gets only those categories whose parent is a catalog. */ private Boolean topLevelOnly; + /** + * To configure security using SSLContextParameters. See + * http://camel.apache.org/camel-configuration-utilities.html + */ + @NestedConfigurationProperty + private SSLContextParameters sslContextParameters; + /** + * To configure http-client + */ + @NestedConfigurationProperty + private HTTPClientPolicy httpClientPolicy; + /** + * To configure proxy authentication + */ + @NestedConfigurationProperty + private ProxyAuthorizationPolicy proxyAuthorizationPolicy; private Map models; /** * Defines the response model @@ -516,6 +535,32 @@ public class ServiceNowComponentConfiguration { this.topLevelOnly = topLevelOnly; } + public SSLContextParameters getSslContextParameters() { + return sslContextParameters; + } + + public void setSslContextParameters( + SSLContextParameters sslContextParameters) { + this.sslContextParameters = sslContextParameters; + } + + public HTTPClientPolicy getHttpClientPolicy() { + return httpClientPolicy; + } + + public void setHttpClientPolicy(HTTPClientPolicy httpClientPolicy) { + this.httpClientPolicy = httpClientPolicy; + } + + public ProxyAuthorizationPolicy getProxyAuthorizationPolicy() { + return proxyAuthorizationPolicy; + } + + public void setProxyAuthorizationPolicy( + ProxyAuthorizationPolicy proxyAuthorizationPolicy) { + this.proxyAuthorizationPolicy = proxyAuthorizationPolicy; + } + public Map getModels() { return models; } http://git-wip-us.apache.org/repos/asf/camel/blob/67a0fc5a/components/camel-servicenow/src/main/docs/servicenow-component.adoc ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/docs/servicenow-component.adoc b/components/camel-servicenow/src/main/docs/servicenow-component.adoc index b91b456..ac87e0d 100644 --- a/components/camel-servicenow/src/main/docs/servicenow-component.adoc +++ b/components/camel-servicenow/src/main/docs/servicenow-component.adoc @@ -57,7 +57,7 @@ The ServiceNow component supports 7 options which are listed below. // endpoint options: START -The ServiceNow component supports 34 endpoint options which are listed below: +The ServiceNow component supports 37 endpoint options which are listed below: {% raw %} [width="100%",cols="2,1,1m,1m,5",options="header"] @@ -89,13 +89,16 @@ The ServiceNow component supports 34 endpoint options which are listed below: | target | producer | | Boolean | Set this parameter to true to return only scorecards that have a target. | topLevelOnly | producer | | Boolean | Gets only those categories whose parent is a catalog. | apiVersion | advanced | | String | The ServiceNow REST API version default latest +| httpClientPolicy | advanced | | HTTPClientPolicy | To configure http-client | mapper | advanced | | ObjectMapper | Sets Jackson's ObjectMapper to use for request/reply +| proxyAuthorizationPolicy | advanced | | ProxyAuthorizationPolicy | To configure proxy authentication | synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | apiUrl | security | | String | The ServiceNow REST API url | oauthClientId | security | | String | OAuth2 ClientID | oauthClientSecret | security | | String | OAuth2 ClientSecret | oauthTokenUrl | security | | String | OAuth token Url | password | security | | String | ServiceNow account password MUST be provided +| sslContextParameters | security | | SSLContextParameters | To configure security using SSLContextParameters. See http://camel.apache.org/camel-configuration-utilities.html | userName | security | | String | ServiceNow user account name MUST be provided |======================================================================= {% endraw %} http://git-wip-us.apache.org/repos/asf/camel/blob/67a0fc5a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/AbstractServiceNowProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/AbstractServiceNowProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/AbstractServiceNowProcessor.java index 6ee9a2e..bbbcb00 100644 --- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/AbstractServiceNowProcessor.java +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/AbstractServiceNowProcessor.java @@ -51,7 +51,7 @@ public abstract class AbstractServiceNowProcessor implements Processor { this.endpoint = endpoint; this.config = endpoint.getConfiguration(); this.mapper = ObjectHelper.notNull(config.getMapper(), "mapper"); - this.client = new ServiceNowClient(config); + this.client = new ServiceNowClient(endpoint.getCamelContext(), config); this.dispatchers = new ArrayList<>(); } http://git-wip-us.apache.org/repos/asf/camel/blob/67a0fc5a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowClient.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowClient.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowClient.java index d754568..0d7fb5d 100644 --- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowClient.java +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowClient.java @@ -18,20 +18,25 @@ package org.apache.camel.component.servicenow; import java.util.Arrays; import java.util.Map; +import javax.net.ssl.SSLContext; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +import org.apache.camel.CamelContext; import org.apache.camel.CamelException; import org.apache.camel.Message; import org.apache.camel.component.servicenow.auth.AuthenticationRequestFilter; +import org.apache.camel.util.jsse.SSLContextParameters; +import org.apache.cxf.configuration.jsse.TLSClientParameters; import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.transport.http.HTTPConduit; -public class ServiceNowClient { +public final class ServiceNowClient { private final ServiceNowConfiguration configuration; private final WebClient client; - public ServiceNowClient(ServiceNowConfiguration configuration) throws Exception { + ServiceNowClient(CamelContext camelContext, ServiceNowConfiguration configuration) throws Exception { this.configuration = configuration; this.client = WebClient.create( configuration.getApiUrl(), @@ -43,9 +48,8 @@ public class ServiceNowClient { true ); - WebClient.getConfig(client) - .getRequestContext() - .put("org.apache.cxf.http.header.split", true); + configureRequestContext(camelContext, configuration, client); + configureTls(camelContext, configuration, client); } public ServiceNowClient types(MediaType type) { @@ -140,4 +144,34 @@ public class ServiceNowClient { return this; } + + // ******************************* + // Helpers + // ******************************* + + private static void configureRequestContext( + CamelContext context, ServiceNowConfiguration configuration, WebClient client) throws Exception { + + WebClient.getConfig(client) + .getRequestContext() + .put("org.apache.cxf.http.header.split", true); + } + + private static void configureTls( + CamelContext camelContext, ServiceNowConfiguration configuration, WebClient client) throws Exception{ + + SSLContextParameters sslContextParams = configuration.getSslContextParameters(); + if (sslContextParams != null) { + HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit(); + TLSClientParameters tlsClientParams = conduit.getTlsClientParameters(); + if (tlsClientParams == null) { + tlsClientParams = new TLSClientParameters(); + } + + SSLContext sslContext = sslContextParams.createSSLContext(camelContext); + tlsClientParams.setSSLSocketFactory(sslContext.getSocketFactory()); + + conduit.setTlsClientParameters(tlsClientParams); + } + } } http://git-wip-us.apache.org/repos/asf/camel/blob/67a0fc5a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java index 422c0ff..fe930e8 100644 --- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java @@ -26,6 +26,9 @@ import org.apache.camel.RuntimeCamelException; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriParams; import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.jsse.SSLContextParameters; +import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy; +import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; @UriParams public class ServiceNowConfiguration implements Cloneable { @@ -102,7 +105,12 @@ public class ServiceNowConfiguration implements Cloneable { private ObjectMapper mapper = MAPPER; @UriParam(defaultValue = "HELSINKI", enums = "FUJI,GENEVA,HELSINKI") private ServiceNowRelease release = ServiceNowRelease.HELSINKI; - + @UriParam(label = "security") + private SSLContextParameters sslContextParameters; + @UriParam(label = "advanced") + private HTTPClientPolicy httpClientPolicy; + @UriParam(label = "advanced") + private ProxyAuthorizationPolicy proxyAuthorizationPolicy; public String getUserName() { return userName; @@ -474,6 +482,39 @@ public class ServiceNowConfiguration implements Cloneable { this.topLevelOnly = topLevelOnly; } + public SSLContextParameters getSslContextParameters() { + return sslContextParameters; + } + + /** + * To configure security using SSLContextParameters. See http://camel.apache.org/camel-configuration-utilities.html + */ + public void setSslContextParameters(SSLContextParameters sslContextParameters) { + this.sslContextParameters = sslContextParameters; + } + + public HTTPClientPolicy getHttpClientPolicy() { + return httpClientPolicy; + } + + /** + * To configure http-client + */ + public void setHttpClientPolicy(HTTPClientPolicy httpClientPolicy) { + this.httpClientPolicy = httpClientPolicy; + } + + public ProxyAuthorizationPolicy getProxyAuthorizationPolicy() { + return proxyAuthorizationPolicy; + } + + /** + * To configure proxy authentication + */ + public void setProxyAuthorizationPolicy(ProxyAuthorizationPolicy proxyAuthorizationPolicy) { + this.proxyAuthorizationPolicy = proxyAuthorizationPolicy; + } + // ************************************************* // // *************************************************