Index: src/test/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest.java =================================================================== --- src/test/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest.java (revision 0) +++ src/test/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest.java (revision 0) @@ -0,0 +1,110 @@ +/** + * 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.cxf.ws.security.wss4j; + + +import java.security.cert.X509Certificate; +import java.util.Collection; + +import javax.xml.soap.MessageFactory; +import javax.xml.soap.SOAPMessage; +import javax.xml.soap.SOAPPart; +import javax.xml.transform.dom.DOMSource; + +import org.w3c.dom.Document; +import org.apache.cxf.Bus; +import org.apache.cxf.BusFactory; +import org.apache.cxf.binding.soap.SoapMessage; +import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.message.Exchange; +import org.apache.cxf.message.ExchangeImpl; +import org.apache.cxf.message.MessageImpl; +import org.apache.cxf.ws.policy.AssertionInfo; +import org.apache.cxf.ws.policy.AssertionInfoMap; +import org.apache.cxf.ws.policy.PolicyBuilder; +import org.apache.cxf.ws.policy.PolicyException; +import org.apache.cxf.ws.security.policy.SP12Constants; +import org.apache.neethi.Policy; +import org.apache.ws.security.WSSecurityEngineResult; +import org.apache.ws.security.handler.WSHandlerConstants; +import org.junit.Before; +import org.junit.Test; + + +public class PolicyBasedWss4JInOutTest extends AbstractSecurityTest { + + private Bus bus; + private PolicyBuilder policyBuilder; + + @Before + public void setUp() { + this.bus = new SpringBusFactory().createBus( + "org/apache/cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest_bus_context.xml"); + BusFactory.setDefaultBus(this.bus); + this.policyBuilder = + this.bus.getExtension(PolicyBuilder.class); + } + + @Test + public void testSignedElementsPolicy() throws Exception { + // Use a static file as source so that we are sure the input is invalid. + Document doc = readDocument("signed_missing_signed_elements.xml"); + + Policy policy = this.policyBuilder.getPolicy( + this.readDocument("signed_elements_policy.xml").getDocumentElement()); + + AssertionInfoMap aim = new AssertionInfoMap(policy); + + PolicyBasedWSS4JInInterceptor inHandler = new PolicyBasedWSS4JInInterceptor(); + + SOAPMessage saajMsg = MessageFactory.newInstance().createMessage(); + SOAPPart part = saajMsg.getSOAPPart(); + part.setContent(new DOMSource(doc)); + saajMsg.saveChanges(); + + SoapMessage inmsg = new SoapMessage(new MessageImpl()); + Exchange ex = new ExchangeImpl(); + ex.setInMessage(inmsg); + inmsg.setContent(SOAPMessage.class, saajMsg); + inmsg.put(AssertionInfoMap.class, aim); + + inHandler.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE); + inHandler.setProperty(WSHandlerConstants.SIG_PROP_FILE, "META-INF/cxf/insecurity.properties"); + + inHandler.handleMessage(inmsg); + + WSSecurityEngineResult result = + (WSSecurityEngineResult) inmsg.get(WSS4JInInterceptor.SIGNATURE_RESULT); + assertNotNull(result); + X509Certificate certificate = (X509Certificate)result + .get(WSSecurityEngineResult.TAG_X509_CERTIFICATE); + assertNotNull(certificate); + + try { + aim.checkEffectivePolicy(policy); + fail("SignedElements policy erroneously asserted."); + } catch (PolicyException e) { + Collection ais = aim.get(SP12Constants.SIGNED_ELEMENTS); + for (AssertionInfo ai : ais) { + assertFalse(ai.getAssertion().isAsserted(aim)); + } + } + } +} Index: src/test/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest_bus_context.xml =================================================================== --- src/test/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest_bus_context.xml (revision 0) +++ src/test/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest_bus_context.xml (revision 0) @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file Index: src/test/java/org/apache/cxf/ws/security/wss4j/signed_elements_policy.xml =================================================================== --- src/test/java/org/apache/cxf/ws/security/wss4j/signed_elements_policy.xml (revision 0) +++ src/test/java/org/apache/cxf/ws/security/wss4j/signed_elements_policy.xml (revision 0) @@ -0,0 +1,13 @@ + + + + + + //ser:Header + + + + \ No newline at end of file Index: src/test/java/org/apache/cxf/ws/security/wss4j/signed_missing_signed_elements.xml =================================================================== --- src/test/java/org/apache/cxf/ws/security/wss4j/signed_missing_signed_elements.xml (revision 0) +++ src/test/java/org/apache/cxf/ws/security/wss4j/signed_missing_signed_elements.xml (revision 0) @@ -0,0 +1,36 @@ + + + + + + + + + + +a0+IBfK+SfKXlyyJcIzg+M6OouI= + + + +VGURrUkUzHrVxveLRhp7ttaGSY6Aj+LR3k75pLLsFgXDEqSHOO2IsUnAt6cLGAGE/ijKKsip6g+O +K1AuHQleQLbc/sGyIkRDLLU+slV2s5XTC0x1DeBGFKy3O8D48obEQFnSfb2MpF/mtOarMLGc0BZ0 +J5bPqmDSmsqTvzcC/MY= + + + + +CN=myAlias +1181668586 + + + + +
1234
+
5678
+
+ + + A + + +
\ No newline at end of file