This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 4c46a130f54f CAMEL-27668: camel-solr - certificatePath and
sslContextParameters need enableSSL, and certificatePath refuses http URLs
(#31026)
4c46a130f54f is described below
commit 4c46a130f54faee9dc75817ca4f6a9110067fb65
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 27 20:33:59 2026 +0100
CAMEL-27668: camel-solr - certificatePath and sslContextParameters need
enableSSL, and certificatePath refuses http URLs (#31026)
The client that Camel creates connects with plain HTTP unless enableSSL is
enabled, so certificatePath and sslContextParameters were ignored without
it. The endpoint now fails at startup with a clear message when they are
set and enableSSL is not enabled (the global SSL context parameters only
log a WARN). The certificatePath option now refuses an http: URL.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../org/apache/camel/catalog/components/solr.json | 8 +-
.../apache/camel/catalog/docs/solr-component.adoc | 22 +++
.../org/apache/camel/component/solr/solr.json | 8 +-
.../camel-solr/src/main/docs/solr-component.adoc | 22 +++
.../apache/camel/component/solr/SolrComponent.java | 4 +-
.../camel/component/solr/SolrConfiguration.java | 15 ++-
.../apache/camel/component/solr/SolrEndpoint.java | 44 +++++-
.../component/solr/SolrSslConfigurationTest.java | 147 +++++++++++++++++++++
.../solr/SolrSslContextParametersTest.java | 2 +-
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 10 ++
.../component/dsl/SolrComponentBuilderFactory.java | 4 +-
.../endpoint/dsl/SolrEndpointBuilderFactory.java | 29 ++--
12 files changed, 280 insertions(+), 35 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/solr.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/solr.json
index bd1ea2f6b7e7..f0a3022a2749 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/solr.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/solr.json
@@ -34,7 +34,7 @@
"solrClient": { "index": 7, "kind": "property", "displayName": "Solr
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "org.apache.solr.client.solrj.SolrClient", "deprecated":
false, "autowired": true, "secret": false, "description": "To use a custom
org.apache.solr.client.solrj.SolrClient for all the endpoints, instead of a
client that Camel creates for each endpoint. The solrClient option of an
endpoint replaces it. Camel does not c [...]
"enableSSL": { "index": 8, "kind": "property", "displayName": "Enable
SSL", "group": "security", "label": "security", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether the clients
that Camel creates connect to Solr with HTTPS instead of HTTP. The enableSSL
option of an endpoint replaces it." },
"password": { "index": 9, "kind": "property", "displayName": "Password",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "description": "The password for HTTP
basic authentication with Solr, for all the endpoints. The password option of
an endpoint replaces it." },
- "sslContextParameters": { "index": 10, "kind": "property", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "The TLS configuration (key
store, trust store, protocols, cipher suites, named groups) of the clients that
Camel creates, for all the endpoints. The sslContextParameters [...]
+ "sslContextParameters": { "index": 10, "kind": "property", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "The TLS configuration (key
store, trust store, protocols, cipher suites, named groups) of the clients that
Camel creates, for all the endpoints. It is used when the enab [...]
"useGlobalSslContextParameters": { "index": 11, "kind": "property",
"displayName": "Use Global Ssl Context Parameters", "group": "security",
"label": "security", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the endpoints use the global SSL
context parameters of the CamelContext when neither the component nor the
endpoint sets the sslContextParameters option." },
"username": { "index": 12, "kind": "property", "displayName": "Username",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "description": "The user name for HTTP
basic authentication with Solr, for all the endpoints. The username option of
an endpoint replaces it." }
},
@@ -71,10 +71,10 @@
"size": { "index": 12, "kind": "parameter", "displayName": "Size",
"group": "producer", "label": "", "required": false, "type": "integer",
"javaType": "java.lang.Integer", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "The maximum number of documents that a search
returns, which is the rows parameter of Solr (10 by default in Solr). The
CamelSol [...]
"lazyStartProducer": { "index": 13, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produ [...]
"solrClient": { "index": 14, "kind": "parameter", "displayName": "Solr
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "org.apache.solr.client.solrj.SolrClient", "deprecated":
false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "To use a custom
org.apache.solr.client.solrj.SolrClient. When set, the host, port, bas [...]
- "certificatePath": { "index": 15, "kind": "parameter", "displayName":
"Certificate Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass": "org.apache.camel.component.solr.SolrConfiguration",
"configurationField": "configuration", "description": "The X.509 certificate of
the certificate authority that the client th [...]
- "enableSSL": { "index": 16, "kind": "parameter", "displayName": "Enable
SSL", "group": "security", "label": "security", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "Whether the client that Camel creates connects
to Solr with HTTPS instead of HTTP." },
+ "certificatePath": { "index": 15, "kind": "parameter", "displayName":
"Certificate Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass": "org.apache.camel.component.solr.SolrConfiguration",
"configurationField": "configuration", "description": "The X.509 certificate of
the certificate authority that the client th [...]
+ "enableSSL": { "index": 16, "kind": "parameter", "displayName": "Enable
SSL", "group": "security", "label": "security", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "Whether the client that Camel creates connects
to Solr with HTTPS instead of HTTP. It must be en [...]
"password": { "index": 17, "kind": "parameter", "displayName": "Password",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "The password for HTTP basic authentication
with Solr, used together with the username option [...]
- "sslContextParameters": { "index": 18, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "The TLS configuration (key store, trust store,
protoco [...]
+ "sslContextParameters": { "index": 18, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "The TLS configuration (key store, trust store,
protoco [...]
"username": { "index": 19, "kind": "parameter", "displayName": "Username",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "The user name for HTTP basic authentication
with Solr, used together with the password option [...]
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/solr-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/solr-component.adoc
index 079fb797175d..53871f3ce589 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/solr-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/solr-component.adoc
@@ -90,6 +90,28 @@ After each operation the message body is the response of
Solr as a Map (a `Simpl
`responseHeader`, and for a search the documents under `response` as a
`SolrDocumentList`. Convert it to a
`QueryResponse` to read it with SolrJ.
+=== Connecting with HTTPS
+
+The client that Camel creates connects to Solr with plain HTTP unless the
`enableSSL` option is enabled. Set
+`enableSSL=true` to connect with HTTPS, and configure the TLS of the client
with the `sslContextParameters` option, or
+with the `certificatePath` option to trust the X.509 certificate of a
certificate authority. Without either, the
+default trust store of the JVM is used.
+
+When the `certificatePath` or `sslContextParameters` option (of the endpoint
or the component) is set, but `enableSSL`
+is not enabled, the endpoint fails at startup, as the options would not be
used. The global SSL context parameters
+(`useGlobalSslContextParameters=true`) only log a WARN in that case.
+
+The `certificatePath` option loads the certificate from the classpath by
default, or with the `classpath:`, `file:` or
+`https:` prefix. An `http:` URL is refused, as the certificate would be loaded
over plain HTTP.
+
+These options do not apply to a client that is set with the `solrClient`
option.
+
+[source,java]
+----
+from("direct:search")
+
.to("solr:solr.example.com:8983?enableSSL=true&certificatePath=file:/etc/solr/ca.crt&operation=SEARCH");
+----
+
== Example
Below is a simple `INSERT`, `DELETE` and `SEARCH` example
diff --git
a/components/camel-solr/src/generated/resources/META-INF/org/apache/camel/component/solr/solr.json
b/components/camel-solr/src/generated/resources/META-INF/org/apache/camel/component/solr/solr.json
index bd1ea2f6b7e7..f0a3022a2749 100644
---
a/components/camel-solr/src/generated/resources/META-INF/org/apache/camel/component/solr/solr.json
+++
b/components/camel-solr/src/generated/resources/META-INF/org/apache/camel/component/solr/solr.json
@@ -34,7 +34,7 @@
"solrClient": { "index": 7, "kind": "property", "displayName": "Solr
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "org.apache.solr.client.solrj.SolrClient", "deprecated":
false, "autowired": true, "secret": false, "description": "To use a custom
org.apache.solr.client.solrj.SolrClient for all the endpoints, instead of a
client that Camel creates for each endpoint. The solrClient option of an
endpoint replaces it. Camel does not c [...]
"enableSSL": { "index": 8, "kind": "property", "displayName": "Enable
SSL", "group": "security", "label": "security", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether the clients
that Camel creates connect to Solr with HTTPS instead of HTTP. The enableSSL
option of an endpoint replaces it." },
"password": { "index": 9, "kind": "property", "displayName": "Password",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "description": "The password for HTTP
basic authentication with Solr, for all the endpoints. The password option of
an endpoint replaces it." },
- "sslContextParameters": { "index": 10, "kind": "property", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "The TLS configuration (key
store, trust store, protocols, cipher suites, named groups) of the clients that
Camel creates, for all the endpoints. The sslContextParameters [...]
+ "sslContextParameters": { "index": 10, "kind": "property", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "The TLS configuration (key
store, trust store, protocols, cipher suites, named groups) of the clients that
Camel creates, for all the endpoints. It is used when the enab [...]
"useGlobalSslContextParameters": { "index": 11, "kind": "property",
"displayName": "Use Global Ssl Context Parameters", "group": "security",
"label": "security", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the endpoints use the global SSL
context parameters of the CamelContext when neither the component nor the
endpoint sets the sslContextParameters option." },
"username": { "index": 12, "kind": "property", "displayName": "Username",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "description": "The user name for HTTP
basic authentication with Solr, for all the endpoints. The username option of
an endpoint replaces it." }
},
@@ -71,10 +71,10 @@
"size": { "index": 12, "kind": "parameter", "displayName": "Size",
"group": "producer", "label": "", "required": false, "type": "integer",
"javaType": "java.lang.Integer", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "The maximum number of documents that a search
returns, which is the rows parameter of Solr (10 by default in Solr). The
CamelSol [...]
"lazyStartProducer": { "index": 13, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produ [...]
"solrClient": { "index": 14, "kind": "parameter", "displayName": "Solr
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "org.apache.solr.client.solrj.SolrClient", "deprecated":
false, "autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "To use a custom
org.apache.solr.client.solrj.SolrClient. When set, the host, port, bas [...]
- "certificatePath": { "index": 15, "kind": "parameter", "displayName":
"Certificate Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass": "org.apache.camel.component.solr.SolrConfiguration",
"configurationField": "configuration", "description": "The X.509 certificate of
the certificate authority that the client th [...]
- "enableSSL": { "index": 16, "kind": "parameter", "displayName": "Enable
SSL", "group": "security", "label": "security", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "Whether the client that Camel creates connects
to Solr with HTTPS instead of HTTP." },
+ "certificatePath": { "index": 15, "kind": "parameter", "displayName":
"Certificate Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass": "org.apache.camel.component.solr.SolrConfiguration",
"configurationField": "configuration", "description": "The X.509 certificate of
the certificate authority that the client th [...]
+ "enableSSL": { "index": 16, "kind": "parameter", "displayName": "Enable
SSL", "group": "security", "label": "security", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "Whether the client that Camel creates connects
to Solr with HTTPS instead of HTTP. It must be en [...]
"password": { "index": 17, "kind": "parameter", "displayName": "Password",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "The password for HTTP basic authentication
with Solr, used together with the username option [...]
- "sslContextParameters": { "index": 18, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "The TLS configuration (key store, trust store,
protoco [...]
+ "sslContextParameters": { "index": 18, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "The TLS configuration (key store, trust store,
protoco [...]
"username": { "index": 19, "kind": "parameter", "displayName": "Username",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.solr.SolrConfiguration", "configurationField":
"configuration", "description": "The user name for HTTP basic authentication
with Solr, used together with the password option [...]
}
}
diff --git a/components/camel-solr/src/main/docs/solr-component.adoc
b/components/camel-solr/src/main/docs/solr-component.adoc
index 079fb797175d..53871f3ce589 100644
--- a/components/camel-solr/src/main/docs/solr-component.adoc
+++ b/components/camel-solr/src/main/docs/solr-component.adoc
@@ -90,6 +90,28 @@ After each operation the message body is the response of
Solr as a Map (a `Simpl
`responseHeader`, and for a search the documents under `response` as a
`SolrDocumentList`. Convert it to a
`QueryResponse` to read it with SolrJ.
+=== Connecting with HTTPS
+
+The client that Camel creates connects to Solr with plain HTTP unless the
`enableSSL` option is enabled. Set
+`enableSSL=true` to connect with HTTPS, and configure the TLS of the client
with the `sslContextParameters` option, or
+with the `certificatePath` option to trust the X.509 certificate of a
certificate authority. Without either, the
+default trust store of the JVM is used.
+
+When the `certificatePath` or `sslContextParameters` option (of the endpoint
or the component) is set, but `enableSSL`
+is not enabled, the endpoint fails at startup, as the options would not be
used. The global SSL context parameters
+(`useGlobalSslContextParameters=true`) only log a WARN in that case.
+
+The `certificatePath` option loads the certificate from the classpath by
default, or with the `classpath:`, `file:` or
+`https:` prefix. An `http:` URL is refused, as the certificate would be loaded
over plain HTTP.
+
+These options do not apply to a client that is set with the `solrClient`
option.
+
+[source,java]
+----
+from("direct:search")
+
.to("solr:solr.example.com:8983?enableSSL=true&certificatePath=file:/etc/solr/ca.crt&operation=SEARCH");
+----
+
== Example
Below is a simple `INSERT`, `DELETE` and `SEARCH` example
diff --git
a/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
b/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
index 3a07ccac866c..da919be99ddc 100644
---
a/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
+++
b/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrComponent.java
@@ -68,8 +68,8 @@ public class SolrComponent extends DefaultComponent
implements SSLContextParamet
private boolean enableSSL;
@Metadata(label = "security",
description = "The TLS configuration (key store, trust store,
protocols, cipher suites, named groups) of the"
- + " clients that Camel creates, for all the
endpoints. The sslContextParameters option of an endpoint"
- + " replaces it.")
+ + " clients that Camel creates, for all the
endpoints. It is used when the enableSSL option is"
+ + " enabled. The sslContextParameters option of an
endpoint replaces it.")
private SSLContextParameters sslContextParameters;
@Metadata(label = "security", defaultValue = "false",
description = "Whether the endpoints use the global SSL context
parameters of the CamelContext when neither the"
diff --git
a/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrConfiguration.java
b/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrConfiguration.java
index a15178cbe383..89703b5aa2b1 100644
---
a/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrConfiguration.java
+++
b/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrConfiguration.java
@@ -80,19 +80,22 @@ public class SolrConfiguration {
+ " documents to delete. The
CamelSolrDeleteByQuery header replaces this option.")
private boolean deleteByQuery;
@UriParam(label = "security",
- description = "Whether the client that Camel creates connects to
Solr with HTTPS instead of HTTP.")
+ description = "Whether the client that Camel creates connects to
Solr with HTTPS instead of HTTP. It must be"
+ + " enabled to use the certificatePath or
sslContextParameters option, otherwise the endpoint"
+ + " fails at startup.")
private boolean enableSSL;
@UriParam(label = "security",
description = "The X.509 certificate of the certificate
authority that the client that Camel creates trusts for"
- + " HTTPS. It is loaded from the classpath by
default, or with the classpath:, file: or http:"
- + " prefix. Not used when the sslContextParameters
option is set.")
+ + " HTTPS (the enableSSL option must be enabled).
It is loaded from the classpath by default, or"
+ + " with the classpath:, file: or https: prefix;
an http: URL is refused. Not used when the"
+ + " sslContextParameters option is set.")
@Metadata(supportFileReference = true)
private String certificatePath;
@UriParam(label = "security",
description = "The TLS configuration (key store, trust store,
protocols, cipher suites, named groups) of the client"
- + " that Camel creates. It takes precedence over
the certificatePath option. If not set, the global"
- + " SSL context parameters are used when the
useGlobalSslContextParameters option of the component"
- + " is enabled.")
+ + " that Camel creates, which is used when the
enableSSL option is enabled. It takes precedence"
+ + " over the certificatePath option. If not set,
the global SSL context parameters are used when"
+ + " the useGlobalSslContextParameters option of
the component is enabled.")
private SSLContextParameters sslContextParameters;
@UriParam(description = "The time in milliseconds that the client that
Camel creates waits for the response to a request. If"
+ " not set, the requestTimeout option of the
component is used.")
diff --git
a/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrEndpoint.java
b/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrEndpoint.java
index 9ac0c408fa7b..8f4353be3c9b 100644
---
a/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrEndpoint.java
+++
b/components/camel-solr/src/main/java/org/apache/camel/component/solr/SolrEndpoint.java
@@ -154,10 +154,12 @@ public class SolrEndpoint extends DefaultEndpoint
implements EndpointServiceLoca
if (ObjectHelper.isNotEmpty(configuration.getUsername()) &&
ObjectHelper.isNotEmpty(configuration.getPassword())) {
builder.withBasicAuthCredentials(configuration.getUsername(),
configuration.getPassword());
}
- if (configuration.getSslContextParameters() != null) {
- builder.withSSLContext(createSslContext(getCamelContext(),
configuration.getSslContextParameters()));
- } else if
(ObjectHelper.isNotEmpty(configuration.getCertificatePath())) {
- builder.withSSLContext(createSslContextFromCa(getCamelContext(),
configuration.getCertificatePath()));
+ if (checkSslConfiguration()) {
+ if (configuration.getSslContextParameters() != null) {
+ builder.withSSLContext(createSslContext(getCamelContext(),
configuration.getSslContextParameters()));
+ } else if
(ObjectHelper.isNotEmpty(configuration.getCertificatePath())) {
+
builder.withSSLContext(createSslContextFromCa(getCamelContext(),
configuration.getCertificatePath()));
+ }
}
if (configuration.getCollection() != null) {
builder.withDefaultCollection(configuration.getCollection());
@@ -165,6 +167,40 @@ public class SolrEndpoint extends DefaultEndpoint
implements EndpointServiceLoca
return builder.build();
}
+ /**
+ * Checks the SSL options of the client that Camel creates.
+ *
+ * @return true when the client connects with HTTPS, so the SSL context is
configured
+ */
+ private boolean checkSslConfiguration() {
+ final String certificatePath = configuration.getCertificatePath();
+ if (ObjectHelper.isNotEmpty(certificatePath) &&
certificatePath.regionMatches(true, 0, "http:", 0, 5)) {
+ throw new IllegalArgumentException(
+ "The certificatePath option must not be an http: URL, as
the certificate would be loaded over plain"
+ + " HTTP. Use the classpath:,
file: or https: prefix instead on endpoint: "
+ +
URISupport.sanitizeUri(getEndpointUri()));
+ }
+ if (configuration.isEnableSSL()) {
+ return true;
+ }
+ final SSLContextParameters sslContextParameters =
configuration.getSslContextParameters();
+ final boolean global
+ = sslContextParameters != null && sslContextParameters ==
getCamelContext().getSSLContextParameters();
+ if (ObjectHelper.isNotEmpty(certificatePath) || (sslContextParameters
!= null && !global)) {
+ throw new IllegalArgumentException(
+ "The certificatePath or sslContextParameters option is
set, but enableSSL is false, so the client would"
+ + " connect to Solr with plain
HTTP and not use them. Set enableSSL=true to"
+ + " connect with HTTPS on
endpoint: "
+ +
URISupport.sanitizeUri(getEndpointUri()));
+ }
+ if (global) {
+ LOG.warn("The global SSL context parameters are not used as
enableSSL is false, so the client connects to Solr"
+ + " with plain HTTP on endpoint: {}",
+ URISupport.sanitizeUri(getEndpointUri()));
+ }
+ return false;
+ }
+
protected static boolean isProcessAsync(SolrClient solrClient,
SolrConfiguration configuration) {
if (!(solrClient instanceof HttpSolrClientBase)) {
return false;
diff --git
a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSslConfigurationTest.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSslConfigurationTest.java
new file mode 100644
index 000000000000..2a643dc3eb62
--- /dev/null
+++
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSslConfigurationTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.component.solr;
+
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.KeyStore;
+import java.util.Collections;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.impl.HttpJdkSolrClient;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The SSL options of the client that Camel creates. The CamelContext is not
started in most tests, so that looking up
+ * the endpoint does not start it, and the test calls {@link
SolrEndpoint#createSolrClient()}, which the endpoint calls
+ * at startup.
+ */
+public class SolrSslConfigurationTest {
+
+ @TempDir
+ Path tempDir;
+
+ @Test
+ public void certificatePathWithoutEnableSslFails() throws Exception {
+ String certificatePath = "file:" + writeCaCertificate();
+ try (CamelContext context = new DefaultCamelContext()) {
+ SolrEndpoint endpoint =
context.getEndpoint("solr://localhost:8983?certificatePath=" + certificatePath,
+ SolrEndpoint.class);
+ IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, endpoint::createSolrClient);
+ assertTrue(e.getMessage().contains("enableSSL=true"),
e.getMessage());
+ }
+ }
+
+ @Test
+ public void sslContextParametersWithoutEnableSslFails() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ SolrComponent component = new SolrComponent(context);
+ component.setSslContextParameters(new SSLContextParameters());
+ context.addComponent("solr", component);
+
+ SolrEndpoint endpoint =
context.getEndpoint("solr://localhost:8983", SolrEndpoint.class);
+ IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, endpoint::createSolrClient);
+ assertTrue(e.getMessage().contains("enableSSL=true"),
e.getMessage());
+ }
+ }
+
+ @Test
+ public void routeWithCertificatePathWithoutEnableSslFailsAtStartup()
throws Exception {
+ String certificatePath = "file:" + writeCaCertificate();
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("direct:start").to("solr://localhost:8983?certificatePath=" +
certificatePath);
+ }
+ });
+
+ Exception e = assertThrows(Exception.class, context::start);
+ IllegalArgumentException cause =
ObjectHelper.getException(IllegalArgumentException.class, e);
+ assertNotNull(cause, "Expected an IllegalArgumentException as
cause of " + e);
+ assertTrue(cause.getMessage().contains("enableSSL=true"),
cause.getMessage());
+ }
+ }
+
+ @Test
+ public void globalSslContextParametersWithoutEnableSslUsePlainHttp()
throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.setSSLContextParameters(new SSLContextParameters());
+ SolrComponent component = new SolrComponent(context);
+ component.setUseGlobalSslContextParameters(true);
+ context.addComponent("solr", component);
+
+ SolrEndpoint endpoint =
context.getEndpoint("solr://localhost:8983", SolrEndpoint.class);
+ try (SolrClient client = endpoint.createSolrClient()) {
+ HttpJdkSolrClient httpClient =
assertInstanceOf(HttpJdkSolrClient.class, client);
+ assertEquals("http://localhost:8983/solr",
httpClient.getBaseURL());
+ }
+ }
+ }
+
+ @Test
+ public void certificatePathWithEnableSslUsesHttps() throws Exception {
+ String certificatePath = "file:" + writeCaCertificate();
+ try (CamelContext context = new DefaultCamelContext()) {
+ SolrEndpoint endpoint = context.getEndpoint(
+ "solr://localhost:8983?enableSSL=true&certificatePath=" +
certificatePath, SolrEndpoint.class);
+ try (SolrClient client = endpoint.createSolrClient()) {
+ HttpJdkSolrClient httpClient =
assertInstanceOf(HttpJdkSolrClient.class, client);
+ assertEquals("https://localhost:8983/solr",
httpClient.getBaseURL());
+ }
+ }
+ }
+
+ @Test
+ public void certificatePathWithHttpUrlFails() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ for (String certificatePath : new String[] {
"http://localhost:8080/ca.crt", "HTTP://localhost:8080/ca.crt" }) {
+ SolrEndpoint endpoint = context.getEndpoint(
+
"solr://localhost:8983?enableSSL=true&certificatePath=" + certificatePath,
SolrEndpoint.class);
+ IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, endpoint::createSolrClient);
+ assertTrue(e.getMessage().contains("http: URL"),
e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Writes the certificate of the test key store as a DER file, to use as
the CA certificate of the client.
+ */
+ private Path writeCaCertificate() throws Exception {
+ KeyStore keyStore = KeyStore.getInstance("JKS");
+ try (InputStream is =
SolrSslConfigurationTest.class.getResourceAsStream("/solrtest.keystore")) {
+ keyStore.load(is, "secret".toCharArray());
+ }
+ String alias = Collections.list(keyStore.aliases()).get(0);
+ Path file = tempDir.resolve("ca.der");
+ Files.write(file, keyStore.getCertificate(alias).getEncoded());
+ return file;
+ }
+}
diff --git
a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSslContextParametersTest.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSslContextParametersTest.java
index a4c65e8259ba..c7074d6ae86d 100644
---
a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSslContextParametersTest.java
+++
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrSslContextParametersTest.java
@@ -29,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class SolrSslContextParametersTest {
- private static final String SOLR_URI = "solr://localhost:8983";
+ private static final String SOLR_URI =
"solr://localhost:8983?enableSSL=true";
@Test
public void configurationPropertyRoundTrip() {
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index dee8dc909981..dcbb2affbacb 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -12464,6 +12464,16 @@ With `allowUrlBody=true`, a body that does not start
with `version: 1` and is no
with a space or a relative name, now fails with an `InvalidPayloadException`,
as a URL with an unknown scheme already
did. Before, it failed with an `IllegalArgumentException`. A URL that cannot
be fetched keeps its own exception.
+=== camel-solr - certificatePath and sslContextParameters need enableSSL
+
+The client that Camel creates connects with plain HTTP unless
`enableSSL=true`, so the `certificatePath` and
+`sslContextParameters` options were ignored without `enableSSL`. Now, when
`certificatePath`, or the
+`sslContextParameters` of the endpoint or the component, is set and
`enableSSL` is not enabled, the endpoint fails at
+startup with a message to set `enableSSL=true`. Enable `enableSSL` to connect
with HTTPS, or remove the options that are
+not used. The global SSL context parameters
(`useGlobalSslContextParameters=true`) only log a WARN in that case.
+
+The `certificatePath` option now refuses an `http:` URL. Load the certificate
from the classpath, or with the
+`classpath:`, `file:` or `https:` prefix.
=== camel-aws - incomplete session or static credentials fail when the client
is created
The AWS components (all that use `camel-aws-common` to create their client,
such as `aws2-s3`, `aws2-sqs`,
diff --git
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SolrComponentBuilderFactory.java
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SolrComponentBuilderFactory.java
index 00b24250344e..f071880c4bef 100644
---
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SolrComponentBuilderFactory.java
+++
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SolrComponentBuilderFactory.java
@@ -239,8 +239,8 @@ public interface SolrComponentBuilderFactory {
/**
* The TLS configuration (key store, trust store, protocols, cipher
* suites, named groups) of the clients that Camel creates, for all the
- * endpoints. The sslContextParameters option of an endpoint replaces
- * it.
+ * endpoints. It is used when the enableSSL option is enabled. The
+ * sslContextParameters option of an endpoint replaces it.
*
* The option is a:
*
<code>org.apache.camel.support.jsse.SSLContextParameters</code>
type.
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SolrEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SolrEndpointBuilderFactory.java
index cdfdff3e5803..00220673c0c1 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SolrEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SolrEndpointBuilderFactory.java
@@ -350,8 +350,9 @@ public interface SolrEndpointBuilderFactory {
}
/**
* The X.509 certificate of the certificate authority that the client
- * that Camel creates trusts for HTTPS. It is loaded from the classpath
- * by default, or with the classpath:, file: or http: prefix. Not used
+ * that Camel creates trusts for HTTPS (the enableSSL option must be
+ * enabled). It is loaded from the classpath by default, or with the
+ * classpath:, file: or https: prefix; an http: URL is refused. Not
used
* when the sslContextParameters option is set.
*
* This option can also be loaded from an existing file, by prefixing
@@ -370,7 +371,8 @@ public interface SolrEndpointBuilderFactory {
}
/**
* Whether the client that Camel creates connects to Solr with HTTPS
- * instead of HTTP.
+ * instead of HTTP. It must be enabled to use the certificatePath or
+ * sslContextParameters option, otherwise the endpoint fails at
startup.
*
* The option is a: <code>boolean</code> type.
*
@@ -386,7 +388,8 @@ public interface SolrEndpointBuilderFactory {
}
/**
* Whether the client that Camel creates connects to Solr with HTTPS
- * instead of HTTP.
+ * instead of HTTP. It must be enabled to use the certificatePath or
+ * sslContextParameters option, otherwise the endpoint fails at
startup.
*
* The option will be converted to a <code>boolean</code> type.
*
@@ -418,10 +421,11 @@ public interface SolrEndpointBuilderFactory {
}
/**
* The TLS configuration (key store, trust store, protocols, cipher
- * suites, named groups) of the client that Camel creates. It takes
- * precedence over the certificatePath option. If not set, the global
- * SSL context parameters are used when the
- * useGlobalSslContextParameters option of the component is enabled.
+ * suites, named groups) of the client that Camel creates, which is
used
+ * when the enableSSL option is enabled. It takes precedence over the
+ * certificatePath option. If not set, the global SSL context
parameters
+ * are used when the useGlobalSslContextParameters option of the
+ * component is enabled.
*
* The option is a:
* <code>org.apache.camel.support.jsse.SSLContextParameters</code>
type.
@@ -437,10 +441,11 @@ public interface SolrEndpointBuilderFactory {
}
/**
* The TLS configuration (key store, trust store, protocols, cipher
- * suites, named groups) of the client that Camel creates. It takes
- * precedence over the certificatePath option. If not set, the global
- * SSL context parameters are used when the
- * useGlobalSslContextParameters option of the component is enabled.
+ * suites, named groups) of the client that Camel creates, which is
used
+ * when the enableSSL option is enabled. It takes precedence over the
+ * certificatePath option. If not set, the global SSL context
parameters
+ * are used when the useGlobalSslContextParameters option of the
+ * component is enabled.
*
* The option will be converted to a
* <code>org.apache.camel.support.jsse.SSLContextParameters</code>
type.