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 e469664e88148b126e5938aa28674019c80955a8 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue May 12 09:26:44 2020 +0200 CAMEL-15050: Templating components - Variable map to be limited to body/headers --- .../StringTemplateComponentConfigurer.java | 5 ++++ .../StringTemplateEndpointConfigurer.java | 5 ++++ .../component/stringtemplate/string-template.json | 2 ++ .../src/main/docs/string-template-component.adoc | 6 ++-- .../stringtemplate/StringTemplateComponent.java | 16 ++++++++++ .../stringtemplate/StringTemplateEndpoint.java | 2 +- .../stringtemplate/StringTemplateTest.java | 2 +- .../dsl/StringTemplateComponentBuilderFactory.java | 18 ++++++++++++ .../dsl/StringTemplateEndpointBuilderFactory.java | 34 ++++++++++++++++++++++ 9 files changed, 86 insertions(+), 4 deletions(-) diff --git a/components/camel-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateComponentConfigurer.java b/components/camel-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateComponentConfigurer.java index 4e38d01..73b9da2 100644 --- a/components/camel-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateComponentConfigurer.java +++ b/components/camel-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateComponentConfigurer.java @@ -19,6 +19,8 @@ public class StringTemplateComponentConfigurer extends PropertyConfigurerSupport public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { StringTemplateComponent target = (StringTemplateComponent) 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": @@ -32,6 +34,7 @@ public class StringTemplateComponentConfigurer extends PropertyConfigurerSupport @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); @@ -42,6 +45,8 @@ public class StringTemplateComponentConfigurer extends PropertyConfigurerSupport public Object getOptionValue(Object obj, String name, boolean ignoreCase) { StringTemplateComponent target = (StringTemplateComponent) 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-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateEndpointConfigurer.java b/components/camel-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateEndpointConfigurer.java index b9fc723..46a2fd1 100644 --- a/components/camel-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateEndpointConfigurer.java +++ b/components/camel-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateEndpointConfigurer.java @@ -19,6 +19,8 @@ public class StringTemplateEndpointConfigurer extends PropertyConfigurerSupport public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { StringTemplateEndpoint target = (StringTemplateEndpoint) 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": @@ -39,6 +41,7 @@ public class StringTemplateEndpointConfigurer extends PropertyConfigurerSupport @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); @@ -53,6 +56,8 @@ public class StringTemplateEndpointConfigurer extends PropertyConfigurerSupport public Object getOptionValue(Object obj, String name, boolean ignoreCase) { StringTemplateEndpoint target = (StringTemplateEndpoint) 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-stringtemplate/src/generated/resources/org/apache/camel/component/stringtemplate/string-template.json b/components/camel-stringtemplate/src/generated/resources/org/apache/camel/component/stringtemplate/string-template.json index d63ca6b..a0e950d 100644 --- a/components/camel-stringtemplate/src/generated/resources/org/apache/camel/component/stringtemplate/string-template.json +++ b/components/camel-stringtemplate/src/generated/resources/org/apache/camel/component/stringtemplate/string-template.json @@ -21,12 +21,14 @@ "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" } }, "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" }, "delimiterStart": { "kind": "parameter", "displayName": "Delimiter Start", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "char", "deprecated": false, "secret": false, "defaultValue": "<", "description": "The variable start delimiter" }, diff --git a/components/camel-stringtemplate/src/main/docs/string-template-component.adoc b/components/camel-stringtemplate/src/main/docs/string-template-component.adoc index 60ef080..e5315ed 100644 --- a/components/camel-stringtemplate/src/main/docs/string-template-component.adoc +++ b/components/camel-stringtemplate/src/main/docs/string-template-component.adoc @@ -46,13 +46,14 @@ You can append query options to the URI in the following format, // component options: START -The String Template component supports 3 options, which are listed below. +The String Template component supports 4 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 @@ -80,12 +81,13 @@ with the following path and query parameters: |=== -=== Query Parameters (7 parameters): +=== Query Parameters (8 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 | *delimiterStart* (producer) | The variable start delimiter | < | char diff --git a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java index 96991e7..3128ffd 100644 --- a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java +++ b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java @@ -29,6 +29,8 @@ public class StringTemplateComponent extends DefaultComponent { @Metadata(defaultValue = "false") private boolean allowTemplateFromHeader; + @Metadata(defaultValue = "false") + private boolean allowContextMapAll; public StringTemplateComponent() { } @@ -37,6 +39,7 @@ public class StringTemplateComponent extends DefaultComponent { protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { StringTemplateEndpoint answer = new StringTemplateEndpoint(uri, this, remaining); answer.setAllowTemplateFromHeader(allowTemplateFromHeader); + answer.setAllowContextMapAll(allowContextMapAll); setProperties(answer, parameters); // if its a http resource then append any remaining parameters and update the resource uri @@ -62,5 +65,18 @@ public class StringTemplateComponent 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; + } } \ No newline at end of file diff --git a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java index d607d1a..f261435 100644 --- a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java +++ b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java @@ -101,7 +101,7 @@ public class StringTemplateEndpoint extends ResourceEndpoint { variableMap = exchange.getIn().getHeader(StringTemplateConstants.STRINGTEMPLATE_VARIABLE_MAP, Map.class); } if (variableMap == null) { - variableMap = ExchangeHelper.createVariableMap(exchange); + variableMap = ExchangeHelper.createVariableMap(exchange, isAllowContextMapAll()); } // getResourceAsInputStream also considers the content cache diff --git a/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java b/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java index 0098bef..976a2b1 100644 --- a/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java +++ b/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java @@ -64,7 +64,7 @@ public class StringTemplateTest extends CamelTestSupport { public void configure() { // START SNIPPET: example from("direct:a"). - to("string-template:org/apache/camel/component/stringtemplate/template.tm?allowTemplateFromHeader=true"); + to("string-template:org/apache/camel/component/stringtemplate/template.tm?allowTemplateFromHeader=true&allowContextMapAll=true"); // END SNIPPET: example } }; diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/StringTemplateComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/StringTemplateComponentBuilderFactory.java index 0e354e9..1ea2f2d 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/StringTemplateComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/StringTemplateComponentBuilderFactory.java @@ -49,6 +49,23 @@ public interface StringTemplateComponentBuilderFactory { extends ComponentBuilder<StringTemplateComponent> { /** + * 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 StringTemplateComponentBuilder 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 @@ -117,6 +134,7 @@ public interface StringTemplateComponentBuilderFactory { String name, Object value) { switch (name) { + case "allowContextMapAll": ((StringTemplateComponent) component).setAllowContextMapAll((boolean) value); return true; case "allowTemplateFromHeader": ((StringTemplateComponent) component).setAllowTemplateFromHeader((boolean) value); return true; case "lazyStartProducer": ((StringTemplateComponent) component).setLazyStartProducer((boolean) value); return true; case "basicPropertyBinding": ((StringTemplateComponent) component).setBasicPropertyBinding((boolean) value); return true; diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/StringTemplateEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/StringTemplateEndpointBuilderFactory.java index 3ff5669..49d6d20 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/StringTemplateEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/StringTemplateEndpointBuilderFactory.java @@ -40,6 +40,40 @@ public interface StringTemplateEndpointBuilderFactory { return (AdvancedStringTemplateEndpointBuilder) 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 StringTemplateEndpointBuilder 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 StringTemplateEndpointBuilder 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