KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > wsdlmodelext > SecurityPolicyModelHelper


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.wsitconf.wsdlmodelext;
21
22 import java.util.Collection JavaDoc;
23 import org.netbeans.modules.websvc.wsitmodelext.addressing.Addressing10QName;
24 import org.netbeans.modules.websvc.wsitmodelext.security.RequiredElements;
25 import org.netbeans.modules.websvc.wsitmodelext.security.TrustElement;
26 import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants;
27 import org.netbeans.modules.websvc.wsitconf.ui.security.listmodels.*;
28 import org.netbeans.modules.websvc.wsitmodelext.policy.All;
29 import org.netbeans.modules.websvc.wsitmodelext.policy.Policy;
30 import org.netbeans.modules.websvc.wsitmodelext.policy.PolicyQName;
31 import org.netbeans.modules.websvc.wsitmodelext.rm.RMQName;
32 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.KeyStore;
33 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.TrustStore;
34 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireDerivedKeys;
35 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireEmbeddedTokenReference;
36 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireExternalReference;
37 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireExternalUriReference;
38 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireInternalReference;
39 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireIssuerSerialReference;
40 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireKeyIdentifierReference;
41 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RequireThumbprintReference;
42 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.SC10SecurityContextToken;
43 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.TokensQName;
44 import org.netbeans.modules.websvc.wsitmodelext.security.AsymmetricBinding;
45 import org.netbeans.modules.websvc.wsitmodelext.security.Body;
46 import org.netbeans.modules.websvc.wsitmodelext.security.BootstrapPolicy;
47 import org.netbeans.modules.websvc.wsitmodelext.security.EncryptedElements;
48 import org.netbeans.modules.websvc.wsitmodelext.security.EncryptedParts;
49 import org.netbeans.modules.websvc.wsitmodelext.security.Header;
50 import org.netbeans.modules.websvc.wsitmodelext.security.Lax;
51 import org.netbeans.modules.websvc.wsitmodelext.security.LaxTsFirst;
52 import org.netbeans.modules.websvc.wsitmodelext.security.LaxTsLast;
53 import org.netbeans.modules.websvc.wsitmodelext.security.Layout;
54 import org.netbeans.modules.websvc.wsitmodelext.security.SecurityPolicyQName;
55 import org.netbeans.modules.websvc.wsitmodelext.security.SignedElements;
56 import org.netbeans.modules.websvc.wsitmodelext.security.SignedParts;
57 import org.netbeans.modules.websvc.wsitmodelext.security.Strict;
58 import org.netbeans.modules.websvc.wsitmodelext.security.SymmetricBinding;
59 import org.netbeans.modules.websvc.wsitmodelext.security.TransportBinding;
60 import org.netbeans.modules.websvc.wsitmodelext.security.Trust10;
61 import org.netbeans.modules.websvc.wsitmodelext.security.Wss10;
62 import org.netbeans.modules.websvc.wsitmodelext.security.Wss11;
63 import org.netbeans.modules.websvc.wsitmodelext.security.WssElement;
64 import org.netbeans.modules.websvc.wsitmodelext.security.XPath;
65 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.EncryptBeforeSigning;
66 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.EncryptSignature;
67 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.IncludeTimestamp;
68 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportClientChallenge;
69 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportIssuedTokens;
70 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefEmbeddedToken;
71 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefEncryptedKey;
72 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefExternalURI;
73 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefIssuerSerial;
74 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefKeyIdentifier;
75 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportRefThumbprint;
76 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.MustSupportServerChallenge;
77 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.OnlySignEntireHeadersAndBody;
78 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.RequireClientEntropy;
79 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.RequireServerEntropy;
80 import org.netbeans.modules.websvc.wsitmodelext.security.parameters.RequireSignatureConfirmation;
81 import org.netbeans.modules.xml.wsdl.model.*;
82 import org.openide.util.NbBundle;
83 import javax.xml.namespace.QName JavaDoc;
84 import java.util.Collections JavaDoc;
85 import java.util.List JavaDoc;
86 import java.util.Vector JavaDoc;
87
88 /**
89  *
90  * @author Martin Grebac
91  */

