You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2023/04/06 12:34:11 UTC
[camel-quarkus] 05/06: Test CXF client with HTTP BASIC authentication #4705
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch 2.13.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 1da852309f3adf254674da471a63bfba052654c6
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Tue Mar 28 17:58:37 2023 +0200
Test CXF client with HTTP BASIC authentication #4705
---
.../cxf-soap/cxf-soap-client/pom.xml | 4 ++
.../cxf/soap/client/it/CxfSoapClientRoutes.java | 20 ++++++
.../resources/wsdl/BasicAuthCalculatorService.wsdl | 75 ++++++++++++++++++++++
.../cxf/soap/client/it/CxfClientTestResource.java | 9 ++-
.../cxf/soap/client/it/CxfSoapClientTest.java | 41 ++++++++++--
5 files changed, 142 insertions(+), 7 deletions(-)
diff --git a/integration-test-groups/cxf-soap/cxf-soap-client/pom.xml b/integration-test-groups/cxf-soap/cxf-soap-client/pom.xml
index 234870240c..71d6b78a78 100644
--- a/integration-test-groups/cxf-soap/cxf-soap-client/pom.xml
+++ b/integration-test-groups/cxf-soap/cxf-soap-client/pom.xml
@@ -46,6 +46,10 @@
<wsdl>${basedir}/src/main/resources/wsdl/CalculatorService.wsdl</wsdl>
<wsdlLocation>classpath:wsdl/CalculatorService.wsdl</wsdlLocation>
</wsdlOption>
+ <wsdlOption>
+ <wsdl>${basedir}/src/main/resources/wsdl/BasicAuthCalculatorService.wsdl</wsdl>
+ <wsdlLocation>classpath:wsdl/BasicAuthCalculatorService.wsdl</wsdlLocation>
+ </wsdlOption>
</wsdlOptions>
</configuration>
</execution>
diff --git a/integration-test-groups/cxf-soap/cxf-soap-client/src/main/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfSoapClientRoutes.java b/integration-test-groups/cxf-soap/cxf-soap-client/src/main/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfSoapClientRoutes.java
index 1f82daac7a..413546cc3d 100644
--- a/integration-test-groups/cxf-soap/cxf-soap-client/src/main/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfSoapClientRoutes.java
+++ b/integration-test-groups/cxf-soap/cxf-soap-client/src/main/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfSoapClientRoutes.java
@@ -36,6 +36,7 @@ import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.apache.camel.component.cxf.jaxws.CxfEndpoint;
import org.apache.cxf.ext.logging.LoggingFeature;
import org.eclipse.microprofile.config.inject.ConfigProperty;
+import org.jboss.eap.quickstarts.wscalculator.basicauthcalculator.BasicAuthCalculatorService;
import org.jboss.eap.quickstarts.wscalculator.calculator.CalculatorService;
@ApplicationScoped
@@ -90,6 +91,13 @@ public class CxfSoapClientRoutes extends RouteBuilder {
from("direct:operandsAdd")
.setHeader(CxfConstants.OPERATION_NAME).constant("addOperands")
.to("cxf:bean:soapClientEndpoint?dataFormat=POJO");
+
+ from("direct:basicAuthAdd")
+ .to("cxf:bean:basicAuthClientEndpoint?dataFormat=POJO&username={{cq.cxf.it.calculator.auth.basic.user}}&password={{cq.cxf.it.calculator.auth.basic.password}}");
+
+ from("direct:basicAuthAddAnonymous")
+ .to("cxf:bean:basicAuthClientEndpoint?dataFormat=POJO");
+
}
@Produces
@@ -113,6 +121,18 @@ public class CxfSoapClientRoutes extends RouteBuilder {
return result;
}
+ @Produces
+ @SessionScoped
+ @Named
+ CxfEndpoint basicAuthClientEndpoint() {
+ final CxfEndpoint result = new CxfEndpoint();
+ result.setServiceClass(BasicAuthCalculatorService.class);
+ result.setAddress(serviceBaseUri + "/calculator-ws/BasicAuthCalculatorService");
+ result.setWsdlURL("wsdl/BasicAuthCalculatorService.wsdl");
+ result.getFeatures().add(loggingFeature);
+ return result;
+ }
+
private String calculatorServiceAddress() {
return serviceBaseUri + "/calculator-ws/CalculatorService";
}
diff --git a/integration-test-groups/cxf-soap/cxf-soap-client/src/main/resources/wsdl/BasicAuthCalculatorService.wsdl b/integration-test-groups/cxf-soap/cxf-soap-client/src/main/resources/wsdl/BasicAuthCalculatorService.wsdl
new file mode 100644
index 0000000000..10ffef8a1d
--- /dev/null
+++ b/integration-test-groups/cxf-soap/cxf-soap-client/src/main/resources/wsdl/BasicAuthCalculatorService.wsdl
@@ -0,0 +1,75 @@
+<?xml version="1.0" ?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.jboss.org/eap/quickstarts/wscalculator/BasicAuthCalculator" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="BasicAuthCalculatorService" targetNamespace="http://www.jboss.org/eap/quickstarts/wscalculator/BasicAuthCalculator">
+<!--
+
+ 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.
+
+-->
+ <wsdl:types>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.jboss.org/eap/quickstarts/wscalculator/BasicAuthCalculator" elementFormDefault="unqualified" targetNamespace="http://www.jboss.org/eap/quickstarts/wscalculator/BasicAuthCalculator" version="1.0">
+
+ <xs:element name="securedAdd" type="tns:securedAdd"></xs:element>
+
+ <xs:element name="securedAddResponse" type="tns:securedAddResponse"></xs:element>
+
+ <xs:complexType name="securedAdd">
+ <xs:sequence>
+ <xs:element name="arg0" type="xs:int"></xs:element>
+ <xs:element name="arg1" type="xs:int"></xs:element>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="securedAddResponse">
+ <xs:sequence>
+ <xs:element name="return" type="xs:int"></xs:element>
+ </xs:sequence>
+ </xs:complexType>
+
+</xs:schema>
+ </wsdl:types>
+ <wsdl:message name="securedAddResponse">
+ <wsdl:part element="tns:securedAddResponse" name="parameters">
+ </wsdl:part>
+ </wsdl:message>
+ <wsdl:message name="securedAdd">
+ <wsdl:part element="tns:securedAdd" name="parameters">
+ </wsdl:part>
+ </wsdl:message>
+ <wsdl:portType name="BasicAuthCalculatorService">
+ <wsdl:operation name="securedAdd">
+ <wsdl:input message="tns:securedAdd" name="securedAdd">
+ </wsdl:input>
+ <wsdl:output message="tns:securedAddResponse" name="securedAddResponse">
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:portType>
+ <wsdl:binding name="BasicAuthCalculatorServiceSoapBinding" type="tns:BasicAuthCalculatorService">
+ <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"></soap:binding>
+ <wsdl:operation name="securedAdd">
+ <soap:operation soapAction="" style="document"></soap:operation>
+ <wsdl:input name="securedAdd">
+ <soap:body use="literal"></soap:body>
+ </wsdl:input>
+ <wsdl:output name="securedAddResponse">
+ <soap:body use="literal"></soap:body>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="BasicAuthCalculatorService">
+ <wsdl:port binding="tns:BasicAuthCalculatorServiceSoapBinding" name="BasicAuthCalculator">
+ <soap:address location="http://192.168.122.1:8080/calculator-ws/BasicAuthCalculatorService"></soap:address>
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
\ No newline at end of file
diff --git a/integration-test-groups/cxf-soap/cxf-soap-client/src/test/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfClientTestResource.java b/integration-test-groups/cxf-soap/cxf-soap-client/src/test/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfClientTestResource.java
index d8ff5eba2c..2d08a62502 100644
--- a/integration-test-groups/cxf-soap/cxf-soap-client/src/test/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfClientTestResource.java
+++ b/integration-test-groups/cxf-soap/cxf-soap-client/src/test/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfClientTestResource.java
@@ -18,6 +18,7 @@
package org.apache.camel.quarkus.component.cxf.soap.client.it;
import java.util.Map;
+import java.util.UUID;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import org.slf4j.Logger;
@@ -34,10 +35,14 @@ public class CxfClientTestResource implements QuarkusTestResourceLifecycleManage
@Override
public Map<String, String> start() {
+ final String BASIC_AUTH_USER = "tester";
+ final String BASIC_AUTH_PASSWORD = UUID.randomUUID().toString();
try {
calculatorContainer = new GenericContainer<>("quay.io/l2x6/calculator-ws:1.1")
.withExposedPorts(WILDFLY_PORT)
+ .withEnv("BASIC_AUTH_USER", BASIC_AUTH_USER)
+ .withEnv("BASIC_AUTH_PASSWORD", BASIC_AUTH_PASSWORD)
.withLogConsumer(new Slf4jLogConsumer(log))
.waitingFor(Wait.forHttp("/calculator-ws/CalculatorService?wsdl"));
@@ -46,7 +51,9 @@ public class CxfClientTestResource implements QuarkusTestResourceLifecycleManage
return Map.of(
"camel-quarkus.it.calculator.baseUri",
"http://" + calculatorContainer.getHost() + ":" +
- calculatorContainer.getMappedPort(WILDFLY_PORT));
+ calculatorContainer.getMappedPort(WILDFLY_PORT),
+ "cq.cxf.it.calculator.auth.basic.user", BASIC_AUTH_USER,
+ "cq.cxf.it.calculator.auth.basic.password", BASIC_AUTH_PASSWORD);
} catch (Exception e) {
throw new RuntimeException(e);
}
diff --git a/integration-test-groups/cxf-soap/cxf-soap-client/src/test/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfSoapClientTest.java b/integration-test-groups/cxf-soap/cxf-soap-client/src/test/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfSoapClientTest.java
index ad9d1cb0e4..f17e279f7c 100644
--- a/integration-test-groups/cxf-soap/cxf-soap-client/src/test/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfSoapClientTest.java
+++ b/integration-test-groups/cxf-soap/cxf-soap-client/src/test/java/org/apache/camel/quarkus/component/cxf/soap/client/it/CxfSoapClientTest.java
@@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
+import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
@QuarkusTest
@@ -81,23 +82,51 @@ class CxfSoapClientTest {
.body(equalTo("7"));
}
+ @Test
+ public void basicAuthClient() {
+ RestAssured.given()
+ .queryParam("a", "7")
+ .queryParam("b", "8")
+ .queryParam("endpointUri", "basicAuthAdd")
+ .queryParam("operation", "securedAdd")
+ .post("/cxf-soap/client/simple")
+ .then()
+ .statusCode(201)
+ .body(equalTo("15"));
+ }
+
+ @Test
+ public void basicAuthClientAnonymous() {
+ RestAssured.given()
+ .queryParam("a", "7")
+ .queryParam("b", "8")
+ .queryParam("endpointUri", "basicAuthAddAnonymous")
+ .queryParam("operation", "securedAdd")
+ .post("/cxf-soap/client/simple")
+ .then()
+ .statusCode(500)
+ .body(containsString("HTTP response '401: Unauthorized'"));
+ }
+
/**
- * Make sure that our static copy is the same as the WSDL served by the container
+ * Make sure that our static copies are the same as the WSDLs served by the container
*
* @throws IOException
*/
- @Test
- void wsdlUpToDate() throws IOException {
+ @ParameterizedTest
+ @ValueSource(strings = { "CalculatorService", "BasicAuthCalculatorService" })
+ void wsdlUpToDate(String serviceName) throws IOException {
final String wsdlUrl = ConfigProvider.getConfig()
.getValue("camel-quarkus.it.calculator.baseUri", String.class);
- final String wsdlRelPath = "wsdl/CalculatorService.wsdl";
+ final String wsdlRelPath = "wsdl/" + serviceName + ".wsdl";
final Path staticCopyPath = Paths.get("src/main/resources/" + wsdlRelPath);
Assumptions.assumeTrue(Files.isRegularFile(staticCopyPath),
staticCopyPath + " does not exist - we probably run inside Quarkus Platform");
/* The changing Docker IP address in the WSDL should not matter */
- final String sanitizerRegex = "<soap:address location=\"http://[^/]*/calculator-ws/CalculatorService\"></soap:address>";
+ final String sanitizerRegex = "<soap:address location=\"http://[^/]*/calculator-ws/" + serviceName
+ + "\"></soap:address>";
final String staticCopyContent = Files
.readString(staticCopyPath, StandardCharsets.UTF_8)
.replaceAll(sanitizerRegex, "")
@@ -107,7 +136,7 @@ class CxfSoapClientTest {
.replaceAll("\\s", "");
final String expected = RestAssured.given()
- .get(wsdlUrl + "/calculator-ws/CalculatorService?wsdl")
+ .get(wsdlUrl + "/calculator-ws/" + serviceName + "?wsdl")
.then()
.statusCode(200)
.extract().body().asString();