Repository: camel Updated Branches: refs/heads/master eb3f69493 -> 0872f9118
CAMEL-8162- UT to invalidate the issue. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b1c57662 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b1c57662 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b1c57662 Branch: refs/heads/master Commit: b1c5766251d9818040b5cfb5de7608e41cfa710c Parents: b413617 Author: onders86 <ondersez...@gmail.com> Authored: Mon Feb 20 15:28:45 2017 +0300 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Feb 21 09:22:35 2017 +0100 ---------------------------------------------------------------------- .../javacrumbs/calc/model/ObjectFactory.java | 65 +++++++++++ .../net/javacrumbs/calc/model/PlusRequest.java | 97 +++++++++++++++++ .../net/javacrumbs/calc/model/PlusResponse.java | 78 ++++++++++++++ .../net/javacrumbs/calc/model/package-info.java | 26 +++++ .../ProducerWss4JSecurityHeaderTest.java | 107 +++++++++++++++++++ ...ducerWss4JSecurityHeaderTestInterceptor.java | 44 ++++++++ .../ProducerWss4JSecurityHeaderTest-context.xml | 80 ++++++++++++++ .../src/test/resources/xsd/calc.xsd | 21 ++++ 8 files changed, 518 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b1c57662/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/ObjectFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/ObjectFactory.java b/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/ObjectFactory.java new file mode 100644 index 0000000..2df1574 --- /dev/null +++ b/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/ObjectFactory.java @@ -0,0 +1,65 @@ +/** + * 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. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) +// Reference Implementation, v2.2.8-b130911.1802 +// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2017.02.12 at 12:58:35 AM EET +// + + +package net.javacrumbs.calc.model; + +import javax.xml.bind.annotation.XmlRegistry; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the net.javacrumbs.calc.model package. + * An ObjectFactory allows you to programatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + + /** + * Create a new ObjectFactory that can be used to create new instances of + * schema derived classes for package: net.javacrumbs.calc.model + * + */ + public ObjectFactory() { + } + + public PlusResponse createPlusResponse() { + return new PlusResponse(); + } + + public PlusRequest createPlusRequest() { + return new PlusRequest(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b1c57662/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/PlusRequest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/PlusRequest.java b/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/PlusRequest.java new file mode 100644 index 0000000..2d6426e --- /dev/null +++ b/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/PlusRequest.java @@ -0,0 +1,97 @@ +/** + * 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. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) +// Reference Implementation, v2.2.8-b130911.1802 +// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2017.02.12 at 12:58:35 AM EET +// + + +package net.javacrumbs.calc.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + * Java class for anonymous complex type. + * + * <p>The following schema fragment specifies the expected content contained within this class. + * + * <pre> + * <complexType> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * <sequence> + * <element name="a" type="{http://www.w3.org/2001/XMLSchema}int"/> + * <element name="b" type="{http://www.w3.org/2001/XMLSchema}int"/> + * </sequence> + * </restriction> + * </complexContent> + * </complexType> + * </pre> + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "a", + "b" + }) +@XmlRootElement(name = "plusRequest") +public class PlusRequest { + + protected int a; + protected int b; + + /** + * Gets the value of the a property. + * + */ + public int getA() { + return a; + } + + /** + * Sets the value of the a property. + * + */ + public void setA(int value) { + this.a = value; + } + + /** + * Gets the value of the b property. + * + */ + public int getB() { + return b; + } + + /** + * Sets the value of the b property. + * + */ + public void setB(int value) { + this.b = value; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b1c57662/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/PlusResponse.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/PlusResponse.java b/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/PlusResponse.java new file mode 100644 index 0000000..11a6a5e --- /dev/null +++ b/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/PlusResponse.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. + */ +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) +// Reference Implementation, v2.2.8-b130911.1802 +// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2017.02.12 at 12:58:35 AM EET +// + + +package net.javacrumbs.calc.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + * Java class for anonymous complex type. + * + * <p>The following schema fragment specifies the expected content contained within this class. + * + * <pre> + * <complexType> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * <sequence> + * <element name="result" type="{http://www.w3.org/2001/XMLSchema}int"/> + * </sequence> + * </restriction> + * </complexContent> + * </complexType> + * </pre> + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "result" + }) +@XmlRootElement(name = "plusResponse") +public class PlusResponse { + + protected int result; + + /** + * Gets the value of the result property. + * + */ + public int getResult() { + return result; + } + + /** + * Sets the value of the result property. + * + */ + public void setResult(int value) { + this.result = value; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b1c57662/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/package-info.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/package-info.java b/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/package-info.java new file mode 100644 index 0000000..04ca6cb --- /dev/null +++ b/components/camel-spring-ws/src/test/java/net/javacrumbs/calc/model/package-info.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. + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) +// Reference Implementation, v2.2.8-b130911.1802 +// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2017.02.12 at 12:58:35 AM EET +// + +@javax.xml.bind.annotation.XmlSchema(namespace = "http://javacrumbs.net/calc", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +package net.javacrumbs.calc.model; http://git-wip-us.apache.org/repos/asf/camel/blob/b1c57662/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTest.java b/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTest.java new file mode 100644 index 0000000..6e6c724 --- /dev/null +++ b/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTest.java @@ -0,0 +1,107 @@ +/** + * 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.spring.ws.security; + +import net.javacrumbs.calc.model.PlusRequest; +import net.javacrumbs.calc.model.PlusResponse; + +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.test.spring.CamelSpringTestSupport; + +import org.junit.Ignore; +import org.junit.Test; + +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.ws.client.core.WebServiceTemplate; +import org.springframework.ws.client.support.interceptor.ClientInterceptor; +import org.springframework.ws.soap.security.wss4j2.Wss4jSecurityInterceptor; + +@Ignore("run manually since it requires running sample" + + " secured ws on j2ee-compliant application server") +public class ProducerWss4JSecurityHeaderTest extends CamelSpringTestSupport { + + @Produce + private ProducerTemplate template; + + private WebServiceTemplate webServiceTemplate; + + @Override + public void setUp() throws Exception { + super.setUp(); + webServiceTemplate = applicationContext.getBean("webServiceTemplate", WebServiceTemplate.class); + } + + @Test + public void testResponseUsingWss4jSampleInterceptorWithoutHeadersRemoved() throws Exception { + + setRemoveHeaders(false); + + PlusResponse result = createSampleRequestResponsePair(); + + assertNotNull(result); + assertEquals(3, result.getResult()); + + assertTrue(ProducerWss4JSecurityHeaderTestInterceptor.isX509DataPresent); + + } + + @Test + public void testResponseUsingWss4jSampleInterceptorWithHeadersRemoved() throws Exception { + + setRemoveHeaders(true); + + PlusResponse result = createSampleRequestResponsePair(); + + assertNotNull(result); + assertEquals(3, result.getResult()); + + assertTrue(ProducerWss4JSecurityHeaderTestInterceptor.isX509DataPresent); + + } + + private PlusResponse createSampleRequestResponsePair() { + PlusRequest request = new PlusRequest(); + request.setA(new Integer(1)); + request.setB(new Integer(2)); + + PlusResponse result = (PlusResponse) template.requestBody("direct:testHeader", request); + + return result; + } + + private void setRemoveHeaders(boolean isRemoved) { + ClientInterceptor[] clientInterceptors = webServiceTemplate.getInterceptors(); + + for (int i = 0; i < clientInterceptors.length; i++) { + if (clientInterceptors[i] instanceof Wss4jSecurityInterceptor) { + Wss4jSecurityInterceptor wss4jSampleInterceptor + = (Wss4jSecurityInterceptor) clientInterceptors[i]; + wss4jSampleInterceptor.setRemoveSecurityHeader(isRemoved); + } + } + } + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext( + "org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTest-context.xml"); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b1c57662/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTestInterceptor.java ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTestInterceptor.java b/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTestInterceptor.java new file mode 100644 index 0000000..33a02a3 --- /dev/null +++ b/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTestInterceptor.java @@ -0,0 +1,44 @@ +/** + * 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.spring.ws.security; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.springframework.ws.context.MessageContext; +import org.springframework.ws.soap.SoapMessage; +import org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor; + +public class ProducerWss4JSecurityHeaderTestInterceptor extends Wss4jSecurityInterceptor{ + + public static boolean isX509DataPresent = false; + + protected void validateMessage(SoapMessage soapMessage, MessageContext messageContext) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + soapMessage.writeTo(out); + } catch (IOException exception) { + // do nothing - because this is a sample class + } + String strMsg = new String(out.toByteArray()); + + isX509DataPresent = strMsg.contains("X509Data"); + super.validateMessage(soapMessage, messageContext); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b1c57662/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTest-context.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTest-context.xml b/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTest-context.xml new file mode 100644 index 0000000..a8be027 --- /dev/null +++ b/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/security/ProducerWss4JSecurityHeaderTest-context.xml @@ -0,0 +1,80 @@ +<?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. --> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <!-- ============================== --> + <!-- Camel routes --> + <!-- ============================== --> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <dataFormats> + <jaxb id="jaxb" contextPath="net.javacrumbs.calc.model" /> + </dataFormats> + <route> + <from uri="direct:testHeader" /> + <to + uri="spring-ws:uri:http://localhost:8080/simple-server-test/soap/calc?webServiceTemplate=#webServiceTemplate&endpointMapping=#endpointMapping" /> + <!-- <convertBodyTo type="java.lang.String"/> --> + <unmarshal ref="jaxb" /> + </route> + </camelContext> + + <bean id="endpointMapping" + class="org.apache.camel.component.spring.ws.bean.CamelEndpointMapping" /> + + <!-- ============================== --> + <!-- Supporting Spring-WS beans --> + <!-- ============================== --> + + <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate"> + <property name="defaultUri" + value="http://localhost:8080/simple-server-test/soap/calc" /> + <property name="interceptors"> + <list> + <bean id="wsClientSecurityInterceptor" + class="org.apache.camel.component.spring.ws.security.ProducerWss4JSecurityHeaderTestInterceptor"> + <property name="securementActions" value="Timestamp Signature Encrypt" /> + <!-- Key alias for signature --> + <property name="securementUsername" value="client" /> + <property name="securementPassword" value="onder123" /> + <property name="securementSignatureCrypto" ref="clientCrypto" /> + <property name="securementEncryptionCrypto" ref="clientCrypto" /> + <property name="securementEncryptionParts" value="{Content}{http://javacrumbs.net/calc}a" /> + <!-- Key alias for encryption --> + <property name="securementEncryptionUser" value="server" /> + + <!-- Validation config --> + <property name="validationActions" value="Signature" /> + <property name="validationSignatureCrypto" ref="clientCrypto" /> + </bean> + </list> + </property> + <property name="marshaller" ref="marshaller" /> + <property name="unmarshaller" ref="marshaller" /> + </bean> + + <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> + <property name="contextPath" value="net.javacrumbs.calc.model" /> + </bean> + + + <bean id="clientCrypto" + class="org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean"> + <property name="keyStorePassword" value="onder123" /> + <property name="keyStoreLocation" value="classpath:security/client.jks" /> + </bean> + +</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b1c57662/components/camel-spring-ws/src/test/resources/xsd/calc.xsd ---------------------------------------------------------------------- diff --git a/components/camel-spring-ws/src/test/resources/xsd/calc.xsd b/components/camel-spring-ws/src/test/resources/xsd/calc.xsd new file mode 100644 index 0000000..f033d50 --- /dev/null +++ b/components/camel-spring-ws/src/test/resources/xsd/calc.xsd @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://javacrumbs.net/calc" + xmlns:tns="http://javacrumbs.net/calc" elementFormDefault="qualified"> + + <element name="plusRequest"> + <complexType> + <sequence> + <element name="a" type="int" /> + <element name="b" type="int" /> + </sequence> + </complexType> + </element> + + <element name="plusResponse"> + <complexType> + <sequence> + <element name="result" type="int" /> + </sequence> + </complexType> + </element> +</schema> \ No newline at end of file