You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/01/31 09:18:31 UTC
(camel) branch main updated: CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth (#12943)
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 aaaed57fa10 CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth (#12943)
aaaed57fa10 is described below
commit aaaed57fa10d6811f36d3ea8c9beaca27475d434
Author: Ivan Kulaga <ku...@gmail.com>
AuthorDate: Wed Jan 31 15:18:25 2024 +0600
CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth (#12943)
* CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth
In vert.x order of adding AuthenticationHandler matters (see https://groups.google.com/g/vertx/c/6lSKBWzK2pE).
Handlers for routes farther in the url path should be added first, that's why we are sorting AuthenticationConfigEntries by path length.
* CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth
final list of AuthenticationConfigEntries is cleaner; fixed minor naming inconsistencies in test
* CAMEL-20237: camel-platform-http-main - Make it possible to configure http auth
added doc + naming inconsistency
---
components/camel-platform-http-vertx/pom.xml | 11 +-
.../src/main/docs/platform-http-vertx.adoc | 43 +++
.../http/vertx/VertxPlatformHttpServer.java | 28 ++
.../VertxPlatformHttpServerConfiguration.java | 10 +
.../http/vertx/auth/AuthenticationConfig.java | 104 +++++++
.../vertx/VertxPlatformHttpAuthenticationTest.java | 336 +++++++++++++++++++++
.../camel-platform-http-vertx-auth.properties | 19 ++
7 files changed, 545 insertions(+), 6 deletions(-)
diff --git a/components/camel-platform-http-vertx/pom.xml b/components/camel-platform-http-vertx/pom.xml
index 45a235b7b47..83638375d9a 100644
--- a/components/camel-platform-http-vertx/pom.xml
+++ b/components/camel-platform-http-vertx/pom.xml
@@ -55,6 +55,11 @@
<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 -->
@@ -84,12 +89,6 @@
<artifactId>camel-log</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>io.vertx</groupId>
- <artifactId>vertx-auth-properties</artifactId>
- <version>${vertx-version}</version>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</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 176d5bef976..ad9bff498f2 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
@@ -108,3 +108,46 @@ from("platform-http:/upload?httpMethodRestrict=POST&useStreaming=true")
.log("Processing large request body...")
.to("file:/uploads?fileName=uploaded.txt")
----
+
+== Setting up http authentication
+
+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 set up custom authentication, you need to create custom `AuthenticationConfigEntries`, as shown in example below.
+Mind that in Vert.x order of adding `AuthenticationHandlers` matters, so `AuthenticationConfigEntries` with more specific url path are applied first.
+
+[source,java]
+----
+final int port = AvailablePortFinder.getNextAvailable();
+final CamelContext context = new DefaultCamelContext();
+
+VertxPlatformHttpServerConfiguration conf = new VertxPlatformHttpServerConfiguration();
+conf.setBindPort(port);
+
+//creating custom auth settings
+AuthenticationConfigEntry customEntry = new AuthenticationConfigEntry();
+AuthenticationProviderFactory provider = vertx -> PropertyFileAuthentication.create(vertx, "myPropFile.properties");
+AuthenticationHandlerFactory handler = BasicAuthHandler::create;
+customEntry.setPath("/path/that/will/be/protected");
+customEntry.setAuthenticationProviderFactory(provider);
+customEntry.setAuthenticationHandlerFactory(handler);
+
+AuthenticationConfig authenticationConfig = new AuthenticationConfig(List.of(customEntry));
+authenticationConfig.setEnabled(true);
+
+conf.setAuthenticationConfig(authenticationConfig);
+
+context.addService(new VertxPlatformHttpServer(conf));
+context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("platform-http:/test")
+ .routeId("get")
+ .setBody().constant("Hello from Camel's PlatformHttp service");
+ }
+});
+
+context.start();
+----
\ No newline at end of file
diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
index 8eed4dd9467..0f85800e383 100644
--- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
+++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
@@ -33,6 +33,8 @@ import org.apache.camel.StaticService;
import org.apache.camel.api.management.ManagedAttribute;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.component.platform.http.PlatformHttpConstants;
+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.support.CamelContextHelper;
import org.apache.camel.support.service.ServiceHelper;
import org.apache.camel.support.service.ServiceSupport;
@@ -188,6 +190,11 @@ public class VertxPlatformHttpServer extends ServiceSupport implements CamelCont
configuration.getSessionConfig().createSessionHandler(vertx));
}
+ AuthenticationConfig authenticationConfig = configuration.getAuthenticationConfig();
+ if (authenticationConfig.isEnabled()) {
+ addAuthenticationHandlersStartingFromMoreSpecificPaths(authenticationConfig);
+ }
+
router.route(configuration.getPath() + "*").subRouter(subRouter);
context.getRegistry().bind(
@@ -318,4 +325,25 @@ public class VertxPlatformHttpServer extends ServiceSupport implements CamelCont
this.localVertx = false;
}
}
+
+ private void addAuthenticationHandlersStartingFromMoreSpecificPaths(AuthenticationConfig authenticationConfig) {
+ authenticationConfig.getEntries()
+ .stream()
+ .sorted(this::compareUrlPathsSpecificity)
+ .forEach(entry -> subRouter.route(entry.getPath()).handler(entry.createAuthenticationHandler(vertx)));
+ }
+
+ private int compareUrlPathsSpecificity(AuthenticationConfigEntry entry1, AuthenticationConfigEntry entry2) {
+ long entry1PathLength = entry1.getPath().chars().filter(ch -> ch == '/').count();
+ long entry2PathLength = entry2.getPath().chars().filter(ch -> ch == '/').count();
+ if (entry1PathLength == entry2PathLength) {
+ if (entry1.getPath().endsWith("*")) {
+ return 1;
+ }
+ if (entry2.getPath().endsWith("*")) {
+ return -1;
+ }
+ }
+ return (int) (entry2PathLength - entry1PathLength);
+ }
}
diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServerConfiguration.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServerConfiguration.java
index b2bcc078e4e..07387884e9e 100644
--- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServerConfiguration.java
+++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServerConfiguration.java
@@ -25,6 +25,7 @@ import io.vertx.ext.web.handler.SessionHandler;
import io.vertx.ext.web.sstore.ClusteredSessionStore;
import io.vertx.ext.web.sstore.LocalSessionStore;
import io.vertx.ext.web.sstore.SessionStore;
+import org.apache.camel.component.platform.http.vertx.auth.AuthenticationConfig;
import org.apache.camel.support.jsse.SSLContextParameters;
/**
@@ -46,6 +47,7 @@ public class VertxPlatformHttpServerConfiguration {
private BodyHandler bodyHandler = new BodyHandler();
private Cors cors = new Cors();
private SessionConfig sessionConfig = new SessionConfig();
+ private AuthenticationConfig authenticationConfig = new AuthenticationConfig();
public int getPort() {
return getBindPort();
@@ -135,6 +137,14 @@ public class VertxPlatformHttpServerConfiguration {
this.bodyHandler = bodyHandler;
}
+ public AuthenticationConfig getAuthenticationConfig() {
+ return authenticationConfig;
+ }
+
+ public void setAuthenticationConfig(AuthenticationConfig authenticationConfig) {
+ this.authenticationConfig = authenticationConfig;
+ }
+
public static class SessionConfig {
private boolean enabled;
private SessionStoreType storeType = SessionStoreType.LOCAL;
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
new file mode 100644
index 00000000000..c1e6d50849b
--- /dev/null
+++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/auth/AuthenticationConfig.java
@@ -0,0 +1,104 @@
+/*
+ * 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.vertx.auth;
+
+import java.util.ArrayList;
+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) {
+ this.entries = authenticationConfigEntries;
+ }
+
+ public List<AuthenticationConfigEntry> getEntries() {
+ return entries;
+ }
+
+ public boolean isEnabled() {
+ return authenticationEnabled;
+ }
+
+ public void setEnabled(boolean authenticationEnabled) {
+ this.authenticationEnabled = authenticationEnabled;
+ }
+
+ public interface AuthenticationProviderFactory {
+ AuthenticationProvider createAuthenticationProvider(Vertx vertx);
+ }
+
+ public interface AuthenticationHandlerFactory {
+ AuthenticationHandler createAuthenticationHandler(AuthenticationProvider authenticationProvider);
+ }
+
+ public static class AuthenticationConfigEntry {
+ private String path;
+ private AuthenticationProviderFactory authenticationProviderFactory;
+ private AuthenticationHandlerFactory authenticationHandlerFactory;
+
+ public Handler<RoutingContext> createAuthenticationHandler(Vertx vertx) {
+ AuthenticationProvider provider = authenticationProviderFactory.createAuthenticationProvider(vertx);
+ return authenticationHandlerFactory.createAuthenticationHandler(provider);
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public AuthenticationProviderFactory getAuthenticationProviderFactory() {
+ return authenticationProviderFactory;
+ }
+
+ public void setAuthenticationProviderFactory(AuthenticationProviderFactory authenticationProviderFactory) {
+ this.authenticationProviderFactory = authenticationProviderFactory;
+ }
+
+ public AuthenticationHandlerFactory getAuthenticationHandlerFactory() {
+ return authenticationHandlerFactory;
+ }
+
+ public void setAuthenticationHandlerFactory(AuthenticationHandlerFactory authenticationHandlerFactory) {
+ this.authenticationHandlerFactory = authenticationHandlerFactory;
+ }
+ }
+
+}
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
new file mode 100644
index 00000000000..0eb18443aa2
--- /dev/null
+++ b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpAuthenticationTest.java
@@ -0,0 +1,336 @@
+/*
+ * 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.vertx;
+
+import io.restassured.RestAssured;
+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.web.handler.BasicAuthHandler;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+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.component.platform.http.vertx.auth.AuthenticationConfig.AuthenticationProviderFactory;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.AvailablePortFinder;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+
+public class VertxPlatformHttpAuthenticationTest {
+
+ @Test
+ public void testAuthenticationDisabled() throws Exception {
+ CamelContext context = createCamelContext(authenticationConfig -> {
+ //authentication disabled by default
+ });
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("platform-http:/disabledAuth")
+ .setBody().constant("disabledAuth");
+ }
+ });
+
+ try {
+ context.start();
+
+ given()
+ .when()
+ .get("/disabledAuth")
+ .then()
+ .statusCode(200)
+ .body(equalTo("disabledAuth"));
+ } finally {
+ context.stop();
+ }
+ }
+
+ @Test
+ public void testDefaultAuthenticationConfig() throws Exception {
+ CamelContext context = createCamelContext(authenticationConfig -> {
+ authenticationConfig.setEnabled(true);
+ });
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ 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"));
+
+ } finally {
+ context.stop();
+ }
+ }
+
+ @Test
+ public void testAuthenticateSpecificPathOnly() throws Exception {
+ CamelContext context = createCamelContext(authenticationConfig -> {
+ authenticationConfig.setEnabled(true);
+ authenticationConfig.getEntries().get(0).setPath("/specific/path");
+ });
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("platform-http:/specific/path")
+ .setBody().constant("specificPath");
+
+ from("platform-http:/unprotected")
+ .setBody().constant("unprotected");
+ }
+ });
+
+ try {
+ context.start();
+
+ given()
+ .when()
+ .get("/specific/path")
+ .then()
+ .statusCode(401)
+ .body(equalTo("Unauthorized"));
+
+ given()
+ .auth().basic("camel", "propertiesPass")
+ .when()
+ .get("/specific/path")
+ .then()
+ .statusCode(200)
+ .body(equalTo("specificPath"));
+
+ given()
+ .when()
+ .get("/unprotected")
+ .then()
+ .statusCode(200)
+ .body(equalTo("unprotected"));
+
+ } finally {
+ context.stop();
+ }
+ }
+
+ @Test
+ public void testAddingCustomAuthenticationProvider() throws Exception {
+ CamelContext context = createCamelContext(authenticationConfig -> {
+ authenticationConfig.setEnabled(true);
+ AuthenticationProviderFactory provider = createCustomProvider("CustomUser", "CustomPass");
+ AuthenticationHandlerFactory handler = BasicAuthHandler::create;
+ AuthenticationConfigEntry customEntry = new AuthenticationConfigEntry();
+ customEntry.setPath("/custom/provider");
+ customEntry.setAuthenticationProviderFactory(provider);
+ customEntry.setAuthenticationHandlerFactory(handler);
+ authenticationConfig.getEntries().add(customEntry);
+ });
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ 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")
+ .then()
+ .statusCode(401)
+ .body(equalTo("Unauthorized"));
+
+ given()
+ .auth().basic("CustomUser", "CustomPass")
+ .when()
+ .get("/custom/provider")
+ .then()
+ .statusCode(200)
+ .body(equalTo("customProvider"));
+
+ } finally {
+ context.stop();
+ }
+ }
+
+ @Test
+ public void testAuthenticateSpecificPathWithCustomAuthenticationProvider() throws Exception {
+ CamelContext context = createCamelContext(authenticationConfig -> {
+ authenticationConfig.setEnabled(true);
+ AuthenticationProviderFactory provider = createCustomProvider("CustomUser", "CustomPass");
+ AuthenticationHandlerFactory handler = BasicAuthHandler::create;
+ AuthenticationConfigEntry customEntry = new AuthenticationConfigEntry();
+ customEntry.setPath("/customProvider");
+ customEntry.setAuthenticationProviderFactory(provider);
+ customEntry.setAuthenticationHandlerFactory(handler);
+ authenticationConfig.getEntries().add(customEntry);
+ });
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ 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")
+ .then()
+ .statusCode(401)
+ .body(equalTo("Unauthorized"));
+
+ given()
+ .auth().basic("CustomUser", "CustomPass")
+ .when()
+ .get("/customProvider")
+ .then()
+ .statusCode(200)
+ .body(equalTo("customProvider"));
+
+ } finally {
+ context.stop();
+ }
+ }
+
+ private AuthenticationProviderFactory createCustomProvider(String username, String pass) {
+ return vertx -> (AuthenticationProvider) (credentials, resultHandler) -> {
+ boolean usernameMatched = credentials.getString("username").equals(username);
+ boolean passwordMatched = credentials.getString("password").equals(pass);
+ if (usernameMatched && passwordMatched) {
+ AsyncResult<User> result = getUser();
+ resultHandler.handle(result);
+ }
+ };
+ }
+
+ private AsyncResult<User> getUser() {
+ return new AsyncResult<>() {
+ @Override
+ public User result() {
+ return new UserImpl();
+ }
+
+ @Override
+ public Throwable cause() {
+ return null;
+ }
+
+ @Override
+ public boolean succeeded() {
+ return true;
+ }
+
+ @Override
+ public boolean failed() {
+ return false;
+ }
+ };
+ }
+
+ private CamelContext createCamelContext(AuthenticationConfigCustomizer customizer)
+ throws Exception {
+ int bindPort = AvailablePortFinder.getNextAvailable();
+ RestAssured.port = bindPort;
+ return createCamelContext(bindPort, customizer);
+ }
+
+ private CamelContext createCamelContext(int bindPort, AuthenticationConfigCustomizer customizer)
+ throws Exception {
+ VertxPlatformHttpServerConfiguration conf = new VertxPlatformHttpServerConfiguration();
+ conf.setBindPort(bindPort);
+
+ AuthenticationConfig authenticationConfig = new AuthenticationConfig();
+ customizer.customize(authenticationConfig);
+ conf.setAuthenticationConfig(authenticationConfig);
+
+ CamelContext camelContext = new DefaultCamelContext();
+ camelContext.addService(new VertxPlatformHttpServer(conf));
+ return camelContext;
+ }
+
+ interface AuthenticationConfigCustomizer {
+ void customize(AuthenticationConfig authenticationConfig);
+ }
+}
diff --git a/components/camel-platform-http-vertx/src/test/resources/camel-platform-http-vertx-auth.properties b/components/camel-platform-http-vertx/src/test/resources/camel-platform-http-vertx-auth.properties
new file mode 100644
index 00000000000..d8490f76ce9
--- /dev/null
+++ b/components/camel-platform-http-vertx/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