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 56d24c1b787a3fa16b760abe568335192b87d575 Author: Peter Palaga <[email protected]> AuthorDate: Mon Oct 24 17:56:42 2022 +0200 Test WS-Security server with UsernameToken --- .../cxf-soap/cxf-soap-ws-security-server/pom.xml | 135 +++++++++++++++++++++ .../soap/wss/server/it/CxfSoapWssServerRoutes.java | 101 +++++++++++++++ .../cxf/soap/wss/server/it/WssRounderService.java | 32 +++++ .../src/main/resources/application.properties | 18 +++ .../cxf/soap/wss/server/it/CxfSoapWssServerIT.java | 23 ++++ .../soap/wss/server/it/CxfSoapWssServerTest.java | 129 ++++++++++++++++++++ .../wss/server/it/CxfWssServerTestResource.java | 38 ++++++ integration-test-groups/cxf-soap/pom.xml | 1 + integration-tests/cxf-soap-grouped/pom.xml | 10 ++ poms/bom-test/pom.xml | 7 ++ 10 files changed, 494 insertions(+) diff --git a/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/pom.xml b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/pom.xml new file mode 100644 index 0000000000..d5bfdc715d --- /dev/null +++ b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/pom.xml @@ -0,0 +1,135 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-build-parent-it</artifactId> + <version>2.13.1-SNAPSHOT</version> + <relativePath>../../../poms/build-parent-it/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-integration-test-cxf-soap-ws-security-server</artifactId> + <name>Camel Quarkus :: Integration Tests :: CXF SOAP WS-Security server</name> + <description>Integration tests for Camel Quarkus CXF extension acting as SOAP server having WS-Security enabled</description> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-cxf-soap</artifactId> + </dependency> + <dependency> + <groupId>io.quarkiverse.cxf</groupId> + <artifactId>quarkus-cxf-rt-ws-security</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</artifactId> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.quarkiverse.cxf</groupId> + <artifactId>quarkus-cxf-test-util</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.package.type>native</quarkus.package.type> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>virtualDependencies</id> + <activation> + <property> + <name>!noVirtualDependencies</name> + </property> + </activation> + <dependencies> + <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-cxf-soap-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + </profile> + <profile> + <id>skip-testcontainers-tests</id> + <activation> + <property> + <name>skip-testcontainers-tests</name> + </property> + </activation> + <properties> + <skipTests>true</skipTests> + </properties> + </profile> + </profiles> + +</project> diff --git a/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfSoapWssServerRoutes.java b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfSoapWssServerRoutes.java new file mode 100644 index 0000000000..ab2a7b6cf6 --- /dev/null +++ b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfSoapWssServerRoutes.java @@ -0,0 +1,101 @@ +/* + * 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.quarkus.component.cxf.soap.wss.server.it; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.inject.Named; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.camel.Message; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.cxf.jaxws.CxfEndpoint; +import org.apache.cxf.ext.logging.LoggingFeature; +import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor; +import org.apache.wss4j.common.ConfigurationConstants; +import org.apache.wss4j.common.ext.WSPasswordCallback; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@ApplicationScoped +public class CxfSoapWssServerRoutes extends RouteBuilder { + + /** Produced in CxfWssServerTestResource */ + @ConfigProperty(name = "camel-quarkus.wss.server.username", defaultValue = "cxf") + String username; + + /** Produced in CxfWssServerTestResource */ + @ConfigProperty(name = "camel-quarkus.wss.server.password", defaultValue = "pwd") + String password; + + @Override + public void configure() { + + from("cxf:bean:wssRounderService?dataFormat=POJO") + .log("exchange: ${exchange}") + .process(exchange -> { + final Message message = exchange.getMessage(); + final double body = message.getBody(double.class); + message.setBody(Math.round(body)); + }); + + } + + @Produces + @ApplicationScoped + @Named + CxfEndpoint wssRounderService() { + final CxfEndpoint result = new CxfEndpoint(); + result.setServiceClass(WssRounderService.class); + result.setAddress("/rounder"); + + final LoggingFeature lf = new LoggingFeature(); + lf.setPrettyLogging(true); + result.getFeatures().add(lf); + + final CallbackHandler passwordCallback = new CallbackHandler() { + @Override + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + for (Callback callback : callbacks) { + if (callback instanceof WSPasswordCallback) { + final WSPasswordCallback pc = (WSPasswordCallback) callback; + if (username.equals(pc.getIdentifier())) { + pc.setPassword(password); + return; + } + break; + } + } + } + }; + + final Map<String, Object> props = new HashMap<>(); + props.put(ConfigurationConstants.ACTION, "UsernameToken"); + props.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordText"); + props.put(ConfigurationConstants.USER, username); + props.put(ConfigurationConstants.PW_CALLBACK_REF, passwordCallback); + result.getInInterceptors().add(new WSS4JInInterceptor(props)); + + return result; + } + +} diff --git a/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/WssRounderService.java b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/WssRounderService.java new file mode 100644 index 0000000000..49b7e8109e --- /dev/null +++ b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/main/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/WssRounderService.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.quarkus.component.cxf.soap.wss.server.it; + +import javax.jws.WebMethod; +import javax.jws.WebService; + +/** + */ +@WebService(targetNamespace = WssRounderService.TARGET_NS, name = "WssRounderService", serviceName = "WssRounderService") +public interface WssRounderService { + + public static final String TARGET_NS = "http://it.server.wss.soap.cxf.component.quarkus.camel.apache.org/"; + + @WebMethod + public long round(double a); + +} diff --git a/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/main/resources/application.properties b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/main/resources/application.properties new file mode 100644 index 0000000000..2eaadf41fb --- /dev/null +++ b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/main/resources/application.properties @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +quarkus.cxf.path=/soapservice diff --git a/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfSoapWssServerIT.java b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfSoapWssServerIT.java new file mode 100644 index 0000000000..1de2c2c32a --- /dev/null +++ b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfSoapWssServerIT.java @@ -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. + */ +package org.apache.camel.quarkus.component.cxf.soap.wss.server.it; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class CxfSoapWssServerIT extends CxfSoapWssServerTest { +} diff --git a/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfSoapWssServerTest.java b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfSoapWssServerTest.java new file mode 100644 index 0000000000..6bde9962f5 --- /dev/null +++ b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfSoapWssServerTest.java @@ -0,0 +1,129 @@ +/* + * 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.quarkus.component.cxf.soap.wss.server.it; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import io.quarkiverse.cxf.test.QuarkusCxfClientTestUtil; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.apache.cxf.endpoint.Client; +import org.apache.cxf.frontend.ClientProxy; +import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; +import org.apache.wss4j.common.ConfigurationConstants; +import org.apache.wss4j.common.ext.WSPasswordCallback; +import org.assertj.core.api.Assertions; +import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; + +import static io.quarkiverse.cxf.test.QuarkusCxfClientTestUtil.anyNs; + +@QuarkusTest +@QuarkusTestResource(CxfWssServerTestResource.class) +class CxfSoapWssServerTest { + + @Test + void wsdl() throws IOException { + /* We do not set any static WSDL resource via org.apache.camel.component.cxf.jaxws.CxfEndpoint.setWsdlURL(String) + * in org.apache.camel.quarkus.component.cxf.soap.wss.server.it.CxfSoapWssServerRoutes.wssRounderService() + * So let's check whether the auto-generated WSDL is served properly */ + RestAssured.given() + .get("/soapservice/rounder?wsdl") + .then() + .statusCode(200) + .body( + Matchers.hasXPath( + anyNs("definitions", "portType") + + "[@name = 'WssRounderService']" + + anyNs("operation") + "/@name", + org.hamcrest.CoreMatchers.is("round"))); + } + + @Test + void usernameTokenCorrectPassword() throws IOException { + + final Config config = ConfigProvider.getConfig(); + final String username = config.getValue("camel-quarkus.wss.server.username", String.class); + final String password = config.getValue("camel-quarkus.wss.server.password", String.class); + + final WssRounderService client = rounderClient(username, password); + + Assertions.assertThat(client.round(2.1)).isEqualTo(2); + + } + + @Test + void usernameTokenBadPassword() throws IOException { + + final Config config = ConfigProvider.getConfig(); + final String username = config.getValue("camel-quarkus.wss.server.username", String.class); + final WssRounderService client = rounderClient(username, "fakePassword"); + + Assertions.assertThatExceptionOfType(javax.xml.ws.soap.SOAPFaultException.class) + .isThrownBy(() -> client.round(2.8)) + .withMessage( + "A security error was encountered when verifying the message"); + + } + + static WssRounderService rounderClient(String username, String password) { + final WssRounderService client = QuarkusCxfClientTestUtil.getClient(WssRounderService.class, "/soapservice/rounder"); + + final CallbackHandler passwordCallback = new CallbackHandler() { + @Override + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + for (Callback callback : callbacks) { + if (callback instanceof WSPasswordCallback) { + ((WSPasswordCallback) callback).setPassword(password); + break; + } + } + } + }; + + final Map<String, Object> props = new HashMap<>(); + props.put(ConfigurationConstants.ACTION, "UsernameToken"); + props.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordText"); + props.put(ConfigurationConstants.USER, username); + props.put(ConfigurationConstants.PW_CALLBACK_REF, passwordCallback); + + Client clientProxy = ClientProxy.getClient(client); + clientProxy.getOutInterceptors().add(new WSS4JOutInterceptor(props)); + return client; + } + + @Test + void anonymous() throws IOException { + final WssRounderService client = QuarkusCxfClientTestUtil.getClient(WssRounderService.class, "/soapservice/rounder"); + /* Make sure that it fails properly when called without a password */ + Assertions.assertThatExceptionOfType(javax.xml.ws.soap.SOAPFaultException.class) + .isThrownBy(() -> client.round(2.8)) + .withMessage( + "A security error was encountered when verifying the message"); + + } + +} diff --git a/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfWssServerTestResource.java b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfWssServerTestResource.java new file mode 100644 index 0000000000..50cbc3197b --- /dev/null +++ b/integration-test-groups/cxf-soap/cxf-soap-ws-security-server/src/test/java/org/apache/camel/quarkus/component/cxf/soap/wss/server/it/CxfWssServerTestResource.java @@ -0,0 +1,38 @@ +/* + * 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.quarkus.component.cxf.soap.wss.server.it; + +import java.util.Map; + +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; + +public class CxfWssServerTestResource implements QuarkusTestResourceLifecycleManager { + + @Override + public Map<String, String> start() { + + final String user = "cxf-user"; + final String password = "secret-password"; + return Map.of( + "camel-quarkus.wss.server.username", user, + "camel-quarkus.wss.server.password", password); + } + + @Override + public void stop() { + } +} diff --git a/integration-test-groups/cxf-soap/pom.xml b/integration-test-groups/cxf-soap/pom.xml index bfb960c740..6df75158f3 100644 --- a/integration-test-groups/cxf-soap/pom.xml +++ b/integration-test-groups/cxf-soap/pom.xml @@ -41,6 +41,7 @@ <module>cxf-soap-mtom</module> <module>cxf-soap-server</module> <module>cxf-soap-ws-security-client</module> + <module>cxf-soap-ws-security-server</module> </modules> </project> diff --git a/integration-tests/cxf-soap-grouped/pom.xml b/integration-tests/cxf-soap-grouped/pom.xml index 6b809b1b6e..310f0ef006 100644 --- a/integration-tests/cxf-soap-grouped/pom.xml +++ b/integration-tests/cxf-soap-grouped/pom.xml @@ -92,6 +92,16 @@ <artifactId>quarkus-junit4-mock</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>io.quarkiverse.cxf</groupId> + <artifactId>quarkus-cxf-test-util</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/poms/bom-test/pom.xml b/poms/bom-test/pom.xml index c13d7f6c61..467f22b22e 100644 --- a/poms/bom-test/pom.xml +++ b/poms/bom-test/pom.xml @@ -61,6 +61,13 @@ <type>pom</type> <scope>import</scope> </dependency> + <dependency> + <groupId>io.quarkiverse.cxf</groupId> + <artifactId>quarkus-cxf-bom-test</artifactId> + <version>${quarkiverse-cxf.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId>
