| /** |
| * 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.wss4j.policy.stax.test; |
| |
| public class LayoutTest extends AbstractPolicyTestBase { |
| |
| /*@Test |
| public void testPolicyStrict() throws Exception { |
| String policyString = |
| "<sp:AsymmetricBinding xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" + |
| "<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" + |
| "<sp:Layout xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" + |
| "<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" + |
| "<sp:LaxTsFirst/>\n" + |
| "</wsp:Policy>\n" + |
| "</sp:Layout>\n" + |
| "</wsp:Policy>\n" + |
| "</sp:AsymmetricBinding>"; |
| |
| PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString); |
| TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent(); |
| policyEnforcer.registerSecurityEvent(timestampSecurityEvent); |
| |
| RequiredElementSecurityEvent requiredElementSecurityEvent = new RequiredElementSecurityEvent(); |
| List<QName> headerPath = new ArrayList<>(); |
| headerPath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH); |
| headerPath.add(WSSConstants.TAG_WSU_TIMESTAMP); |
| requiredElementSecurityEvent.setElementPath(headerPath); |
| policyEnforcer.registerSecurityEvent(requiredElementSecurityEvent); |
| |
| X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent(); |
| SecurityToken securityToken = getX509Token(WSSecurityTokenConstants.X509V3Token); |
| securityToken.addTokenUsage(WSTokenConstants.TOKENUSAGE_MAIN_SIGNATURE); |
| x509TokenSecurityEvent.setSecurityToken(securityToken); |
| policyEnforcer.registerSecurityEvent(x509TokenSecurityEvent); |
| |
| List<XMLSecurityConstants.ContentType> protectionOrder = new LinkedList<>(); |
| protectionOrder.add(XMLSecurityConstants.ContentType.SIGNATURE); |
| protectionOrder.add(XMLSecurityConstants.ContentType.ENCRYPTION); |
| SignedPartSecurityEvent signedPartSecurityEvent = new SignedPartSecurityEvent(x509TokenSecurityEvent.getSecurityToken(), true, protectionOrder); |
| signedPartSecurityEvent.setElementPath(WSSConstants.SOAP_11_BODY_PATH); |
| policyEnforcer.registerSecurityEvent(signedPartSecurityEvent); |
| |
| OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent(); |
| operationSecurityEvent.setOperation(new QName("definitions")); |
| policyEnforcer.registerSecurityEvent(operationSecurityEvent); |
| |
| policyEnforcer.doFinal(); |
| }*/ |
| |
| /*@Test |
| public void testPolicyLaxTsFirst() throws Exception { |
| String policyString = |
| "<sp:AsymmetricBinding xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" + |
| "<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" + |
| "<sp:Layout xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" + |
| "<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" + |
| "<sp:LaxTsFirst/>\n" + |
| "</wsp:Policy>\n" + |
| "</sp:Layout>\n" + |
| "</wsp:Policy>\n" + |
| "</sp:AsymmetricBinding>"; |
| |
| PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString); |
| TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent(); |
| policyEnforcer.registerSecurityEvent(timestampSecurityEvent); |
| |
| RequiredElementSecurityEvent requiredElementSecurityEvent = new RequiredElementSecurityEvent(); |
| List<QName> headerPath = new ArrayList<>(); |
| headerPath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH); |
| headerPath.add(WSSConstants.TAG_WSU_TIMESTAMP); |
| requiredElementSecurityEvent.setElementPath(headerPath); |
| policyEnforcer.registerSecurityEvent(requiredElementSecurityEvent); |
| |
| X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent(); |
| SecurityToken securityToken = getX509Token(WSSecurityTokenConstants.X509V3Token); |
| securityToken.addTokenUsage(WSTokenConstants.TOKENUSAGE_MAIN_SIGNATURE); |
| x509TokenSecurityEvent.setSecurityToken(securityToken); |
| policyEnforcer.registerSecurityEvent(x509TokenSecurityEvent); |
| |
| List<XMLSecurityConstants.ContentType> protectionOrder = new LinkedList<>(); |
| protectionOrder.add(XMLSecurityConstants.ContentType.SIGNATURE); |
| protectionOrder.add(XMLSecurityConstants.ContentType.ENCRYPTION); |
| SignedPartSecurityEvent signedPartSecurityEvent = new SignedPartSecurityEvent(x509TokenSecurityEvent.getSecurityToken(), true, protectionOrder); |
| signedPartSecurityEvent.setElementPath(WSSConstants.SOAP_11_BODY_PATH); |
| policyEnforcer.registerSecurityEvent(signedPartSecurityEvent); |
| |
| OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent(); |
| operationSecurityEvent.setOperation(new QName("definitions")); |
| policyEnforcer.registerSecurityEvent(operationSecurityEvent); |
| |
| policyEnforcer.doFinal(); |
| }*/ |
| |
| /*@Test |
| public void testPolicyLaxTsFirstNegative() throws Exception { |
| String policyString = |
| "<sp:Layout xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" + |
| "<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" + |
| "<sp:LaxTsFirst/>\n" + |
| "</wsp:Policy>\n" + |
| "</sp:Layout>"; |
| PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString); |
| X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent(); |
| SecurityToken securityToken = getX509Token(WSSecurityTokenConstants.X509V3Token); |
| securityToken.addTokenUsage(WSTokenConstants.TOKENUSAGE_MAIN_SIGNATURE); |
| x509TokenSecurityEvent.setSecurityToken(securityToken); |
| policyEnforcer.registerSecurityEvent(x509TokenSecurityEvent); |
| |
| OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent(); |
| operationSecurityEvent.setOperation(new QName("definitions")); |
| try { |
| policyEnforcer.registerSecurityEvent(operationSecurityEvent); |
| Assert.fail("Exception expected"); |
| } catch (WSSecurityException e) { |
| Assert.assertTrue(e.getCause() instanceof PolicyViolationException); |
| Assert.assertEquals(e.getCause().getMessage(), "\n" + |
| "Policy enforces LaxTsFirst but X509Token occured first"); |
| } |
| }*/ |
| |
| /*@Test |
| public void testPolicyLaxTsLast() throws Exception { |
| String policyString = |
| "<sp:Layout xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" + |
| "<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" + |
| "<sp:LaxTsLast/>\n" + |
| "</wsp:Policy>\n" + |
| "</sp:Layout>"; |
| PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString); |
| X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent(); |
| SecurityToken securityToken = getX509Token(WSSecurityTokenConstants.X509V3Token); |
| securityToken.addTokenUsage(WSTokenConstants.TOKENUSAGE_MAIN_SIGNATURE); |
| x509TokenSecurityEvent.setSecurityToken(securityToken); |
| policyEnforcer.registerSecurityEvent(x509TokenSecurityEvent); |
| TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent(); |
| policyEnforcer.registerSecurityEvent(timestampSecurityEvent); |
| |
| OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent(); |
| operationSecurityEvent.setOperation(new QName("definitions")); |
| policyEnforcer.registerSecurityEvent(operationSecurityEvent); |
| |
| policyEnforcer.doFinal(); |
| }*/ |
| |
| /*@Test |
| public void testPolicyLaxTsLastNegative() throws Exception { |
| String policyString = |
| "<sp:Layout xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" + |
| "<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" + |
| "<sp:LaxTsLast/>\n" + |
| "</wsp:Policy>\n" + |
| "</sp:Layout>"; |
| PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString); |
| TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent(); |
| policyEnforcer.registerSecurityEvent(timestampSecurityEvent); |
| X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent(); |
| SecurityToken securityToken = getX509Token(WSSecurityTokenConstants.X509V3Token); |
| securityToken.addTokenUsage(WSTokenConstants.TOKENUSAGE_MAIN_SIGNATURE); |
| x509TokenSecurityEvent.setSecurityToken(securityToken); |
| policyEnforcer.registerSecurityEvent(x509TokenSecurityEvent); |
| |
| OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent(); |
| operationSecurityEvent.setOperation(new QName("definitions")); |
| try { |
| policyEnforcer.registerSecurityEvent(operationSecurityEvent); |
| Assert.fail("Exception expected"); |
| } catch (WSSecurityException e) { |
| Assert.assertTrue(e.getCause() instanceof PolicyViolationException); |
| Assert.assertEquals(e.getCause().getMessage(), "\n" + |
| "Policy enforces LaxTsLast but X509Token occured last"); |
| } |
| }*/ |
| } |