92 public class SecurityPolicyModelHelper {
93     
94     /**
95      * Creates a new instance of SecurityPolicyModelHelper
96      */

97     public SecurityPolicyModelHelper() { }
98
99     // checks if Security is enabled in the config wsdl on specified element (Binding/Operation/Message)
100
public static boolean isSecurityEnabled(WSDLComponent c) {
101         WSDLModel model = c.getModel();
102         Policy p = PolicyModelHelper.getPolicyForElement(c);
103         if (p != null) {
104             ExtensibilityElement secElem = getSecurityBindingTypeElement(c);
105             return (secElem != null);
106         }
107         return false;
108     }
109
110     public static void disableSecurity(WSDLComponent c, boolean removeStoreConfig) {
111         assert ((c instanceof Binding) || (c instanceof BindingOperation));
112         setSecurityBindingType(c, null);
113         SecurityTokensModelHelper.setSupportingTokens(c, null, SecurityTokensModelHelper.NONE);
114         disableWss(c);
115         disableTrust10(c);
116         removeTargets(c);
117         Policy p = PolicyModelHelper.getPolicyForElement(c);
118         if ((p != null) && (removeStoreConfig)) {
119             KeyStore ks = PolicyModelHelper.getTopLevelElement(p, KeyStore.class);
120             TrustStore ts = PolicyModelHelper.getTopLevelElement(p, TrustStore.class);
121             if (ks != null) PolicyModelHelper.removeElement(ks);
122             if (ts != null) PolicyModelHelper.removeElement(ts);
123         }
124         if (c instanceof Binding) {
125             Binding b = (Binding)c;
126             Collection JavaDoc<BindingOperation> ops = b.getBindingOperations();
127             for (BindingOperation op : ops) {
128                 disableSecurity(op, removeStoreConfig);
129             }
130         } else {
131             BindingOperation bop = (BindingOperation)c;
132             BindingInput bi = bop.getBindingInput();
133             BindingOutput bo = bop.getBindingOutput();
134             if (bi != null) PolicyModelHelper.removePolicyForElement(bi);
135             if (bo != null) PolicyModelHelper.removePolicyForElement(bo);
136         }
137         PolicyModelHelper.cleanPolicies(c);
138     }
139     
140     public static WssElement enableWss(WSDLComponent c, boolean wss11) {
141     
142         if ((c instanceof Binding) ||
143             (c instanceof BindingOperation) ||
144             (c instanceof BindingInput) || (c instanceof BindingOutput) || (c instanceof BindingFault)) {
145             c = PolicyModelHelper.createPolicy(c);
146         }
147         
148         if (wss11) {
149             if (isWss10(c)) {
150                 disableWss(c);
151             }
152             if (!isWss11(c)) {
153                 return PolicyModelHelper.createElement(c, SecurityPolicyQName.WSS11.getQName(), Wss11.class, false);
154             } else {
155                 return getWss11(c);
156             }
157         } else {
158             if (isWss11(c)) {
159                 disableWss(c);
160             }
161             if (!isWss10(c)) {
162                 return PolicyModelHelper.createElement(c, SecurityPolicyQName.WSS10.getQName(), Wss10.class, false);
163             } else {
164                 return getWss10(c);
165             }
166         }
167     }
168     
169     public static TrustElement enableTrust10(WSDLComponent c) {
170         if ((c instanceof Binding) ||
171             (c instanceof BindingOperation) ||
172             (c instanceof BindingInput) || (c instanceof BindingOutput) || (c instanceof BindingFault)) {
173             c = PolicyModelHelper.createPolicy(c);
174         }
175         if (!isTrust10(c)) {
176             return PolicyModelHelper.createElement(c, SecurityPolicyQName.TRUST10.getQName(), Trust10.class, false);
177         } else {
178             return getTrust10(c);
179         }
180     }
181
182     // disables Wss in the config wsdl on specified binding
183
public static void disableWss(WSDLComponent c) {
184         WSDLModel model = c.getModel();
185         if ((c instanceof Binding) ||
186             (c instanceof BindingOperation) ||
187             (c instanceof BindingInput) || (c instanceof BindingOutput) || (c instanceof BindingFault)) {
188             c = PolicyModelHelper.createPolicy(c);
189         }
190         WssElement wss10 = getWss10(c);
191         WssElement wss11 = getWss11(c);
192         boolean isTransaction = model.isIntransaction();
193         if (!isTransaction) {
194             model.startTransaction();
195         }
196         try {
197             if (wss10 != null) {
198                 wss10.getParent().removeExtensibilityElement(wss10);
199             }
200             if (wss11 != null) {
201                 wss11.getParent().removeExtensibilityElement(wss11);
202             }
203         } finally {
204             if (!isTransaction) {
205                 model.endTransaction();
206             }
207         }
208     }
209     
210     /* Disables Trust10 in the config wsdl on specified component
211      */

212     public static void disableTrust10(WSDLComponent c) {
213         WSDLModel model = c.getModel();
214         if ((c instanceof Binding) ||
215             (c instanceof BindingOperation) ||
216             (c instanceof BindingInput) || (c instanceof BindingOutput) || (c instanceof BindingFault)) {
217             c = PolicyModelHelper.createPolicy(c);
218         }
219         boolean isTransaction = model.isIntransaction();
220         if (!isTransaction) {
221             model.startTransaction();
222         }
223         Trust10 trust = getTrust10(c);
224         try {
225             if (trust != null) {
226                 trust.getParent().removeExtensibilityElement(trust);
227             }
228         } finally {
229             if (!isTransaction) {
230                 model.endTransaction();
231             }
232         }
233     }
234
235     public static boolean isWss10(WSDLComponent c) {
236         return getWss10(c) != null;
237     }
238
239     public static boolean isWss11(WSDLComponent c) {
240         return getWss11(c) != null;
241     }
242
243     public static boolean isTrust10(WSDLComponent c) {
244         return getTrust10(c) != null;
245     }
246
247     public static Wss10 getWss10(WSDLComponent c) {
248         if ((c instanceof Binding) || (c instanceof BindingOperation)) {
249             c = PolicyModelHelper.getPolicyForElement(c);
250         }
251         return PolicyModelHelper.getTopLevelElement(c, Wss10.class);
252     }
253
254     public static Wss11 getWss11(WSDLComponent c) {
255         if ((c instanceof Binding) || (c instanceof BindingOperation)) {
256             c = PolicyModelHelper.getPolicyForElement(c);
257         }
258         return PolicyModelHelper.getTopLevelElement(c, Wss11.class);
259     }
260     
261     public static Trust10 getTrust10(WSDLComponent c) {
262         if ((c instanceof Binding) || (c instanceof BindingOperation)) {
263             c = PolicyModelHelper.getPolicyForElement(c);
264         }
265         return PolicyModelHelper.getTopLevelElement(c, Trust10.class);
266     }
267
268     // -------- WSS10 & 11 ELEMENTS -----------
269
public static boolean isMustSupportRefEmbeddedToken(WSDLComponent comp) {
270         Wss11 wss11 = getWss11(comp);
271         Wss10 wss10 = getWss10(comp);
272         return isAttributeEnabled(wss10, MustSupportRefEmbeddedToken.class)
273         || isAttributeEnabled(wss11, MustSupportRefEmbeddedToken.class);
274     }
275
276     public static boolean isMustSupportRefExternalURI(WSDLComponent comp) {
277         Wss11 wss11 = getWss11(comp);
278         Wss10 wss10 = getWss10(comp);
279         return isAttributeEnabled(wss10, MustSupportRefExternalURI.class)
280         || isAttributeEnabled(wss11, MustSupportRefExternalURI.class);
281     }
282
283     public static boolean isMustSupportRefIssuerSerial(WSDLComponent comp) {
284         Wss11 wss11 = getWss11(comp);
285         Wss10 wss10 = getWss10(comp);
286         return isAttributeEnabled(wss10, MustSupportRefIssuerSerial.class)
287         || isAttributeEnabled(wss11, MustSupportRefIssuerSerial.class);
288     }
289
290     public static boolean isMustSupportRefKeyIdentifier(WSDLComponent comp) {
291         Wss11 wss11 = getWss11(comp);
292         Wss10 wss10 = getWss10(comp);
293         return isAttributeEnabled(wss10, MustSupportRefKeyIdentifier.class)
294         || isAttributeEnabled(wss11, MustSupportRefKeyIdentifier.class);
295     }
296
297     // ----------- WSS11 ONLY ELEMENTS -----------
298
public static boolean isMustSupportRefEncryptedKey(WSDLComponent comp) {
299         Wss11 wss11 = getWss11(comp);
300         return isAttributeEnabled(wss11, MustSupportRefEncryptedKey.class);
301     }
302
303     public static boolean isMustSupportRefThumbprint(WSDLComponent comp) {
304         Wss11 wss11 = getWss11(comp);
305         return isAttributeEnabled(wss11, MustSupportRefThumbprint.class);
306     }
307
308     public static boolean isRequireSignatureConfirmation(WSDLComponent comp) {
309         Wss11 wss11 = getWss11(comp);
310         return isAttributeEnabled(wss11, RequireSignatureConfirmation.class);
311     }
312
313     // -------- TRUST ELEMENTS -----------
314
public static boolean isRequireServerEntropy(WSDLComponent comp) {
315         Trust10 trust = getTrust10(comp);
316         return isAttributeEnabled(trust, RequireServerEntropy.class);
317     }
318     
319     public static boolean isRequireClientEntropy(WSDLComponent comp) {
320         Trust10 trust = getTrust10(comp);
321         return isAttributeEnabled(trust, RequireClientEntropy.class);
322     }
323     
324     public static boolean isMustSupportIssuedTokens(WSDLComponent comp) {
325         Trust10 trust = getTrust10(comp);
326         return isAttributeEnabled(trust, MustSupportIssuedTokens.class);
327     }
328     
329     public static boolean isMustSupportClientChallenge(WSDLComponent comp) {
330         Trust10 trust = getTrust10(comp);
331         return isAttributeEnabled(trust, MustSupportClientChallenge.class);
332     }
333
334     public static boolean isMustSupportServerChallenge(WSDLComponent comp) {
335         Trust10 trust = getTrust10(comp);
336         return isAttributeEnabled(trust, MustSupportServerChallenge.class);
337     }
338
339     /* Used to get values of attributes defined in WSS10/WSS11/TRUST10 assertions, for tokens, ...
340      * first retrieves the Policy element and then element of class a underneath
341      */

342     public static boolean isAttributeEnabled(ExtensibilityElement element, Class JavaDoc a) {
343         if (element != null) {
344             Policy p = PolicyModelHelper.getTopLevelElement(element, Policy.class);
345             return (PolicyModelHelper.getTopLevelElement(p, a) != null);
346         }
347         return false;
348     }
349
350     public static void enableIncludeTimestamp(WSDLComponent secBinding, boolean enable) {
351         if (enable) {
352             PolicyModelHelper.createElement(secBinding, SecurityPolicyQName.INCLUDETIMESTAMP.getQName(), IncludeTimestamp.class, true);
353         } else {
354             PolicyModelHelper.removeElement(secBinding, IncludeTimestamp.class, true);
355         }
356     }
357     
358     public static void enableEncryptSignature(WSDLComponent secBinding, boolean enable) {
359         if (enable) {
360             PolicyModelHelper.createElement(secBinding, SecurityPolicyQName.ENCRYPTSIGNATURE.getQName(), EncryptSignature.class, true);
361         } else {
362             PolicyModelHelper.removeElement(secBinding, EncryptSignature.class, true);
363         }
364     }
365
366     public static void enableSignEntireHeadersAndBody(WSDLComponent secBinding, boolean enable) {
367         if (enable) {
368             PolicyModelHelper.createElement(secBinding, SecurityPolicyQName.ONLYSIGNENTIREHEADERSANDBODY.getQName(), OnlySignEntireHeadersAndBody.class, true);
369         } else {
370             PolicyModelHelper.removeElement(secBinding, OnlySignEntireHeadersAndBody.class, true);
371         }
372     }
373
374     public static void enableEncryptBeforeSigning(WSDLComponent secBinding, boolean enable) {
375         if (enable) {
376             PolicyModelHelper.createElement(secBinding, SecurityPolicyQName.ENCRYPTBEFORESIGNING.getQName(), EncryptBeforeSigning.class, true);
377         } else {
378             PolicyModelHelper.removeElement(secBinding, EncryptBeforeSigning.class, true);
379         }
380     }
381
382     public static void enableMustSupportRefEmbeddedToken(WssElement wss, boolean enable) {
383         if (enable) {
384             PolicyModelHelper.createElement(wss, SecurityPolicyQName.MUSTSUPPORTREFEMBEDDEDTOKEN.getQName(), MustSupportRefEmbeddedToken.class, true);
385         } else {
386             PolicyModelHelper.removeElement(wss, MustSupportRefEmbeddedToken.class, true);
387         }
388     }
389     
390     public static void enableMustSupportRefExternalURI(WssElement wss, boolean enable) {
391         if (enable) {
392             PolicyModelHelper.createElement(wss, SecurityPolicyQName.MUSTSUPPORTREFEXTERNALURI.getQName(), MustSupportRefExternalURI.class, true);
393         } else {
394             PolicyModelHelper.removeElement(wss, MustSupportRefExternalURI.class, true);
395         }
396     }
397     
398     public static void enableMustSupportRefIssuerSerial(WssElement wss, boolean enable) {
399         if (enable) {
400             PolicyModelHelper.createElement(wss, SecurityPolicyQName.MUSTSUPPORTREFISSUERSERIAL.getQName(), MustSupportRefIssuerSerial.class, true);
401         } else {
402             PolicyModelHelper.removeElement(wss, MustSupportRefIssuerSerial.class, true);
403         }
404     }
405     
406     public static void enableMustSupportRefKeyIdentifier(WssElement wss, boolean enable) {
407         if (enable) {
408             PolicyModelHelper.createElement(wss, SecurityPolicyQName.MUSTSUPPORTREFKEYIDENTIFIER.getQName(), MustSupportRefKeyIdentifier.class, true);
409         } else {
410             PolicyModelHelper.removeElement(wss, MustSupportRefKeyIdentifier.class, true);
411         }
412     }
413
414     public static boolean isRequireDerivedKeys(WSDLComponent token) {
415         return isAttributeEnabled((ExtensibilityElement) token, RequireDerivedKeys.class);
416     }
417
418     public static void enableRequireDerivedKeys(WSDLComponent tokenType, boolean enable) {
419         if (enable) {
420             PolicyModelHelper.createElement(tokenType, TokensQName.REQUIREDERIVEDKEYS.getQName(), RequireDerivedKeys.class, true);
421         } else {
422             PolicyModelHelper.removeElement(tokenType, RequireDerivedKeys.class, true);
423         }
424     }
425
426     public static void enableRequireExternalUri(WSDLComponent tokenType, boolean enable) {
427         if (enable) {
428             PolicyModelHelper.createElement(tokenType, TokensQName.REQUIREEXTERNALURIREFERENCE.getQName(), RequireExternalUriReference.class, true);
429         } else {
430             PolicyModelHelper.removeElement(tokenType, RequireExternalUriReference.class, true);
431         }
432     }
433
434     public static void enableRequireKeyIdentifierReference(WSDLComponent tokenType, boolean enable) {
435         if (enable) {
436             PolicyModelHelper.createElement(tokenType, TokensQName.REQUIREKEYIDENTIFIERREFERENCE.getQName(), RequireKeyIdentifierReference.class, true);
437         } else {
438             PolicyModelHelper.removeElement(tokenType, RequireKeyIdentifierReference.class, true);
439         }
440     }
441     
442     public static void enableRequireSecurityContextToken(WSDLComponent tokenType, boolean enable) {
443         if (enable) {
444             PolicyModelHelper.createElement(tokenType, TokensQName.SC10SECURITYCONTEXTTOKEN.getQName(), SC10SecurityContextToken.class, true);
445         } else {
446             PolicyModelHelper.removeElement(tokenType, SC10SecurityContextToken.class, true);
447         }
448     }
449
450     public static void enableRequireIssuerSerialReference(WSDLComponent tokenType, boolean enable) {
451         if (enable) {
452             PolicyModelHelper.createElement(tokenType, TokensQName.REQUIREISSUERSERIALREFERENCE.getQName(), RequireIssuerSerialReference.class, true);
453         } else {
454             PolicyModelHelper.removeElement(tokenType, RequireIssuerSerialReference.class, true);
455         }
456     }
457
458     public static void enableRequireEmbeddedTokenReference(WSDLComponent tokenType, boolean enable) {
459         if (enable) {
460             PolicyModelHelper.createElement(tokenType, TokensQName.REQUIREEMBEDDEDTOKENREFERENCE.getQName(), RequireEmbeddedTokenReference.class, true);
461         } else {
462             PolicyModelHelper.removeElement(tokenType, RequireEmbeddedTokenReference.class, true);
463         }
464     }
465
466     public static void enableRequireThumbprintReference(WSDLComponent tokenType, boolean enable) {
467         if (enable) {
468             PolicyModelHelper.createElement(tokenType, TokensQName.REQUIRETHUMBPRINTREFERENCE.getQName(), RequireThumbprintReference.class, true);
469         } else {
470             PolicyModelHelper.removeElement(tokenType, RequireThumbprintReference.class, true);
471         }
472     }
473     
474     public static void enableRequireExternalReference(WSDLComponent tokenType, boolean enable) {
475         if (enable) {
476             PolicyModelHelper.createElement(tokenType, TokensQName.REQUIREEXTERNALREFERENCE.getQName(), RequireExternalReference.class, true);
477         } else {
478             PolicyModelHelper.removeElement(tokenType, RequireExternalReference.class, true);
479         }
480     }
481
482     public static void enableRequireInternalReference(WSDLComponent tokenType, boolean enable) {
483         if (enable) {
484             PolicyModelHelper.createElement(tokenType, TokensQName.REQUIREINTERNALREFERENCE.getQName(), RequireInternalReference.class, true);
485         } else {
486             PolicyModelHelper.removeElement(tokenType, RequireInternalReference.class, true);
487         }
488     }
489
490     public static void enableMustSupportRefEncryptedKey(WssElement wss, boolean enable) {
491         if (enable) {
492             PolicyModelHelper.createElement(wss, SecurityPolicyQName.MUSTSUPPORTREFENCRYPTEDKEY.getQName(), MustSupportRefEncryptedKey.class, true);
493         } else {
494             PolicyModelHelper.removeElement(wss, MustSupportRefEncryptedKey.class, true);
495         }
496     }
497
498     public static void enableMustSupportRefThumbprint(WssElement wss, boolean enable) {
499         if (enable) {
500             PolicyModelHelper.createElement(wss, SecurityPolicyQName.MUSTSUPPORTREFTHUMBPRINT.getQName(), MustSupportRefThumbprint.class, true);
501         } else {
502             PolicyModelHelper.removeElement(wss, MustSupportRefThumbprint.class, true);
503         }
504     }
505     
506     public static void enableRequireSignatureConfirmation(WssElement wss, boolean enable) {
507         if (enable) {
508             PolicyModelHelper.createElement(wss, SecurityPolicyQName.REQUIRESIGNATURECONFIRMATION.getQName(), RequireSignatureConfirmation.class, true);
509         } else {
510             PolicyModelHelper.removeElement(wss, RequireSignatureConfirmation.class, true);
511         }
512     }
513
514     // ----------- TRUST -------------------
515
public static void enableRequireClientEntropy(TrustElement trust, boolean enable) {
516         if (enable) {
517             PolicyModelHelper.createElement(trust, SecurityPolicyQName.REQUIRECLIENTENTROPY.getQName(), RequireClientEntropy.class, true);
518         } else {
519             PolicyModelHelper.removeElement(trust, RequireClientEntropy.class, true);
520         }
521     }
522     
523     public static void enableRequireServerEntropy(TrustElement trust, boolean enable) {
524         if (enable) {
525             PolicyModelHelper.createElement(trust, SecurityPolicyQName.REQUIRESERVERENTROPY.getQName(), RequireServerEntropy.class, true);
526         } else {
527             PolicyModelHelper.removeElement(trust, RequireServerEntropy.class, true);
528         }
529     }
530
531     public static void enableMustSupportIssuedTokens(TrustElement trust, boolean enable) {
532         if (enable) {
533             PolicyModelHelper.createElement(trust, SecurityPolicyQName.MUSTSUPPORTISSUEDTOKENS.getQName(), MustSupportIssuedTokens.class, true);
534         } else {
535             PolicyModelHelper.removeElement(trust, MustSupportIssuedTokens.class, true);
536         }
537     }
538
539     public static void enableMustSupportClientChallenge(TrustElement trust, boolean enable) {
540         if (enable) {
541             PolicyModelHelper.createElement(trust, SecurityPolicyQName.MUSTSUPPORTCLIENTCHALLENGE.getQName(), MustSupportClientChallenge.class, true);
542         } else {
543             PolicyModelHelper.removeElement(trust, MustSupportClientChallenge.class, true);
544         }
545     }
546     
547     public static void enableMustSupportServerChallenge(TrustElement trust, boolean enable) {
548         if (enable) {
549             PolicyModelHelper.createElement(trust, SecurityPolicyQName.MUSTSUPPORTSERVERCHALLENGE.getQName(), MustSupportServerChallenge.class, true);
550         } else {
551             PolicyModelHelper.removeElement(trust, MustSupportServerChallenge.class, true);
552         }
553     }
554         
555     /*************** SIGN ENCRYPT TARGETS PARTS *******************/
556     
557     public static Vector JavaDoc<Vector JavaDoc> getTargets(WSDLComponent comp) {
558         
559         WSDLModel model = comp.getModel();
560         Vector JavaDoc<Vector JavaDoc> rows = new Vector JavaDoc();
561         
562         Policy p = null;
563         p = PolicyModelHelper.getPolicyForElement(comp);
564         if (p == null) {
565             return rows;
566         }
567
568         // ENCRYPTED PARTS FIRST
569
List JavaDoc<Body> bodies = Collections.EMPTY_LIST;
570         List JavaDoc<Header> headers = Collections.EMPTY_LIST;
571         List JavaDoc<XPath> xpaths = Collections.EMPTY_LIST;
572         EncryptedParts encryptedParts = (EncryptedParts)PolicyModelHelper.getTopLevelElement(p, EncryptedParts.class);
573         EncryptedElements encryptedElements = (EncryptedElements)PolicyModelHelper.getTopLevelElement(p, EncryptedElements.class);
574         if (encryptedParts != null) {
575             bodies = encryptedParts.getExtensibilityElements(Body.class);
576             headers = encryptedParts.getExtensibilityElements(Header.class);
577         }
578         if (encryptedElements != null) {
579             xpaths = encryptedElements.getExtensibilityElements(XPath.class);
580         }
581         // BODY
582
if ((bodies != null) && (!bodies.isEmpty())) {
583             Vector JavaDoc columns = new Vector JavaDoc();
584             columns.add(TargetElement.DATA, new MessageBody());
585             columns.add(TargetElement.SIGN, Boolean.FALSE);
586             columns.add(TargetElement.ENCRYPT, Boolean.TRUE);
587             columns.add(TargetElement.REQUIRE, Boolean.FALSE);
588             rows.add(columns);
589         }
590         // HEADERS
591
for (Header h : headers) {
592             MessageHeader header = getListModelForHeader(h);
593             if (header != null) {
594                 Vector JavaDoc columns = new Vector JavaDoc();
595                 columns.add(TargetElement.DATA, header);
596                 columns.add(TargetElement.SIGN, Boolean.FALSE);
597                 columns.add(TargetElement.ENCRYPT, Boolean.TRUE);
598                 columns.add(TargetElement.REQUIRE, Boolean.FALSE);
599                 rows.add(columns);
600             }
601         }
602         // XPATH ELEMENTS
603
for (XPath x : xpaths) {
604             MessageElement e = getListModelForXPath(x);
605             if (e != null) {
606                 Vector JavaDoc columns = new Vector JavaDoc();
607                 columns.add(TargetElement.DATA, e);
608                 columns.add(TargetElement.SIGN, Boolean.FALSE);
609                 columns.add(TargetElement.ENCRYPT, Boolean.TRUE);
610                 columns.add(TargetElement.REQUIRE, Boolean.FALSE);
611                 rows.add(columns);
612             }
613         }
614         
615         SignedParts signedParts = (SignedParts)PolicyModelHelper.getTopLevelElement(p, SignedParts.class);
616         SignedElements signedElements = (SignedElements)PolicyModelHelper.getTopLevelElement(p, SignedElements.class);
617         if (signedParts != null) {
618             bodies = signedParts.getExtensibilityElements(Body.class);
619             headers = signedParts.getExtensibilityElements(Header.class);
620         }
621         if (signedElements != null) {
622             xpaths = signedElements.getExtensibilityElements(XPath.class);
623         }
624
625         if ((bodies != null) && (!bodies.isEmpty())) {
626             MessageBody body = new MessageBody();
627             Vector JavaDoc existing = targetExists(rows, body);
628             if (existing != null) {
629                 existing.set(TargetElement.SIGN, Boolean.TRUE);
630             } else {
631                 Vector JavaDoc columns = new Vector JavaDoc();
632                 columns.add(TargetElement.DATA, body);
633                 columns.add(TargetElement.SIGN, Boolean.TRUE);
634                 columns.add(TargetElement.ENCRYPT, Boolean.FALSE);
635                 columns.add(TargetElement.REQUIRE, Boolean.FALSE);
636                 rows.add(columns);
637             }
638         }
639         for (Header h : headers) {
640             MessageHeader header = getListModelForHeader(h);
641             if (header != null) {
642                 Vector JavaDoc existing = targetExists(rows, header);
643                 if (existing != null) {
644                     existing.set(TargetElement.SIGN, Boolean.TRUE);
645                 } else {
646                     Vector JavaDoc columns = new Vector JavaDoc();
647                     columns.add(TargetElement.DATA, header);
648                     columns.add(TargetElement.SIGN, Boolean.TRUE);
649                     columns.add(TargetElement.ENCRYPT, Boolean.FALSE);
650                     columns.add(TargetElement.REQUIRE, Boolean.FALSE);
651                     rows.add(columns);
652                 }
653             }
654         }
655         for (XPath x : xpaths) {
656             MessageElement e = getListModelForXPath(x);
657             if (e != null) {
658                 Vector JavaDoc existing = targetExists(rows, e);
659                 if (existing != null) {
660                     existing.set(TargetElement.SIGN, Boolean.TRUE);
661                 } else {
662                     Vector JavaDoc columns = new Vector JavaDoc();
663                     columns.add(TargetElement.DATA, e);
664                     columns.add(TargetElement.SIGN, Boolean.TRUE);
665                     columns.add(TargetElement.ENCRYPT, Boolean.FALSE);
666                     columns.add(TargetElement.REQUIRE, Boolean.FALSE);
667                     rows.add(columns);
668                 }
669             }
670         }
671
672         RequiredElements requiredElements = (RequiredElements)PolicyModelHelper.getTopLevelElement(p, RequiredElements.class);
673         if (requiredElements != null) {
674             xpaths = requiredElements.getExtensibilityElements(XPath.class);
675         }
676         for (XPath x : xpaths) {
677             MessageElement e = getListModelForXPath(x);
678             if (e != null) {
679                 Vector JavaDoc existing = targetExists(rows, e);
680                 if (existing != null) {
681                     existing.set(TargetElement.REQUIRE, Boolean.TRUE);
682                 } else {
683                     Vector JavaDoc columns = new Vector JavaDoc();
684                     columns.add(TargetElement.DATA, e);
685                     columns.add(TargetElement.SIGN, Boolean.FALSE);
686                     columns.add(TargetElement.ENCRYPT, Boolean.FALSE);
687                     columns.add(TargetElement.REQUIRE, Boolean.TRUE);
688                     rows.add(columns);
689                 }
690             }
691         }
692
693         return rows;
694     }
695
696     public static Vector JavaDoc targetExists(Vector JavaDoc<Vector JavaDoc> rows, TargetElement e) {
697         for (Vector JavaDoc row : rows) {
698             TargetElement te = (TargetElement) row.get(TargetElement.DATA);
699             if (te.equals(e)) {
700                 return row;
701             }
702         }
703         return null;
704     }
705
706     public static void setTargets(WSDLComponent comp, Vector JavaDoc<Vector JavaDoc> targetModel) {
707
708         if (comp == null) return;
709         
710         WSDLModel model = comp.getModel();
711
712         Policy p = null;
713         if (comp instanceof Policy) {
714             p = (Policy) comp;
715         } else {
716             p = PolicyModelHelper.getPolicyForElement(comp);
717         }
718         EncryptedParts encryptedParts = (EncryptedParts) PolicyModelHelper.getTopLevelElement(p, EncryptedParts.class);
719         SignedParts signedParts = (SignedParts) PolicyModelHelper.getTopLevelElement(p, SignedParts.class);
720         EncryptedElements encryptedElements = (EncryptedElements) PolicyModelHelper.getTopLevelElement(p, EncryptedElements.class);
721         SignedElements signedElements = (SignedElements) PolicyModelHelper.getTopLevelElement(p, SignedElements.class);
722         RequiredElements requiredElements = (RequiredElements) PolicyModelHelper.getTopLevelElement(p, RequiredElements.class);
723         WSDLComponentFactory wcf = model.getFactory();
724
725         boolean isTransaction = model.isIntransaction();
726         if (!isTransaction) {
727             model.startTransaction();
728         }
729
730         try {
731             WSDLComponent topLevel = null;
732             if (encryptedParts != null) {
733                 topLevel = encryptedParts.getParent();
734                 topLevel.removeExtensibilityElement(encryptedParts);
735                 encryptedParts = null;
736             }
737             if (signedParts != null) {
738                 topLevel = signedParts.getParent();
739                 topLevel.removeExtensibilityElement(signedParts);
740                 signedParts = null;
741             }
742             if (encryptedElements != null) {
743                 topLevel = encryptedElements.getParent();
744                 topLevel.removeExtensibilityElement(encryptedElements);
745                 encryptedElements = null;
746             }
747             if (signedElements != null) {
748                 topLevel = signedElements.getParent();
749                 topLevel.removeExtensibilityElement(signedElements);
750                 signedElements = null;
751             }
752             if (requiredElements != null) {
753                 topLevel = requiredElements.getParent();
754                 topLevel.removeExtensibilityElement(requiredElements);
755                 requiredElements = null;
756             }
757
758             if (targetModel == null) {
759                 return;
760             }
761             
762             if (p == null) {
763                 topLevel = PolicyModelHelper.createPolicy(comp);
764             } else if (!(comp instanceof Policy)) {
765                 topLevel = PolicyModelHelper.createTopExactlyOneAll(p);
766             } else {
767                 topLevel = p;
768             }
769            
770             encryptedParts = PolicyModelHelper.createElement(topLevel, SecurityPolicyQName.ENCRYPTEDPARTS.getQName(), EncryptedParts.class, false);
771             signedParts = PolicyModelHelper.createElement(topLevel, SecurityPolicyQName.SIGNEDPARTS.getQName(), SignedParts.class, false);
772
773             for (Vector JavaDoc v : targetModel) {
774                 TargetElement te = (TargetElement) v.get(TargetElement.DATA);
775                 boolean encrypt = ((Boolean JavaDoc)v.get(TargetElement.ENCRYPT)).booleanValue();
776                 boolean sign = ((Boolean JavaDoc)v.get(TargetElement.SIGN)).booleanValue();
777                 boolean require = ((Boolean JavaDoc)v.get(TargetElement.REQUIRE)).booleanValue();
778                 
779                 if (te instanceof MessageHeader) {
780                     if (encrypt) {
781                         addHeaderElementForListItem(te.toString(), encryptedParts, wcf);
782                     }
783                     if (sign) {
784                         addHeaderElementForListItem(te.toString(), signedParts, wcf);
785                     }
786                 } else if (te instanceof MessageElement) {
787                     
788                     if (encrypt) {
789                         if (encryptedElements == null) {
790                             encryptedElements = PolicyModelHelper.createElement(topLevel, SecurityPolicyQName.ENCRYPTEDELEMENTS.getQName(), EncryptedElements.class, false);
791                         }
792                         addElementForListItem(te.toString(), encryptedElements, wcf);
793                     }
794                     if (sign) {
795                         if (signedElements == null) {
796                             signedElements = PolicyModelHelper.createElement(topLevel, SecurityPolicyQName.SIGNEDELEMENTS.getQName(), SignedElements.class, false);
797                         }
798                         addElementForListItem(te.toString(), signedElements, wcf);
799                     }
800                     if (require) {
801                         if (requiredElements == null) {
802                             requiredElements = PolicyModelHelper.createElement(topLevel, SecurityPolicyQName.REQUIREDELEMENTS.getQName(), RequiredElements.class, false);
803                         }
804                         addElementForListItem(te.toString(), requiredElements, wcf);
805                     }
806                 } else if (te instanceof MessageBody) {
807                     if (encrypt) {
808                         addBody(encryptedParts, wcf);
809                     }
810                     if (sign) {
811                         addBody(signedParts, wcf);
812                     }
813                 }
814             }
815         } finally {
816             if (!isTransaction) {
817                 model.endTransaction();
818             }
819         }
820     }
821
822     public static MessageHeader getListModelForHeader(Header h) {
823         String JavaDoc name = h.getName();
824         if ("To".equals(name)) return new MessageHeader(MessageHeader.ADDRESSING_TO); //NOI18N
825
if ("From".equals(name)) return new MessageHeader(MessageHeader.ADDRESSING_FROM); //NOI18N
826
if ("FaultTo".equals(name)) return new MessageHeader(MessageHeader.ADDRESSING_FAULTTO); //NOI18N
827
if ("ReplyTo".equals(name)) return new MessageHeader(MessageHeader.ADDRESSING_REPLYTO); //NOI18N
828
if ("MessageID".equals(name)) return new MessageHeader(MessageHeader.ADDRESSING_MESSAGEID); //NOI18N
829
if ("RelatesTo".equals(name)) return new MessageHeader(MessageHeader.ADDRESSING_RELATESTO); //NOI18N
830
if ("Action".equals(name)) return new MessageHeader(MessageHeader.ADDRESSING_ACTION); //NOI18N
831
if ("AckRequested".equals(name)) return new MessageHeader(MessageHeader.RM_ACKREQUESTED); //NOI18N
832
if ("SequenceAcknowledgement".equals(name)) return new MessageHeader(MessageHeader.RM_SEQUENCEACK); //NOI18N
833
if ("Sequence".equals(name)) return new MessageHeader(MessageHeader.RM_SEQUENCE); //NOI18N
834
return null;
835     }
836
837     public static MessageElement getListModelForXPath(XPath x) {
838         String JavaDoc xpath = x.getXPath();
839         return new MessageElement(xpath);
840     }
841     
842     public static ExtensibilityElement addHeaderElementForListItem(String JavaDoc item, WSDLComponent c, WSDLComponentFactory wcf) {
843         
844         //TODO - get addressing namespace
845

846         Header h = null;
847         h = (Header)wcf.create(c, SecurityPolicyQName.HEADER.getQName());
848         if (MessageHeader.ADDRESSING_TO.equals(item)) {
849             h.setName("To"); //NOI18N
850
h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
851         }
852         if (MessageHeader.ADDRESSING_FROM.equals(item)) {
853             h.setName("From"); //NOI18N
854
h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
855         }
856         if (MessageHeader.ADDRESSING_FAULTTO.equals(item)) {
857             h.setName("FaultTo"); //NOI18N
858
h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
859         }
860         if (MessageHeader.ADDRESSING_REPLYTO.equals(item)) {
861             h.setName("ReplyTo"); //NOI18N
862
h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
863         }
864         if (MessageHeader.ADDRESSING_MESSAGEID.equals(item)) {
865             h.setName("MessageID"); //NOI18N
866
h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
867         }
868         if (MessageHeader.ADDRESSING_RELATESTO.equals(item)) {
869             h.setName("RelatesTo"); //NOI18N
870
h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
871         }
872         if (MessageHeader.ADDRESSING_ACTION.equals(item)) {
873             h.setName("Action"); //NOI18N
874
h.setNamespace(Addressing10QName.ADDRESSING10_NS_URI);
875         }
876         if (MessageHeader.RM_ACKREQUESTED.equals(item)) {
877             h.setName("AckRequested"); //NOI18N
878
h.setNamespace(RMQName.RM_NS_URI);
879         }
880         if (MessageHeader.RM_SEQUENCEACK.equals(item)) {
881             h.setName("SequenceAcknowledgement"); //NOI18N
882
h.setNamespace(RMQName.RM_NS_URI);
883         }
884         if (MessageHeader.RM_SEQUENCE.equals(item)) {
885             h.setName("Sequence"); //NOI18N
886
h.setNamespace(RMQName.RM_NS_URI);
887         }
888         if (h != null) {
889             c.addExtensibilityElement(h);
890         }
891         return h;
892     }
893     
894     public static ExtensibilityElement addElementForListItem(String JavaDoc item, WSDLComponent c, WSDLComponentFactory wcf) {
895         XPath x = null;
896         x = (XPath)wcf.create(c, SecurityPolicyQName.XPATH.getQName());
897         if (x != null) {
898             c.addExtensibilityElement(x);
899             x.setXPath(item);
900         }
901         return x;
902     }
903
904     public static ExtensibilityElement addBody(WSDLComponent c, WSDLComponentFactory wcf) {
905         Body b = null;
906         b = (Body)wcf.create(c, SecurityPolicyQName.BODY.getQName());
907         c.addExtensibilityElement(b);
908         return b;
909     }
910
911     /**************************** SECURITY BINDING TYPE *********************/
912
913     /**
914      * Returns string representation of security binding type
915      * TODO: maybe this method is not required with the new UI, as there's no mention of it
916      */

917     public static String JavaDoc getSecurityBindingType(WSDLComponent c) {
918         assert c != null;
919         ExtensibilityElement e = getSecurityBindingTypeElement(c);
920         if (e instanceof SymmetricBinding) return ComboConstants.SYMMETRIC;
921         if (e instanceof AsymmetricBinding) return ComboConstants.ASYMMETRIC;
922         if (e instanceof TransportBinding) return ComboConstants.TRANSPORT;
923         return ComboConstants.NOSECURITY;
924     }
925
926     /**
927      * Returns security binding type element for specified element which can be either top level Binding, BindingOperation, ...
928      * or sub-level like SecureConversationToken
929      */

930     public static ExtensibilityElement getSecurityBindingTypeElement(WSDLComponent c) {
931         assert c != null;
932         WSDLModel model = c.getModel();
933         WSDLComponent p = c;
934         
935         if ((c instanceof Binding) || (c instanceof BindingOperation) ||
936             (c instanceof BindingInput) || (c instanceof BindingOutput) || (c instanceof BindingFault)) {
937             p = PolicyModelHelper.getPolicyForElement(c);
938         } else if (c instanceof BootstrapPolicy) {
939             p = PolicyModelHelper.getTopLevelElement(c, Policy.class);
940         }
941         
942         ExtensibilityElement ee = PolicyModelHelper.getTopLevelElement(p, SymmetricBinding.class);
943         if (ee != null) return ee;
944         ee = (AsymmetricBinding)PolicyModelHelper.getTopLevelElement(p, AsymmetricBinding.class);
945         if (ee != null) return ee;
946         ee = (TransportBinding)PolicyModelHelper.getTopLevelElement(p, TransportBinding.class);
947         if (ee != null) return ee;
948         
949         return null;
950     }
951
952     public static WSDLComponent setSecurityBindingType(WSDLComponent c, String JavaDoc bindingType) {
953         assert (c!=null);
954         WSDLModel model = c.getModel();
955         WSDLComponentFactory wcf = model.getFactory();
956         WSDLComponent secBindingType = null;
957                
958         boolean isTransaction = model.isIntransaction();
959         if (!isTransaction) {
960             model.startTransaction();
961         }
962
963         All a = PolicyModelHelper.createPolicy(c);
964         
965         try {
966             SymmetricBinding sb = (SymmetricBinding)PolicyModelHelper.getTopLevelElement(a, SymmetricBinding.class);
967             AsymmetricBinding ab = (AsymmetricBinding)PolicyModelHelper.getTopLevelElement(a, AsymmetricBinding.class);
968             TransportBinding tb = (TransportBinding)PolicyModelHelper.getTopLevelElement(a, TransportBinding.class);
969
970             if (sb != null) sb.getParent().removeExtensibilityElement(sb);
971             if (ab != null) ab.getParent().removeExtensibilityElement(ab);
972             if (tb != null) tb.getParent().removeExtensibilityElement(tb);
973
974             if (ComboConstants.SYMMETRIC.equals(bindingType)) {
975                 sb = PolicyModelHelper.createElement(a, SecurityPolicyQName.SYMMETRICBINDING.getQName(), SymmetricBinding.class, false);
976                 secBindingType = sb;
977             }
978             if (ComboConstants.ASYMMETRIC.equals(bindingType)) {
979                 ab = PolicyModelHelper.createElement(a, SecurityPolicyQName.ASYMMETRICBINDING.getQName(), AsymmetricBinding.class, false);
980                 secBindingType = ab;
981             }
982             if (ComboConstants.TRANSPORT.equals(bindingType)) {
983                 tb = PolicyModelHelper.createElement(a, SecurityPolicyQName.TRANSPORTBINDING.getQName(), TransportBinding.class, false);
984                 secBindingType = tb;
985             }
986
987         } finally {
988             if (!isTransaction) {
989                 model.endTransaction();
990             }
991         }
992         
993         return secBindingType;
994     }
995
996     public static void setDefaultTargets(WSDLComponent c, boolean wss11) {
997
998         WSDLModel model = c.getModel();
999         Vector JavaDoc<Vector JavaDoc> targets = new Vector JavaDoc();
1000
1001        Vector JavaDoc row = new Vector JavaDoc();
1002        MessageBody body = new MessageBody();
1003        row.add(TargetElement.DATA, body);
1004        row.add(TargetElement.SIGN, Boolean.TRUE);
1005        row.add(TargetElement.ENCRYPT, Boolean.TRUE);
1006        row.add(TargetElement.REQUIRE, Boolean.FALSE);
1007        targets.add(row);
1008
1009        if (wss11) {
1010            for (String JavaDoc s : MessageHeader.ALL_HEADERS) {
1011                row = new Vector JavaDoc();
1012                MessageHeader h = new MessageHeader(s);
1013                row.add(TargetElement.DATA, h);
1014                row.add(TargetElement.SIGN, Boolean.TRUE);
1015                row.add(TargetElement.ENCRYPT, Boolean.TRUE);
1016                row.add(TargetElement.REQUIRE, Boolean.FALSE);
1017                targets.add(row);
1018            }
1019        }
1020
1021        setTargets(c, targets);
1022    }
1023
1024    public static void removeTargets(WSDLComponent c) {
1025        WSDLModel model = c.getModel();
1026        setTargets(c, null);
1027    }
1028    
1029    /********** Other binding attributes ****************/
1030
1031    public static String JavaDoc getComboItemForElement(WSDLComponent wc) {
1032        String JavaDoc cName = wc.getClass().getSimpleName();
1033        String JavaDoc msg = "COMBO_" + cName.substring(0, cName.length()-4); //NOI18N
1034
return NbBundle.getMessage(ComboConstants.class, msg);
1035    }
1036
1037    public static String JavaDoc getMessageLayout(WSDLComponent comp) {
1038        WSDLComponent layout = getMessageLayoutElement(comp);
1039        if (layout != null) {
1040            if (layout instanceof Strict) return ComboConstants.STRICT;
1041            if (layout instanceof Lax) return ComboConstants.LAX;
1042            if (layout instanceof LaxTsFirst) return ComboConstants.LAXTSFIRST;
1043            if (layout instanceof LaxTsLast) return ComboConstants.LAXTSLAST;
1044        }
1045        return null;
1046    }
1047    
1048    public static WSDLComponent getMessageLayoutElement(WSDLComponent comp) {
1049        if ((comp instanceof Binding) || (comp instanceof BindingOperation)) {
1050            comp = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp);
1051        }
1052        if (comp == null) return null;
1053        Policy p = PolicyModelHelper.getTopLevelElement(comp, Policy.class);
1054        Layout l = PolicyModelHelper.getTopLevelElement(p, Layout.class);
1055        p = PolicyModelHelper.getTopLevelElement(l, Policy.class);
1056        if (p != null) {
1057            List JavaDoc<ExtensibilityElement> elements = p.getExtensibilityElements();
1058            if ((elements != null) && !(elements.isEmpty())) {
1059                ExtensibilityElement e = elements.get(0);
1060                return e;
1061            }
1062        }
1063        return null;
1064    }
1065    
1066    public static boolean isIncludeTimestamp(WSDLComponent c) {
1067        ExtensibilityElement e = getSecurityBindingTypeElement(c);
1068        if (e != null) {
1069            return isAttributeEnabled(e, IncludeTimestamp.class);
1070        }
1071        return false;
1072    }
1073    
1074    public static boolean isEncryptBeforeSigning(WSDLComponent c) {
1075        ExtensibilityElement e = getSecurityBindingTypeElement(c);
1076        if (e != null) {
1077            return isAttributeEnabled(e, EncryptBeforeSigning.class);
1078        }
1079        return false;
1080    }
1081
1082    public static boolean isEncryptSignature(WSDLComponent c) {
1083        ExtensibilityElement e = getSecurityBindingTypeElement(c);
1084        if (e != null) {
1085            return isAttributeEnabled(e, EncryptSignature.class);
1086        }
1087        return false;
1088    }
1089    
1090    public static boolean isSignEntireHeadersAndBody(WSDLComponent c) {
1091        ExtensibilityElement e = getSecurityBindingTypeElement(c);
1092        if (e != null) {
1093            return isAttributeEnabled(e, OnlySignEntireHeadersAndBody.class);
1094        }
1095        return false;
1096    }
1097
1098   public static void setLayout(WSDLComponent c, String JavaDoc msgLayout) {
1099        WSDLModel model = c.getModel();
1100        WSDLComponentFactory wcf = model.getFactory();
1101
1102        boolean isTransaction = model.isIntransaction();
1103        if (!isTransaction) {
1104            model.startTransaction();
1105        }
1106        try {
1107            QName qnameToCreate = null;
1108            if (ComboConstants.STRICT.equals(msgLayout)) {
1109                qnameToCreate = SecurityPolicyQName.STRICT.getQName();
1110            } else if (ComboConstants.LAX.equals(msgLayout)) {
1111                qnameToCreate = SecurityPolicyQName.LAX.getQName();
1112            } else if (ComboConstants.LAXTSFIRST.equals(msgLayout)) {
1113                qnameToCreate = SecurityPolicyQName.LAXTSFIRST.getQName();
1114            } else if (ComboConstants.LAXTSLAST.equals(msgLayout)) {
1115                qnameToCreate = SecurityPolicyQName.LAXTSLAST.getQName();
1116            }
1117
1118            Layout layout = PolicyModelHelper.createElement(c, SecurityPolicyQName.LAYOUT.getQName(), Layout.class, true);
1119
1120            List JavaDoc<Policy> policies = layout.getExtensibilityElements(Policy.class);
1121            if ((policies != null) && (!policies.isEmpty())) {
1122                for (Policy pol : policies) {
1123                    layout.removeExtensibilityElement(pol);
1124                }
1125            }
1126            Policy p = PolicyModelHelper.createElement(layout, PolicyQName.POLICY.getQName(), Policy.class, false);
1127            ExtensibilityElement e = (ExtensibilityElement) wcf.create(p, qnameToCreate);
1128            p.addExtensibilityElement(e);
1129        } finally {
1130            if (!isTransaction) {
1131                model.endTransaction();
1132            }
1133        }
1134    }
1135    
1136}
1137
Popular Tags