This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0ac82c8bd42e9840e8912b2c9ae1ce9914c3165a
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue May 12 09:10:25 2020 +0200

    CAMEL-15050: Templating components - Variable map to be limited to 
body/headers
---
 .../mustache/MustacheComponentConfigurer.java      |  5 ++++
 .../mustache/MustacheEndpointConfigurer.java       |  5 ++++
 .../apache/camel/component/mustache/mustache.json  |  2 ++
 .../src/main/docs/mustache-component.adoc          |  6 ++--
 .../component/mustache/MustacheComponent.java      | 18 ++++++++++++
 .../camel/component/mustache/MustacheEndpoint.java |  2 +-
 .../dsl/MustacheComponentBuilderFactory.java       | 18 ++++++++++++
 .../dsl/MustacheEndpointBuilderFactory.java        | 34 ++++++++++++++++++++++
 8 files changed, 87 insertions(+), 3 deletions(-)

diff --git 
a/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheComponentConfigurer.java
 
b/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheComponentConfigurer.java
index 23d71aa..f163ba4 100644
--- 
a/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheComponentConfigurer.java
+++ 
b/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheComponentConfigurer.java
@@ -19,6 +19,8 @@ public class MustacheComponentConfigurer extends 
PropertyConfigurerSupport imple
     public boolean configure(CamelContext camelContext, Object obj, String 
name, Object value, boolean ignoreCase) {
         MustacheComponent target = (MustacheComponent) obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
+        case "allowcontextmapall":
+        case "allowContextMapAll": 
target.setAllowContextMapAll(property(camelContext, boolean.class, value)); 
return true;
         case "allowtemplatefromheader":
         case "allowTemplateFromHeader": 
target.setAllowTemplateFromHeader(property(camelContext, boolean.class, 
value)); return true;
         case "basicpropertybinding":
@@ -34,6 +36,7 @@ public class MustacheComponentConfigurer extends 
PropertyConfigurerSupport imple
     @Override
     public Map<String, Object> getAllOptions(Object target) {
         Map<String, Object> answer = new CaseInsensitiveMap();
+        answer.put("allowContextMapAll", boolean.class);
         answer.put("allowTemplateFromHeader", boolean.class);
         answer.put("basicPropertyBinding", boolean.class);
         answer.put("lazyStartProducer", boolean.class);
@@ -45,6 +48,8 @@ public class MustacheComponentConfigurer extends 
PropertyConfigurerSupport imple
     public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
         MustacheComponent target = (MustacheComponent) obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
+        case "allowcontextmapall":
+        case "allowContextMapAll": return target.isAllowContextMapAll();
         case "allowtemplatefromheader":
         case "allowTemplateFromHeader": return 
target.isAllowTemplateFromHeader();
         case "basicpropertybinding":
diff --git 
a/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheEndpointConfigurer.java
 
b/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheEndpointConfigurer.java
index 08555a5..b5e698a 100644
--- 
a/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheEndpointConfigurer.java
+++ 
b/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheEndpointConfigurer.java
@@ -19,6 +19,8 @@ public class MustacheEndpointConfigurer extends 
PropertyConfigurerSupport implem
     public boolean configure(CamelContext camelContext, Object obj, String 
name, Object value, boolean ignoreCase) {
         MustacheEndpoint target = (MustacheEndpoint) obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
+        case "allowcontextmapall":
+        case "allowContextMapAll": 
target.setAllowContextMapAll(property(camelContext, boolean.class, value)); 
return true;
         case "allowtemplatefromheader":
         case "allowTemplateFromHeader": 
target.setAllowTemplateFromHeader(property(camelContext, boolean.class, 
value)); return true;
         case "basicpropertybinding":
@@ -40,6 +42,7 @@ public class MustacheEndpointConfigurer extends 
PropertyConfigurerSupport implem
     @Override
     public Map<String, Object> getAllOptions(Object target) {
         Map<String, Object> answer = new CaseInsensitiveMap();
+        answer.put("allowContextMapAll", boolean.class);
         answer.put("allowTemplateFromHeader", boolean.class);
         answer.put("basicPropertyBinding", boolean.class);
         answer.put("contentCache", boolean.class);
@@ -55,6 +58,8 @@ public class MustacheEndpointConfigurer extends 
PropertyConfigurerSupport implem
     public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
         MustacheEndpoint target = (MustacheEndpoint) obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
+        case "allowcontextmapall":
+        case "allowContextMapAll": return target.isAllowContextMapAll();
         case "allowtemplatefromheader":
         case "allowTemplateFromHeader": return 
target.isAllowTemplateFromHeader();
         case "basicpropertybinding":
diff --git 
a/components/camel-mustache/src/generated/resources/org/apache/camel/component/mustache/mustache.json
 
b/components/camel-mustache/src/generated/resources/org/apache/camel/component/mustache/mustache.json
index b367f50..1341b00 100644
--- 
a/components/camel-mustache/src/generated/resources/org/apache/camel/component/mustache/mustache.json
+++ 
b/components/camel-mustache/src/generated/resources/org/apache/camel/component/mustache/mustache.json
@@ -21,6 +21,7 @@
     "lenientProperties": false
   },
   "componentProperties": {
+    "allowContextMapAll": { "kind": "property", "displayName": "Allow Context 
Map All", "group": "producer", "label": "", "required": false, "type": 
"boolean", "javaType": "boolean", "deprecated": false, "secret": false, 
"defaultValue": "false", "description": "Sets whether the context map should 
allow access to all details. By default only the message body and headers can 
be accessed. This option can be enabled for full access to the current Exchange 
and CamelContext. Doing so impose a  [...]
     "allowTemplateFromHeader": { "kind": "property", "displayName": "Allow 
Template From Header", "group": "producer", "label": "", "required": false, 
"type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, 
"defaultValue": "false", "description": "Whether to allow to use resource 
template from header or not (default false). Enabling this allows to specify 
dynamic templates via message header. However this can be seen as a potential 
security vulnerability if the he [...]
     "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start 
Producer", "group": "producer", "label": "producer", "required": false, "type": 
"boolean", "javaType": "boolean", "deprecated": 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 producer may otherwise 
fail during starting and cause the r [...]
     "basicPropertyBinding": { "kind": "property", "displayName": "Basic 
Property Binding", "group": "advanced", "label": "advanced", "required": false, 
"type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, 
"defaultValue": false, "description": "Whether the component should use basic 
property binding (Camel 2.x) or the newer property binding with additional 
capabilities" },
@@ -28,6 +29,7 @@
   },
   "properties": {
     "resourceUri": { "kind": "path", "displayName": "Resource Uri", "group": 
"producer", "label": "", "required": true, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "deprecationNote": "", "secret": 
false, "description": "Path to the resource. You can prefix with: classpath, 
file, http, ref, or bean. classpath, file and http loads the resource using 
these protocols (classpath is default). ref will lookup the resource in the 
registry. bean will call a method on a  [...]
+    "allowContextMapAll": { "kind": "parameter", "displayName": "Allow Context 
Map All", "group": "producer", "label": "", "required": false, "type": 
"boolean", "javaType": "boolean", "deprecated": false, "secret": false, 
"defaultValue": "false", "description": "Sets whether the context map should 
allow access to all details. By default only the message body and headers can 
be accessed. This option can be enabled for full access to the current Exchange 
and CamelContext. Doing so impose a [...]
     "allowTemplateFromHeader": { "kind": "parameter", "displayName": "Allow 
Template From Header", "group": "producer", "label": "", "required": false, 
"type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, 
"defaultValue": "false", "description": "Whether to allow to use resource 
template from header or not (default false). Enabling this allows to specify 
dynamic templates via message header. However this can be seen as a potential 
security vulnerability if the h [...]
     "contentCache": { "kind": "parameter", "displayName": "Content Cache", 
"group": "producer", "label": "", "required": false, "type": "boolean", 
"javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": 
"false", "description": "Sets whether to use resource content cache or not" },
     "encoding": { "kind": "parameter", "displayName": "Encoding", "group": 
"producer", "label": "", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "secret": false, "description": 
"Character encoding of the resource content." },
diff --git a/components/camel-mustache/src/main/docs/mustache-component.adoc 
b/components/camel-mustache/src/main/docs/mustache-component.adoc
index bd32e4b..fbcbf7a 100644
--- a/components/camel-mustache/src/main/docs/mustache-component.adoc
+++ b/components/camel-mustache/src/main/docs/mustache-component.adoc
@@ -46,13 +46,14 @@ You can append query options to the URI in the following 
format,
 
 
 // component options: START
-The Mustache component supports 4 options, which are listed below.
+The Mustache component supports 5 options, which are listed below.
 
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
+| *allowContextMapAll* (producer) | Sets whether the context map should allow 
access to all details. By default only the message body and headers can be 
accessed. This option can be enabled for full access to the current Exchange 
and CamelContext. Doing so impose a potential security risk as this opens 
access to the full power of CamelContext API. | false | boolean
 | *allowTemplateFromHeader* (producer) | Whether to allow to use resource 
template from header or not (default false). Enabling this allows to specify 
dynamic templates via message header. However this can be seen as a potential 
security vulnerability if the header is coming from a malicious user, so use 
this with care. | false | boolean
 | *lazyStartProducer* (producer) | 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 producer may otherwise fail during 
starting and cause the route to fail being started. By deferring this startup 
to be lazy then the startup failure can be handled during routing messages via 
Camel's routing error handlers. Beware that when the first message is processed 
then creating and [...]
 | *basicPropertyBinding* (advanced) | Whether the component should use basic 
property binding (Camel 2.x) or the newer property binding with additional 
capabilities | false | boolean
@@ -86,12 +87,13 @@ with the following path and query parameters:
 |===
 
 
-=== Query Parameters (8 parameters):
+=== Query Parameters (9 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
+| *allowContextMapAll* (producer) | Sets whether the context map should allow 
access to all details. By default only the message body and headers can be 
accessed. This option can be enabled for full access to the current Exchange 
and CamelContext. Doing so impose a potential security risk as this opens 
access to the full power of CamelContext API. | false | boolean
 | *allowTemplateFromHeader* (producer) | Whether to allow to use resource 
template from header or not (default false). Enabling this allows to specify 
dynamic templates via message header. However this can be seen as a potential 
security vulnerability if the header is coming from a malicious user, so use 
this with care. | false | boolean
 | *contentCache* (producer) | Sets whether to use resource content cache or 
not | false | boolean
 | *encoding* (producer) | Character encoding of the resource content. |  | 
String
diff --git 
a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java
 
b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java
index a5bce85..1195747 100644
--- 
a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java
+++ 
b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java
@@ -40,6 +40,8 @@ public class MustacheComponent extends DefaultComponent {
 
     @Metadata(defaultValue = "false")
     private boolean allowTemplateFromHeader;
+    @Metadata(defaultValue = "false")
+    private boolean allowContextMapAll;
 
     @Metadata(label = "advanced")
     private MustacheFactory mustacheFactory = new DefaultMustacheFactory();
@@ -52,6 +54,7 @@ public class MustacheComponent extends DefaultComponent {
         MustacheEndpoint endpoint = new MustacheEndpoint(uri, this, remaining);
         endpoint.setMustacheFactory(getMustacheFactory());
         endpoint.setAllowTemplateFromHeader(allowTemplateFromHeader);
+        endpoint.setAllowContextMapAll(allowContextMapAll);
         setProperties(endpoint, parameters);
         return endpoint;
     }
@@ -81,4 +84,19 @@ public class MustacheComponent extends DefaultComponent {
         this.allowTemplateFromHeader = allowTemplateFromHeader;
     }
 
+    public boolean isAllowContextMapAll() {
+        return allowContextMapAll;
+    }
+
+    /**
+     * Sets whether the context map should allow access to all details.
+     * By default only the message body and headers can be accessed.
+     * This option can be enabled for full access to the current Exchange and 
CamelContext.
+     * Doing so impose a potential security risk as this opens access to the 
full power of CamelContext API.
+     */
+    public void setAllowContextMapAll(boolean allowContextMapAll) {
+        this.allowContextMapAll = allowContextMapAll;
+    }
+
+
 }
diff --git 
a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java
 
b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java
index a365cbc..515075e 100644
--- 
a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java
+++ 
b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java
@@ -107,7 +107,7 @@ public class MustacheEndpoint extends ResourceEndpoint {
         }
 
         // Execute Mustache
-        Map<String, Object> variableMap = 
ExchangeHelper.createVariableMap(exchange);
+        Map<String, Object> variableMap = 
ExchangeHelper.createVariableMap(exchange, isAllowContextMapAll());
         StringWriter writer = new StringWriter();
         newMustache.execute(writer, variableMap);
         writer.flush();
diff --git 
a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/MustacheComponentBuilderFactory.java
 
b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/MustacheComponentBuilderFactory.java
index 2896ba7..cdeb7f4 100644
--- 
a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/MustacheComponentBuilderFactory.java
+++ 
b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/MustacheComponentBuilderFactory.java
@@ -49,6 +49,23 @@ public interface MustacheComponentBuilderFactory {
             extends
                 ComponentBuilder<MustacheComponent> {
         /**
+         * Sets whether the context map should allow access to all details. By
+         * default only the message body and headers can be accessed. This
+         * option can be enabled for full access to the current Exchange and
+         * CamelContext. Doing so impose a potential security risk as this 
opens
+         * access to the full power of CamelContext API.
+         * 
+         * The option is a: <code>boolean</code> type.
+         * 
+         * Default: false
+         * Group: producer
+         */
+        default MustacheComponentBuilder allowContextMapAll(
+                boolean allowContextMapAll) {
+            doSetProperty("allowContextMapAll", allowContextMapAll);
+            return this;
+        }
+        /**
          * Whether to allow to use resource template from header or not 
(default
          * false). Enabling this allows to specify dynamic templates via 
message
          * header. However this can be seen as a potential security
@@ -130,6 +147,7 @@ public interface MustacheComponentBuilderFactory {
                 String name,
                 Object value) {
             switch (name) {
+            case "allowContextMapAll": ((MustacheComponent) 
component).setAllowContextMapAll((boolean) value); return true;
             case "allowTemplateFromHeader": ((MustacheComponent) 
component).setAllowTemplateFromHeader((boolean) value); return true;
             case "lazyStartProducer": ((MustacheComponent) 
component).setLazyStartProducer((boolean) value); return true;
             case "basicPropertyBinding": ((MustacheComponent) 
component).setBasicPropertyBinding((boolean) value); return true;
diff --git 
a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MustacheEndpointBuilderFactory.java
 
b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MustacheEndpointBuilderFactory.java
index 487fb9a..3425739 100644
--- 
a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MustacheEndpointBuilderFactory.java
+++ 
b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/MustacheEndpointBuilderFactory.java
@@ -38,6 +38,40 @@ public interface MustacheEndpointBuilderFactory {
             return (AdvancedMustacheEndpointBuilder) this;
         }
         /**
+         * Sets whether the context map should allow access to all details. By
+         * default only the message body and headers can be accessed. This
+         * option can be enabled for full access to the current Exchange and
+         * CamelContext. Doing so impose a potential security risk as this 
opens
+         * access to the full power of CamelContext API.
+         * 
+         * The option is a: <code>boolean</code> type.
+         * 
+         * Default: false
+         * Group: producer
+         */
+        default MustacheEndpointBuilder allowContextMapAll(
+                boolean allowContextMapAll) {
+            doSetProperty("allowContextMapAll", allowContextMapAll);
+            return this;
+        }
+        /**
+         * Sets whether the context map should allow access to all details. By
+         * default only the message body and headers can be accessed. This
+         * option can be enabled for full access to the current Exchange and
+         * CamelContext. Doing so impose a potential security risk as this 
opens
+         * access to the full power of CamelContext API.
+         * 
+         * The option will be converted to a <code>boolean</code> type.
+         * 
+         * Default: false
+         * Group: producer
+         */
+        default MustacheEndpointBuilder allowContextMapAll(
+                String allowContextMapAll) {
+            doSetProperty("allowContextMapAll", allowContextMapAll);
+            return this;
+        }
+        /**
          * Whether to allow to use resource template from header or not 
(default
          * false). Enabling this allows to specify dynamic templates via 
message
          * header. However this can be seen as a potential security

Reply via email to