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 3a2dd2fb0a6 CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth via properties file (#14849) 3a2dd2fb0a6 is described below commit 3a2dd2fb0a676fce2d84a6d90fe104c586aa5293 Author: Ivan Kulaga <kulagaivanandreev...@gmail.com> AuthorDate: Thu Aug 8 09:55:15 2024 +0500 CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth via properties file (#14849) * CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth - add properties configuration for camel-main-http for basic and jwt auth - add logic in DefaultMainHttpServerFactory that configures MainHttpServer auth based on HttpServerConfigurationProperties - remove default auth settings from camel-platform-http-vertx as this does little sense when it is possible to configure via properties file * CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth - replace checks for empty strings with ObjecHelper static calls * CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth - format file with "mvn net.revelc.code.formatter:formatter-maven-plugin:2.24.1:format" so that sourcecheck passes * CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth - vertx.auth dependencies are not needed in camel-platform-http-vertx, they are needed only in camel-platform-http-main * CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth - rewrite reflection to use camel helper objects, add javadoc to the ConfigurationPropertiesWithMandatoryFields interface * CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth - use injector instead of instantiating via reflection; add context injection when creating MainHttpServerFactory * CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth - add autogenerated changes --- .../main/camel-main-configuration-metadata.json | 8 ++ components/camel-platform-http-main/pom.xml | 17 +++ .../http/main/DefaultMainHttpServerFactory.java | 72 ++++++++++ .../BasicAuthenticationConfigurer.java | 46 +++++++ .../JWTAuthenticationConfigurer.java | 62 +++++++++ .../MainAuthenticationConfigurer.java | 26 ++++ ...henticationConfigurationMainHttpServerTest.java | 47 +++++++ .../BasicAuthenticationMainHttpServerTest.java | 78 +++++++++++ .../JWTAuthenticationMainHttpServerTest.java | 102 ++++++++++++++ .../src/test/resources/basic-auth.properties | 21 +++ .../camel-platform-http-vertx-auth.properties | 19 +++ .../src/test/resources/incomplete-auth.properties | 23 ++++ .../src/test/resources/jwt-auth.properties | 23 ++++ .../test/resources/test-camel-main-auth-jwt.jks | Bin 0 -> 2716 bytes components/camel-platform-http-vertx/pom.xml | 17 ++- .../src/main/docs/platform-http-vertx.adoc | 7 +- .../http/vertx/auth/AuthenticationConfig.java | 12 +- .../vertx/VertxPlatformHttpAuthenticationTest.java | 52 ++------ ...nticationConfigurationPropertiesConfigurer.java | 60 +++++++++ ...nticationConfigurationPropertiesConfigurer.java | 51 +++++++ ...verBasicAuthenticationPropertiesConfigurer.java | 32 +++++ ...ttpServerConfigurationPropertiesConfigurer.java | 3 + ...nticationConfigurationPropertiesConfigurer.java | 63 +++++++++ .../camel-main-configuration-metadata.json | 8 ++ ...HttpServerAuthenticationConfigurationProperties | 2 + ...erverBasicAuthenticationConfigurationProperties | 2 + ...el.main.HttpServerBasicAuthenticationProperties | 2 + ...pServerJWTAuthenticationConfigurationProperties | 2 + core/camel-main/src/main/docs/main.adoc | 10 +- .../org/apache/camel/main/BaseMainSupport.java | 3 +- ...ConfigurationPropertiesWithMandatoryFields.java | 32 +++++ ...erverAuthenticationConfigurationProperties.java | 146 +++++++++++++++++++++ ...BasicAuthenticationConfigurationProperties.java | 70 ++++++++++ .../main/HttpServerConfigurationProperties.java | 40 ++++++ ...erJWTAuthenticationConfigurationProperties.java | 109 +++++++++++++++ 35 files changed, 1209 insertions(+), 58 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json index a9ec26761cf..bca1d8b9d0e 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json @@ -256,14 +256,22 @@ { "name": "camel.routecontroller.threadPoolSize", "description": "The number of threads used by the route controller scheduled thread pool that are used for restarting routes. The pool uses 1 thread by default, but you can increase this to allow the controller to concurrently attempt to restart multiple routes in case more than one route has problems starting.", "sourceType": "org.apache.camel.main.RouteControllerConfigurationProperties", "type": "integer", "javaType": "int", "defaul [...] { "name": "camel.routecontroller.unhealthyOnExhausted", "description": "Whether to mark the route as unhealthy (down) when all restarting attempts (backoff) have failed and the route is not successfully started and the route manager is giving up. If setting this to false will make health checks ignore this problem and allow to report the Camel application as UP.", "sourceType": "org.apache.camel.main.RouteControllerConfigurationProperties", "type": "boolean", "javaType": "boolean", " [...] { "name": "camel.routecontroller.unhealthyOnRestarting", "description": "Whether to mark the route as unhealthy (down) when the route failed to initially start, and is being controlled for restarting (backoff). If setting this to false will make health checks ignore this problem and allow to report the Camel application as UP.", "sourceType": "org.apache.camel.main.RouteControllerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true }, + { "name": "camel.server.authentication", "description": "To configure embedded HTTP server authentication (for standalone applications; not Spring Boot or Quarkus)", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "object", "javaType": "org.apache.camel.main.HttpServerAuthenticationConfigurationProperties" }, + { "name": "camel.server.authenticationPropertiesFile", "description": "Name of the file that contains authentication info for Vert.x property file auth provider.", "sourceType": "org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, + { "name": "camel.server.basic", "description": "To configure Basic HTTP authentication for embedded server.", "sourceType": "org.apache.camel.main.HttpServerAuthenticationConfigurationProperties", "type": "object", "javaType": "org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties" }, { "name": "camel.server.devConsoleEnabled", "description": "Whether to enable developer console (not intended for production use). Dev console must also be enabled on CamelContext. For example by setting camel.context.dev-console=true in application.properties, or via code camelContext.setDevConsole(true); If enabled then you can access a basic developer console on context-path: \/q\/dev.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "j [...] + { "name": "camel.server.enabled", "description": "Whether to enable HTTP authentication for embedded server.", "sourceType": "org.apache.camel.main.HttpServerAuthenticationConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.enabled", "description": "Whether embedded HTTP server is enabled. By default, the server is not enabled.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.healthCheckEnabled", "description": "Whether to enable health-check console. If enabled then you can access health-check status on context-path: \/q\/health", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.host", "description": "Hostname to use for binding embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "0.0.0.0" }, { "name": "camel.server.infoEnabled", "description": "Whether to enable info console. If enabled then you can see some basic Camel information at \/q\/info", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.jolokiaEnabled", "description": "Whether to enable jolokia. If enabled then you can access jolokia api on context-path: \/q\/jolokia", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, + { "name": "camel.server.keystorePassword", "description": "Password from the keystore used for JWT tokens validation.", "sourceType": "org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, + { "name": "camel.server.keystorePath", "description": "Path to the keystore file used for JWT tokens validation.", "sourceType": "org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, + { "name": "camel.server.keystoreType", "description": "Type of the keystore used for JWT tokens validation (jks, pkcs12, etc.).", "sourceType": "org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.server.maxBodySize", "description": "Maximum HTTP body size the embedded HTTP server can accept.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", "javaType": "java.lang.Long" }, { "name": "camel.server.metricsEnabled", "description": "Whether to enable metrics. If enabled then you can access metrics on context-path: \/q\/metrics", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, + { "name": "camel.server.path", "description": "Set HTTP url path of embedded server that is protected by authentication configuration.", "sourceType": "org.apache.camel.main.HttpServerAuthenticationConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.server.path", "description": "Context-path to use for embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "\/" }, { "name": "camel.server.port", "description": "Port to use for binding embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 8080 }, { "name": "camel.server.uploadEnabled", "description": "Whether to enable file upload via HTTP (not intended for production use). This functionality is for development to be able to reload Camel routes and code with source changes (if reload is enabled). If enabled then you can upload\/delete files via HTTP PUT\/DELETE on context-path: \/q\/upload\/{name}. You must also configure the uploadSourceDir option.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "t [...] diff --git a/components/camel-platform-http-main/pom.xml b/components/camel-platform-http-main/pom.xml index 4492361b901..f50ea55333d 100644 --- a/components/camel-platform-http-main/pom.xml +++ b/components/camel-platform-http-main/pom.xml @@ -57,6 +57,17 @@ </exclusions> </dependency> + <dependency> + <groupId>io.vertx</groupId> + <artifactId>vertx-auth-properties</artifactId> + <version>${vertx-version}</version> + </dependency> + <dependency> + <groupId>io.vertx</groupId> + <artifactId>vertx-auth-jwt</artifactId> + <version>${vertx-version}</version> + </dependency> + <!-- test dependencies --> <dependency> <groupId>org.apache.camel</groupId> @@ -68,6 +79,12 @@ <artifactId>camel-health</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <version>${rest-assured-version}</version> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java index 6e49fd94303..aba8ab3ea7c 100644 --- a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java +++ b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java @@ -16,13 +16,23 @@ */ package org.apache.camel.component.platform.http.main; +import java.lang.reflect.InvocationTargetException; +import java.util.Optional; + import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; import org.apache.camel.Service; +import org.apache.camel.component.platform.http.main.authentication.MainAuthenticationConfigurer; +import org.apache.camel.component.platform.http.vertx.auth.AuthenticationConfig; +import org.apache.camel.main.ConfigurationPropertiesWithMandatoryFields; +import org.apache.camel.main.HttpServerAuthenticationConfigurationProperties; import org.apache.camel.main.HttpServerConfigurationProperties; import org.apache.camel.main.MainConstants; import org.apache.camel.main.MainHttpServerFactory; +import org.apache.camel.spi.ClassResolver; +import org.apache.camel.spi.Injector; import org.apache.camel.spi.annotations.JdkService; +import org.apache.camel.support.ObjectHelper; @JdkService(MainConstants.PLATFORM_HTTP_SERVER) public class DefaultMainHttpServerFactory implements CamelContextAware, MainHttpServerFactory { @@ -59,6 +69,68 @@ public class DefaultMainHttpServerFactory implements CamelContextAware, MainHttp server.setUploadEnabled(configuration.isUploadEnabled()); server.setUploadSourceDir(configuration.getUploadSourceDir()); + if (configuration.authentication().isEnabled()) { + configureAuthentication(server, configuration); + } + return server; } + + private void configureAuthentication(MainHttpServer server, HttpServerConfigurationProperties configuration) { + AuthenticationConfig authenticationConfig = server.getConfiguration().getAuthenticationConfig(); + + HttpServerAuthenticationConfigurationProperties authenticationProperties = configuration.getAuthentication(); + Optional<MainAuthenticationConfigurer> authenticationConfigurer + = findAuthenticationConfigurerByConfigurationProperties(authenticationProperties); + + authenticationConfigurer.ifPresentOrElse( + (configurer -> configurer.configureAuthentication(authenticationConfig, authenticationProperties)), + (() -> { + throw new RuntimeException( + "Authentication for camel-platform-http-main is enabled but no complete authentication configuration is found."); + })); + } + + private Optional<MainAuthenticationConfigurer> findAuthenticationConfigurerByConfigurationProperties( + HttpServerAuthenticationConfigurationProperties authenticationConfigurationProperties) { + + MainAuthenticationConfigurer result = null; + for (String authenticationTypeName : HttpServerAuthenticationConfigurationProperties.SUPPORTED_AUTHENTICATION_TYPES) { + if (authenticationTypeIsEnabled(authenticationConfigurationProperties, authenticationTypeName)) { + try { + if (result != null) { + throw new RuntimeException( + "Cannot configure authentication for MainHttpServer as more than one authentication configuration is present"); + } + String configurerQualifiedName = MainAuthenticationConfigurer.class.getPackageName() + "." + + authenticationTypeName + "AuthenticationConfigurer"; + ClassResolver resolver = camelContext.getClassResolver(); + Injector injector = camelContext.getInjector(); + result = injector.newInstance( + resolver.resolveMandatoryClass(configurerQualifiedName, MainAuthenticationConfigurer.class)); + } catch (Exception e) { + throw new RuntimeException( + "Could not create MainAuthenticationConfigurer for authentication type " + authenticationTypeName, + e); + } + } + } + return Optional.ofNullable(result); + } + + private boolean authenticationTypeIsEnabled( + HttpServerAuthenticationConfigurationProperties authenticationProperties, String authenticationTypeName) { + try { + String authenticationTypeGetterMethodName = "get" + authenticationTypeName; + ConfigurationPropertiesWithMandatoryFields propertiesForAuthenticationType + = (ConfigurationPropertiesWithMandatoryFields) ObjectHelper + .invokeMethodSafe(authenticationTypeGetterMethodName, authenticationProperties); + return propertiesForAuthenticationType.areMandatoryFieldsFilled(); + } catch (NoSuchMethodException noSuchMethodException) { + throw new RuntimeException( + "Not found authentication configuration of type " + authenticationTypeName, noSuchMethodException); + } catch (InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } } diff --git a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/authentication/BasicAuthenticationConfigurer.java b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/authentication/BasicAuthenticationConfigurer.java new file mode 100644 index 00000000000..a5f23826792 --- /dev/null +++ b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/authentication/BasicAuthenticationConfigurer.java @@ -0,0 +1,46 @@ +/* + * 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.platform.http.main.authentication; + +import io.vertx.ext.auth.properties.PropertyFileAuthentication; +import io.vertx.ext.web.handler.BasicAuthHandler; +import org.apache.camel.component.platform.http.vertx.auth.AuthenticationConfig; +import org.apache.camel.component.platform.http.vertx.auth.AuthenticationConfig.AuthenticationConfigEntry; +import org.apache.camel.main.HttpServerAuthenticationConfigurationProperties; +import org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties; + +import static org.apache.camel.util.ObjectHelper.isEmpty; + +public class BasicAuthenticationConfigurer implements MainAuthenticationConfigurer { + @Override + public void configureAuthentication( + AuthenticationConfig authenticationConfig, + HttpServerAuthenticationConfigurationProperties authenticationProperties) { + HttpServerBasicAuthenticationConfigurationProperties properties = authenticationProperties.getBasic(); + String authPropertiesFileName = properties.getAuthenticationPropertiesFile(); + String path = isEmpty(authenticationProperties.getPath()) ? authenticationProperties.getPath() : "/*"; + + AuthenticationConfigEntry entry = new AuthenticationConfigEntry(); + entry.setPath(path); + entry.setAuthenticationHandlerFactory(BasicAuthHandler::create); + entry.setAuthenticationProviderFactory( + vertx -> PropertyFileAuthentication.create(vertx, authPropertiesFileName)); + + authenticationConfig.getEntries().add(entry); + authenticationConfig.setEnabled(true); + } +} diff --git a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/authentication/JWTAuthenticationConfigurer.java b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/authentication/JWTAuthenticationConfigurer.java new file mode 100644 index 00000000000..5de63a3cda9 --- /dev/null +++ b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/authentication/JWTAuthenticationConfigurer.java @@ -0,0 +1,62 @@ +/* + * 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.platform.http.main.authentication; + +import io.vertx.core.json.JsonObject; +import io.vertx.ext.auth.authentication.AuthenticationProvider; +import io.vertx.ext.auth.jwt.JWTAuth; +import io.vertx.ext.auth.jwt.JWTAuthOptions; +import io.vertx.ext.web.handler.AuthenticationHandler; +import io.vertx.ext.web.handler.JWTAuthHandler; +import org.apache.camel.component.platform.http.vertx.auth.AuthenticationConfig; +import org.apache.camel.component.platform.http.vertx.auth.AuthenticationConfig.AuthenticationConfigEntry; +import org.apache.camel.component.platform.http.vertx.auth.AuthenticationConfig.AuthenticationHandlerFactory; +import org.apache.camel.main.HttpServerAuthenticationConfigurationProperties; +import org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties; + +import static org.apache.camel.util.ObjectHelper.isEmpty; + +public class JWTAuthenticationConfigurer implements MainAuthenticationConfigurer { + @Override + public void configureAuthentication( + AuthenticationConfig authenticationConfig, + HttpServerAuthenticationConfigurationProperties authenticationProperties) { + HttpServerJWTAuthenticationConfigurationProperties properties = authenticationProperties.getJWT(); + String path = isEmpty(authenticationProperties.getPath()) ? authenticationProperties.getPath() : "/*"; + + AuthenticationConfigEntry entry = new AuthenticationConfigEntry(); + entry.setPath(path); + entry.setAuthenticationHandlerFactory(new AuthenticationHandlerFactory() { + @Override + public <T extends AuthenticationProvider> AuthenticationHandler createAuthenticationHandler( + T authenticationProvider) { + JWTAuth authProvider = (JWTAuth) authenticationProvider; + return JWTAuthHandler.create(authProvider); + } + }); + entry.setAuthenticationProviderFactory(vertx -> JWTAuth.create( + vertx, + new JWTAuthOptions( + new JsonObject().put("keyStore", new JsonObject() + .put("type", properties.getKeystoreType()) + .put("path", properties.getKeystorePath()) + .put("password", properties.getKeystorePassword()))))); + + authenticationConfig.getEntries().add(entry); + authenticationConfig.setEnabled(true); + } +} diff --git a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/authentication/MainAuthenticationConfigurer.java b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/authentication/MainAuthenticationConfigurer.java new file mode 100644 index 00000000000..29678fd3f7e --- /dev/null +++ b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/authentication/MainAuthenticationConfigurer.java @@ -0,0 +1,26 @@ +/* + * 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.platform.http.main.authentication; + +import org.apache.camel.component.platform.http.vertx.auth.AuthenticationConfig; +import org.apache.camel.main.HttpServerAuthenticationConfigurationProperties; + +public interface MainAuthenticationConfigurer { + void configureAuthentication( + AuthenticationConfig authenticationConfig, + HttpServerAuthenticationConfigurationProperties authenticationProperties); +} diff --git a/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/AuthenticationConfigurationMainHttpServerTest.java b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/AuthenticationConfigurationMainHttpServerTest.java new file mode 100644 index 00000000000..bc35684cc0f --- /dev/null +++ b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/AuthenticationConfigurationMainHttpServerTest.java @@ -0,0 +1,47 @@ +/* + * 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.platform.http.main.authentication; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.main.Main; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class AuthenticationConfigurationMainHttpServerTest { + + @Test + public void testIncompleteAuthenticationConfiguration() { + Main main = new Main(); + main.setPropertyPlaceholderLocations("incomplete-auth.properties"); + main.configure().addRoutesBuilder(new PlatformHttpRouteBuilder()); + main.enableTrace(); + + assertThrows(RuntimeException.class, main::start); + + main.stop(); + } + + private static class PlatformHttpRouteBuilder extends RouteBuilder { + @Override + public void configure() throws Exception { + from("platform-http:/main-http-test") + .log("Received request with headers: ${headers}\nWith body: ${body}") + .setBody(simple("main-http-auth-basic-test-response")); + } + } +} diff --git a/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/BasicAuthenticationMainHttpServerTest.java b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/BasicAuthenticationMainHttpServerTest.java new file mode 100644 index 00000000000..c30b9c1ade6 --- /dev/null +++ b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/BasicAuthenticationMainHttpServerTest.java @@ -0,0 +1,78 @@ +/* + * 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.platform.http.main.authentication; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.main.Main; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class BasicAuthenticationMainHttpServerTest { + + private static Main main; + + @BeforeAll + static void init() { + main = new Main(); + main.setPropertyPlaceholderLocations("basic-auth.properties"); + main.configure().addRoutesBuilder(new BasicAuthenticationMainHttpServerTest.PlatformHttpRouteBuilder()); + main.enableTrace(); + main.start(); + } + + @AfterAll + static void tearDown() { + main.stop(); + } + + @Test + public void testBasicAuthWithAuthenticationPropertiesFile() { + CamelContext camelContext = main.getCamelContext(); + assertNotNull(camelContext); + + given() + .when() + .get("/main-http-test") + .then() + .statusCode(401) + .body(equalTo("Unauthorized")); + + given() + .auth().basic("camel", "propertiesPass") + .when() + .get("/main-http-test") + .then() + .statusCode(200) + .body(equalTo("main-http-auth-basic-test-response")); + } + + private static class PlatformHttpRouteBuilder extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("platform-http:/main-http-test") + .log("Received request with headers: ${headers}\nWith body: ${body}") + .setBody(simple("main-http-auth-basic-test-response")); + } + } +} diff --git a/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/JWTAuthenticationMainHttpServerTest.java b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/JWTAuthenticationMainHttpServerTest.java new file mode 100644 index 00000000000..afa6347d496 --- /dev/null +++ b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/JWTAuthenticationMainHttpServerTest.java @@ -0,0 +1,102 @@ +/* + * 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.platform.http.main.authentication; + +import io.vertx.core.Vertx; +import io.vertx.core.json.JsonObject; +import io.vertx.ext.auth.JWTOptions; +import io.vertx.ext.auth.jwt.JWTAuth; +import io.vertx.ext.auth.jwt.JWTAuthOptions; +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.main.Main; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class JWTAuthenticationMainHttpServerTest { + + private static Main main; + + private static JWTAuth jwtAuth; + + @BeforeAll + static void init() { + main = new Main(); + main.setPropertyPlaceholderLocations("jwt-auth.properties"); + main.configure().addRoutesBuilder(new PlatformHttpRouteBuilder()); + main.enableTrace(); + main.start(); + + jwtAuth = JWTAuth.create(Vertx.vertx(), new JWTAuthOptions( + new JsonObject().put("keyStore", new JsonObject() + .put("type", "jks") + .put("path", "test-camel-main-auth-jwt.jks") + .put("password", "changeme")))); + } + + @AfterAll + static void tearDown() { + main.stop(); + } + + @Test + void testJWTAuth() { + String validToken = jwtAuth.generateToken(new JsonObject().put("admin", "camel"), new JWTOptions()); + String invalidToken = validToken.substring(0, (validToken.length() - 2)); + + CamelContext camelContext = main.getCamelContext(); + assertNotNull(camelContext); + + given() + .when() + .get("/main-http-test") + .then() + .statusCode(401) + .body(equalTo("Unauthorized")); + + given() + .header("Authorization", "Bearer " + validToken) + .when() + .get("/main-http-test") + .then() + .statusCode(200) + .body(equalTo("main-http-auth-jwt-test-response")); + + given() + .header("Authorization", "Bearer " + invalidToken) + .when() + .get("/main-http-test") + .then() + .statusCode(401) + .body(equalTo("Unauthorized")); + } + + private static class PlatformHttpRouteBuilder extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("platform-http:/main-http-test") + .log("Received request with headers: ${headers}\nWith body: ${body}") + .setBody(simple("main-http-auth-jwt-test-response")); + } + } +} diff --git a/components/camel-platform-http-main/src/test/resources/basic-auth.properties b/components/camel-platform-http-main/src/test/resources/basic-auth.properties new file mode 100644 index 00000000000..7d42ec63f47 --- /dev/null +++ b/components/camel-platform-http-main/src/test/resources/basic-auth.properties @@ -0,0 +1,21 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +camel.server.enabled=true + +camel.server.authentication.enabled=true +camel.server.authentication.path=/* +camel.server.authentication.basic.authenticationPropertiesFile=camel-platform-http-vertx-auth.properties diff --git a/components/camel-platform-http-main/src/test/resources/camel-platform-http-vertx-auth.properties b/components/camel-platform-http-main/src/test/resources/camel-platform-http-vertx-auth.properties new file mode 100644 index 00000000000..d8490f76ce9 --- /dev/null +++ b/components/camel-platform-http-main/src/test/resources/camel-platform-http-vertx-auth.properties @@ -0,0 +1,19 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +user.camel=propertiesPass,admin +role.admin=create,read,update,delete diff --git a/components/camel-platform-http-main/src/test/resources/incomplete-auth.properties b/components/camel-platform-http-main/src/test/resources/incomplete-auth.properties new file mode 100644 index 00000000000..6c56e1638c5 --- /dev/null +++ b/components/camel-platform-http-main/src/test/resources/incomplete-auth.properties @@ -0,0 +1,23 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +camel.server.enabled=true + +camel.server.authentication.enabled=true +camel.server.authentication.path=/* +camel.server.authentication.jwt.keystoreType=jks + +camel.server.authentication.jwt.keystorePassword=changeme diff --git a/components/camel-platform-http-main/src/test/resources/jwt-auth.properties b/components/camel-platform-http-main/src/test/resources/jwt-auth.properties new file mode 100644 index 00000000000..8b0a3ccda18 --- /dev/null +++ b/components/camel-platform-http-main/src/test/resources/jwt-auth.properties @@ -0,0 +1,23 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +camel.server.enabled=true + +camel.server.authentication.enabled=true +camel.server.authentication.path=/* +camel.server.authentication.jwt.keystoreType=jks +camel.server.authentication.jwt.keystorePath=test-camel-main-auth-jwt.jks +camel.server.authentication.jwt.keystorePassword=changeme diff --git a/components/camel-platform-http-main/src/test/resources/test-camel-main-auth-jwt.jks b/components/camel-platform-http-main/src/test/resources/test-camel-main-auth-jwt.jks new file mode 100644 index 00000000000..45a01afeea7 Binary files /dev/null and b/components/camel-platform-http-main/src/test/resources/test-camel-main-auth-jwt.jks differ diff --git a/components/camel-platform-http-vertx/pom.xml b/components/camel-platform-http-vertx/pom.xml index 972a7331b4a..ac4b6d2f967 100644 --- a/components/camel-platform-http-vertx/pom.xml +++ b/components/camel-platform-http-vertx/pom.xml @@ -55,11 +55,6 @@ <artifactId>vertx-web</artifactId> <version>${vertx-version}</version> </dependency> - <dependency> - <groupId>io.vertx</groupId> - <artifactId>vertx-auth-properties</artifactId> - <version>${vertx-version}</version> - </dependency> <!-- test dependencies --> <!-- jakarta mime types for upload support --> @@ -112,6 +107,18 @@ <version>${wiremock-version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>io.vertx</groupId> + <artifactId>vertx-auth-properties</artifactId> + <version>${vertx-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.vertx</groupId> + <artifactId>vertx-auth-jwt</artifactId> + <version>${vertx-version}</version> + <scope>test</scope> + </dependency> <dependency> <groupId>org.awaitility</groupId> <artifactId>awaitility</artifactId> diff --git a/components/camel-platform-http-vertx/src/main/docs/platform-http-vertx.adoc b/components/camel-platform-http-vertx/src/main/docs/platform-http-vertx.adoc index 6b03844f1f4..aad199ecf11 100644 --- a/components/camel-platform-http-vertx/src/main/docs/platform-http-vertx.adoc +++ b/components/camel-platform-http-vertx/src/main/docs/platform-http-vertx.adoc @@ -112,10 +112,11 @@ from("platform-http:/upload?httpMethodRestrict=POST&useStreaming=true") Http authentication is disabled by default. In can be enabled by calling `setEnabled(true)` of `AuthenticationConfig`. Default http authentication takes http-basic credentials and compares them with those provided in camel-platform-http-vertx-auth.properties file. -To be more specific, default http authentication uses https://vertx.io/docs/apidocs/io/vertx/ext/web/handler/BasicAuthHandler.html[BasicAuthHandler] and https://vertx.io/docs/vertx-auth-properties/java/[PropertyFileAuthentication]. +To be more specific, default http authentication -To set up custom authentication, you need to create custom `AuthenticationConfigEntries`, as shown in the example below. -Mind that in Vert.x order of adding `AuthenticationHandlers` matters, so `AuthenticationConfigEntries` with a more specific url path is applied first. +To set up authentication, you need to create `AuthenticationConfigEntries`, as shown in the example below. +This example uses Vert.x https://vertx.io/docs/apidocs/io/vertx/ext/web/handler/BasicAuthHandler.html[BasicAuthHandler] and https://vertx.io/docs/vertx-auth-properties/java/[PropertyFileAuthentication] to configure Basic http authentication with users info stored in `myPropFile.properties` file. +Mind that in Vert.x order of adding `AuthenticationHandlers` matters, so `AuthenticationConfigEntries` with a more specific url path are applied first. [source,java] ---- diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/auth/AuthenticationConfig.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/auth/AuthenticationConfig.java index c1e6d50849b..b2c36bbbcb6 100644 --- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/auth/AuthenticationConfig.java +++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/auth/AuthenticationConfig.java @@ -22,24 +22,16 @@ import java.util.List; import io.vertx.core.Handler; import io.vertx.core.Vertx; import io.vertx.ext.auth.authentication.AuthenticationProvider; -import io.vertx.ext.auth.properties.PropertyFileAuthentication; import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.handler.AuthenticationHandler; -import io.vertx.ext.web.handler.BasicAuthHandler; public class AuthenticationConfig { - public static final String DEFAULT_VERTX_PROPERTIES_FILE = "camel-platform-http-vertx-auth.properties"; + private boolean authenticationEnabled; private final List<AuthenticationConfigEntry> entries; public AuthenticationConfig() { - AuthenticationConfigEntry defaultAuthConfig = new AuthenticationConfigEntry(); - defaultAuthConfig.setPath("/*"); - defaultAuthConfig.setAuthenticationProviderFactory( - vertx -> PropertyFileAuthentication.create(vertx, DEFAULT_VERTX_PROPERTIES_FILE)); - defaultAuthConfig.setAuthenticationHandlerFactory(BasicAuthHandler::create); this.entries = new ArrayList<>(); - this.entries.add(defaultAuthConfig); } public AuthenticationConfig(List<AuthenticationConfigEntry> authenticationConfigEntries) { @@ -63,7 +55,7 @@ public class AuthenticationConfig { } public interface AuthenticationHandlerFactory { - AuthenticationHandler createAuthenticationHandler(AuthenticationProvider authenticationProvider); + <T extends AuthenticationProvider> AuthenticationHandler createAuthenticationHandler(T authenticationProvider); } public static class AuthenticationConfigEntry { diff --git a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpAuthenticationTest.java b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpAuthenticationTest.java index 0eb18443aa2..fa63c984af9 100644 --- a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpAuthenticationTest.java +++ b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpAuthenticationTest.java @@ -21,6 +21,7 @@ import io.vertx.core.AsyncResult; import io.vertx.ext.auth.User; import io.vertx.ext.auth.authentication.AuthenticationProvider; import io.vertx.ext.auth.impl.UserImpl; +import io.vertx.ext.auth.properties.PropertyFileAuthentication; import io.vertx.ext.web.handler.BasicAuthHandler; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; @@ -66,9 +67,15 @@ public class VertxPlatformHttpAuthenticationTest { } @Test - public void testDefaultAuthenticationConfig() throws Exception { + public void testBasicAuthenticationConfig() throws Exception { CamelContext context = createCamelContext(authenticationConfig -> { authenticationConfig.setEnabled(true); + AuthenticationConfigEntry entry = new AuthenticationConfigEntry(); + entry.setAuthenticationProviderFactory( + vertx -> PropertyFileAuthentication.create(vertx, "camel-platform-http-vertx-auth.properties")); + entry.setAuthenticationHandlerFactory(BasicAuthHandler::create); + entry.setPath("/*"); + authenticationConfig.getEntries().add(entry); }); context.addRoutes(new RouteBuilder() { @@ -106,7 +113,12 @@ public class VertxPlatformHttpAuthenticationTest { public void testAuthenticateSpecificPathOnly() throws Exception { CamelContext context = createCamelContext(authenticationConfig -> { authenticationConfig.setEnabled(true); - authenticationConfig.getEntries().get(0).setPath("/specific/path"); + AuthenticationConfigEntry entry = new AuthenticationConfigEntry(); + entry.setAuthenticationProviderFactory( + vertx -> PropertyFileAuthentication.create(vertx, "camel-platform-http-vertx-auth.properties")); + entry.setAuthenticationHandlerFactory(BasicAuthHandler::create); + entry.setPath("/specific/path"); + authenticationConfig.getEntries().add(entry); }); context.addRoutes(new RouteBuilder() { @@ -168,30 +180,12 @@ public class VertxPlatformHttpAuthenticationTest { public void configure() { from("platform-http:/custom/provider") .setBody().constant("customProvider"); - - from("platform-http:/defaultAuth") - .setBody().constant("defaultAuth"); } }); try { context.start(); - given() - .when() - .get("/defaultAuth") - .then() - .statusCode(401) - .body(equalTo("Unauthorized")); - - given() - .auth().basic("camel", "propertiesPass") - .when() - .get("/defaultAuth") - .then() - .statusCode(200) - .body(equalTo("defaultAuth")); - given() .when() .get("/custom/provider") @@ -230,30 +224,12 @@ public class VertxPlatformHttpAuthenticationTest { public void configure() { from("platform-http:/customProvider") .setBody().constant("customProvider"); - - from("platform-http:/defaultAuth") - .setBody().constant("defaultAuth"); } }); try { context.start(); - given() - .when() - .get("/defaultAuth") - .then() - .statusCode(401) - .body(equalTo("Unauthorized")); - - given() - .auth().basic("camel", "propertiesPass") - .when() - .get("/defaultAuth") - .then() - .statusCode(200) - .body(equalTo("defaultAuth")); - given() .when() .get("/customProvider") diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerAuthenticationConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerAuthenticationConfigurationPropertiesConfigurer.java new file mode 100644 index 00000000000..d741492ac23 --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerAuthenticationConfigurationPropertiesConfigurer.java @@ -0,0 +1,60 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.main; + +import javax.annotation.processing.Generated; +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.ExtendedPropertyConfigurerGetter; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.spi.ConfigurerStrategy; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.util.CaseInsensitiveMap; +import org.apache.camel.main.HttpServerAuthenticationConfigurationProperties; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@Generated("org.apache.camel.maven.packaging.GenerateConfigurerMojo") +@SuppressWarnings("unchecked") +public class HttpServerAuthenticationConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.main.HttpServerAuthenticationConfigurationProperties target = (org.apache.camel.main.HttpServerAuthenticationConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "basic": target.setBasic(property(camelContext, org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties.class, value)); return true; + case "enabled": target.setEnabled(property(camelContext, boolean.class, value)); return true; + case "jwt": + case "jWT": target.setJWT(property(camelContext, org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties.class, value)); return true; + case "path": target.setPath(property(camelContext, java.lang.String.class, value)); return true; + default: return false; + } + } + + @Override + public Class<?> getOptionType(String name, boolean ignoreCase) { + switch (ignoreCase ? name.toLowerCase() : name) { + case "basic": return org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties.class; + case "enabled": return boolean.class; + case "jwt": + case "jWT": return org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties.class; + case "path": return java.lang.String.class; + default: return null; + } + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + org.apache.camel.main.HttpServerAuthenticationConfigurationProperties target = (org.apache.camel.main.HttpServerAuthenticationConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "basic": return target.getBasic(); + case "enabled": return target.isEnabled(); + case "jwt": + case "jWT": return target.getJWT(); + case "path": return target.getPath(); + default: return null; + } + } +} + diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerBasicAuthenticationConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerBasicAuthenticationConfigurationPropertiesConfigurer.java new file mode 100644 index 00000000000..28590ac6f6d --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerBasicAuthenticationConfigurationPropertiesConfigurer.java @@ -0,0 +1,51 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.main; + +import javax.annotation.processing.Generated; +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.ExtendedPropertyConfigurerGetter; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.spi.ConfigurerStrategy; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.util.CaseInsensitiveMap; +import org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@Generated("org.apache.camel.maven.packaging.GenerateConfigurerMojo") +@SuppressWarnings("unchecked") +public class HttpServerBasicAuthenticationConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties target = (org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "authenticationpropertiesfile": + case "authenticationPropertiesFile": target.setAuthenticationPropertiesFile(property(camelContext, java.lang.String.class, value)); return true; + default: return false; + } + } + + @Override + public Class<?> getOptionType(String name, boolean ignoreCase) { + switch (ignoreCase ? name.toLowerCase() : name) { + case "authenticationpropertiesfile": + case "authenticationPropertiesFile": return java.lang.String.class; + default: return null; + } + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties target = (org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "authenticationpropertiesfile": + case "authenticationPropertiesFile": return target.getAuthenticationPropertiesFile(); + default: return null; + } + } +} + diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerBasicAuthenticationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerBasicAuthenticationPropertiesConfigurer.java new file mode 100644 index 00000000000..8f7d54e5c3a --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerBasicAuthenticationPropertiesConfigurer.java @@ -0,0 +1,32 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.main; + +import javax.annotation.processing.Generated; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.spi.GeneratedPropertyConfigurer; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@Generated("org.apache.camel.maven.packaging.GenerateConfigurerMojo") +@SuppressWarnings("unchecked") +public class HttpServerBasicAuthenticationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + return false; + } + + @Override + public Class<?> getOptionType(String name, boolean ignoreCase) { + return null; + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + return null; + } +} + diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java index 2408e6c3aff..5d4397a141d 100644 --- a/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java +++ b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java @@ -23,6 +23,7 @@ public class HttpServerConfigurationPropertiesConfigurer extends org.apache.came public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { org.apache.camel.main.HttpServerConfigurationProperties target = (org.apache.camel.main.HttpServerConfigurationProperties) obj; switch (ignoreCase ? name.toLowerCase() : name) { + case "authentication": target.setAuthentication(property(camelContext, org.apache.camel.main.HttpServerAuthenticationConfigurationProperties.class, value)); return true; case "devconsoleenabled": case "devConsoleEnabled": target.setDevConsoleEnabled(property(camelContext, boolean.class, value)); return true; case "enabled": target.setEnabled(property(camelContext, boolean.class, value)); return true; @@ -52,6 +53,7 @@ public class HttpServerConfigurationPropertiesConfigurer extends org.apache.came @Override public Class<?> getOptionType(String name, boolean ignoreCase) { switch (ignoreCase ? name.toLowerCase() : name) { + case "authentication": return org.apache.camel.main.HttpServerAuthenticationConfigurationProperties.class; case "devconsoleenabled": case "devConsoleEnabled": return boolean.class; case "enabled": return boolean.class; @@ -82,6 +84,7 @@ public class HttpServerConfigurationPropertiesConfigurer extends org.apache.came public Object getOptionValue(Object obj, String name, boolean ignoreCase) { org.apache.camel.main.HttpServerConfigurationProperties target = (org.apache.camel.main.HttpServerConfigurationProperties) obj; switch (ignoreCase ? name.toLowerCase() : name) { + case "authentication": return target.getAuthentication(); case "devconsoleenabled": case "devConsoleEnabled": return target.isDevConsoleEnabled(); case "enabled": return target.isEnabled(); diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerJWTAuthenticationConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerJWTAuthenticationConfigurationPropertiesConfigurer.java new file mode 100644 index 00000000000..3d23f665a08 --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerJWTAuthenticationConfigurationPropertiesConfigurer.java @@ -0,0 +1,63 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.main; + +import javax.annotation.processing.Generated; +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.ExtendedPropertyConfigurerGetter; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.spi.ConfigurerStrategy; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.util.CaseInsensitiveMap; +import org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@Generated("org.apache.camel.maven.packaging.GenerateConfigurerMojo") +@SuppressWarnings("unchecked") +public class HttpServerJWTAuthenticationConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties target = (org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "keystorepassword": + case "keystorePassword": target.setKeystorePassword(property(camelContext, java.lang.String.class, value)); return true; + case "keystorepath": + case "keystorePath": target.setKeystorePath(property(camelContext, java.lang.String.class, value)); return true; + case "keystoretype": + case "keystoreType": target.setKeystoreType(property(camelContext, java.lang.String.class, value)); return true; + default: return false; + } + } + + @Override + public Class<?> getOptionType(String name, boolean ignoreCase) { + switch (ignoreCase ? name.toLowerCase() : name) { + case "keystorepassword": + case "keystorePassword": return java.lang.String.class; + case "keystorepath": + case "keystorePath": return java.lang.String.class; + case "keystoretype": + case "keystoreType": return java.lang.String.class; + default: return null; + } + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties target = (org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "keystorepassword": + case "keystorePassword": return target.getKeystorePassword(); + case "keystorepath": + case "keystorePath": return target.getKeystorePath(); + case "keystoretype": + case "keystoreType": return target.getKeystoreType(); + default: return null; + } + } +} + diff --git a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json index a9ec26761cf..bca1d8b9d0e 100644 --- a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json +++ b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json @@ -256,14 +256,22 @@ { "name": "camel.routecontroller.threadPoolSize", "description": "The number of threads used by the route controller scheduled thread pool that are used for restarting routes. The pool uses 1 thread by default, but you can increase this to allow the controller to concurrently attempt to restart multiple routes in case more than one route has problems starting.", "sourceType": "org.apache.camel.main.RouteControllerConfigurationProperties", "type": "integer", "javaType": "int", "defaul [...] { "name": "camel.routecontroller.unhealthyOnExhausted", "description": "Whether to mark the route as unhealthy (down) when all restarting attempts (backoff) have failed and the route is not successfully started and the route manager is giving up. If setting this to false will make health checks ignore this problem and allow to report the Camel application as UP.", "sourceType": "org.apache.camel.main.RouteControllerConfigurationProperties", "type": "boolean", "javaType": "boolean", " [...] { "name": "camel.routecontroller.unhealthyOnRestarting", "description": "Whether to mark the route as unhealthy (down) when the route failed to initially start, and is being controlled for restarting (backoff). If setting this to false will make health checks ignore this problem and allow to report the Camel application as UP.", "sourceType": "org.apache.camel.main.RouteControllerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true }, + { "name": "camel.server.authentication", "description": "To configure embedded HTTP server authentication (for standalone applications; not Spring Boot or Quarkus)", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "object", "javaType": "org.apache.camel.main.HttpServerAuthenticationConfigurationProperties" }, + { "name": "camel.server.authenticationPropertiesFile", "description": "Name of the file that contains authentication info for Vert.x property file auth provider.", "sourceType": "org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, + { "name": "camel.server.basic", "description": "To configure Basic HTTP authentication for embedded server.", "sourceType": "org.apache.camel.main.HttpServerAuthenticationConfigurationProperties", "type": "object", "javaType": "org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties" }, { "name": "camel.server.devConsoleEnabled", "description": "Whether to enable developer console (not intended for production use). Dev console must also be enabled on CamelContext. For example by setting camel.context.dev-console=true in application.properties, or via code camelContext.setDevConsole(true); If enabled then you can access a basic developer console on context-path: \/q\/dev.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "j [...] + { "name": "camel.server.enabled", "description": "Whether to enable HTTP authentication for embedded server.", "sourceType": "org.apache.camel.main.HttpServerAuthenticationConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.enabled", "description": "Whether embedded HTTP server is enabled. By default, the server is not enabled.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.healthCheckEnabled", "description": "Whether to enable health-check console. If enabled then you can access health-check status on context-path: \/q\/health", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.host", "description": "Hostname to use for binding embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "0.0.0.0" }, { "name": "camel.server.infoEnabled", "description": "Whether to enable info console. If enabled then you can see some basic Camel information at \/q\/info", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.jolokiaEnabled", "description": "Whether to enable jolokia. If enabled then you can access jolokia api on context-path: \/q\/jolokia", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, + { "name": "camel.server.keystorePassword", "description": "Password from the keystore used for JWT tokens validation.", "sourceType": "org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, + { "name": "camel.server.keystorePath", "description": "Path to the keystore file used for JWT tokens validation.", "sourceType": "org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, + { "name": "camel.server.keystoreType", "description": "Type of the keystore used for JWT tokens validation (jks, pkcs12, etc.).", "sourceType": "org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.server.maxBodySize", "description": "Maximum HTTP body size the embedded HTTP server can accept.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", "javaType": "java.lang.Long" }, { "name": "camel.server.metricsEnabled", "description": "Whether to enable metrics. If enabled then you can access metrics on context-path: \/q\/metrics", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, + { "name": "camel.server.path", "description": "Set HTTP url path of embedded server that is protected by authentication configuration.", "sourceType": "org.apache.camel.main.HttpServerAuthenticationConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.server.path", "description": "Context-path to use for embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "\/" }, { "name": "camel.server.port", "description": "Port to use for binding embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 8080 }, { "name": "camel.server.uploadEnabled", "description": "Whether to enable file upload via HTTP (not intended for production use). This functionality is for development to be able to reload Camel routes and code with source changes (if reload is enabled). If enabled then you can upload\/delete files via HTTP PUT\/DELETE on context-path: \/q\/upload\/{name}. You must also configure the uploadSourceDir option.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "t [...] diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerAuthenticationConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerAuthenticationConfigurationProperties new file mode 100644 index 00000000000..45be2f173ef --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerAuthenticationConfigurationProperties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.main.HttpServerAuthenticationConfigurationPropertiesConfigurer diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties new file mode 100644 index 00000000000..8c4264fffa6 --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerBasicAuthenticationConfigurationProperties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.main.HttpServerBasicAuthenticationConfigurationPropertiesConfigurer diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerBasicAuthenticationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerBasicAuthenticationProperties new file mode 100644 index 00000000000..c2658bf00f4 --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerBasicAuthenticationProperties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.main.HttpServerBasicAuthenticationPropertiesConfigurer diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties new file mode 100644 index 00000000000..bfc14a5405d --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.HttpServerJWTAuthenticationConfigurationProperties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.main.HttpServerJWTAuthenticationConfigurationPropertiesConfigurer diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc index 7eaa1c65a3a..ce260ced54b 100644 --- a/core/camel-main/src/main/docs/main.adoc +++ b/core/camel-main/src/main/docs/main.adoc @@ -169,19 +169,27 @@ The camel.routecontroller supports 12 options, which are listed below. === Camel Embedded HTTP Server (only for standalone; not Spring Boot or Quarkus) configurations -The camel.server supports 13 options, which are listed below. +The camel.server supports 21 options, which are listed below. [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type +| *camel.server.authentication* | To configure embedded HTTP server authentication (for standalone applications; not Spring Boot or Quarkus) | | HttpServerAuthenticationConfigurationProperties +| *camel.server.authentication{zwsp}PropertiesFile* | Name of the file that contains authentication info for Vert.x property file auth provider. | | String +| *camel.server.basic* | To configure Basic HTTP authentication for embedded server. | | HttpServerBasicAuthenticationConfigurationProperties | *camel.server.devConsoleEnabled* | Whether to enable developer console (not intended for production use). Dev console must also be enabled on CamelContext. For example by setting camel.context.dev-console=true in application.properties, or via code camelContext.setDevConsole(true); If enabled then you can access a basic developer console on context-path: /q/dev. | false | boolean +| *camel.server.enabled* | Whether to enable HTTP authentication for embedded server. | false | boolean | *camel.server.enabled* | Whether embedded HTTP server is enabled. By default, the server is not enabled. | false | boolean | *camel.server.healthCheck{zwsp}Enabled* | Whether to enable health-check console. If enabled then you can access health-check status on context-path: /q/health | false | boolean | *camel.server.host* | Hostname to use for binding embedded HTTP server | 0.0.0.0 | String | *camel.server.infoEnabled* | Whether to enable info console. If enabled then you can see some basic Camel information at /q/info | false | boolean | *camel.server.jolokiaEnabled* | Whether to enable jolokia. If enabled then you can access jolokia api on context-path: /q/jolokia | false | boolean +| *camel.server.keystorePassword* | Password from the keystore used for JWT tokens validation. | | String +| *camel.server.keystorePath* | Path to the keystore file used for JWT tokens validation. | | String +| *camel.server.keystoreType* | Type of the keystore used for JWT tokens validation (jks, pkcs12, etc.). | | String | *camel.server.maxBodySize* | Maximum HTTP body size the embedded HTTP server can accept. | | Long | *camel.server.metricsEnabled* | Whether to enable metrics. If enabled then you can access metrics on context-path: /q/metrics | false | boolean +| *camel.server.path* | Set HTTP url path of embedded server that is protected by authentication configuration. | | String | *camel.server.path* | Context-path to use for embedded HTTP server | / | String | *camel.server.port* | Port to use for binding embedded HTTP server | 8080 | int | *camel.server.uploadEnabled* | Whether to enable file upload via HTTP (not intended for production use). This functionality is for development to be able to reload Camel routes and code with source changes (if reload is enabled). If enabled then you can upload/delete files via HTTP PUT/DELETE on context-path: /q/upload/\{name}. You must also configure the uploadSourceDir option. | false | boolean diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java index a644305701a..c8505586f73 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java @@ -36,6 +36,7 @@ import java.util.stream.Collectors; import org.apache.camel.CamelConfiguration; import org.apache.camel.CamelContext; +import org.apache.camel.CamelContextAware; import org.apache.camel.Component; import org.apache.camel.Configuration; import org.apache.camel.ExtendedCamelContext; @@ -2283,7 +2284,7 @@ public abstract class BaseMainSupport extends BaseService { .orElseThrow(() -> new IllegalArgumentException( "Cannot find MainHttpServerFactory on classpath. Add camel-platform-http-main to classpath.")); } - return answer; + return CamelContextAware.trySetCamelContext(answer, camelContext); } private static final class PropertyPlaceholderListener implements PropertiesLookupListener { diff --git a/core/camel-main/src/main/java/org/apache/camel/main/ConfigurationPropertiesWithMandatoryFields.java b/core/camel-main/src/main/java/org/apache/camel/main/ConfigurationPropertiesWithMandatoryFields.java new file mode 100644 index 00000000000..43dcd825603 --- /dev/null +++ b/core/camel-main/src/main/java/org/apache/camel/main/ConfigurationPropertiesWithMandatoryFields.java @@ -0,0 +1,32 @@ +/* + * 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.main; + +/** + * This interface marks ConfigurationProperties classes that have one or more mandatory fields, i.e. fields without + * which configuration does not make sense. + */ +public interface ConfigurationPropertiesWithMandatoryFields { + + /** + * Checks is this ConfigurationProperties has no mandatory fields absent. + * + * @return true if all mandatory fields are filled, false otherwise + */ + boolean areMandatoryFieldsFilled(); + +} diff --git a/core/camel-main/src/main/java/org/apache/camel/main/HttpServerAuthenticationConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerAuthenticationConfigurationProperties.java new file mode 100644 index 00000000000..4f888f9aef4 --- /dev/null +++ b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerAuthenticationConfigurationProperties.java @@ -0,0 +1,146 @@ +/* + * 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.main; + +import org.apache.camel.spi.BootstrapCloseable; +import org.apache.camel.spi.Configurer; +import org.apache.camel.spi.Metadata; + +/** + * Authentication configuration for embedded HTTP server for standalone Camel applications (not Spring Boot / Quarkus). + */ +@Configurer(bootstrap = true) +public class HttpServerAuthenticationConfigurationProperties implements BootstrapCloseable { + + public static final String[] SUPPORTED_AUTHENTICATION_TYPES = { "Basic", "JWT" }; + + private HttpServerConfigurationProperties parent; + + @Metadata + private boolean enabled; + + private String path; + + private HttpServerBasicAuthenticationConfigurationProperties basic; + + private HttpServerJWTAuthenticationConfigurationProperties jwt; + + public HttpServerAuthenticationConfigurationProperties(HttpServerConfigurationProperties parent) { + basic = new HttpServerBasicAuthenticationConfigurationProperties(this); + jwt = new HttpServerJWTAuthenticationConfigurationProperties(this); + this.parent = parent; + } + + public HttpServerConfigurationProperties end() { + return parent; + } + + @Override + public void close() { + if (basic != null) { + basic.close(); + basic = null; + } + if (jwt != null) { + jwt.close(); + jwt = null; + } + parent = null; + } + + public boolean isEnabled() { + return enabled; + } + + /** + * Whether to enable HTTP authentication for embedded server. + */ + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + /** + * Whether to enable HTTP authentication for embedded server. + */ + public HttpServerAuthenticationConfigurationProperties withEnabled(boolean enabled) { + this.enabled = enabled; + return this; + } + + /** + * To configure Basic HTTP authentication for embedded server. + */ + public HttpServerBasicAuthenticationConfigurationProperties basic() { + if (basic == null) { + basic = new HttpServerBasicAuthenticationConfigurationProperties(this); + } + return basic; + } + + public HttpServerBasicAuthenticationConfigurationProperties getBasic() { + return basic; + } + + /** + * To configure Basic HTTP authentication for embedded server. + */ + public void setBasic( + HttpServerBasicAuthenticationConfigurationProperties basic) { + this.basic = basic; + } + + /** + * To configure JWT HTTP authentication for embedded server. + */ + public HttpServerJWTAuthenticationConfigurationProperties jwt() { + if (jwt == null) { + jwt = new HttpServerJWTAuthenticationConfigurationProperties(this); + } + return jwt; + } + + public HttpServerJWTAuthenticationConfigurationProperties getJWT() { + return jwt; + } + + /** + * To configure JWT HTTP authentication for embedded server. + */ + public void setJWT( + HttpServerJWTAuthenticationConfigurationProperties jwt) { + this.jwt = jwt; + } + + public String getPath() { + return path; + } + + /** + * Set HTTP url path of embedded server that is protected by authentication configuration. + */ + public void setPath(String path) { + this.path = path; + } + + /** + * Set HTTP url path of embedded server that is protected by authentication configuration. + */ + public HttpServerAuthenticationConfigurationProperties withPath(String path) { + this.path = path; + return this; + } +} diff --git a/core/camel-main/src/main/java/org/apache/camel/main/HttpServerBasicAuthenticationConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerBasicAuthenticationConfigurationProperties.java new file mode 100644 index 00000000000..4f2d9967c8f --- /dev/null +++ b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerBasicAuthenticationConfigurationProperties.java @@ -0,0 +1,70 @@ +/* + * 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.main; + +import org.apache.camel.spi.BootstrapCloseable; +import org.apache.camel.spi.Configurer; + +import static org.apache.camel.util.ObjectHelper.isNotEmpty; + +/** + * Basic HTTP authentication for embedded server. + */ +@Configurer(bootstrap = true) +public class HttpServerBasicAuthenticationConfigurationProperties + implements ConfigurationPropertiesWithMandatoryFields, BootstrapCloseable { + + private String authenticationPropertiesFile; + + private HttpServerAuthenticationConfigurationProperties parent; + + public HttpServerBasicAuthenticationConfigurationProperties(HttpServerAuthenticationConfigurationProperties parent) { + this.parent = parent; + } + + public String getAuthenticationPropertiesFile() { + return authenticationPropertiesFile; + } + + /** + * Name of the file that contains authentication info for Vert.x <a + * href=https://vertx.io/docs/vertx-auth-properties/java/>property file auth provider</a>. + */ + public void setAuthenticationPropertiesFile(String authenticationPropertiesFile) { + this.authenticationPropertiesFile = authenticationPropertiesFile; + } + + /** + * Name of the file that contains authentication info for Vert.x <a + * href=https://vertx.io/docs/vertx-auth-properties/java/>property file auth provider</a>. + */ + public HttpServerBasicAuthenticationConfigurationProperties withAuthenticationPropertiesFile( + String authenticationPropertiesFile) { + this.authenticationPropertiesFile = authenticationPropertiesFile; + return this; + } + + @Override + public void close() { + parent = null; + } + + @Override + public boolean areMandatoryFieldsFilled() { + return isNotEmpty(authenticationPropertiesFile); + } +} diff --git a/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java index c9f2d63cc2c..f56ad8c5325 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java @@ -47,7 +47,10 @@ public class HttpServerConfigurationProperties implements BootstrapCloseable { private boolean uploadEnabled; private String uploadSourceDir; + private HttpServerAuthenticationConfigurationProperties authentication; + public HttpServerConfigurationProperties(MainConfigurationProperties parent) { + authentication = new HttpServerAuthenticationConfigurationProperties(this); this.parent = parent; } @@ -57,6 +60,10 @@ public class HttpServerConfigurationProperties implements BootstrapCloseable { @Override public void close() { + if (authentication != null) { + authentication.close(); + authentication = null; + } parent = null; } @@ -321,4 +328,37 @@ public class HttpServerConfigurationProperties implements BootstrapCloseable { return this; } + /** + * To configure embedded HTTP server authentication (for standalone applications; not Spring Boot or Quarkus) + */ + public HttpServerAuthenticationConfigurationProperties authentication() { + if (authentication == null) { + authentication = new HttpServerAuthenticationConfigurationProperties(this); + } + return authentication; + } + + /** + * To configure embedded HTTP server authentication (for standalone applications; not Spring Boot or Quarkus) + */ + public HttpServerAuthenticationConfigurationProperties getAuthentication() { + return authentication; + } + + /** + * To configure embedded HTTP server authentication (for standalone applications; not Spring Boot or Quarkus) + */ + public void setAuthentication( + HttpServerAuthenticationConfigurationProperties authentication) { + this.authentication = authentication; + } + + /** + * To configure embedded HTTP server authentication (for standalone applications; not Spring Boot or Quarkus) + */ + public HttpServerConfigurationProperties withAuthentication( + HttpServerAuthenticationConfigurationProperties authentication) { + this.authentication = authentication; + return this; + } } diff --git a/core/camel-main/src/main/java/org/apache/camel/main/HttpServerJWTAuthenticationConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerJWTAuthenticationConfigurationProperties.java new file mode 100644 index 00000000000..0ac37c6d473 --- /dev/null +++ b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerJWTAuthenticationConfigurationProperties.java @@ -0,0 +1,109 @@ +/* + * 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.main; + +import org.apache.camel.spi.BootstrapCloseable; +import org.apache.camel.spi.Configurer; + +import static org.apache.camel.util.ObjectHelper.isNotEmpty; + +/** + * JWT HTTP authentication for embedded server. + */ +@Configurer(bootstrap = true) +public class HttpServerJWTAuthenticationConfigurationProperties + implements ConfigurationPropertiesWithMandatoryFields, BootstrapCloseable { + + private String keystoreType; + + private String keystorePath; + + private String keystorePassword; + + private HttpServerAuthenticationConfigurationProperties parent; + + public HttpServerJWTAuthenticationConfigurationProperties(HttpServerAuthenticationConfigurationProperties parent) { + this.parent = parent; + } + + public String getKeystoreType() { + return keystoreType; + } + + /** + * Type of the keystore used for JWT tokens validation (jks, pkcs12, etc.). + */ + public void setKeystoreType(String keystoreType) { + this.keystoreType = keystoreType; + } + + /** + * Type of the keystore used for JWT tokens validation (jks, pkcs12, etc.). + */ + public HttpServerJWTAuthenticationConfigurationProperties withKeystoreType(String keystoreType) { + this.keystoreType = keystoreType; + return this; + } + + public String getKeystorePath() { + return keystorePath; + } + + /** + * Path to the keystore file used for JWT tokens validation. + */ + public void setKeystorePath(String keystorePath) { + this.keystorePath = keystorePath; + } + + /** + * Path to the keystore file used for JWT tokens validation. + */ + public HttpServerJWTAuthenticationConfigurationProperties withKeystorePath(String keystorePath) { + this.keystorePath = keystorePath; + return this; + } + + public String getKeystorePassword() { + return keystorePassword; + } + + /** + * Password from the keystore used for JWT tokens validation. + */ + public void setKeystorePassword(String keystorePassword) { + this.keystorePassword = keystorePassword; + } + + /** + * Password from the keystore used for JWT tokens validation. + */ + public HttpServerJWTAuthenticationConfigurationProperties withKeystorePassword(String keystorePassword) { + this.keystorePassword = keystorePassword; + return this; + } + + @Override + public void close() { + parent = null; + } + + @Override + public boolean areMandatoryFieldsFilled() { + return isNotEmpty(keystoreType) && isNotEmpty(keystorePath) && isNotEmpty(keystorePassword); + } +}