Source Code Cross Referenced for SecurityPolicyModelHelper.java in  » IDE-Netbeans » web.core » org » netbeans » modules » websvc » wsitconf » wsdlmodelext » 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 » IDE Netbeans » web.core » org.netbeans.modules.websvc.wsitconf.wsdlmodelext 
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
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 2006 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.modules.websvc.wsitconf.wsdlmodelext;
0043:
0044:        import java.util.Collection;
0045:        import org.netbeans.modules.websvc.wsitmodelext.addressing.Addressing10QName;
0046:        import org.netbeans.modules.websvc.wsitmodelext.security.RequiredElements;
0047:        import org.netbeans.modules.websvc.wsitmodelext.security.TrustElement;
0048:        import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants;
0049:        import org.netbeans.modules.websvc.wsitconf.ui.security.listmodels.*;
0050:        import org.netbeans.modules.websvc.wsitmodelext.policy.All;
0051:        import org.netbeans.modules.websvc.wsitmodelext.policy.Policy;
0052:        import org.netbeans.modules.websvc.wsitmodelext.policy.PolicyQName;
0053:        import org.netbeans.modules.websvc.wsitmodelext.rm.RMQName;
0054:        import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.KeyStore;
0055:        import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.TrustStore;
0056:        import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireDerivedKeys;
0057:        import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireEmbeddedTokenReference;
0058:        import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireExternalReference;
0059:        import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireExternalUriReference;
0060:        import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireInternalReference;
0061:        import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireIssuerSerialReference;
0062:        import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireKeyIdentifierReference;
0063:        import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireThumbprintReference;
0064:        import org.netbeans.modules.websvc.wsitmodelext.security.tokens.SC10SecurityContextToken;
0065:        import org.netbeans.modules.websvc.wsitmodelext.security.tokens.TokensQName;
0066:        import org.netbeans.modules.websvc.wsitmodelext.security.AsymmetricBinding;
0067:        import org.netbeans.modules.websvc.wsitmodelext.security.Body;
0068:        import org.netbeans.modules.websvc.wsitmodelext.security.BootstrapPolicy;
0069:        import org.netbeans.modules.websvc.wsitmodelext.security.EncryptedElements;
0070:        import org.netbeans.modules.websvc.wsitmodelext.security.EncryptedParts;
0071:        import org.netbeans.modules.websvc.wsitmodelext.security.Header;
0072:        import org.netbeans.modules.websvc.wsitmodelext.security.Lax;
0073:        import org.netbeans.modules.websvc.wsitmodelext.security.LaxTsFirst;
0074:        import org.netbeans.modules.websvc.wsitmodelext.security.LaxTsLast;
0075:        import org.netbeans.modules.websvc.wsitmodelext.security.Layout;
0076:        import org.netbeans.modules.websvc.wsitmodelext.security.SecurityPolicyQName;
0077:        import org.netbeans.modules.websvc.wsitmodelext.security.SignedElements;
0078:        import org.netbeans.modules.websvc.wsitmodelext.security.SignedParts;
0079:        import org.netbeans.modules.websvc.wsitmodelext.security.Strict;
0080:        import org.netbeans.modules.websvc.wsitmodelext.security.SymmetricBinding;
0081:        import org.netbeans.modules.websvc.wsitmodelext.security.TransportBinding;
0082:        import org.netbeans.modules.websvc.wsitmodelext.security.Trust10;
0083:        import org.netbeans.modules.websvc.wsitmodelext.security.Wss10;
0084:        import org.netbeans.modules.websvc.wsitmodelext.security.Wss11;
0085:        import org.netbeans.modules.websvc.wsitmodelext.security.WssElement;
0086:        import org.netbeans.modules.websvc.wsitmodelext.security.XPath;
0087:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.EncryptBeforeSigning;
0088:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.EncryptSignature;
0089:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.IncludeTimestamp;
0090:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportClientChallenge;
0091:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportIssuedTokens;
0092:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefEmbeddedToken;
0093:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefEncryptedKey;
0094:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefExternalURI;
0095:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefIssuerSerial;
0096:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefKeyIdentifier;
0097:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefThumbprint;
0098:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportServerChallenge;
0099:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.OnlySignEntireHeadersAndBody;
0100:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.RequireClientEntropy;
0101:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.RequireServerEntropy;
0102:        import org.netbeans.modules.websvc.wsitmodelext.security.parameters.RequireSignatureConfirmation;
0103:        import org.netbeans.modules.xml.wsdl.model.*;
0104:        import org.openide.util.NbBundle;
0105:        import javax.xml.namespace.QName;
0106:        import java.util.Collections;
0107:        import java.util.List;
0108:        import java.util.Vector;
0109:
0110:        /**
0111:         *
0112:         * @author Martin Grebac
0113:         */
0114:        public class SecurityPolicyModelHelper {
0115:
0116:            /**
0117:             * Creates a new instance of SecurityPolicyModelHelper
0118:             */
0119:            public SecurityPolicyModelHelper() {
0120:            }
0121:
0122:            // checks if Security is enabled in the config wsdl on specified element (Binding/Operation/Message)
0123:            public static boolean isSecurityEnabled(WSDLComponent c) {
0124:                Policy p = PolicyModelHelper.getPolicyForElement(c);
0125:                if (p != null) {
0126:                    ExtensibilityElement secElem = getSecurityBindingTypeElement(c);
0127:                    return (secElem != null);
0128:                }
0129:                return false;
0130:            }
0131:
0132:            public static void disableSecurity(WSDLComponent c,
0133:                    boolean removeStoreConfig) {
0134:                assert ((c instanceof  Binding) || (c instanceof  BindingOperation));
0135:                setSecurityBindingType(c, null);
0136:                SecurityTokensModelHelper.setSupportingTokens(c, null,
0137:                        SecurityTokensModelHelper.NONE);
0138:                if (c instanceof  Binding) {
0139:                    ProprietarySecurityPolicyModelHelper.setStreamingSecurity(
0140:                            (Binding) c, true);
0141:                }
0142:                disableWss(c);
0143:                disableTrust10(c);
0144:                removeTargets(c);
0145:                Policy p = PolicyModelHelper.getPolicyForElement(c);
0146:                if ((p != null) && (removeStoreConfig)) {
0147:                    KeyStore ks = PolicyModelHelper.getTopLevelElement(p,
0148:                            KeyStore.class);
0149:                    TrustStore ts = PolicyModelHelper.getTopLevelElement(p,
0150:                            TrustStore.class);
0151:                    if (ks != null)
0152:                        PolicyModelHelper.removeElement(ks);
0153:                    if (ts != null)
0154:                        PolicyModelHelper.removeElement(ts);
0155:                }
0156:                if (c instanceof  Binding) {
0157:                    Binding b = (Binding) c;
0158:                    Collection<BindingOperation> ops = b.getBindingOperations();
0159:                    for (BindingOperation op : ops) {
0160:                        disableSecurity(op, removeStoreConfig);
0161:                    }
0162:                } else {
0163:                    BindingOperation bop = (BindingOperation) c;
0164:                    BindingInput bi = bop.getBindingInput();
0165:                    BindingOutput bo = bop.getBindingOutput();
0166:                    if (bi != null)
0167:                        PolicyModelHelper.removePolicyForElement(bi);
0168:                    if (bo != null)
0169:                        PolicyModelHelper.removePolicyForElement(bo);
0170:                }
0171:                PolicyModelHelper.cleanPolicies(c);
0172:            }
0173:
0174:            public static WssElement enableWss(WSDLComponent c, boolean wss11) {
0175:
0176:                if ((c instanceof  Binding) || (c instanceof  BindingOperation)
0177:                        || (c instanceof  BindingInput)
0178:                        || (c instanceof  BindingOutput)
0179:                        || (c instanceof  BindingFault)) {
0180:                    c = PolicyModelHelper.createPolicy(c, true);
0181:                }
0182:
0183:                if (wss11) {
0184:                    if (isWss10(c)) {
0185:                        disableWss(c);
0186:                    }
0187:                    if (!isWss11(c)) {
0188:                        return PolicyModelHelper.createElement(c,
0189:                                SecurityPolicyQName.WSS11.getQName(),
0190:                                Wss11.class, false);
0191:                    } else {
0192:                        return getWss11(c);
0193:                    }
0194:                } else {
0195:                    if (isWss11(c)) {
0196:                        disableWss(c);
0197:                    }
0198:                    if (!isWss10(c)) {
0199:                        return PolicyModelHelper.createElement(c,
0200:                                SecurityPolicyQName.WSS10.getQName(),
0201:                                Wss10.class, false);
0202:                    } else {
0203:                        return getWss10(c);
0204:                    }
0205:                }
0206:            }
0207:
0208:            public static TrustElement enableTrust10(WSDLComponent c) {
0209:                if ((c instanceof  Binding) || (c instanceof  BindingOperation)
0210:                        || (c instanceof  BindingInput)
0211:                        || (c instanceof  BindingOutput)
0212:                        || (c instanceof  BindingFault)) {
0213:                    c = PolicyModelHelper.createPolicy(c, true);
0214:                }
0215:                if (!isTrust10(c)) {
0216:                    return PolicyModelHelper.createElement(c,
0217:                            SecurityPolicyQName.TRUST10.getQName(),
0218:                            Trust10.class, false);
0219:                } else {
0220:                    return getTrust10(c);
0221:                }
0222:            }
0223:
0224:            // disables Wss in the config wsdl on specified binding
0225:            public static void disableWss(WSDLComponent c) {
0226:                WSDLModel model = c.getModel();
0227:                if ((c instanceof  Binding) || (c instanceof  BindingOperation)
0228:                        || (c instanceof  BindingInput)
0229:                        || (c instanceof  BindingOutput)
0230:                        || (c instanceof  BindingFault)) {
0231:                    c = PolicyModelHelper.createPolicy(c, true);
0232:                }
0233:                WssElement wss10 = getWss10(c);
0234:                WssElement wss11 = getWss11(c);
0235:                boolean isTransaction = model.isIntransaction();
0236:                if (!isTransaction) {
0237:                    model.startTransaction();
0238:                }
0239:                try {
0240:                    if (wss10 != null) {
0241:                        wss10.getParent().removeExtensibilityElement(wss10);
0242:                    }
0243:                    if (wss11 != null) {
0244:                        wss11.getParent().removeExtensibilityElement(wss11);
0245:                    }
0246:                } finally {
0247:                    if (!isTransaction) {
0248:                        model.endTransaction();
0249:                    }
0250:                }
0251:            }
0252:
0253:            /* Disables Trust10 in the config wsdl on specified component
0254:             */
0255:            public static void disableTrust10(WSDLComponent c) {
0256:                WSDLModel model = c.getModel();
0257:                if ((c instanceof  Binding) || (c instanceof  BindingOperation)
0258:                        || (c instanceof  BindingInput)
0259:                        || (c instanceof  BindingOutput)
0260:                        || (c instanceof  BindingFault)) {
0261:                    c = PolicyModelHelper.createPolicy(c, true);
0262:                }
0263:                boolean isTransaction = model.isIntransaction();
0264:                if (!isTransaction) {
0265:                    model.startTransaction();
0266:                }
0267:                Trust10 trust = getTrust10(c);
0268:                try {
0269:                    if (trust != null) {
0270:                        trust.getParent().removeExtensibilityElement(trust);
0271:                    }
0272:                } finally {
0273:                    if (!isTransaction) {
0274:                        model.endTransaction();
0275:                    }
0276:                }
0277:            }
0278:
0279:            public static boolean isWss10(WSDLComponent c) {
0280:                return getWss10(c) != null;
0281:            }
0282:
0283:            public static boolean isWss11(WSDLComponent c) {
0284:                return getWss11(c) != null;
0285:            }
0286:
0287:            public static boolean isTrust10(WSDLComponent c) {
0288:                return getTrust10(c) != null;
0289:            }
0290:
0291:            public static Wss10 getWss10(WSDLComponent c) {
0292:                if ((c instanceof  Binding) || (c instanceof  BindingOperation)) {
0293:                    c = PolicyModelHelper.getPolicyForElement(c);
0294:                }
0295:                return PolicyModelHelper.getTopLevelElement(c, Wss10.class);
0296:            }
0297:
0298:            public static Wss11 getWss11(WSDLComponent c) {
0299:                if ((c instanceof  Binding) || (c instanceof  BindingOperation)) {
0300:                    c = PolicyModelHelper.getPolicyForElement(c);
0301:                }
0302:                return PolicyModelHelper.getTopLevelElement(c, Wss11.class);
0303:            }
0304:
0305:            public static Trust10 getTrust10(WSDLComponent c) {
0306:                if ((c instanceof  Binding) || (c instanceof  BindingOperation)) {
0307:                    c = PolicyModelHelper.getPolicyForElement(c);
0308:                }
0309:                return PolicyModelHelper.getTopLevelElement(c, Trust10.class);
0310:            }
0311:
0312:            // -------- WSS10 & 11 ELEMENTS -----------
0313:            public static boolean isMustSupportRefEmbeddedToken(
0314:                    WSDLComponent comp) {
0315:                Wss11 wss11 = getWss11(comp);
0316:                Wss10 wss10 = getWss10(comp);
0317:                return isAttributeEnabled(wss10,
0318:                        MustSupportRefEmbeddedToken.class)
0319:                        || isAttributeEnabled(wss11,
0320:                                MustSupportRefEmbeddedToken.class);
0321:            }
0322:
0323:            public static boolean isMustSupportRefExternalURI(WSDLComponent comp) {
0324:                Wss11 wss11 = getWss11(comp);
0325:                Wss10 wss10 = getWss10(comp);
0326:                return isAttributeEnabled(wss10,
0327:                        MustSupportRefExternalURI.class)
0328:                        || isAttributeEnabled(wss11,
0329:                                MustSupportRefExternalURI.class);
0330:            }
0331:
0332:            public static boolean isMustSupportRefIssuerSerial(
0333:                    WSDLComponent comp) {
0334:                Wss11 wss11 = getWss11(comp);
0335:                Wss10 wss10 = getWss10(comp);
0336:                return isAttributeEnabled(wss10,
0337:                        MustSupportRefIssuerSerial.class)
0338:                        || isAttributeEnabled(wss11,
0339:                                MustSupportRefIssuerSerial.class);
0340:            }
0341:
0342:            public static boolean isMustSupportRefKeyIdentifier(
0343:                    WSDLComponent comp) {
0344:                Wss11 wss11 = getWss11(comp);
0345:                Wss10 wss10 = getWss10(comp);
0346:                return isAttributeEnabled(wss10,
0347:                        MustSupportRefKeyIdentifier.class)
0348:                        || isAttributeEnabled(wss11,
0349:                                MustSupportRefKeyIdentifier.class);
0350:            }
0351:
0352:            // ----------- WSS11 ONLY ELEMENTS -----------
0353:            public static boolean isMustSupportRefEncryptedKey(
0354:                    WSDLComponent comp) {
0355:                Wss11 wss11 = getWss11(comp);
0356:                return isAttributeEnabled(wss11,
0357:                        MustSupportRefEncryptedKey.class);
0358:            }
0359:
0360:            public static boolean isMustSupportRefThumbprint(WSDLComponent comp) {
0361:                Wss11 wss11 = getWss11(comp);
0362:                return isAttributeEnabled(wss11, MustSupportRefThumbprint.class);
0363:            }
0364:
0365:            public static boolean isRequireSignatureConfirmation(
0366:                    WSDLComponent comp) {
0367:                Wss11 wss11 = getWss11(comp);
0368:                return isAttributeEnabled(wss11,
0369:                        RequireSignatureConfirmation.class);
0370:            }
0371:
0372:            // -------- TRUST ELEMENTS -----------
0373:            public static boolean isRequireServerEntropy(WSDLComponent comp) {
0374:                Trust10 trust = getTrust10(comp);
0375:                return isAttributeEnabled(trust, RequireServerEntropy.class);
0376:            }
0377:
0378:            public static boolean isRequireClientEntropy(WSDLComponent comp) {
0379:                Trust10 trust = getTrust10(comp);
0380:                return isAttributeEnabled(trust, RequireClientEntropy.class);
0381:            }
0382:
0383:            public static boolean isMustSupportIssuedTokens(WSDLComponent comp) {
0384:                Trust10 trust = getTrust10(comp);
0385:                return isAttributeEnabled(trust, MustSupportIssuedTokens.class);
0386:            }
0387:
0388:            public static boolean isMustSupportClientChallenge(
0389:                    WSDLComponent comp) {
0390:                Trust10 trust = getTrust10(comp);
0391:                return isAttributeEnabled(trust,
0392:                        MustSupportClientChallenge.class);
0393:            }
0394:
0395:            public static boolean isMustSupportServerChallenge(
0396:                    WSDLComponent comp) {
0397:                Trust10 trust = getTrust10(comp);
0398:                return isAttributeEnabled(trust,
0399:                        MustSupportServerChallenge.class);
0400:            }
0401:
0402:            /* Used to get values of attributes defined in WSS10/WSS11/TRUST10 assertions, for tokens, ...
0403:             * first retrieves the Policy element and then element of class a underneath
0404:             */
0405:            public static boolean isAttributeEnabled(
0406:                    ExtensibilityElement element, Class a) {
0407:                if (element != null) {
0408:                    Policy p = PolicyModelHelper.getTopLevelElement(element,
0409:                            Policy.class);
0410:                    return (PolicyModelHelper.getTopLevelElement(p, a) != null);
0411:                }
0412:                return false;
0413:            }
0414:
0415:            public static void enableIncludeTimestamp(WSDLComponent secBinding,
0416:                    boolean enable) {
0417:                if (enable) {
0418:                    PolicyModelHelper.createElement(secBinding,
0419:                            SecurityPolicyQName.INCLUDETIMESTAMP.getQName(),
0420:                            IncludeTimestamp.class, true);
0421:                } else {
0422:                    PolicyModelHelper.removeElement(secBinding,
0423:                            IncludeTimestamp.class, true);
0424:                }
0425:            }
0426:
0427:            public static void enableEncryptSignature(WSDLComponent secBinding,
0428:                    boolean enable) {
0429:                if (enable) {
0430:                    PolicyModelHelper.createElement(secBinding,
0431:                            SecurityPolicyQName.ENCRYPTSIGNATURE.getQName(),
0432:                            EncryptSignature.class, true);
0433:                } else {
0434:                    PolicyModelHelper.removeElement(secBinding,
0435:                            EncryptSignature.class, true);
0436:                }
0437:            }
0438:
0439:            public static void enableSignEntireHeadersAndBody(
0440:                    WSDLComponent secBinding, boolean enable) {
0441:                if (enable) {
0442:                    PolicyModelHelper.createElement(secBinding,
0443:                            SecurityPolicyQName.ONLYSIGNENTIREHEADERSANDBODY
0444:                                    .getQName(),
0445:                            OnlySignEntireHeadersAndBody.class, true);
0446:                } else {
0447:                    PolicyModelHelper.removeElement(secBinding,
0448:                            OnlySignEntireHeadersAndBody.class, true);
0449:                }
0450:            }
0451:
0452:            public static void enableEncryptBeforeSigning(
0453:                    WSDLComponent secBinding, boolean enable) {
0454:                if (enable) {
0455:                    PolicyModelHelper
0456:                            .createElement(secBinding,
0457:                                    SecurityPolicyQName.ENCRYPTBEFORESIGNING
0458:                                            .getQName(),
0459:                                    EncryptBeforeSigning.class, true);
0460:                } else {
0461:                    PolicyModelHelper.removeElement(secBinding,
0462:                            EncryptBeforeSigning.class, true);
0463:                }
0464:            }
0465:
0466:            public static void enableMustSupportRefEmbeddedToken(
0467:                    WssElement wss, boolean enable) {
0468:                if (enable) {
0469:                    PolicyModelHelper.createElement(wss,
0470:                            SecurityPolicyQName.MUSTSUPPORTREFEMBEDDEDTOKEN
0471:                                    .getQName(),
0472:                            MustSupportRefEmbeddedToken.class, true);
0473:                } else {
0474:                    PolicyModelHelper.removeElement(wss,
0475:                            MustSupportRefEmbeddedToken.class, true);
0476:                }
0477:            }
0478:
0479:            public static void enableMustSupportRefExternalURI(WssElement wss,
0480:                    boolean enable) {
0481:                if (enable) {
0482:                    PolicyModelHelper.createElement(wss,
0483:                            SecurityPolicyQName.MUSTSUPPORTREFEXTERNALURI
0484:                                    .getQName(),
0485:                            MustSupportRefExternalURI.class, true);
0486:                } else {
0487:                    PolicyModelHelper.removeElement(wss,
0488:                            MustSupportRefExternalURI.class, true);
0489:                }
0490:            }
0491:
0492:            public static void enableMustSupportRefIssuerSerial(WssElement wss,
0493:                    boolean enable) {
0494:                if (enable) {
0495:                    PolicyModelHelper.createElement(wss,
0496:                            SecurityPolicyQName.MUSTSUPPORTREFISSUERSERIAL
0497:                                    .getQName(),
0498:                            MustSupportRefIssuerSerial.class, true);
0499:                } else {
0500:                    PolicyModelHelper.removeElement(wss,
0501:                            MustSupportRefIssuerSerial.class, true);
0502:                }
0503:            }
0504:
0505:            public static void enableMustSupportRefKeyIdentifier(
0506:                    WssElement wss, boolean enable) {
0507:                if (enable) {
0508:                    PolicyModelHelper.createElement(wss,
0509:                            SecurityPolicyQName.MUSTSUPPORTREFKEYIDENTIFIER
0510:                                    .getQName(),
0511:                            MustSupportRefKeyIdentifier.class, true);
0512:                } else {
0513:                    PolicyModelHelper.removeElement(wss,
0514:                            MustSupportRefKeyIdentifier.class, true);
0515:                }
0516:            }
0517:
0518:            public static boolean isRequireDerivedKeys(WSDLComponent token) {
0519:                return isAttributeEnabled((ExtensibilityElement) token,
0520:                        RequireDerivedKeys.class);
0521:            }
0522:
0523:            public static void enableRequireDerivedKeys(
0524:                    WSDLComponent tokenType, boolean enable) {
0525:                if (enable) {
0526:                    PolicyModelHelper.createElement(tokenType,
0527:                            TokensQName.REQUIREDERIVEDKEYS.getQName(),
0528:                            RequireDerivedKeys.class, true);
0529:                } else {
0530:                    PolicyModelHelper.removeElement(tokenType,
0531:                            RequireDerivedKeys.class, true);
0532:                }
0533:            }
0534:
0535:            public static void enableRequireExternalUri(
0536:                    WSDLComponent tokenType, boolean enable) {
0537:                if (enable) {
0538:                    PolicyModelHelper.createElement(tokenType,
0539:                            TokensQName.REQUIREEXTERNALURIREFERENCE.getQName(),
0540:                            RequireExternalUriReference.class, true);
0541:                } else {
0542:                    PolicyModelHelper.removeElement(tokenType,
0543:                            RequireExternalUriReference.class, true);
0544:                }
0545:            }
0546:
0547:            public static void enableRequireKeyIdentifierReference(
0548:                    WSDLComponent tokenType, boolean enable) {
0549:                if (enable) {
0550:                    PolicyModelHelper.createElement(tokenType,
0551:                            TokensQName.REQUIREKEYIDENTIFIERREFERENCE
0552:                                    .getQName(),
0553:                            RequireKeyIdentifierReference.class, true);
0554:                } else {
0555:                    PolicyModelHelper.removeElement(tokenType,
0556:                            RequireKeyIdentifierReference.class, true);
0557:                }
0558:            }
0559:
0560:            public static void enableRequireSecurityContextToken(
0561:                    WSDLComponent tokenType, boolean enable) {
0562:                if (enable) {
0563:                    PolicyModelHelper.createElement(tokenType,
0564:                            TokensQName.SC10SECURITYCONTEXTTOKEN.getQName(),
0565:                            SC10SecurityContextToken.class, true);
0566:                } else {
0567:                    PolicyModelHelper.removeElement(tokenType,
0568:                            SC10SecurityContextToken.class, true);
0569:                }
0570:            }
0571:
0572:            public static void enableRequireIssuerSerialReference(
0573:                    WSDLComponent tokenType, boolean enable) {
0574:                if (enable) {
0575:                    PolicyModelHelper
0576:                            .createElement(tokenType,
0577:                                    TokensQName.REQUIREISSUERSERIALREFERENCE
0578:                                            .getQName(),
0579:                                    RequireIssuerSerialReference.class, true);
0580:                } else {
0581:                    PolicyModelHelper.removeElement(tokenType,
0582:                            RequireIssuerSerialReference.class, true);
0583:                }
0584:            }
0585:
0586:            public static void enableRequireEmbeddedTokenReference(
0587:                    WSDLComponent tokenType, boolean enable) {
0588:                if (enable) {
0589:                    PolicyModelHelper.createElement(tokenType,
0590:                            TokensQName.REQUIREEMBEDDEDTOKENREFERENCE
0591:                                    .getQName(),
0592:                            RequireEmbeddedTokenReference.class, true);
0593:                } else {
0594:                    PolicyModelHelper.removeElement(tokenType,
0595:                            RequireEmbeddedTokenReference.class, true);
0596:                }
0597:            }
0598:
0599:            public static void enableRequireThumbprintReference(
0600:                    WSDLComponent tokenType, boolean enable) {
0601:                if (enable) {
0602:                    PolicyModelHelper.createElement(tokenType,
0603:                            TokensQName.REQUIRETHUMBPRINTREFERENCE.getQName(),
0604:                            RequireThumbprintReference.class, true);
0605:                } else {
0606:                    PolicyModelHelper.removeElement(tokenType,
0607:                            RequireThumbprintReference.class, true);
0608:                }
0609:            }
0610:
0611:            public static void enableRequireExternalReference(
0612:                    WSDLComponent tokenType, boolean enable) {
0613:                if (enable) {
0614:                    PolicyModelHelper.createElement(tokenType,
0615:                            TokensQName.REQUIREEXTERNALREFERENCE.getQName(),
0616:                            RequireExternalReference.class, true);
0617:                } else {
0618:                    PolicyModelHelper.removeElement(tokenType,
0619:                            RequireExternalReference.class, true);
0620:                }
0621:            }
0622:
0623:            public static void enableRequireInternalReference(
0624:                    WSDLComponent tokenType, boolean enable) {
0625:                if (enable) {
0626:                    PolicyModelHelper.createElement(tokenType,
0627:                            TokensQName.REQUIREINTERNALREFERENCE.getQName(),
0628:                            RequireInternalReference.class, true);
0629:                } else {
0630:                    PolicyModelHelper.removeElement(tokenType,
0631:                            RequireInternalReference.class, true);
0632:                }
0633:            }
0634:
0635:            public static void enableMustSupportRefEncryptedKey(WssElement wss,
0636:                    boolean enable) {
0637:                if (enable) {
0638:                    PolicyModelHelper.createElement(wss,
0639:                            SecurityPolicyQName.MUSTSUPPORTREFENCRYPTEDKEY
0640:                                    .getQName(),
0641:                            MustSupportRefEncryptedKey.class, true);
0642:                } else {
0643:                    PolicyModelHelper.removeElement(wss,
0644:                            MustSupportRefEncryptedKey.class, true);
0645:                }
0646:            }
0647:
0648:            public static void enableMustSupportRefThumbprint(WssElement wss,
0649:                    boolean enable) {
0650:                if (enable) {
0651:                    PolicyModelHelper.createElement(wss,
0652:                            SecurityPolicyQName.MUSTSUPPORTREFTHUMBPRINT
0653:                                    .getQName(),
0654:                            MustSupportRefThumbprint.class, true);
0655:                } else {
0656:                    PolicyModelHelper.removeElement(wss,
0657:                            MustSupportRefThumbprint.class, true);
0658:                }
0659:            }
0660:
0661:            public static void enableRequireSignatureConfirmation(
0662:                    WssElement wss, boolean enable) {
0663:                if (enable) {
0664:                    PolicyModelHelper.createElement(wss,
0665:                            SecurityPolicyQName.REQUIRESIGNATURECONFIRMATION
0666:                                    .getQName(),
0667:                            RequireSignatureConfirmation.class, true);
0668:                } else {
0669:                    PolicyModelHelper.removeElement(wss,
0670:                            RequireSignatureConfirmation.class, true);
0671:                }
0672:            }
0673:
0674:            // ----------- TRUST -------------------
0675:            public static void enableRequireClientEntropy(TrustElement trust,
0676:                    boolean enable) {
0677:                if (enable) {
0678:                    PolicyModelHelper
0679:                            .createElement(trust,
0680:                                    SecurityPolicyQName.REQUIRECLIENTENTROPY
0681:                                            .getQName(),
0682:                                    RequireClientEntropy.class, true);
0683:                } else {
0684:                    PolicyModelHelper.removeElement(trust,
0685:                            RequireClientEntropy.class, true);
0686:                }
0687:            }
0688:
0689:            public static void enableRequireServerEntropy(TrustElement trust,
0690:                    boolean enable) {
0691:                if (enable) {
0692:                    PolicyModelHelper
0693:                            .createElement(trust,
0694:                                    SecurityPolicyQName.REQUIRESERVERENTROPY
0695:                                            .getQName(),
0696:                                    RequireServerEntropy.class, true);
0697:                } else {
0698:                    PolicyModelHelper.removeElement(trust,
0699:                            RequireServerEntropy.class, true);
0700:                }
0701:            }
0702:
0703:            public static void enableMustSupportIssuedTokens(
0704:                    TrustElement trust, boolean enable) {
0705:                if (enable) {
0706:                    PolicyModelHelper.createElement(trust,
0707:                            SecurityPolicyQName.MUSTSUPPORTISSUEDTOKENS
0708:                                    .getQName(), MustSupportIssuedTokens.class,
0709:                            true);
0710:                } else {
0711:                    PolicyModelHelper.removeElement(trust,
0712:                            MustSupportIssuedTokens.class, true);
0713:                }
0714:            }
0715:
0716:            public static void enableMustSupportClientChallenge(
0717:                    TrustElement trust, boolean enable) {
0718:                if (enable) {
0719:                    PolicyModelHelper.createElement(trust,
0720:                            SecurityPolicyQName.MUSTSUPPORTCLIENTCHALLENGE
0721:                                    .getQName(),
0722:                            MustSupportClientChallenge.class, true);
0723:                } else {
0724:                    PolicyModelHelper.removeElement(trust,
0725:                            MustSupportClientChallenge.class, true);
0726:                }
0727:            }
0728:
0729:            public static void enableMustSupportServerChallenge(
0730:                    TrustElement trust, boolean enable) {
0731:                if (enable) {
0732:                    PolicyModelHelper.createElement(trust,
0733:                            SecurityPolicyQName.MUSTSUPPORTSERVERCHALLENGE
0734:                                    .getQName(),
0735:                            MustSupportServerChallenge.class, true);
0736:                } else {
0737:                    PolicyModelHelper.removeElement(trust,
0738:                            MustSupportServerChallenge.class, true);
0739:                }
0740:            }
0741:
0742:            /*************** SIGN ENCRYPT TARGETS PARTS *******************/
0743:
0744:            public static Vector<Vector> getTargets(WSDLComponent comp) {
0745:
0746:                Vector<Vector> rows = new Vector<Vector>();
0747:
0748:                Policy p = null;
0749:                p = PolicyModelHelper.getPolicyForElement(comp);
0750:                if (p == null) {
0751:                    return rows;
0752:                }
0753:
0754:                // ENCRYPTED PARTS FIRST
0755:                List<Body> bodies = Collections.emptyList();
0756:                List<Header> headers = Collections.emptyList();
0757:                List<XPath> xpaths = Collections.emptyList();
0758:                EncryptedParts encryptedParts = (EncryptedParts) PolicyModelHelper
0759:                        .getTopLevelElement(p, EncryptedParts.class);
0760:                EncryptedElements encryptedElements = (EncryptedElements) PolicyModelHelper
0761:                        .getTopLevelElement(p, EncryptedElements.class);
0762:                if (encryptedParts != null) {
0763:                    bodies = encryptedParts
0764:                            .getExtensibilityElements(Body.class);
0765:                    headers = encryptedParts
0766:                            .getExtensibilityElements(Header.class);
0767:                }
0768:                if (encryptedElements != null) {
0769:                    xpaths = encryptedElements
0770:                            .getExtensibilityElements(XPath.class);
0771:                }
0772:                // BODY
0773:                if ((bodies != null) && (!bodies.isEmpty())) {
0774:                    Vector<Object> columns = new Vector<Object>();
0775:                    columns.add(TargetElement.DATA, new MessageBody());
0776:                    columns.add(TargetElement.SIGN, Boolean.FALSE);
0777:                    columns.add(TargetElement.ENCRYPT, Boolean.TRUE);
0778:                    columns.add(TargetElement.REQUIRE, Boolean.FALSE);
0779:                    rows.add(columns);
0780:                }
0781:                // HEADERS
0782:                for (Header h : headers) {
0783:                    MessageHeader header = getListModelForHeader(h);
0784:                    if (header != null) {
0785:                        Vector<Object> columns = new Vector<Object>();
0786:                        columns.add(TargetElement.DATA, header);
0787:                        columns.add(TargetElement.SIGN, Boolean.FALSE);
0788:                        columns.add(TargetElement.ENCRYPT, Boolean.TRUE);
0789:                        columns.add(TargetElement.REQUIRE, Boolean.FALSE);
0790:                        rows.add(columns);
0791:                    }
0792:                }
0793:                // XPATH ELEMENTS
0794:                for (XPath x : xpaths) {
0795:                    MessageElement e = getListModelForXPath(x);
0796:                    if (e != null) {
0797:                        Vector<Object> columns = new Vector<Object>();
0798:                        columns.add(TargetElement.DATA, e);
0799:                        columns.add(TargetElement.SIGN, Boolean.FALSE);
0800:                        columns.add(TargetElement.ENCRYPT, Boolean.TRUE);
0801:                        columns.add(TargetElement.REQUIRE, Boolean.FALSE);
0802:                        rows.add(columns);
0803:                    }
0804:                }
0805:
0806:                SignedParts signedParts = (SignedParts) PolicyModelHelper
0807:                        .getTopLevelElement(p, SignedParts.class);
0808:                SignedElements signedElements = (SignedElements) PolicyModelHelper
0809:                        .getTopLevelElement(p, SignedElements.class);
0810:                if (signedParts != null) {
0811:                    bodies = signedParts.getExtensibilityElements(Body.class);
0812:                    headers = signedParts
0813:                            .getExtensibilityElements(Header.class);
0814:                }
0815:                if (signedElements != null) {
0816:                    xpaths = signedElements
0817:                            .getExtensibilityElements(XPath.class);
0818:                }
0819:
0820:                if ((bodies != null) && (!bodies.isEmpty())) {
0821:                    MessageBody body = new MessageBody();
0822:                    Vector existing = targetExists(rows, body);
0823:                    if (existing != null) {
0824:                        existing.set(TargetElement.SIGN, Boolean.TRUE);
0825:                    } else {
0826:                        Vector<Object> columns = new Vector<Object>();
0827:                        columns.add(TargetElement.DATA, body);
0828:                        columns.add(TargetElement.SIGN, Boolean.TRUE);
0829:                        columns.add(TargetElement.ENCRYPT, Boolean.FALSE);
0830:                        columns.add(TargetElement.REQUIRE, Boolean.FALSE);
0831:                        rows.add(columns);
0832:                    }
0833:                }
0834:                for (Header h : headers) {
0835:                    MessageHeader header = getListModelForHeader(h);
0836:                    if (header != null) {
0837:                        Vector existing = targetExists(rows, header);
0838:                        if (existing != null) {
0839:                            existing.set(TargetElement.SIGN, Boolean.TRUE);
0840:                        } else {
0841:                            Vector<Object> columns = new Vector<Object>();
0842:                            columns.add(TargetElement.DATA, header);
0843:                            columns.add(TargetElement.SIGN, Boolean.TRUE);
0844:                            columns.add(TargetElement.ENCRYPT, Boolean.FALSE);
0845:                            columns.add(TargetElement.REQUIRE, Boolean.FALSE);
0846:                            rows.add(columns);
0847:                        }
0848:                    }
0849:                }
0850:                for (XPath x : xpaths) {
0851:                    MessageElement e = getListModelForXPath(x);
0852:                    if (e != null) {
0853:                        Vector existing = targetExists(rows, e);
0854:                        if (existing != null) {
0855:                            existing.set(TargetElement.SIGN, Boolean.TRUE);
0856:                        } else {
0857:                            Vector<Object> columns = new Vector<Object>();
0858:                            columns.add(TargetElement.DATA, e);
0859:                            columns.add(TargetElement.SIGN, Boolean.TRUE);
0860:                            columns.add(TargetElement.ENCRYPT, Boolean.FALSE);
0861:                            columns.add(TargetElement.REQUIRE, Boolean.FALSE);
0862:                            rows.add(columns);
0863:                        }
0864:                    }
0865:                }
0866:
0867:                RequiredElements requiredElements = (RequiredElements) PolicyModelHelper
0868:                        .getTopLevelElement(p, RequiredElements.class);
0869:                if (requiredElements != null) {
0870:                    xpaths = requiredElements
0871:                            .getExtensibilityElements(XPath.class);
0872:                }
0873:                for (XPath x : xpaths) {
0874:                    MessageElement e = getListModelForXPath(x);
0875:                    if (e != null) {
0876:                        Vector existing = targetExists(rows, e);
0877:                        if (existing != null) {
0878:                            existing.set(TargetElement.REQUIRE, Boolean.TRUE);
0879:                        } else {
0880:                            Vector<Object> columns = new Vector<Object>();
0881:                            columns.add(TargetElement.DATA, e);
0882:                            columns.add(TargetElement.SIGN, Boolean.FALSE);
0883:                            columns.add(TargetElement.ENCRYPT, Boolean.FALSE);
0884:                            columns.add(TargetElement.REQUIRE, Boolean.TRUE);
0885:                            rows.add(columns);
0886:                        }
0887:                    }
0888:                }
0889:
0890:                return rows;
0891:            }
0892:
0893:            public static Vector targetExists(Vector<Vector> rows,
0894:                    TargetElement e) {
0895:                for (Vector row : rows) {
0896:                    TargetElement te = (TargetElement) row
0897:                            .get(TargetElement.DATA);
0898:                    if (te.equals(e)) {
0899:                        return row;
0900:                    }
0901:                }
0902:                return null;
0903:            }
0904:
0905:            public static void setTargets(WSDLComponent comp,
0906:                    Vector<Vector> targetModel) {
0907:
0908:                if (comp == null)
0909:                    return;
0910:
0911:                WSDLModel model = comp.getModel();
0912:
0913:                Policy p = null;
0914:                if (comp instanceof  Policy) {
0915:                    p = (Policy) comp;
0916:                } else {
0917:                    p = PolicyModelHelper.getPolicyForElement(comp);
0918:                }
0919:                EncryptedParts encryptedParts = (EncryptedParts) PolicyModelHelper
0920:                        .getTopLevelElement(p, EncryptedParts.class);
0921:                SignedParts signedParts = (SignedParts) PolicyModelHelper
0922:                        .getTopLevelElement(p, SignedParts.class);
0923:                EncryptedElements encryptedElements = (EncryptedElements) PolicyModelHelper
0924:                        .getTopLevelElement(p, EncryptedElements.class);
0925:                SignedElements signedElements = (SignedElements) PolicyModelHelper
0926:                        .getTopLevelElement(p, SignedElements.class);
0927:                RequiredElements requiredElements = (RequiredElements) PolicyModelHelper
0928:                        .getTopLevelElement(p, RequiredElements.class);
0929:                WSDLComponentFactory wcf = model.getFactory();
0930:
0931:                boolean isTransaction = model.isIntransaction();
0932:                if (!isTransaction) {
0933:                    model.startTransaction();
0934:                }
0935:
0936:                try {
0937:                    WSDLComponent topLevel = null;
0938:                    if (encryptedParts != null) {
0939:                        topLevel = encryptedParts.getParent();
0940:                        topLevel.removeExtensibilityElement(encryptedParts);
0941:                        encryptedParts = null;
0942:                    }
0943:                    if (signedParts != null) {
0944:                        topLevel = signedParts.getParent();
0945:                        topLevel.removeExtensibilityElement(signedParts);
0946:                        signedParts = null;
0947:                    }
0948:                    if (encryptedElements != null) {
0949:                        topLevel = encryptedElements.getParent();
0950:                        topLevel.removeExtensibilityElement(encryptedElements);
0951:                        encryptedElements = null;
0952:                    }
0953:                    if (signedElements != null) {
0954:                        topLevel = signedElements.getParent();
0955:                        topLevel.removeExtensibilityElement(signedElements);
0956:                        signedElements = null;
0957:                    }
0958:                    if (requiredElements != null) {
0959:                        topLevel = requiredElements.getParent();
0960:                        topLevel.removeExtensibilityElement(requiredElements);
0961:                        requiredElements = null;
0962:                    }
0963:
0964:                    if (targetModel == null) {
0965:                        return;
0966:                    }
0967:
0968:                    if (p == null) {
0969:                        topLevel = PolicyModelHelper.createPolicy(comp, true);
0970:                    } else if (!(comp instanceof  Policy)) {
0971:                        topLevel = PolicyModelHelper.createTopExactlyOneAll(p);
0972:                    } else {
0973:                        topLevel = p;
0974:                    }
0975:
0976:                    boolean streamingSecurity = true;
0977:                    for (Vector v : targetModel) {
0978:                        TargetElement te = (TargetElement) v
0979:                                .get(TargetElement.DATA);
0980:                        boolean encrypt = ((Boolean) v
0981:                                .get(TargetElement.ENCRYPT)).booleanValue();
0982:                        boolean sign = ((Boolean) v.get(TargetElement.SIGN))
0983:                                .booleanValue();
0984:                        boolean require = ((Boolean) v
0985:                                .get(TargetElement.REQUIRE)).booleanValue();
0986:
0987:                        if (te instanceof  MessageHeader) {
0988:                            if (encrypt) {
0989:                                if (encryptedParts == null) {
0990:                                    encryptedParts = PolicyModelHelper
0991:                                            .createElement(
0992:                                                    topLevel,
0993:                                                    SecurityPolicyQName.ENCRYPTEDPARTS
0994:                                                            .getQName(),
0995:                                                    EncryptedParts.class, false);
0996:                                }
0997:                                addHeaderElementForListItem(te.toString(),
0998:                                        encryptedParts, wcf);
0999:                            }
1000:                            if (sign) {
1001:                                if (signedParts == null) {
1002:                                    signedParts = PolicyModelHelper
1003:                                            .createElement(
1004:                                                    topLevel,
1005:                                                    SecurityPolicyQName.SIGNEDPARTS
1006:                                                            .getQName(),
1007:                                                    SignedParts.class, false);
1008:                                }
1009:                                addHeaderElementForListItem(te.toString(),
1010:                                        signedParts, wcf);
1011:                            }
1012:                        } else if (te instanceof  MessageElement) {
1013:                            streamingSecurity = false;
1014:                            if (encrypt) {
1015:                                if (encryptedElements == null) {
1016:                                    encryptedElements = PolicyModelHelper
1017:                                            .createElement(
1018:                                                    topLevel,
1019:                                                    SecurityPolicyQName.ENCRYPTEDELEMENTS
1020:                                                            .getQName(),
1021:                                                    EncryptedElements.class,
1022:                                                    false);
1023:                                }
1024:                                addElementForListItem(te.toString(),
1025:                                        encryptedElements, wcf);
1026:                            }
1027:                            if (sign) {
1028:                                if (signedElements == null) {
1029:                                    signedElements = PolicyModelHelper
1030:                                            .createElement(
1031:                                                    topLevel,
1032:                                                    SecurityPolicyQName.SIGNEDELEMENTS
1033:                                                            .getQName(),
1034:                                                    SignedElements.class, false);
1035:                                }
1036:                                addElementForListItem(te.toString(),
1037:                                        signedElements, wcf);
1038:                            }
1039:                            if (require) {
1040:                                if (requiredElements == null) {
1041:                                    requiredElements = PolicyModelHelper
1042:                                            .createElement(
1043:                                                    topLevel,
1044:                                                    SecurityPolicyQName.REQUIREDELEMENTS
1045:                                                            .getQName(),
1046:                                                    RequiredElements.class,
1047:                                                    false);
1048:                                }
1049:                                addElementForListItem(te.toString(),
1050:                                        requiredElements, wcf);
1051:                            }
1052:                        } else if (te instanceof  MessageBody) {
1053:                            if (encrypt) {
1054:                                if (encryptedParts == null) {
1055:                                    encryptedParts = PolicyModelHelper
1056:                                            .createElement(
1057:                                                    topLevel,
1058:                                                    SecurityPolicyQName.ENCRYPTEDPARTS
1059:                                                            .getQName(),
1060:                                                    EncryptedParts.class, false);
1061:                                }
1062:                                addBody(encryptedParts, wcf);
1063:                            }
1064:                            if (sign) {
1065:                                if (signedParts == null) {
1066:                                    signedParts = PolicyModelHelper
1067:                                            .createElement(
1068:                                                    topLevel,
1069:                                                    SecurityPolicyQName.SIGNEDPARTS
1070:                                                            .getQName(),
1071:                                                    SignedParts.class, false);
1072:                                }
1073:                                addBody(signedParts, wcf);
1074:                            }
1075:                        }
1076:                    }
1077:                    if ((comp instanceof  BindingInput)
1078:                            || (comp instanceof  BindingOutput)
1079:                            || (comp instanceof  BindingFault)) {
1080:                        Binding b = (Binding) comp.getParent().getParent();
1081:                        ProprietarySecurityPolicyModelHelper
1082:                                .setStreamingSecurity(b, streamingSecurity);
1083:                    }
1084:                } finally {
1085:                    if (!isTransaction) {
1086:                        model.endTransaction();
1087:                    }
1088:                }
1089:            }
1090:
1091:            public static MessageHeader getListModelForHeader(Header h) {
1092:                String name = h.getName();
1093:                if ("To".equals(name))
1094:                    return new MessageHeader(MessageHeader.ADDRESSING_TO); //NOI18N
1095:                if ("From".equals(name))
1096:                    return new MessageHeader(MessageHeader.ADDRESSING_FROM); //NOI18N
1097:                if ("FaultTo".equals(name))
1098:                    return new MessageHeader(MessageHeader.ADDRESSING_FAULTTO); //NOI18N
1099:                if ("ReplyTo".equals(name))
1100:                    return new MessageHeader(MessageHeader.ADDRESSING_REPLYTO); //NOI18N
1101:                if ("MessageID".equals(name))
1102:                    return new MessageHeader(MessageHeader.ADDRESSING_MESSAGEID); //NOI18N
1103:                if ("RelatesTo".equals(name))
1104:                    return new MessageHeader(MessageHeader.ADDRESSING_RELATESTO); //NOI18N
1105:                if ("Action".equals(name))
1106:                    return new MessageHeader(MessageHeader.ADDRESSING_ACTION); //NOI18N
1107:                if ("AckRequested".equals(name))
1108:                    return new MessageHeader(MessageHeader.RM_ACKREQUESTED); //NOI18N
1109:                if ("SequenceAcknowledgement".equals(name))
1110:                    return new MessageHeader(MessageHeader.RM_SEQUENCEACK); //NOI18N
1111:                if ("Sequence".equals(name))
1112:                    return new MessageHeader(MessageHeader.RM_SEQUENCE); //NOI18N
1113:                return null;
1114:            }
1115:
1116:            public static MessageElement getListModelForXPath(XPath x) {
1117:                String xpath = x.getXPath();
1118:                return new MessageElement(xpath);
1119:            }
1120:
1121:            public static ExtensibilityElement addHeaderElementForListItem(
1122:                    String item, WSDLComponent c, WSDLComponentFactory wcf) {
1123:
1124:                Header h = (Header) wcf.create(c, SecurityPolicyQName.HEADER
1125:                        .getQName());
1126:                if (MessageHeader.ADDRESSING_TO.equals(item)) {
1127:                    h.setName("To"); //NOI18N
1128:                    h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
1129:                }
1130:                if (MessageHeader.ADDRESSING_FROM.equals(item)) {
1131:                    h.setName("From"); //NOI18N
1132:                    h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
1133:                }
1134:                if (MessageHeader.ADDRESSING_FAULTTO.equals(item)) {
1135:                    h.setName("FaultTo"); //NOI18N
1136:                    h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
1137:                }
1138:                if (MessageHeader.ADDRESSING_REPLYTO.equals(item)) {
1139:                    h.setName("ReplyTo"); //NOI18N
1140:                    h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
1141:                }
1142:                if (MessageHeader.ADDRESSING_MESSAGEID.equals(item)) {
1143:                    h.setName("MessageID"); //NOI18N
1144:                    h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
1145:                }
1146:                if (MessageHeader.ADDRESSING_RELATESTO.equals(item)) {
1147:                    h.setName("RelatesTo"); //NOI18N
1148:                    h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
1149:                }
1150:                if (MessageHeader.ADDRESSING_ACTION.equals(item)) {
1151:                    h.setName("Action"); //NOI18N
1152:                    h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
1153:                }
1154:                if (MessageHeader.RM_ACKREQUESTED.equals(item)) {
1155:                    h.setName("AckRequested"); //NOI18N
1156:                    h.setNamespace(RMQName.RM_HEADERS_NS_URI);
1157:                }
1158:                if (MessageHeader.RM_SEQUENCEACK.equals(item)) {
1159:                    h.setName("SequenceAcknowledgement"); //NOI18N
1160:                    h.setNamespace(RMQName.RM_HEADERS_NS_URI);
1161:                }
1162:                if (MessageHeader.RM_SEQUENCE.equals(item)) {
1163:                    h.setName("Sequence"); //NOI18N
1164:                    h.setNamespace(RMQName.RM_HEADERS_NS_URI);
1165:                }
1166:                if (h != null) {
1167:                    c.addExtensibilityElement(h);
1168:                }
1169:                return h;
1170:            }
1171:
1172:            public static ExtensibilityElement addElementForListItem(
1173:                    String item, WSDLComponent c, WSDLComponentFactory wcf) {
1174:                XPath x = null;
1175:                x = (XPath) wcf.create(c, SecurityPolicyQName.XPATH.getQName());
1176:                if (x != null) {
1177:                    c.addExtensibilityElement(x);
1178:                    x.setXPath(item);
1179:                }
1180:                return x;
1181:            }
1182:
1183:            public static ExtensibilityElement addBody(WSDLComponent c,
1184:                    WSDLComponentFactory wcf) {
1185:                Body b = null;
1186:                b = (Body) wcf.create(c, SecurityPolicyQName.BODY.getQName());
1187:                c.addExtensibilityElement(b);
1188:                return b;
1189:            }
1190:
1191:            /**************************** SECURITY BINDING TYPE *********************/
1192:
1193:            /** 
1194:             * Returns string representation of security binding type
1195:             * TODO: maybe this method is not required with the new UI, as there's no mention of it
1196:             */
1197:            public static String getSecurityBindingType(WSDLComponent c) {
1198:                assert c != null;
1199:                ExtensibilityElement e = getSecurityBindingTypeElement(c);
1200:                if (e instanceof  SymmetricBinding)
1201:                    return ComboConstants.SYMMETRIC;
1202:                if (e instanceof  AsymmetricBinding)
1203:                    return ComboConstants.ASYMMETRIC;
1204:                if (e instanceof  TransportBinding)
1205:                    return ComboConstants.TRANSPORT;
1206:                return ComboConstants.NOSECURITY;
1207:            }
1208:
1209:            /**
1210:             * Returns security binding type element for specified element which can be either top level Binding, BindingOperation, ...
1211:             * or sub-level like SecureConversationToken
1212:             */
1213:            public static ExtensibilityElement getSecurityBindingTypeElement(
1214:                    WSDLComponent c) {
1215:                assert c != null;
1216:                WSDLComponent p = c;
1217:
1218:                if ((c instanceof  Binding) || (c instanceof  BindingOperation)
1219:                        || (c instanceof  BindingInput)
1220:                        || (c instanceof  BindingOutput)
1221:                        || (c instanceof  BindingFault)) {
1222:                    p = PolicyModelHelper.getPolicyForElement(c);
1223:                } else if (c instanceof  BootstrapPolicy) {
1224:                    p = PolicyModelHelper.getTopLevelElement(c, Policy.class);
1225:                }
1226:
1227:                ExtensibilityElement ee = PolicyModelHelper.getTopLevelElement(
1228:                        p, SymmetricBinding.class);
1229:                if (ee != null)
1230:                    return ee;
1231:                ee = (AsymmetricBinding) PolicyModelHelper.getTopLevelElement(
1232:                        p, AsymmetricBinding.class);
1233:                if (ee != null)
1234:                    return ee;
1235:                ee = (TransportBinding) PolicyModelHelper.getTopLevelElement(p,
1236:                        TransportBinding.class);
1237:                if (ee != null)
1238:                    return ee;
1239:
1240:                return null;
1241:            }
1242:
1243:            public static WSDLComponent setSecurityBindingType(WSDLComponent c,
1244:                    String bindingType) {
1245:                assert (c != null);
1246:                WSDLModel model = c.getModel();
1247:                WSDLComponent secBindingType = null;
1248:
1249:                boolean isTransaction = model.isIntransaction();
1250:                if (!isTransaction) {
1251:                    model.startTransaction();
1252:                }
1253:
1254:                All a = PolicyModelHelper.createPolicy(c, true);
1255:
1256:                try {
1257:                    SymmetricBinding sb = (SymmetricBinding) PolicyModelHelper
1258:                            .getTopLevelElement(a, SymmetricBinding.class);
1259:                    AsymmetricBinding ab = (AsymmetricBinding) PolicyModelHelper
1260:                            .getTopLevelElement(a, AsymmetricBinding.class);
1261:                    TransportBinding tb = (TransportBinding) PolicyModelHelper
1262:                            .getTopLevelElement(a, TransportBinding.class);
1263:
1264:                    if (sb != null)
1265:                        sb.getParent().removeExtensibilityElement(sb);
1266:                    if (ab != null)
1267:                        ab.getParent().removeExtensibilityElement(ab);
1268:                    if (tb != null)
1269:                        tb.getParent().removeExtensibilityElement(tb);
1270:
1271:                    if (ComboConstants.SYMMETRIC.equals(bindingType)) {
1272:                        sb = PolicyModelHelper
1273:                                .createElement(a,
1274:                                        SecurityPolicyQName.SYMMETRICBINDING
1275:                                                .getQName(),
1276:                                        SymmetricBinding.class, false);
1277:                        secBindingType = sb;
1278:                    }
1279:                    if (ComboConstants.ASYMMETRIC.equals(bindingType)) {
1280:                        ab = PolicyModelHelper.createElement(a,
1281:                                SecurityPolicyQName.ASYMMETRICBINDING
1282:                                        .getQName(), AsymmetricBinding.class,
1283:                                false);
1284:                        secBindingType = ab;
1285:                    }
1286:                    if (ComboConstants.TRANSPORT.equals(bindingType)) {
1287:                        tb = PolicyModelHelper
1288:                                .createElement(a,
1289:                                        SecurityPolicyQName.TRANSPORTBINDING
1290:                                                .getQName(),
1291:                                        TransportBinding.class, false);
1292:                        secBindingType = tb;
1293:                    }
1294:
1295:                } finally {
1296:                    if (!isTransaction) {
1297:                        model.endTransaction();
1298:                    }
1299:                }
1300:
1301:                return secBindingType;
1302:            }
1303:
1304:            public static void setDefaultTargets(WSDLComponent c,
1305:                    boolean headers, boolean rm) {
1306:
1307:                Vector<Vector> targets = new Vector<Vector>();
1308:
1309:                Vector<Object> row = new Vector<Object>();
1310:                MessageBody body = new MessageBody();
1311:                row.add(TargetElement.DATA, body);
1312:                row.add(TargetElement.SIGN, Boolean.TRUE);
1313:                row.add(TargetElement.ENCRYPT, Boolean.TRUE);
1314:                row.add(TargetElement.REQUIRE, Boolean.FALSE);
1315:                targets.add(row);
1316:
1317:                if (headers) {
1318:                    for (String s : MessageHeader.ADDRESSING_HEADERS) {
1319:                        row = new Vector<Object>();
1320:                        MessageHeader h = new MessageHeader(s);
1321:                        row.add(TargetElement.DATA, h);
1322:                        row.add(TargetElement.SIGN, Boolean.TRUE);
1323:                        row.add(TargetElement.ENCRYPT, Boolean.FALSE);
1324:                        row.add(TargetElement.REQUIRE, Boolean.FALSE);
1325:                        targets.add(row);
1326:                    }
1327:                    //            if (rm) {
1328:                    for (String s : MessageHeader.RM_HEADERS) {
1329:                        row = new Vector<Object>();
1330:                        MessageHeader h = new MessageHeader(s);
1331:                        row.add(TargetElement.DATA, h);
1332:                        row.add(TargetElement.SIGN, Boolean.TRUE);
1333:                        row.add(TargetElement.ENCRYPT, Boolean.FALSE);
1334:                        row.add(TargetElement.REQUIRE, Boolean.FALSE);
1335:                        targets.add(row);
1336:                        //              }
1337:                    }
1338:                }
1339:
1340:                setTargets(c, targets);
1341:            }
1342:
1343:            public static void removeTargets(WSDLComponent c) {
1344:                setTargets(c, null);
1345:            }
1346:
1347:            /********** Other binding attributes ****************/
1348:
1349:            public static String getComboItemForElement(WSDLComponent wc) {
1350:                String cName = wc.getClass().getSimpleName();
1351:                String msg = "COMBO_" + cName.substring(0, cName.length() - 4); //NOI18N
1352:                return NbBundle.getMessage(ComboConstants.class, msg);
1353:            }
1354:
1355:            public static String getMessageLayout(WSDLComponent comp) {
1356:                WSDLComponent layout = getMessageLayoutElement(comp);
1357:                if (layout != null) {
1358:                    if (layout instanceof  Strict)
1359:                        return ComboConstants.STRICT;
1360:                    if (layout instanceof  Lax)
1361:                        return ComboConstants.LAX;
1362:                    if (layout instanceof  LaxTsFirst)
1363:                        return ComboConstants.LAXTSFIRST;
1364:                    if (layout instanceof  LaxTsLast)
1365:                        return ComboConstants.LAXTSLAST;
1366:                }
1367:                return null;
1368:            }
1369:
1370:            public static WSDLComponent getMessageLayoutElement(
1371:                    WSDLComponent comp) {
1372:                if ((comp instanceof  Binding)
1373:                        || (comp instanceof  BindingOperation)) {
1374:                    comp = SecurityPolicyModelHelper
1375:                            .getSecurityBindingTypeElement(comp);
1376:                }
1377:                if (comp == null)
1378:                    return null;
1379:                Policy p = PolicyModelHelper.getTopLevelElement(comp,
1380:                        Policy.class);
1381:                Layout l = PolicyModelHelper
1382:                        .getTopLevelElement(p, Layout.class);
1383:                p = PolicyModelHelper.getTopLevelElement(l, Policy.class);
1384:                if (p != null) {
1385:                    List<ExtensibilityElement> elements = p
1386:                            .getExtensibilityElements();
1387:                    if ((elements != null) && !(elements.isEmpty())) {
1388:                        ExtensibilityElement e = elements.get(0);
1389:                        return e;
1390:                    }
1391:                }
1392:                return null;
1393:            }
1394:
1395:            public static boolean isIncludeTimestamp(WSDLComponent c) {
1396:                ExtensibilityElement e = getSecurityBindingTypeElement(c);
1397:                if (e != null) {
1398:                    return isAttributeEnabled(e, IncludeTimestamp.class);
1399:                }
1400:                return false;
1401:            }
1402:
1403:            public static boolean isEncryptBeforeSigning(WSDLComponent c) {
1404:                ExtensibilityElement e = getSecurityBindingTypeElement(c);
1405:                if (e != null) {
1406:                    return isAttributeEnabled(e, EncryptBeforeSigning.class);
1407:                }
1408:                return false;
1409:            }
1410:
1411:            public static boolean isEncryptSignature(WSDLComponent c) {
1412:                ExtensibilityElement e = getSecurityBindingTypeElement(c);
1413:                if (e != null) {
1414:                    return isAttributeEnabled(e, EncryptSignature.class);
1415:                }
1416:                return false;
1417:            }
1418:
1419:            public static boolean isSignEntireHeadersAndBody(WSDLComponent c) {
1420:                ExtensibilityElement e = getSecurityBindingTypeElement(c);
1421:                if (e != null) {
1422:                    return isAttributeEnabled(e,
1423:                            OnlySignEntireHeadersAndBody.class);
1424:                }
1425:                return false;
1426:            }
1427:
1428:            public static void setLayout(WSDLComponent c, String msgLayout) {
1429:                WSDLModel model = c.getModel();
1430:                WSDLComponentFactory wcf = model.getFactory();
1431:
1432:                boolean isTransaction = model.isIntransaction();
1433:                if (!isTransaction) {
1434:                    model.startTransaction();
1435:                }
1436:                try {
1437:                    QName qnameToCreate = null;
1438:                    if (ComboConstants.STRICT.equals(msgLayout)) {
1439:                        qnameToCreate = SecurityPolicyQName.STRICT.getQName();
1440:                    } else if (ComboConstants.LAX.equals(msgLayout)) {
1441:                        qnameToCreate = SecurityPolicyQName.LAX.getQName();
1442:                    } else if (ComboConstants.LAXTSFIRST.equals(msgLayout)) {
1443:                        qnameToCreate = SecurityPolicyQName.LAXTSFIRST
1444:                                .getQName();
1445:                    } else if (ComboConstants.LAXTSLAST.equals(msgLayout)) {
1446:                        qnameToCreate = SecurityPolicyQName.LAXTSLAST
1447:                                .getQName();
1448:                    }
1449:
1450:                    Layout layout = PolicyModelHelper.createElement(c,
1451:                            SecurityPolicyQName.LAYOUT.getQName(),
1452:                            Layout.class, true);
1453:
1454:                    List<Policy> policies = layout
1455:                            .getExtensibilityElements(Policy.class);
1456:                    if ((policies != null) && (!policies.isEmpty())) {
1457:                        for (Policy pol : policies) {
1458:                            layout.removeExtensibilityElement(pol);
1459:                        }
1460:                    }
1461:                    Policy p = PolicyModelHelper.createElement(layout,
1462:                            PolicyQName.POLICY.getQName(), Policy.class, false);
1463:                    ExtensibilityElement e = (ExtensibilityElement) wcf.create(
1464:                            p, qnameToCreate);
1465:                    p.addExtensibilityElement(e);
1466:                } finally {
1467:                    if (!isTransaction) {
1468:                        model.endTransaction();
1469:                    }
1470:                }
1471:            }
1472:
1473:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.