Source Code Cross Referenced for SecurityPoliciesTest.java in  » 6.0-JDK-Modules-com.sun » wsit » com » sun » xml » ws » security » impl » policy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules com.sun » wsit » com.sun.xml.ws.security.impl.policy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         * 
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         * 
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common Development
0008:         * and Distribution License("CDDL") (collectively, the "License").  You
0009:         * may not use this file except in compliance with the License. You can obtain
0010:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
0011:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
0012:         * language governing permissions and limitations under the License.
0013:         * 
0014:         * When distributing the software, include this License Header Notice in each
0015:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
0016:         * Sun designates this particular file as subject to the "Classpath" exception
0017:         * as provided by Sun in the GPL Version 2 section of the License file that
0018:         * accompanied this code.  If applicable, add the following below the License
0019:         * Header, with the fields enclosed by brackets [] replaced by your own
0020:         * identifying information: "Portions Copyrighted [year]
0021:         * [name of copyright owner]"
0022:         * 
0023:         * Contributor(s):
0024:         * 
0025:         * If you wish your version of this file to be governed by only the CDDL or
0026:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
0027:         * elects to include this software in this distribution under the [CDDL or GPL
0028:         * Version 2] license."  If you don't indicate a single choice of license, a
0029:         * recipient has the option to distribute your version of this file under
0030:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
0031:         * its licensees as provided above.  However, if you add GPL Version 2 code
0032:         * and therefore, elected the GPL Version 2 license, then the option applies
0033:         * only if the new code is made subject to such option by the copyright
0034:         * holder.
0035:         */
0036:        /*
0037:         * SecurityPoliciesTest.java
0038:         * JUnit based test
0039:         *
0040:         * Created on August 24, 2006, 4:26 AM
0041:         */
0042:
0043:        package com.sun.xml.ws.security.impl.policy;
0044:
0045:        import com.sun.xml.stream.buffer.XMLStreamBuffer;
0046:        import com.sun.xml.ws.api.model.wsdl.WSDLExtensible;
0047:        import com.sun.xml.ws.policy.Policy;
0048:        import com.sun.xml.ws.policy.PolicyException;
0049:        import com.sun.xml.ws.policy.PolicyMap;
0050:        import com.sun.xml.ws.policy.PolicyMapKey;
0051:        import com.sun.xml.ws.policy.PolicyMerger;
0052:        import com.sun.xml.ws.policy.jaxws.PolicyConfigParser;
0053:        import com.sun.xml.ws.policy.jaxws.WSDLPolicyMapWrapper;
0054:        import com.sun.xml.ws.policy.sourcemodel.PolicyModelTranslator;
0055:        import com.sun.xml.ws.policy.sourcemodel.PolicyModelUnmarshaller;
0056:        import com.sun.xml.ws.policy.sourcemodel.PolicySourceModel;
0057:        import com.sun.xml.ws.security.impl.policyconv.XWSSPolicyGenerator;
0058:        import com.sun.xml.wss.impl.PolicyTypeUtil;
0059:        import com.sun.xml.wss.impl.policy.SecurityPolicy;
0060:        import com.sun.xml.wss.impl.policy.mls.AuthenticationTokenPolicy;
0061:        import com.sun.xml.wss.impl.policy.mls.EncryptionPolicy;
0062:        import com.sun.xml.wss.impl.policy.mls.EncryptionTarget;
0063:        import com.sun.xml.wss.impl.policy.mls.MessagePolicy;
0064:        import com.sun.xml.wss.impl.policy.mls.SignatureConfirmationPolicy;
0065:        import com.sun.xml.wss.impl.policy.mls.SignaturePolicy;
0066:        import com.sun.xml.wss.impl.policy.mls.SignatureTarget;
0067:        import com.sun.xml.wss.impl.policy.mls.Target;
0068:        import com.sun.xml.wss.impl.policy.mls.TimestampPolicy;
0069:        import com.sun.xml.wss.impl.policy.mls.WSSPolicy;
0070:        import java.io.IOException;
0071:        import java.io.InputStream;
0072:        import java.io.InputStreamReader;
0073:        import java.io.Reader;
0074:        import java.net.URL;
0075:        import java.util.ArrayList;
0076:        import java.util.Collection;
0077:        import java.util.HashMap;
0078:        import java.util.Iterator;
0079:        import java.util.List;
0080:        import javax.xml.stream.XMLInputFactory;
0081:        import javax.xml.stream.XMLStreamReader;
0082:        import junit.framework.*;
0083:        import java.util.logging.Logger;
0084:        import javax.xml.namespace.QName;
0085:
0086:        /**
0087:         *
0088:         * @author K.Venugopal@SUN.com
0089:         * @author Mayank.Mishra@SUN.com
0090:         */
0091:        public class SecurityPoliciesTest extends TestCase {
0092:
0093:            public SecurityPoliciesTest(String testName) {
0094:                super (testName);
0095:            }
0096:
0097:            protected void setUp() throws Exception {
0098:            }
0099:
0100:            protected void tearDown() throws Exception {
0101:            }
0102:
0103:            public static Test suite() {
0104:                TestSuite suite = new TestSuite(SecurityPoliciesTest.class);
0105:
0106:                return suite;
0107:            }
0108:
0109:            public void testInteropScenario3_1() throws Exception {
0110:                String filaname = "security/interop-1.wsdl";
0111:                execute(filaname, false, false, 1);
0112:                execute(filaname, false, true, 1);
0113:                execute(filaname, true, false, 1);
0114:                execute(filaname, true, true, 1);
0115:            }
0116:
0117:            public void testInteropScenario3_2() throws Exception {
0118:                String filaname = "security/interop-2.wsdl";
0119:                execute(filaname, false, false, 2);
0120:                execute(filaname, false, true, 2);
0121:                execute(filaname, true, false, 2);
0122:                execute(filaname, true, true, 2);
0123:            }
0124:
0125:            public void testInteropScenario3_3() throws Exception {
0126:                String filaname = "security/interop-3.wsdl";
0127:                execute(filaname, false, false, 3);
0128:                execute(filaname, false, true, 3);
0129:                execute(filaname, true, false, 3);
0130:                execute(filaname, true, true, 3);
0131:            }
0132:
0133:            public void testInteropScenario3_4() throws Exception {
0134:                String filaname = "security/interop-4.wsdl";
0135:                execute(filaname, false, false, 4);
0136:                execute(filaname, false, true, 4);
0137:                execute(filaname, true, false, 4);
0138:                execute(filaname, true, true, 4);
0139:            }
0140:
0141:            public void testInteropScenario3_5() throws Exception {
0142:                String filaname = "security/interop-5.wsdl";
0143:                execute(filaname, false, false, 5);
0144:                execute(filaname, false, true, 5);
0145:                execute(filaname, true, false, 5);
0146:                execute(filaname, true, true, 5);
0147:            }
0148:
0149:            public void testInteropScenario3_6() throws Exception {
0150:                String filaname = "security/interop-6.wsdl";
0151:                execute(filaname, false, false, 6);
0152:                execute(filaname, false, true, 6);
0153:                execute(filaname, true, false, 6);
0154:                execute(filaname, true, true, 6);
0155:            }
0156:
0157:            public void testInteropScenario3_7() throws Exception {
0158:                String filaname = "security/interop-7.wsdl";
0159:                execute(filaname, false, false, 7);
0160:                execute(filaname, false, true, 7);
0161:                execute(filaname, true, false, 7);
0162:                execute(filaname, true, true, 7);
0163:            }
0164:
0165:            public void testTimeStampCR6398675() throws Exception {
0166:                String filename = "security/TimeStamp.wsdl";
0167:                execute(filename, false, false, 10);
0168:                execute(filename, false, true, 10);
0169:                execute(filename, true, false, 10);
0170:                execute(filename, true, true, 10);
0171:            }
0172:
0173:            public void testUMPolicy() throws Exception {
0174:                String xmlFile = "security/interop-1.xml";
0175:                unmarshalPolicy(xmlFile);
0176:            }
0177:
0178:            public boolean hasXPathTarget(String xpathExpr, Iterator itr) {
0179:                while (itr.hasNext()) {
0180:                    if (xpathExpr.equals(itr.next())) {
0181:                        return true;
0182:                    }
0183:                }
0184:                return false;
0185:            }
0186:
0187:            private PolicySourceModel unmarshalPolicyResource(String resource)
0188:                    throws PolicyException, IOException {
0189:                Reader reader = getResourceReader(resource);
0190:                PolicySourceModel model = PolicyModelUnmarshaller
0191:                        .getXmlUnmarshaller().unmarshalModel(reader);
0192:                reader.close();
0193:                return model;
0194:            }
0195:
0196:            private Reader getResourceReader(String resourceName) {
0197:                return new InputStreamReader(Thread.currentThread()
0198:                        .getContextClassLoader().getResourceAsStream(
0199:                                resourceName));
0200:            }
0201:
0202:            public Policy unmarshalPolicy(String xmlFile) throws Exception {
0203:                PolicySourceModel model = unmarshalPolicyResource(xmlFile);
0204:                Policy mbp = PolicyModelTranslator.getTranslator().translate(
0205:                        model);
0206:                return mbp;
0207:
0208:            }
0209:
0210:            public boolean isHeaderPresent(QName expected, Iterator headers) {
0211:                while (headers.hasNext()) {
0212:                    Header header = (Header) headers.next();
0213:                    if (expected.getLocalPart().equals(header.getLocalName())) {
0214:                        if (expected.getNamespaceURI().equals(header.getURI())) {
0215:                            return true;
0216:                        }
0217:                    }
0218:                }
0219:                return false;
0220:            }
0221:
0222:            public List<SignatureTarget> createSignatureTargetList(
0223:                    List<String> targetType, List<String> targetValue,
0224:                    List<Boolean> contentOnly,
0225:                    List<List<SignatureTarget.Transform>> transformList) {
0226:                int size = targetType.size();
0227:                List<SignatureTarget> targetList = new ArrayList<SignatureTarget>();
0228:                for (int i = 0; i < size; i++) {
0229:                    SignatureTarget t1 = new SignatureTarget();
0230:                    t1.setContentOnly(contentOnly.get(i));
0231:                    t1.setType(targetType.get(i));
0232:                    t1.setValue(targetValue.get(i));
0233:
0234:                    List<SignatureTarget.Transform> transList = transformList
0235:                            .get(i);
0236:                    for (int j = 0; j < transList.size(); j++) {
0237:                        t1.addTransform(transList.get(j));
0238:                    }
0239:                    targetList.add(t1);
0240:                }
0241:                return targetList;
0242:            }
0243:
0244:            public void addToSPTList(WSSPolicy policy, SignaturePolicy sp) {
0245:                SignaturePolicy.FeatureBinding spFB = (SignaturePolicy.FeatureBinding) sp
0246:                        .getFeatureBinding();
0247:                SignatureTarget st = new SignatureTarget();
0248:                st.setType(SignatureTarget.TARGET_TYPE_VALUE_URI);
0249:                st.setValue(policy.getType());
0250:                spFB.addTargetBinding(st);
0251:            }
0252:
0253:            public void addQTToSPTList(WSSPolicy policy, SignaturePolicy sp) {
0254:                SignaturePolicy.FeatureBinding spFB = (SignaturePolicy.FeatureBinding) sp
0255:                        .getFeatureBinding();
0256:                SignatureTarget st = new SignatureTarget();
0257:                st.setType(SignatureTarget.TARGET_TYPE_VALUE_QNAME);
0258:                st.setValue(policy.getType());
0259:                spFB.addTargetBinding(st);
0260:            }
0261:
0262:            public SignaturePolicy createSignaturePolicy(
0263:                    List<SignatureTarget> targetList) {
0264:                SignaturePolicy policy = new SignaturePolicy();
0265:                SignaturePolicy.FeatureBinding featureBinding = (SignaturePolicy.FeatureBinding) policy
0266:                        .getFeatureBinding();
0267:                for (Target t : targetList) {
0268:                    featureBinding.addTargetBinding(t);
0269:                }
0270:
0271:                return policy;
0272:            }
0273:
0274:            public EncryptionPolicy createEncryptionPolicy(
0275:                    List<EncryptionTarget> targetList) {
0276:                EncryptionPolicy policy = new EncryptionPolicy();
0277:                EncryptionPolicy.FeatureBinding featureBinding = (EncryptionPolicy.FeatureBinding) policy
0278:                        .getFeatureBinding();
0279:                for (Target t : targetList) {
0280:                    featureBinding.addTargetBinding(t);
0281:                }
0282:
0283:                return policy;
0284:            }
0285:
0286:            public SignaturePolicy addSignKeyBinding(SignaturePolicy policy,
0287:                    String type, String ref) {
0288:                if ("x509".equals(type)) {
0289:                    ((AuthenticationTokenPolicy.X509CertificateBinding) policy
0290:                            .newX509CertificateKeyBinding())
0291:                            .setReferenceType(ref);
0292:                } else if ("symmetric".equals(type)) {
0293:                    policy.newSymmetricKeyBinding();
0294:                } else if ("derivedkey".equals(type)) {
0295:                    policy.newDerivedTokenKeyBinding();
0296:                }
0297:
0298:                return policy;
0299:            }
0300:
0301:            public EncryptionPolicy addEncryptKeyBinding(
0302:                    EncryptionPolicy policy, String type, String ref) {
0303:                if ("x509".equals(type)) {
0304:                    ((AuthenticationTokenPolicy.X509CertificateBinding) policy
0305:                            .newX509CertificateKeyBinding())
0306:                            .setReferenceType(ref);
0307:                } else if ("symmetric".equals(type)) {
0308:                    policy.newSymmetricKeyBinding();
0309:                } else if ("derivedkey".equals(type)) {
0310:                    policy.newDerivedTokenKeyBinding();
0311:                }
0312:
0313:                return policy;
0314:            }
0315:
0316:            public AuthenticationTokenPolicy createUTPolicy(String username,
0317:                    String pass, String nonce, boolean doDigest) {
0318:                AuthenticationTokenPolicy at = new AuthenticationTokenPolicy();
0319:                AuthenticationTokenPolicy.UsernameTokenBinding UT = new AuthenticationTokenPolicy.UsernameTokenBinding();
0320:                if (username != null) {
0321:                    UT.setUsername(username);
0322:                }
0323:
0324:                if (pass != null) {
0325:                    UT.setPassword(pass);
0326:                }
0327:
0328:                if (nonce != null) {
0329:                    UT.setNonce(nonce);
0330:                }
0331:
0332:                if (doDigest) {
0333:                    UT.setDigestOn(doDigest);
0334:                }
0335:                at.setFeatureBinding(UT);
0336:                return at;
0337:            }
0338:
0339:            public boolean comparePolicies(MessagePolicy policy1,
0340:                    MessagePolicy policy2) throws Exception {
0341:                //boolean asrt = false;
0342:                if (policy1.size() != policy2.size()) {
0343:                    for (int i = 0; i < policy1.size(); i++) {
0344:                        System.out.println("Policy1:" + policy1.get(i));
0345:                    }
0346:                    for (int i = 0; i < policy2.size(); i++) {
0347:                        System.out.println("Policy2:" + policy2.get(i));
0348:                    }
0349:                    return false;
0350:                }
0351:
0352:                for (int i = 0; i < policy1.size(); i++) {
0353:                    if (policy1.get(i).getType() != policy2.get(i).getType()) {
0354:                        return false;
0355:                    }
0356:
0357:                    if (PolicyTypeUtil.signaturePolicy(policy1.get(i))) {
0358:                        if (!compareSignaturePolicy(
0359:                                ((WSSPolicy) policy1.get(i)),
0360:                                ((WSSPolicy) policy2.get(i)))) {
0361:                            return false;
0362:                        }
0363:                    } else if (PolicyTypeUtil.encryptionPolicy(policy1.get(i))) {
0364:                        if (!compareEncryptionPolicy(
0365:                                (WSSPolicy) policy1.get(i), (WSSPolicy) policy2
0366:                                        .get(i))) {
0367:                            return false;
0368:                        }
0369:                    }
0370:                }
0371:                return true;
0372:            }
0373:
0374:            public void modifyMessagePolicy(MessagePolicy msgPolicy) {
0375:                Iterator it = msgPolicy.iterator();
0376:                HashMap<String, String> map = new HashMap<String, String>();
0377:                while (it.hasNext()) {
0378:                    Object obj = it.next();
0379:                    if (obj instanceof  WSSPolicy) {
0380:
0381:                        WSSPolicy pol = (WSSPolicy) obj;
0382:
0383:                        if (PolicyTypeUtil.AUTH_POLICY_TYPE.equals(pol
0384:                                .getType())) {
0385:                            pol = (WSSPolicy) pol.getFeatureBinding();
0386:                        }
0387:                        if (pol.getUUID() != null) {
0388:                            map.put(pol.getUUID(), pol.getType());
0389:                            pol.setUUID(pol.getType());
0390:                        }
0391:
0392:                        if (PolicyTypeUtil.signaturePolicy(pol)) {
0393:                            SignaturePolicy sigPolicy = (SignaturePolicy) pol;
0394:                            ArrayList<SignatureTarget> targetList = ((SignaturePolicy.FeatureBinding) pol
0395:                                    .getFeatureBinding()).getTargetBindings();
0396:                            for (SignatureTarget target : targetList) {
0397:                                if ("uri".equals(target.getType())
0398:                                        && map.get(target.getValue()) != null) {
0399:                                    target.setValue(map.get(target.getValue()));
0400:                                }
0401:                            }
0402:                        }
0403:
0404:                        if (PolicyTypeUtil.encryptionPolicy(pol)) {
0405:                            EncryptionPolicy encPolicy = (EncryptionPolicy) pol;
0406:                            ArrayList<EncryptionTarget> targetList = ((EncryptionPolicy.FeatureBinding) pol
0407:                                    .getFeatureBinding()).getTargetBindings();
0408:                            for (EncryptionTarget target : targetList) {
0409:                                if ("uri".equals(target.getType())
0410:                                        && map.get(target.getValue()) != null) {
0411:                                    target.setValue(map.get(target.getValue()));
0412:                                }
0413:                            }
0414:                        }
0415:                    }
0416:                }
0417:            }
0418:
0419:            public List<SignatureTarget> createSignatureTargetEndorsingSignature(
0420:                    boolean contentonlyflag) {
0421:                List<String> targetType = new ArrayList<String>();
0422:                targetType.add("uri");
0423:
0424:                List<String> targetValue = new ArrayList<String>();
0425:                targetValue.add("#Sign");
0426:
0427:                List<Boolean> contentOnly = new ArrayList<Boolean>();
0428:                contentOnly.add(contentonlyflag);
0429:
0430:                List<SignatureTarget.Transform> tl1 = new ArrayList<SignatureTarget.Transform>();
0431:                List<List<SignatureTarget.Transform>> tl = new ArrayList<List<SignatureTarget.Transform>>();
0432:
0433:                tl.add(tl1);
0434:
0435:                List<SignatureTarget> sigTargetList = createSignatureTargetList(
0436:                        targetType, targetValue, contentOnly, tl);
0437:
0438:                return sigTargetList;
0439:            }
0440:
0441:            public List<SignatureTarget> createSignatureTargetBody(
0442:                    boolean contentonlyflag) {
0443:                List<String> targetType = new ArrayList<String>();
0444:                targetType.add("qname");
0445:
0446:                List<String> targetValue = new ArrayList<String>();
0447:                targetValue.add(Target.BODY);
0448:
0449:                List<Boolean> contentOnly = new ArrayList<Boolean>();
0450:                contentOnly.add(contentonlyflag);
0451:
0452:                List<SignatureTarget.Transform> tl1 = new ArrayList<SignatureTarget.Transform>();
0453:                List<List<SignatureTarget.Transform>> tl = new ArrayList<List<SignatureTarget.Transform>>();
0454:
0455:                tl.add(tl1);
0456:
0457:                List<SignatureTarget> sigTargetList = createSignatureTargetList(
0458:                        targetType, targetValue, contentOnly, tl);
0459:
0460:                return sigTargetList;
0461:            }
0462:
0463:            public List<SignatureTarget> createSignatureTargetBodyAllHeader(
0464:                    boolean contentonlyflag) {
0465:                List<String> targetType = new ArrayList<String>();
0466:                targetType.add("qname");
0467:                targetType.add("qname");
0468:                targetType.add("qname");
0469:                targetType.add("qname");
0470:                targetType.add("qname");
0471:                targetType.add("qname");
0472:                targetType.add("qname");
0473:                targetType.add("qname");
0474:
0475:                List<String> targetValue = new ArrayList<String>();
0476:                targetValue.add(Target.BODY);
0477:                //targetValue.add(Target.ALL_MESSAGE_HEADERS);
0478:                targetValue
0479:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}ReplyTo");
0480:                targetValue
0481:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}From");
0482:                targetValue
0483:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}To");
0484:                targetValue
0485:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}Action");
0486:                targetValue
0487:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}RelatesTo");
0488:                targetValue
0489:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}MessageID");
0490:                targetValue
0491:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}FaultTo");
0492:
0493:                List<Boolean> contentOnly = new ArrayList<Boolean>();
0494:                contentOnly.add(contentonlyflag);
0495:                contentOnly.add(contentonlyflag);
0496:                contentOnly.add(contentonlyflag);
0497:                contentOnly.add(contentonlyflag);
0498:                contentOnly.add(contentonlyflag);
0499:                contentOnly.add(contentonlyflag);
0500:                contentOnly.add(contentonlyflag);
0501:                contentOnly.add(contentonlyflag);
0502:
0503:                List<SignatureTarget.Transform> tl1 = new ArrayList<SignatureTarget.Transform>();
0504:                List<SignatureTarget.Transform> tl2 = new ArrayList<SignatureTarget.Transform>();
0505:                List<SignatureTarget.Transform> tl3 = new ArrayList<SignatureTarget.Transform>();
0506:                List<SignatureTarget.Transform> tl4 = new ArrayList<SignatureTarget.Transform>();
0507:                List<SignatureTarget.Transform> tl5 = new ArrayList<SignatureTarget.Transform>();
0508:                List<SignatureTarget.Transform> tl6 = new ArrayList<SignatureTarget.Transform>();
0509:                List<SignatureTarget.Transform> tl7 = new ArrayList<SignatureTarget.Transform>();
0510:                List<SignatureTarget.Transform> tl8 = new ArrayList<SignatureTarget.Transform>();
0511:
0512:                List<List<SignatureTarget.Transform>> tl = new ArrayList<List<SignatureTarget.Transform>>();
0513:
0514:                tl.add(tl1);
0515:                tl.add(tl2);
0516:                tl.add(tl3);
0517:                tl.add(tl4);
0518:                tl.add(tl5);
0519:                tl.add(tl6);
0520:                tl.add(tl7);
0521:                tl.add(tl8);
0522:
0523:                List<SignatureTarget> sigTargetList = createSignatureTargetList(
0524:                        targetType, targetValue, contentOnly, tl);
0525:
0526:                return sigTargetList;
0527:            }
0528:
0529:            public List<EncryptionTarget> createEncryptionTargetBody(
0530:                    boolean contentonlyflag) {
0531:                List<String> targetType = new ArrayList<String>();
0532:                targetType.add("qname");
0533:
0534:                List<String> targetValue = new ArrayList<String>();
0535:                targetValue.add(Target.BODY);
0536:
0537:                List<Boolean> contentOnly = new ArrayList<Boolean>();
0538:                contentOnly.add(contentonlyflag);
0539:
0540:                List<EncryptionTarget.Transform> tl1 = new ArrayList<EncryptionTarget.Transform>();
0541:                List<List<EncryptionTarget.Transform>> tl = new ArrayList<List<EncryptionTarget.Transform>>();
0542:
0543:                tl.add(tl1);
0544:
0545:                List<EncryptionTarget> encTargetList = createEncryptionTargetList(
0546:                        targetType, targetValue, contentOnly, tl);
0547:
0548:                return encTargetList;
0549:            }
0550:
0551:            public List<EncryptionTarget> createEncryptionTargetBodyAndUT(
0552:                    boolean contentonlyflag) {
0553:                List<String> targetType = new ArrayList<String>();
0554:                targetType.add("qname");
0555:                targetType.add("uri");
0556:
0557:                List<String> targetValue = new ArrayList<String>();
0558:                targetValue.add(Target.BODY);
0559:                targetValue.add("UsernameTokenBinding");
0560:
0561:                List<Boolean> contentOnly = new ArrayList<Boolean>();
0562:                contentOnly.add(contentonlyflag);
0563:                contentOnly.add(contentonlyflag);
0564:
0565:                List<EncryptionTarget.Transform> tl1 = new ArrayList<EncryptionTarget.Transform>();
0566:                List<EncryptionTarget.Transform> tl2 = new ArrayList<EncryptionTarget.Transform>();
0567:                List<List<EncryptionTarget.Transform>> tl = new ArrayList<List<EncryptionTarget.Transform>>();
0568:
0569:                tl.add(tl1);
0570:                tl.add(tl2);
0571:
0572:                List<EncryptionTarget> encTargetList = createEncryptionTargetList(
0573:                        targetType, targetValue, contentOnly, tl);
0574:
0575:                return encTargetList;
0576:            }
0577:
0578:            public List<EncryptionTarget> createEncryptionTargetList(
0579:                    List<String> targetType, List<String> targetValue,
0580:                    List<Boolean> contentOnly,
0581:                    List<List<EncryptionTarget.Transform>> transformList) {
0582:                int size = targetType.size();
0583:                List<EncryptionTarget> targetList = new ArrayList<EncryptionTarget>();
0584:                for (int i = 0; i < size; i++) {
0585:                    EncryptionTarget t1 = new EncryptionTarget();
0586:                    t1.setContentOnly(contentOnly.get(i));
0587:                    t1.setType(targetType.get(i));
0588:                    t1.setValue(targetValue.get(i));
0589:
0590:                    List<EncryptionTarget.Transform> transList = transformList
0591:                            .get(i);
0592:                    for (int j = 0; j < transList.size(); j++) {
0593:                        t1.addCipherReferenceTransform(transList.get(j));
0594:                    }
0595:                    targetList.add(t1);
0596:                }
0597:                return targetList;
0598:            }
0599:
0600:            public List<EncryptionTarget> createEncryptionTargetBodyAllHeader(
0601:                    boolean contentonlyflag) {
0602:                List<String> targetType = new ArrayList<String>();
0603:                targetType.add("qname");
0604:                targetType.add("qname");
0605:
0606:                List<String> targetValue = new ArrayList<String>();
0607:                targetValue.add(Target.BODY);
0608:                targetValue.add(Target.ALL_MESSAGE_HEADERS);
0609:
0610:                List<Boolean> contentOnly = new ArrayList<Boolean>();
0611:                contentOnly.add(contentonlyflag);
0612:                contentOnly.add(contentonlyflag);
0613:
0614:                List<EncryptionTarget.Transform> tl1 = new ArrayList<EncryptionTarget.Transform>();
0615:                List<EncryptionTarget.Transform> tl2 = new ArrayList<EncryptionTarget.Transform>();
0616:                List<List<EncryptionTarget.Transform>> tl = new ArrayList<List<EncryptionTarget.Transform>>();
0617:
0618:                tl.add(tl1);
0619:                tl.add(tl2);
0620:
0621:                List<EncryptionTarget> encTargetList = createEncryptionTargetList(
0622:                        targetType, targetValue, contentOnly, tl);
0623:
0624:                return encTargetList;
0625:            }
0626:
0627:            public List<SignatureTarget> createSignatureTargetBodySelectedHeader(
0628:                    List<String> targetqname, boolean contentonlyflag) {
0629:                List<String> targetType = new ArrayList<String>();
0630:                targetType.add("qname");
0631:                for (String qname : targetqname) {
0632:                    targetType.add("qname");
0633:                }
0634:
0635:                List<String> targetValue = new ArrayList<String>();
0636:                targetValue.add(Target.BODY);
0637:                for (String qname : targetqname) {
0638:                    targetValue.add(qname);
0639:                }
0640:
0641:                List<Boolean> contentOnly = new ArrayList<Boolean>();
0642:                contentOnly.add(contentonlyflag);
0643:                for (String qname : targetqname) {
0644:                    contentOnly.add(contentonlyflag);
0645:                }
0646:
0647:                List<SignatureTarget.Transform> tl1 = new ArrayList<SignatureTarget.Transform>();
0648:                List<List<SignatureTarget.Transform>> tl = new ArrayList<List<SignatureTarget.Transform>>();
0649:
0650:                tl.add(tl1);
0651:                for (String qname : targetqname) {
0652:                    List<SignatureTarget.Transform> tl2 = new ArrayList<SignatureTarget.Transform>();
0653:                    tl.add(tl2);
0654:                }
0655:
0656:                List<SignatureTarget> sigTargetList = createSignatureTargetList(
0657:                        targetType, targetValue, contentOnly, tl);
0658:
0659:                return sigTargetList;
0660:            }
0661:
0662:            public List<EncryptionTarget> createEncryptionTargetBodySelectedHeader(
0663:                    List<String> targetqname, boolean contentonlyflag,
0664:                    List<String> targetType) {
0665:                //List<String> targetType = new ArrayList<String>();
0666:                //targetType.add("qname");
0667:                //for ( String qname : targetqname ) {
0668:                //    targetType.add("qname");
0669:                //}
0670:
0671:                List<String> targetValue = new ArrayList<String>();
0672:                targetValue.add(Target.BODY);
0673:                for (String qname : targetqname) {
0674:                    targetValue.add(qname);
0675:                }
0676:
0677:                List<Boolean> contentOnly = new ArrayList<Boolean>();
0678:                contentOnly.add(contentonlyflag);
0679:                for (String qname : targetqname) {
0680:                    contentOnly.add(contentonlyflag);
0681:                }
0682:
0683:                List<EncryptionTarget.Transform> tl1 = new ArrayList<EncryptionTarget.Transform>();
0684:                List<List<EncryptionTarget.Transform>> tl = new ArrayList<List<EncryptionTarget.Transform>>();
0685:
0686:                tl.add(tl1);
0687:                for (String qname : targetqname) {
0688:                    List<EncryptionTarget.Transform> tl2 = new ArrayList<EncryptionTarget.Transform>();
0689:                    tl.add(tl2);
0690:                }
0691:
0692:                List<EncryptionTarget> encTargetList = createEncryptionTargetList(
0693:                        targetType, targetValue, contentOnly, tl);
0694:
0695:                return encTargetList;
0696:            }
0697:
0698:            public List<String> createAddressingHeaderQNameList() {
0699:                List<String> l = new ArrayList<String>();
0700:                l.add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}To");
0701:                l.add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}From");
0702:                l
0703:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}FaultTo");
0704:                l
0705:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}ReplyTo");
0706:                l
0707:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}MessageID");
0708:                l
0709:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}RelatesTo");
0710:                l
0711:                        .add("{http://schemas.xmlsoap.org/ws/2004/08/addressing}Action");
0712:                return l;
0713:
0714:            }
0715:
0716:            //Comparing two message policies
0717:            public boolean compileMessagePolicies(MessagePolicy pol1,
0718:                    MessagePolicy pol2) throws Exception {
0719:                if (pol1.getType() != pol2.getType()) {
0720:                    return false;
0721:                }
0722:                boolean asrt = true;
0723:                ArrayList p1 = pol1.getPrimaryPolicies();
0724:                ArrayList p2 = pol2.getPrimaryPolicies();
0725:
0726:                if (p1.size() != p2.size()) {
0727:                    return false;
0728:                }
0729:
0730:                for (int i = 0; i < p1.size(); i++) {
0731:                    WSSPolicy wp1 = (WSSPolicy) p1.get(i);
0732:                    WSSPolicy wp2 = (WSSPolicy) p2.get(i);
0733:                    if (wp1.getType() != wp2.getType()) {
0734:                        return false;
0735:                    } else {
0736:                        if (PolicyTypeUtil.signaturePolicy(wp1)) {
0737:                            asrt = asrt && compareSignaturePolicy(wp1, wp2);
0738:                        } else if (PolicyTypeUtil.encryptionPolicy(wp1)) {
0739:                            asrt = asrt && compareEncryptionPolicy(wp1, wp2);
0740:                        }
0741:                    }
0742:
0743:                }
0744:
0745:                return asrt;
0746:            }
0747:
0748:            public boolean compareSignaturePolicy(WSSPolicy wp1, WSSPolicy wp2)
0749:                    throws Exception {
0750:                SignaturePolicy sp1 = (SignaturePolicy) wp1;
0751:                SignaturePolicy sp2 = (SignaturePolicy) wp2;
0752:                if (sp1.getKeyBinding().getType() != sp2.getKeyBinding()
0753:                        .getType()) {
0754:                    return false;
0755:                }
0756:
0757:                //Verify targets
0758:                SignaturePolicy.FeatureBinding f1 = (SignaturePolicy.FeatureBinding) sp1
0759:                        .getFeatureBinding();
0760:                List<Target> t1 = f1.getTargetBindings();
0761:
0762:                SignaturePolicy.FeatureBinding f2 = (SignaturePolicy.FeatureBinding) sp2
0763:                        .getFeatureBinding();
0764:                List<Target> t2 = f2.getTargetBindings();
0765:
0766:                if (t1.size() != t2.size()) {
0767:                    System.err.println("Expected number of Targets" + t1.size()
0768:                            + " Got " + t2.size());
0769:                    throw new Exception(
0770:                            "Number of targets in the signature policy did not match");
0771:                }
0772:
0773:                for (int i = 0; i < t1.size(); i++) {
0774:                    Target s1 = (Target) t1.get(i);
0775:                    Target s2 = (Target) t2.get(i);
0776:                    if (s1.getType() != s2.getType()) {
0777:                        System.err.println("Expected Target Type"
0778:                                + s1.getType() + " Got " + s2.getType());
0779:                        throw new Exception(
0780:                                "Target type in signature policy did not match");
0781:                    }
0782:
0783:                    //            if ( !s1.getValue().equals(s2.getValue() )) {
0784:                    //                System.err.println("Expected Target Value"+s1.getValue()+" Got "+s2.getValue());
0785:                    //                throw new Exception("Target Value in signature policydid not match");
0786:                    //            }
0787:                }
0788:
0789:                return true;
0790:            }
0791:
0792:            public boolean compareEncryptionPolicy(WSSPolicy wp1, WSSPolicy wp2)
0793:                    throws Exception {
0794:                EncryptionPolicy sp1 = (EncryptionPolicy) wp1;
0795:                EncryptionPolicy sp2 = (EncryptionPolicy) wp2;
0796:                if (sp1.getKeyBinding().getType() != sp2.getKeyBinding()
0797:                        .getType()) {
0798:                    return false;
0799:                }
0800:
0801:                //Verify targets
0802:                EncryptionPolicy.FeatureBinding f1 = (EncryptionPolicy.FeatureBinding) sp1
0803:                        .getFeatureBinding();
0804:                List<Target> t1 = f1.getTargetBindings();
0805:
0806:                EncryptionPolicy.FeatureBinding f2 = (EncryptionPolicy.FeatureBinding) sp2
0807:                        .getFeatureBinding();
0808:                List<Target> t2 = f2.getTargetBindings();
0809:
0810:                if (t1.size() != t2.size()) {
0811:                    System.err.println("Expected number of Targets" + t1.size()
0812:                            + " Got " + t2.size());
0813:                    throw new Exception(
0814:                            "Number of targets in the Encryption policy did not match");
0815:                }
0816:
0817:                for (int i = 0; i < t1.size(); i++) {
0818:                    Target s1 = (Target) t1.get(i);
0819:                    Target s2 = (Target) t2.get(i);
0820:                    if (s1.getType() != s2.getType()) {
0821:                        System.err.println("Expected Target Type"
0822:                                + s1.getType() + " Got " + s2.getType());
0823:                        throw new Exception(
0824:                                "Target type in encryption policy did not match");
0825:                    }
0826:
0827:                    if (s1.getValue() != s2.getValue()) {
0828:                        System.err.println("Expected Target Value"
0829:                                + s1.getValue() + " Got " + s2.getValue());
0830:                        throw new Exception(
0831:                                "Target Value in encryption policy did not match");
0832:                    }
0833:                }
0834:
0835:                return true;
0836:            }
0837:
0838:            public MessagePolicy executeTest(String fileName, boolean isServer,
0839:                    boolean isIncoming) throws Exception {
0840:                //        QName serviceName = new QName("PingService");
0841:                //        QName portName = new QName("Port");
0842:                //        QName operationName = new QName("Ping");
0843:                //        QName inputName = new QName("PingRequest");
0844:                //        QName outputName = new QName("PingResponse");
0845:                //        WSPolicyBuilder builder = WSPolicyBuilder.getBuilder();
0846:                //        WSPolicyFromXmlHandler handler = null;
0847:
0848:                PolicyMap map = null;
0849:                ClassLoader cl = Thread.currentThread().getContextClassLoader();
0850:                String wsdlFile = fileName;
0851:                URL inUrl = null;
0852:                if (cl == null) {
0853:                    inUrl = ClassLoader.getSystemResource(wsdlFile);
0854:                } else {
0855:                    inUrl = cl.getResource(wsdlFile);
0856:                }
0857:                //WSDLModel model = PolicyConfigParser.parse(buffer);
0858:                map = PolicyConfigParser.parse(inUrl, false);
0859:
0860:                //        QName serviceName = new QName(UUID.randomUUID().toString());
0861:                //        QName portName = new QName(UUID.randomUUID().toString());
0862:                //        QName operationName = new QName(UUID.randomUUID().toString());
0863:                //        QName inputName = new QName(UUID.randomUUID().toString());
0864:                //        QName outputName = new QName(UUID.randomUUID().toString());
0865:                //
0866:                //
0867:                //        int count = 0;
0868:                //        for ( String file : policies) {
0869:                //            if ( count == 0 ) {
0870:                //                handler = new WSPolicyFromXmlHandler(file, null, serviceName, portName);
0871:                //                builder.registerHandler(handler);
0872:                //            } else if ( count == 1 ) {
0873:                //                handler = new WSPolicyFromXmlHandler(file ,WSPolicyFromXmlHandler.Scope.InputMessageScope, null, serviceName, portName,operationName,inputName,outputName);
0874:                //                builder.registerHandler(handler);
0875:                //            } else if ( count == 2 ) {
0876:                //                handler = new WSPolicyFromXmlHandler(file, WSPolicyFromXmlHandler.Scope.OutputMessageScope,null, serviceName, portName,operationName,inputName,outputName);
0877:                //                builder.registerHandler(handler);
0878:                //            }
0879:                //            count++;
0880:                //        }
0881:                //
0882:                //        PolicyMap map = builder.create();
0883:                //        PolicyMapKey endpointKey = map.createWsdlEndpointScopeKey(serviceName, portName);
0884:                //        One key should be enough , just testing.
0885:                //        PolicyMapKey inputKey =map.createWsdlOperationScopeKey(serviceName, portName,operationName);
0886:                //        PolicyMapKey outputKey = map.createWsdlOperationScopeKey(serviceName, portName,operationName);
0887:
0888:                Collection c = null;
0889:                Iterator itr = null;
0890:
0891:                c = map.getAllEndpointScopeKeys();
0892:                itr = c.iterator();
0893:                PolicyMapKey endpointKey = null;
0894:                while (itr.hasNext()) {
0895:                    endpointKey = (PolicyMapKey) itr.next();
0896:                }
0897:
0898:                c = map.getAllInputMessageScopeKeys();
0899:                itr = c.iterator();
0900:                PolicyMapKey inputKey = null;
0901:                while (itr.hasNext()) {
0902:                    inputKey = (PolicyMapKey) itr.next();
0903:                }
0904:
0905:                c = map.getAllOutputMessageScopeKeys();
0906:                itr = c.iterator();
0907:                PolicyMapKey outputKey = null;
0908:                while (itr.hasNext()) {
0909:                    outputKey = (PolicyMapKey) itr.next();
0910:                }
0911:
0912:                Policy ipEP = null;
0913:                Policy opEP = null;
0914:                Policy endpointEP = null;
0915:
0916:                endpointEP = (Policy) map
0917:                        .getEndpointEffectivePolicy(endpointKey);
0918:                ipEP = (Policy) map.getInputMessageEffectivePolicy(inputKey);
0919:                opEP = (Policy) map.getOutputMessageEffectivePolicy(outputKey);
0920:
0921:                ArrayList<Policy> pl = new ArrayList<Policy>();
0922:
0923:                if (endpointEP != null)
0924:                    pl.add(endpointEP);
0925:
0926:                if (ipEP != null)
0927:                    pl.add(ipEP);
0928:
0929:                if (opEP != null)
0930:                    pl.add(opEP);
0931:
0932:                //Start Processing client side policy
0933:                PolicyMerger pm = PolicyMerger.getMerger();
0934:                Policy ep = pm.merge(pl);
0935:
0936:                XWSSPolicyGenerator generator = new XWSSPolicyGenerator(ep,
0937:                        isServer, isIncoming);
0938:                generator.process();
0939:                MessagePolicy pol = generator.getXWSSPolicy();
0940:                System.out.println("\n\nGenerated Policies ........");
0941:
0942:                for (int i = 0; i < pol.size(); i++) {
0943:                    System.out.println(pol.get(i).getType());
0944:                }
0945:
0946:                return pol;
0947:
0948:                //        System.out.println("\n\nExpected Policies ........");
0949:                //        for ( int i=0; i< expectedPolicy.size(); i++ ) {
0950:                //            System.out.println(expectedPolicy.get(i).getType());
0951:                //        }
0952:                //        System.out.println("Verification status : " + comparePolicies(expectedPolicy,pol) );
0953:                //        return comparePolicies(expectedPolicy,pol);
0954:
0955:            }
0956:
0957:            public void execute(String filename, boolean isServer,
0958:                    boolean isIncoming, int scenario) throws Exception {
0959:                MessagePolicy generated = executeTest(filename, isServer,
0960:                        isIncoming);
0961:                modifyMessagePolicy(generated);
0962:                print(generated);
0963:                MessagePolicy expectedPolicy;
0964:
0965:                if (!isServer && isIncoming) {
0966:                    expectedPolicy = createClientIncomingPolicy(scenario);
0967:                } else if (!isServer && !isIncoming) {
0968:                    expectedPolicy = createClientOutgoingPolicy(scenario);
0969:                } else if (isServer && isIncoming) {
0970:                    expectedPolicy = createServerIncomingPolicy(scenario);
0971:                } else {
0972:                    expectedPolicy = createServerOutgoingPolicy(scenario);
0973:                }
0974:                System.out.println("\nExpectedPolicy");
0975:
0976:                print(expectedPolicy);
0977:                compare(expectedPolicy, generated);
0978:            }
0979:
0980:            public void print(MessagePolicy generated) throws Exception {
0981:                for (int i = 0; i < generated.size(); i++) {
0982:                    System.out.println("Type : " + generated.get(i).getType());
0983:
0984:                    if (PolicyTypeUtil.signaturePolicy(generated.get(i))) {
0985:                        WSSPolicy p = (WSSPolicy) generated.get(i);
0986:                        System.out.println("KeyBinding : "
0987:                                + p.getKeyBinding().getType());
0988:
0989:                        SignaturePolicy.FeatureBinding f1 = (SignaturePolicy.FeatureBinding) p
0990:                                .getFeatureBinding();
0991:                        List<Target> t1 = f1.getTargetBindings();
0992:                        System.out.println("No of Targets : " + t1.size());
0993:                        for (Target t : t1) {
0994:                            System.out.println(t.getType() + "  "
0995:                                    + t.getValue());
0996:                        }
0997:                    }
0998:
0999:                    if (PolicyTypeUtil.encryptionPolicy(generated.get(i))) {
1000:                        WSSPolicy p = (WSSPolicy) generated.get(i);
1001:                        System.out.println("KeyBinding : "
1002:                                + p.getKeyBinding().getType());
1003:
1004:                        EncryptionPolicy.FeatureBinding f1 = (EncryptionPolicy.FeatureBinding) p
1005:                                .getFeatureBinding();
1006:                        List<Target> t1 = f1.getTargetBindings();
1007:                        System.out.println("No of Targets : " + t1.size());
1008:                        for (Target t : t1) {
1009:                            System.out.println(t.getType() + "  "
1010:                                    + t.getValue());
1011:                        }
1012:                    }
1013:                }
1014:            }
1015:
1016:            public void compare(MessagePolicy expectedPolicy,
1017:                    MessagePolicy generated) throws Exception {
1018:                System.out.println("Comparing two message policies ...");
1019:                if (!comparePolicies(expectedPolicy, generated)) {
1020:                    throw new Exception(
1021:                            "Expected and Generated policy did not match");
1022:                }
1023:            }
1024:
1025:            public List<String> getList(String pattern) {
1026:                //G:\\optimizedpath\\tango\\jaxrpc-sec\\Tango\\tests\\data\\
1027:                List<String> l = new ArrayList<String>();
1028:                l.add(pattern + ".xml");
1029:                l.add(pattern + "-input.xml");
1030:                l.add(pattern + "-output.xml");
1031:                return l;
1032:            }
1033:
1034:            private MessagePolicy reverse(MessagePolicy tmpPolicy)
1035:                    throws Exception {
1036:                MessagePolicy msgPolicy = new MessagePolicy();
1037:                boolean foundSigConf = false;
1038:                boolean foundts = false;
1039:                SecurityPolicy sigConf = null;
1040:                SecurityPolicy tpolicy = null;
1041:                for (int i = 0; i < tmpPolicy.size(); i++) {
1042:                    if (tmpPolicy.get(i).getType().equals(
1043:                            PolicyTypeUtil.SIGNATURE_CONFIRMATION_POLICY_TYPE)) {
1044:                        foundSigConf = true;
1045:                        sigConf = tmpPolicy.get(i);
1046:                    } else if (tmpPolicy.get(i).getType().equals(
1047:                            PolicyTypeUtil.TIMESTAMP_POLICY_TYPE)) {
1048:                        foundts = true;
1049:                        tpolicy = tmpPolicy.get(i);
1050:                    } else {
1051:                        msgPolicy.prepend(tmpPolicy.get(i));
1052:                    }
1053:                }
1054:                if (foundSigConf) {
1055:                    msgPolicy.append(sigConf);
1056:                }
1057:                if (foundts) {
1058:                    msgPolicy.prepend(tpolicy);
1059:                }
1060:                return msgPolicy;
1061:            }
1062:
1063:            public MessagePolicy createClientIncomingPolicy(int scenario)
1064:                    throws Exception {
1065:                switch (scenario) {
1066:                case 1:
1067:                    return createScenario1ClientIncoming();
1068:                case 2:
1069:                    return createScenario2ClientIncoming();
1070:                case 3:
1071:                    return createScenario3ClientIncoming();
1072:                case 4:
1073:                    return createScenario4ClientIncoming();
1074:                case 5:
1075:                    return createScenario5ClientIncoming();
1076:                case 6:
1077:                    return createScenario6ClientIncoming();
1078:                case 7:
1079:                    return createScenario7ClientIncoming();
1080:                case 8:
1081:                    return createScenario8ClientIncoming();
1082:                case 9:
1083:                    //return createScenario9ClientIncoming();
1084:                case 10:
1085:                    return createScenario10ClientIncoming();
1086:                case 11:
1087:                    return createScenario11ClientIncoming();
1088:                case 21:
1089:                    return createScenario21ClientIncoming();
1090:                case 22:
1091:                    return createScenario22ClientIncoming();
1092:                case 23:
1093:                    return createScenario23ClientIncoming();
1094:                case 24:
1095:                    return createScenario24ClientIncoming();
1096:                }
1097:                return null;
1098:            }
1099:
1100:            public MessagePolicy createClientOutgoingPolicy(int scenario)
1101:                    throws Exception {
1102:                switch (scenario) {
1103:                case 1:
1104:                    return createScenario1ClientOutgoing();
1105:                case 2:
1106:                    return createScenario2ClientOutgoing();
1107:                case 3:
1108:                    return createScenario3ClientOutgoing();
1109:                case 4:
1110:                    return createScenario4ClientOutgoing();
1111:                case 5:
1112:                    return createScenario5ClientOutgoing();
1113:                case 6:
1114:                    return createScenario6ClientOutgoing();
1115:                case 7:
1116:                    return createScenario7ClientOutgoing();
1117:                case 8:
1118:                    return createScenario8ClientOutgoing();
1119:                case 9:
1120:                    //return createScenario9ClientOutgoing();
1121:                case 10:
1122:                    return createScenario10ClientOutgoing();
1123:                case 11:
1124:                    return createScenario11ClientOutgoing();
1125:                case 21:
1126:                    return createScenario21ClientOutgoing();
1127:                case 22:
1128:                    return createScenario22ClientOutgoing();
1129:                case 23:
1130:                    return createScenario23ClientOutgoing();
1131:                case 24:
1132:                    return createScenario24ClientOutgoing();
1133:                }
1134:                return null;
1135:            }
1136:
1137:            public MessagePolicy createServerIncomingPolicy(int scenario)
1138:                    throws Exception {
1139:                //
1140:
1141:                if (scenario == 5) {
1142:                    return createScenario5ServerIncoming();
1143:                }
1144:                if (scenario == 1) {
1145:                    return createScenario1ServerIncoming();
1146:                }
1147:                if (scenario == 6) {
1148:                    return createScenario6ServerIncoming();
1149:                }
1150:                if (scenario == 7) {
1151:                    return createScenario7ServerIncoming();
1152:                }
1153:                return reverse(createClientOutgoingPolicy(scenario));
1154:
1155:            }
1156:
1157:            public MessagePolicy createServerOutgoingPolicy(int scenario)
1158:                    throws Exception {
1159:                if (scenario == 6) {
1160:                    return createScenario6ServerOutgoing();
1161:                }
1162:                if (scenario == 7) {
1163:                    return createScenario7ServerOutgoing();
1164:                }
1165:                return reverse(createClientIncomingPolicy(scenario));
1166:            }
1167:
1168:            //UserNameOverTransport_IPingService_policy
1169:            public MessagePolicy createScenario1ClientOutgoing()
1170:                    throws Exception {
1171:                MessagePolicy msgPolicy = new MessagePolicy();
1172:
1173:                AuthenticationTokenPolicy at = createUTPolicy("testuser", null,
1174:                        null, false);
1175:                at.setUUID("UsernameTokenBinding");
1176:                msgPolicy.append(at);
1177:                TimestampPolicy tp = new TimestampPolicy();
1178:                msgPolicy.append(tp);
1179:
1180:                return msgPolicy;
1181:            }
1182:
1183:            public MessagePolicy createScenario1ClientIncoming()
1184:                    throws Exception {
1185:                MessagePolicy msgPolicy = new MessagePolicy();
1186:                TimestampPolicy tp = new TimestampPolicy();
1187:                msgPolicy.append(tp);
1188:                return msgPolicy;
1189:            }
1190:
1191:            public MessagePolicy createScenario1ServerIncoming()
1192:                    throws Exception {
1193:                MessagePolicy msgPolicy = new MessagePolicy();
1194:
1195:                AuthenticationTokenPolicy at = createUTPolicy("testuser", null,
1196:                        null, false);
1197:                at.setUUID("UsernameTokenBinding");
1198:                msgPolicy.append(at);
1199:
1200:                TimestampPolicy tp = new TimestampPolicy();
1201:                msgPolicy.append(tp);
1202:
1203:                return msgPolicy;
1204:            }
1205:
1206:            //MutualCertificate10SignEncrypt_IPingService_policy
1207:            public MessagePolicy createScenario2ClientOutgoing()
1208:                    throws Exception {
1209:                MessagePolicy msgPolicy = new MessagePolicy();
1210:                TimestampPolicy tp = new TimestampPolicy();
1211:                msgPolicy.append(tp);
1212:
1213:                List<SignatureTarget> sigTargetList = createSignatureTargetBody(true);
1214:
1215:                //       AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1216:                //      suite.setType(AlgorithmSuiteValue.Basic256);
1217:
1218:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1219:                addSignKeyBinding(sigPolicy, "x509", "Direct");
1220:                msgPolicy.append(sigPolicy);
1221:                addToSPTList(tp, sigPolicy);
1222:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1223:
1224:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1225:                addEncryptKeyBinding(encPolicy, "x509", "Identifier");
1226:                msgPolicy.append(encPolicy);
1227:
1228:                return msgPolicy;
1229:            }
1230:
1231:            public MessagePolicy createScenario2ClientIncoming()
1232:                    throws Exception {
1233:                MessagePolicy msgPolicy = new MessagePolicy();
1234:
1235:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1236:
1237:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1238:                addEncryptKeyBinding(encPolicy, "x509", "Identifier");
1239:                msgPolicy.append(encPolicy);
1240:
1241:                TimestampPolicy tp = new TimestampPolicy();
1242:                msgPolicy.append(tp);
1243:
1244:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1245:                //        suite.setType(AlgorithmSuiteValue.Basic256);
1246:
1247:                List<SignatureTarget> sigTargetList = createSignatureTargetBody(true);
1248:
1249:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1250:                addSignKeyBinding(sigPolicy, "x509", "Direct");
1251:                msgPolicy.append(sigPolicy);
1252:                addToSPTList(tp, sigPolicy);
1253:
1254:                return msgPolicy;
1255:
1256:            }
1257:
1258:            //MutualCertificate10SignEncryptRsa15TripleDes_IPingService_policy
1259:            public MessagePolicy createScenario3ClientOutgoing()
1260:                    throws Exception {
1261:                MessagePolicy msgPolicy = new MessagePolicy();
1262:                TimestampPolicy tp = new TimestampPolicy();
1263:                msgPolicy.append(tp);
1264:
1265:                List<SignatureTarget> sigTargetList = createSignatureTargetBody(true);
1266:
1267:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1268:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1269:
1270:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1271:                addSignKeyBinding(sigPolicy, "x509", "Direct");
1272:                msgPolicy.append(sigPolicy);
1273:                addToSPTList(tp, sigPolicy);
1274:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1275:
1276:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1277:                addEncryptKeyBinding(encPolicy, "x509", "Identifier");
1278:                msgPolicy.append(encPolicy);
1279:
1280:                return msgPolicy;
1281:            }
1282:
1283:            public MessagePolicy createScenario3ClientIncoming()
1284:                    throws Exception {
1285:                MessagePolicy msgPolicy = new MessagePolicy();
1286:
1287:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1288:
1289:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1290:                addEncryptKeyBinding(encPolicy, "x509", "Identifier");
1291:                msgPolicy.append(encPolicy);
1292:
1293:                TimestampPolicy tp = new TimestampPolicy();
1294:                msgPolicy.append(tp);
1295:
1296:                List<SignatureTarget> sigTargetList = createSignatureTargetBody(true);
1297:
1298:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1299:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1300:
1301:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1302:                addSignKeyBinding(sigPolicy, "x509", "Direct");
1303:                msgPolicy.append(sigPolicy);
1304:                addToSPTList(tp, sigPolicy);
1305:
1306:                return msgPolicy;
1307:            }
1308:
1309:            //MutualCertificate10Sign_IPingServiceSign_policy
1310:            public MessagePolicy createScenario4ClientOutgoing()
1311:                    throws Exception {
1312:                MessagePolicy msgPolicy = new MessagePolicy();
1313:                TimestampPolicy tp = new TimestampPolicy();
1314:                msgPolicy.append(tp);
1315:
1316:                List<SignatureTarget> sigTargetList = createSignatureTargetBody(true);
1317:
1318:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1319:                //        suite.setType(AlgorithmSuiteValue.Basic256);
1320:
1321:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1322:                addSignKeyBinding(sigPolicy, "x509", "Direct");
1323:                msgPolicy.append(sigPolicy);
1324:                addToSPTList(tp, sigPolicy);
1325:                return msgPolicy;
1326:            }
1327:
1328:            public MessagePolicy createScenario4ClientIncoming()
1329:                    throws Exception {
1330:                return reverse(createScenario4ClientOutgoing());
1331:            }
1332:
1333:            //UserNameForCertificateSignEncrypt_IPingService_policy
1334:            public MessagePolicy createScenario5ClientOutgoing()
1335:                    throws Exception {
1336:                MessagePolicy msgPolicy = new MessagePolicy();
1337:
1338:                AuthenticationTokenPolicy at = createUTPolicy("testuser", null,
1339:                        null, false);
1340:                at.setUUID("UsernameTokenBinding");
1341:                msgPolicy.append(at);
1342:
1343:                TimestampPolicy tp = new TimestampPolicy();
1344:                msgPolicy.append(tp);
1345:
1346:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1347:
1348:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1349:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1350:
1351:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1352:                addSignKeyBinding(sigPolicy, "derivedkey", "Thumbprint");
1353:                msgPolicy.append(sigPolicy);
1354:                addToSPTList(tp, sigPolicy);
1355:                addToSPTList(at, sigPolicy);
1356:                List<EncryptionTarget> encTargetList = createEncryptionTargetBodyAndUT(true);
1357:
1358:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1359:                addEncryptKeyBinding(encPolicy, "derivedkey", "Thumbprint");
1360:                msgPolicy.append(encPolicy);
1361:
1362:                return msgPolicy;
1363:            }
1364:
1365:            public MessagePolicy createScenario5ServerIncoming()
1366:                    throws Exception {
1367:                MessagePolicy msgPolicy = new MessagePolicy();
1368:
1369:                AuthenticationTokenPolicy at = createUTPolicy("testuser", null,
1370:                        null, false);
1371:                at.setUUID("UsernameTokenBinding");
1372:                msgPolicy.append(at);
1373:
1374:                TimestampPolicy tp = new TimestampPolicy();
1375:                msgPolicy.append(tp);
1376:
1377:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1378:
1379:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1380:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1381:
1382:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1383:                addSignKeyBinding(sigPolicy, "derivedkey", "Thumbprint");
1384:
1385:                addToSPTList(tp, sigPolicy);
1386:                addToSPTList(at, sigPolicy);
1387:                List<EncryptionTarget> encTargetList = createEncryptionTargetBodyAndUT(true);
1388:
1389:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1390:                addEncryptKeyBinding(encPolicy, "derivedkey", "Thumbprint");
1391:                msgPolicy.append(encPolicy);
1392:                msgPolicy.append(sigPolicy);
1393:
1394:                return msgPolicy;
1395:            }
1396:
1397:            public MessagePolicy createScenario5ClientIncoming()
1398:                    throws Exception {
1399:                MessagePolicy msgPolicy = new MessagePolicy();
1400:
1401:                TimestampPolicy tp = new TimestampPolicy();
1402:
1403:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1404:
1405:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1406:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1407:
1408:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1409:                addSignKeyBinding(sigPolicy, "derivedkey", "Thumbprint");
1410:
1411:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1412:
1413:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1414:                addEncryptKeyBinding(encPolicy, "derivedkey", "Thumbprint");
1415:
1416:                msgPolicy.append(encPolicy);
1417:                msgPolicy.append(tp);
1418:
1419:                msgPolicy.append(sigPolicy);
1420:                addToSPTList(tp, sigPolicy);
1421:
1422:                return msgPolicy;
1423:            }
1424:
1425:            //AnonymousForCertificateSignEncrypt_IPingService_policy
1426:            public MessagePolicy createScenario6ClientOutgoing()
1427:                    throws Exception {
1428:                MessagePolicy msgPolicy = new MessagePolicy();
1429:
1430:                SignatureConfirmationPolicy sigConf = new SignatureConfirmationPolicy();
1431:                msgPolicy.append(sigConf);
1432:
1433:                TimestampPolicy tp = new TimestampPolicy();
1434:                msgPolicy.append(tp);
1435:
1436:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1437:
1438:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1439:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1440:
1441:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1442:                addSignKeyBinding(sigPolicy, "derivedkey", "Thumbprint");
1443:                msgPolicy.append(sigPolicy);
1444:                addQTToSPTList(sigConf, sigPolicy);
1445:                addToSPTList(tp, sigPolicy);
1446:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1447:
1448:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1449:                addEncryptKeyBinding(encPolicy, "derivedkey", "Thumbprint");
1450:                msgPolicy.append(encPolicy);
1451:
1452:                return msgPolicy;
1453:            }
1454:
1455:            // if 5 then ????
1456:            public MessagePolicy createScenario6ClientIncoming()
1457:                    throws Exception {
1458:                MessagePolicy msgPolicy = new MessagePolicy();
1459:
1460:                SignatureConfirmationPolicy sigConf = new SignatureConfirmationPolicy();
1461:                msgPolicy.append(sigConf);
1462:
1463:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1464:
1465:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1466:                addEncryptKeyBinding(encPolicy, "derivedkey", "Thumbprint");
1467:                msgPolicy.append(encPolicy);
1468:
1469:                TimestampPolicy tp = new TimestampPolicy();
1470:                msgPolicy.append(tp);
1471:
1472:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1473:
1474:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1475:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1476:
1477:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1478:                addSignKeyBinding(sigPolicy, "derivedkey", "Thumbprint");
1479:                msgPolicy.append(sigPolicy);
1480:                addQTToSPTList(sigConf, sigPolicy);
1481:                addToSPTList(tp, sigPolicy);
1482:
1483:                return msgPolicy;
1484:            }
1485:
1486:            public MessagePolicy createScenario6ServerOutgoing()
1487:                    throws Exception {
1488:                MessagePolicy msgPolicy = new MessagePolicy();
1489:
1490:                SignatureConfirmationPolicy sigConf = new SignatureConfirmationPolicy();
1491:                msgPolicy.append(sigConf);
1492:
1493:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1494:
1495:                TimestampPolicy tp = new TimestampPolicy();
1496:                msgPolicy.append(tp);
1497:
1498:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1499:
1500:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1501:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1502:
1503:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1504:                addSignKeyBinding(sigPolicy, "derivedkey", "Thumbprint");
1505:                msgPolicy.append(sigPolicy);
1506:                addQTToSPTList(sigConf, sigPolicy);
1507:                addToSPTList(tp, sigPolicy);
1508:
1509:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1510:                addEncryptKeyBinding(encPolicy, "derivedkey", "Thumbprint");
1511:                msgPolicy.append(encPolicy);
1512:
1513:                return msgPolicy;
1514:            }
1515:
1516:            public MessagePolicy createScenario6ServerIncoming()
1517:                    throws Exception {
1518:                MessagePolicy msgPolicy = new MessagePolicy();
1519:
1520:                SignatureConfirmationPolicy sigConf = new SignatureConfirmationPolicy();
1521:                msgPolicy.append(sigConf);
1522:
1523:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1524:
1525:                TimestampPolicy tp = new TimestampPolicy();
1526:                msgPolicy.append(tp);
1527:
1528:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1529:
1530:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1531:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1532:
1533:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1534:                addEncryptKeyBinding(encPolicy, "derivedkey", "Thumbprint");
1535:                msgPolicy.append(encPolicy);
1536:
1537:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1538:                addSignKeyBinding(sigPolicy, "derivedkey", "Thumbprint");
1539:                msgPolicy.append(sigPolicy);
1540:                addQTToSPTList(sigConf, sigPolicy);
1541:                addToSPTList(tp, sigPolicy);
1542:
1543:                return msgPolicy;
1544:            }
1545:
1546:            //MutualCertificate11SignEncrypt_IPingService_policy
1547:            public MessagePolicy createScenario7ClientOutgoing()
1548:                    throws Exception {
1549:                MessagePolicy msgPolicy = new MessagePolicy();
1550:
1551:                SignatureConfirmationPolicy sigConf = new SignatureConfirmationPolicy();
1552:                msgPolicy.append(sigConf);
1553:
1554:                AuthenticationTokenPolicy at = createUTPolicy("testuser", null,
1555:                        null, false);
1556:                at.setUUID("UsernameTokenBinding");
1557:                msgPolicy.append(at);
1558:
1559:                TimestampPolicy tp = new TimestampPolicy();
1560:                msgPolicy.append(tp);
1561:
1562:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1563:
1564:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1565:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1566:
1567:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1568:                addSignKeyBinding(sigPolicy, "symmetric", "");
1569:                msgPolicy.append(sigPolicy);
1570:                addQTToSPTList(sigConf, sigPolicy);
1571:                addToSPTList(tp, sigPolicy);
1572:
1573:                List<SignatureTarget> sigTargetList1 = createSignatureTargetEndorsingSignature(true);
1574:                SignaturePolicy sigPolicy1 = createSignaturePolicy(sigTargetList1);
1575:                addSignKeyBinding(sigPolicy1, "x509", "Identifier");
1576:                msgPolicy.append(sigPolicy1);
1577:
1578:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1579:
1580:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1581:                addEncryptKeyBinding(encPolicy, "symmetric", "");
1582:                msgPolicy.append(encPolicy);
1583:
1584:                return msgPolicy;
1585:            }
1586:
1587:            public MessagePolicy createScenario7ClientIncoming()
1588:                    throws Exception {
1589:                MessagePolicy msgPolicy = new MessagePolicy();
1590:
1591:                //        AuthenticationTokenPolicy at =
1592:                //                createUTPolicy("testuser", null, null, false);
1593:                //        at.setUUID("UsernameTokenBinding");
1594:                //        msgPolicy.append(at);
1595:                SignatureConfirmationPolicy sigConf = new SignatureConfirmationPolicy();
1596:                msgPolicy.append(sigConf);
1597:
1598:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1599:
1600:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1601:                addEncryptKeyBinding(encPolicy, "symmetric", "");
1602:                msgPolicy.append(encPolicy);
1603:
1604:                TimestampPolicy tp = new TimestampPolicy();
1605:                msgPolicy.append(tp);
1606:
1607:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1608:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1609:
1610:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1611:
1612:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1613:                addSignKeyBinding(sigPolicy, "symmetric", "");
1614:                msgPolicy.append(sigPolicy);
1615:                addQTToSPTList(sigConf, sigPolicy);
1616:                addToSPTList(tp, sigPolicy);
1617:
1618:                return msgPolicy;
1619:            }
1620:
1621:            //MutualCertificate11SignEncrypt_IPingService_policy
1622:            public MessagePolicy createScenario7ServerIncoming()
1623:                    throws Exception {
1624:                MessagePolicy msgPolicy = new MessagePolicy();
1625:
1626:                SignatureConfirmationPolicy sigConf = new SignatureConfirmationPolicy();
1627:                msgPolicy.append(sigConf);
1628:
1629:                AuthenticationTokenPolicy at = createUTPolicy("testuser", null,
1630:                        null, false);
1631:                at.setUUID("UsernameTokenBinding");
1632:                msgPolicy.append(at);
1633:
1634:                TimestampPolicy tp = new TimestampPolicy();
1635:                msgPolicy.append(tp);
1636:
1637:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1638:
1639:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1640:                addEncryptKeyBinding(encPolicy, "symmetric", "");
1641:                msgPolicy.append(encPolicy);
1642:
1643:                List<SignatureTarget> sigTargetList1 = createSignatureTargetEndorsingSignature(true);
1644:                SignaturePolicy sigPolicy1 = createSignaturePolicy(sigTargetList1);
1645:                addSignKeyBinding(sigPolicy1, "x509", "Identifier");
1646:                msgPolicy.append(sigPolicy1);
1647:
1648:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1649:
1650:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1651:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1652:
1653:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1654:                addSignKeyBinding(sigPolicy, "symmetric", "");
1655:                msgPolicy.append(sigPolicy);
1656:                addQTToSPTList(sigConf, sigPolicy);
1657:                addToSPTList(tp, sigPolicy);
1658:
1659:                return msgPolicy;
1660:            }
1661:
1662:            //MutualCertificate11SignEncrypt_IPingService_policy
1663:            public MessagePolicy createScenario7ServerOutgoing()
1664:                    throws Exception {
1665:                MessagePolicy msgPolicy = new MessagePolicy();
1666:
1667:                SignatureConfirmationPolicy sigConf = new SignatureConfirmationPolicy();
1668:                msgPolicy.append(sigConf);
1669:
1670:                /*    AuthenticationTokenPolicy at =
1671:                            createUTPolicy("testuser", null, null, false);
1672:                    at.setUUID("UsernameTokenBinding");
1673:                    msgPolicy.append(at);
1674:                 */
1675:                TimestampPolicy tp = new TimestampPolicy();
1676:                msgPolicy.append(tp);
1677:
1678:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1679:
1680:                /*    List<SignatureTarget> sigTargetList1 =
1681:                            createSignatureTargetEndorsingSignature(true);
1682:                    SignaturePolicy sigPolicy1 = createSignaturePolicy(sigTargetList1);
1683:                    addSignKeyBinding(sigPolicy1, "x509", "Identifier");
1684:                    msgPolicy.append(sigPolicy1);
1685:                 */
1686:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1687:
1688:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1689:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1690:
1691:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1692:                addSignKeyBinding(sigPolicy, "symmetric", "");
1693:                msgPolicy.append(sigPolicy);
1694:                addQTToSPTList(sigConf, sigPolicy);
1695:                addToSPTList(tp, sigPolicy);
1696:
1697:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1698:                addEncryptKeyBinding(encPolicy, "symmetric", "");
1699:                msgPolicy.append(encPolicy);
1700:
1701:                return msgPolicy;
1702:            }
1703:
1704:            //MutualCertificate11SignEncryptDerivedKeys_IPingService_policy
1705:            public MessagePolicy createScenario8ClientOutgoing()
1706:                    throws Exception {
1707:                MessagePolicy msgPolicy = new MessagePolicy();
1708:
1709:                TimestampPolicy tp = new TimestampPolicy();
1710:                msgPolicy.append(tp);
1711:
1712:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1713:
1714:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1715:                //        suite.setType(AlgorithmSuiteValue.TripleDesRsa15);
1716:
1717:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1718:                addSignKeyBinding(sigPolicy, "derivedkey", "");
1719:                msgPolicy.append(sigPolicy);
1720:
1721:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1722:
1723:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1724:                addEncryptKeyBinding(encPolicy, "derivedkey", "");
1725:                msgPolicy.append(encPolicy);
1726:
1727:                List<SignatureTarget> sigTargetList1 = createSignatureTargetEndorsingSignature(true);
1728:                SignaturePolicy sigPolicy1 = createSignaturePolicy(sigTargetList1);
1729:                addSignKeyBinding(sigPolicy1, "derivedkey", "");
1730:                msgPolicy.append(sigPolicy1);
1731:
1732:                SignatureConfirmationPolicy sigConf = new SignatureConfirmationPolicy();
1733:                msgPolicy.append(sigConf);
1734:
1735:                return msgPolicy;
1736:            }
1737:
1738:            public MessagePolicy createScenario8ClientIncoming()
1739:                    throws Exception {
1740:                return (reverse(createScenario7ClientOutgoing()));
1741:            }
1742:
1743:            public MessagePolicy createScenario10ClientOutgoing()
1744:                    throws Exception {
1745:                MessagePolicy msgPolicy = new MessagePolicy();
1746:                //     TimestampPolicy tp = new TimestampPolicy();
1747:                // msgPolicy.append(tp);
1748:
1749:                List<SignatureTarget> sigTargetList = createSignatureTargetBody(true);
1750:
1751:                //       AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1752:                //      suite.setType(AlgorithmSuiteValue.Basic256);
1753:
1754:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1755:                addSignKeyBinding(sigPolicy, "x509", "Direct");
1756:                msgPolicy.append(sigPolicy);
1757:                //    addToSPTList(tp,sigPolicy);
1758:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1759:
1760:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1761:                addEncryptKeyBinding(encPolicy, "x509", "Identifier");
1762:                msgPolicy.append(encPolicy);
1763:
1764:                return msgPolicy;
1765:            }
1766:
1767:            public MessagePolicy createScenario10ClientIncoming()
1768:                    throws Exception {
1769:                MessagePolicy msgPolicy = new MessagePolicy();
1770:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1771:
1772:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1773:                addEncryptKeyBinding(encPolicy, "x509", "Identifier");
1774:                msgPolicy.append(encPolicy);
1775:
1776:                // TimestampPolicy tp = new TimestampPolicy();
1777:                // msgPolicy.append(tp);
1778:
1779:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1780:                //        suite.setType(AlgorithmSuiteValue.Basic256);
1781:
1782:                List<SignatureTarget> sigTargetList = createSignatureTargetBody(true);
1783:
1784:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1785:                addSignKeyBinding(sigPolicy, "x509", "Direct");
1786:                msgPolicy.append(sigPolicy);
1787:                //   addToSPTList(tp,sigPolicy);
1788:                return msgPolicy;
1789:            }
1790:
1791:            public MessagePolicy createScenario11ClientOutgoing()
1792:                    throws Exception {
1793:                MessagePolicy msgPolicy = new MessagePolicy();
1794:
1795:                TimestampPolicy tp = new TimestampPolicy();
1796:                msgPolicy.append(tp);
1797:
1798:                List<String> targetSignType = new ArrayList<String>();
1799:                targetSignType.add("uri");
1800:                List<String> targetSignValue = new ArrayList<String>();
1801:                targetSignValue.add("TimestampPolicy");
1802:                List<Boolean> targetSignContent = new ArrayList<Boolean>();
1803:                targetSignContent.add(true);
1804:                List<SignatureTarget.Transform> transform = new ArrayList<SignatureTarget.Transform>();
1805:                List<List<SignatureTarget.Transform>> tl = new ArrayList<List<SignatureTarget.Transform>>();
1806:                tl.add(transform);
1807:
1808:                List<SignatureTarget> sigTargetList = createSignatureTargetList(
1809:                        targetSignType, targetSignValue, targetSignContent, tl);
1810:
1811:                //       AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1812:                //      suite.setType(AlgorithmSuiteValue.Basic256);
1813:
1814:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1815:                addSignKeyBinding(sigPolicy, "symmetric", "");
1816:                msgPolicy.append(sigPolicy);
1817:                // addToSPTList(tp,sigPolicy);
1818:                List<String> listHeaders = createAddressingHeaderQNameList();
1819:
1820:                List<String> targetType = new ArrayList<String>();
1821:                targetType.add("qname");
1822:                targetType.add("qname");
1823:                targetType.add("qname");
1824:                targetType.add("qname");
1825:                targetType.add("qname");
1826:                targetType.add("qname");
1827:                targetType.add("qname");
1828:                targetType.add("qname");
1829:
1830:                List<EncryptionTarget> encTargetList = createEncryptionTargetBodySelectedHeader(
1831:                        listHeaders, true, targetType);
1832:
1833:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1834:                addEncryptKeyBinding(encPolicy, "symmetric", "");
1835:                msgPolicy.append(encPolicy);
1836:
1837:                return msgPolicy;
1838:            }
1839:
1840:            public MessagePolicy createScenario11ClientIncoming()
1841:                    throws Exception {
1842:                MessagePolicy msgPolicy = new MessagePolicy();
1843:
1844:                TimestampPolicy tp = new TimestampPolicy();
1845:                msgPolicy.append(tp);
1846:
1847:                List<String> targetSignType = new ArrayList<String>();
1848:                targetSignType.add("uri");
1849:                List<String> targetSignValue = new ArrayList<String>();
1850:                targetSignValue.add("TimestampPolicy");
1851:                List<Boolean> targetSignContent = new ArrayList<Boolean>();
1852:                targetSignContent.add(true);
1853:                List<SignatureTarget.Transform> transform = new ArrayList<SignatureTarget.Transform>();
1854:                List<List<SignatureTarget.Transform>> tl = new ArrayList<List<SignatureTarget.Transform>>();
1855:                tl.add(transform);
1856:
1857:                List<SignatureTarget> sigTargetList = createSignatureTargetList(
1858:                        targetSignType, targetSignValue, targetSignContent, tl);
1859:
1860:                //       AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1861:                //      suite.setType(AlgorithmSuiteValue.Basic256);
1862:
1863:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1864:                addSignKeyBinding(sigPolicy, "symmetric", "");
1865:                msgPolicy.append(sigPolicy);
1866:                // addToSPTList(tp,sigPolicy);
1867:                List<String> listHeaders = createAddressingHeaderQNameList();
1868:
1869:                List<String> targetType = new ArrayList<String>();
1870:                targetType.add("qname");
1871:                targetType.add("qname");
1872:                targetType.add("qname");
1873:                targetType.add("qname");
1874:                targetType.add("qname");
1875:                targetType.add("qname");
1876:                targetType.add("qname");
1877:                targetType.add("qname");
1878:
1879:                List<EncryptionTarget> encTargetList = createEncryptionTargetBodySelectedHeader(
1880:                        listHeaders, true, targetType);
1881:
1882:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1883:                addEncryptKeyBinding(encPolicy, "symmetric", "");
1884:                msgPolicy.append(encPolicy);
1885:
1886:                return msgPolicy;
1887:            }
1888:
1889:            public MessagePolicy createScenario21ClientOutgoing()
1890:                    throws Exception {
1891:                MessagePolicy msgPolicy = new MessagePolicy();
1892:
1893:                TimestampPolicy tp = new TimestampPolicy();
1894:                msgPolicy.append(tp);
1895:
1896:                /*    AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1897:                    suite.setType(AlgorithmSuiteValue.Basic256);
1898:                 
1899:                    List<SignatureTarget> sigTargetList =
1900:                            createSignatureTargetBodyAllHeader(true);
1901:                 
1902:                    SignaturePolicy sigPolicy =
1903:                            createSignaturePolicy(sigTargetList, suite);
1904:                    addSignKeyBinding(sigPolicy, "derivedkey", "");
1905:                    msgPolicy.append(sigPolicy);
1906:                 
1907:                    List<EncryptionTarget> encTargetList =
1908:                            createEncryptionTargetBody(true);
1909:                 
1910:                    EncryptionPolicy encPolicy =
1911:                            createEncryptionPolicy(encTargetList, suite);
1912:                    addEncryptKeyBinding(encPolicy, "derivedkey", "");
1913:                    msgPolicy.append(encPolicy);
1914:                 */
1915:                List<SignatureTarget> sigTargetList1 = createSignatureTargetEndorsingSignature(true);
1916:                SignaturePolicy sigPolicy1 = createSignaturePolicy(sigTargetList1);
1917:                addSignKeyBinding(sigPolicy1, "derivedkey", "");
1918:                msgPolicy.append(sigPolicy1);
1919:
1920:                return msgPolicy;
1921:            }
1922:
1923:            public MessagePolicy createScenario21ClientIncoming()
1924:                    throws Exception {
1925:                return (reverse(createScenario21ClientOutgoing()));
1926:            }
1927:
1928:            public MessagePolicy createScenario22ClientOutgoing()
1929:                    throws Exception {
1930:                MessagePolicy msgPolicy = new MessagePolicy();
1931:
1932:                TimestampPolicy tp = new TimestampPolicy();
1933:                msgPolicy.append(tp);
1934:
1935:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1936:
1937:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1938:                //        suite.setType(AlgorithmSuiteValue.Basic256);
1939:
1940:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1941:                addSignKeyBinding(sigPolicy, "derivedkey", "Thumbprint");
1942:                msgPolicy.append(sigPolicy);
1943:                addToSPTList(tp, sigPolicy);
1944:
1945:                /*  List<SignatureTarget> sigTargetList1 =
1946:                        createSignatureTargetEndorsingSignature(true);
1947:                SignaturePolicy sigPolicy1 = createSignaturePolicy(sigTargetList1, suite);
1948:                addSignKeyBinding(sigPolicy1, "derivedkey", "");
1949:                msgPolicy.append(sigPolicy1);
1950:                 */
1951:
1952:                return msgPolicy;
1953:            }
1954:
1955:            public MessagePolicy createScenario22ClientIncoming()
1956:                    throws Exception {
1957:                return (reverse(createScenario22ClientOutgoing()));
1958:            }
1959:
1960:            public MessagePolicy createScenario23ClientOutgoing()
1961:                    throws Exception {
1962:                MessagePolicy msgPolicy = new MessagePolicy();
1963:
1964:                TimestampPolicy tp = new TimestampPolicy();
1965:                msgPolicy.append(tp);
1966:
1967:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1968:
1969:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
1970:                //        suite.setType(AlgorithmSuiteValue.Basic256);
1971:
1972:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
1973:                addSignKeyBinding(sigPolicy, "derivedkey", "Thumbprint");
1974:                msgPolicy.append(sigPolicy);
1975:                addToSPTList(tp, sigPolicy);
1976:
1977:                List<EncryptionTarget> encTargetList = createEncryptionTargetBody(true);
1978:
1979:                EncryptionPolicy encPolicy = createEncryptionPolicy(encTargetList);
1980:                addEncryptKeyBinding(encPolicy, "derivedkey", "");
1981:                msgPolicy.append(encPolicy);
1982:
1983:                return msgPolicy;
1984:            }
1985:
1986:            public MessagePolicy createScenario23ClientIncoming()
1987:                    throws Exception {
1988:                return (reverse(createScenario23ClientOutgoing()));
1989:            }
1990:
1991:            public MessagePolicy createScenario24ClientOutgoing()
1992:                    throws Exception {
1993:                MessagePolicy msgPolicy = new MessagePolicy();
1994:
1995:                TimestampPolicy tp = new TimestampPolicy();
1996:                msgPolicy.append(tp);
1997:
1998:                List<SignatureTarget> sigTargetList = createSignatureTargetBodyAllHeader(true);
1999:
2000:                //        AlgorithmSuite suite = new com.sun.xml.ws.security.impl.policy.AlgorithmSuite();
2001:                //        suite.setType(AlgorithmSuiteValue.Basic256);
2002:
2003:                SignaturePolicy sigPolicy = createSignaturePolicy(sigTargetList);
2004:                addSignKeyBinding(sigPolicy, "derivedkey", "Thumbprint");
2005:                msgPolicy.append(sigPolicy);
2006:
2007:                addToSPTList(tp, sigPolicy);
2008:
2009:                return msgPolicy;
2010:            }
2011:
2012:            public MessagePolicy createScenario24ClientIncoming()
2013:                    throws Exception {
2014:                return (reverse(createScenario24ClientOutgoing()));
2015:            }
2016:
2017:        }
w_w__w___._ja___v___a__2s___.___co_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.