KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.websvc.wsitconf.ui.security.listmodels.ServiceProviderElement;
23 import org.netbeans.modules.websvc.wsitmodelext.policy.All;
24 import org.netbeans.modules.websvc.wsitmodelext.policy.Policy;
25 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.ProprietaryPolicyQName;
26 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.Timestamp;
27 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.Validator;
28 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.ValidatorConfiguration;
29 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.CertAlias;
30 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.Contract;
31 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.Issuer;
32 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.KeyType;
33 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.ProprietarySCServiceQName;
34 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.ProprietarySecurityPolicyServiceQName;
35 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.ProprietaryTrustServiceQName;
36 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.SCConfiguration;
37 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.STSConfiguration;
38 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.ServiceProviders;
39 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.TokenType;
40 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.CallbackHandler;
41 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.CallbackHandlerConfiguration;
42 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.KeyStore;
43 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.LifeTime;
44 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.PreconfiguredSTS;
45 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.ProprietarySCClientQName;
46 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.ProprietarySecurityPolicyQName;
47 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.ProprietaryTrustClientQName;
48 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.SCClientConfiguration;
49 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.TrustStore;
50 import org.netbeans.modules.xml.wsdl.model.*;
51 import java.util.List JavaDoc;
52 import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants;
53 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.ServiceProvider;
54
55 /**
56  *
57  * @author Martin Grebac
58  */

59 public class ProprietarySecurityPolicyModelHelper {
60
61     public static final String JavaDoc DEFAULT_LIFETIME = "300000"; //NOI18N
62
public static final String JavaDoc DEFAULT_CONTRACT_CLASS = "com.sun.xml.ws.trust.impl.IssueSamlTokenContractImpl"; //NOI18N
63

64     /**
65      * Creates a new instance of ProprietarySecurityPolicyModelHelper
66      */

67     public ProprietarySecurityPolicyModelHelper() {
68     }
69    
70 // public static String getMaxNonceAge(Binding b, boolean client) {
71
// WSDLModel model = b.getModel();
72
// Policy p = PolicyModelHelper.getPolicyForElement(b);
73
// ValidatorConfiguration vc = (ValidatorConfiguration) PolicyModelHelper.getTopLevelElement(p, ValidatorConfiguration.class);
74
// if (vc != null) {
75
// return vc.getMaxNonceAge();
76
// }
77
// return null;
78
// }
79

80     public static String JavaDoc getSTSLifeTime(Binding b) {
81         WSDLModel model = b.getModel();
82         Policy p = PolicyModelHelper.getPolicyForElement(b);
83         WSDLComponent sc = getSTSConfiguration(p);
84         if (sc != null) {
85             List JavaDoc<LifeTime> elems = sc.getExtensibilityElements(LifeTime.class);
86             if ((elems != null) && (!elems.isEmpty())) {
87                 return elems.get(0).getLifeTime();
88             }
89         }
90         return null;
91     }
92
93     public static String JavaDoc getSTSIssuer(Binding b) {
94         WSDLModel model = b.getModel();
95         Policy p = PolicyModelHelper.getPolicyForElement(b);
96         WSDLComponent sc = getSTSConfiguration(p);
97         if (sc != null) {
98             List JavaDoc<Issuer> elems = sc.getExtensibilityElements(Issuer.class);
99             if ((elems != null) && (!elems.isEmpty())) {
100                 return elems.get(0).getIssuer();
101             }
102         }
103         return null;
104     }
105     
106     public static STSConfiguration getSTSConfiguration(Binding b) {
107         WSDLModel model = b.getModel();
108         Policy p = PolicyModelHelper.getPolicyForElement(b);
109         return getSTSConfiguration(p);
110     }
111     
112     public static String JavaDoc getSTSContractClass(Binding b) {
113         WSDLModel model = b.getModel();
114         Policy p = PolicyModelHelper.getPolicyForElement(b);
115         WSDLComponent sc = getSTSConfiguration(p);
116         if (sc != null) {
117             List JavaDoc<Contract> elems = sc.getExtensibilityElements(Contract.class);
118             if ((elems != null) && (!elems.isEmpty())) {
119                 return elems.get(0).getContract();
120             }
121         }
122         return null;
123     }
124
125     public static boolean getSTSEncryptKey(Binding b) {
126         WSDLModel model = b.getModel();
127         Policy p = PolicyModelHelper.getPolicyForElement(b);
128         STSConfiguration sc = getSTSConfiguration(p);
129         if (sc != null) {
130             return sc.getEncryptIssuedKey();
131         }
132         return false;
133     }
134     
135     public static boolean getSTSEncryptToken(Binding b) {
136         WSDLModel model = b.getModel();
137         Policy p = PolicyModelHelper.getPolicyForElement(b);
138         STSConfiguration sc = getSTSConfiguration(p);
139         if (sc != null) {
140             return sc.getEncryptIssuedToken();
141         }
142         return false;
143     }
144
145     public static String JavaDoc getSPCertAlias(ServiceProvider sp) {
146         WSDLModel model = sp.getModel();
147         if (sp != null) {
148             List JavaDoc<CertAlias> elems = sp.getExtensibilityElements(CertAlias.class);
149             if ((elems != null) && !(elems.isEmpty())) {
150                 return elems.get(0).getCertAlias();
151             }
152         }
153         return null;
154     }
155
156     public static String JavaDoc getSPTokenType(ServiceProvider sp) {
157         WSDLModel model = sp.getModel();
158         if (sp != null) {
159             List JavaDoc<TokenType> elems = sp.getExtensibilityElements(TokenType.class);
160             if ((elems != null) && !(elems.isEmpty())) {
161                 String JavaDoc tType = elems.get(0).getTokenType();
162                 if (tType != null) {
163                     if (ComboConstants.ISSUED_TOKENTYPE_SAML10_POLICYSTR.equals(tType)) {
164                         return ComboConstants.ISSUED_TOKENTYPE_SAML10;
165                     }
166                     if (ComboConstants.ISSUED_TOKENTYPE_SAML11_POLICYSTR.equals(tType)) {
167                         return ComboConstants.ISSUED_TOKENTYPE_SAML11;
168                     }
169                     if (ComboConstants.ISSUED_TOKENTYPE_SAML20_POLICYSTR.equals(tType)) {
170                         return ComboConstants.ISSUED_TOKENTYPE_SAML20;
171                     }
172                 }
173             }
174         }
175         return null;
176         
177
178     }
179
180     public static String JavaDoc getSPKeyType(ServiceProvider sp) {
181         WSDLModel model = sp.getModel();
182         if (sp != null) {
183             List JavaDoc<KeyType> elems = sp.getExtensibilityElements(KeyType.class);
184             if ((elems != null) && !(elems.isEmpty())) {
185                 return elems.get(0).getKeyType();
186             }
187         }
188         return null;
189     }
190     
191     public static List JavaDoc<ServiceProvider> getSTSServiceProviders(Binding b) {
192         WSDLModel model = b.getModel();
193         Policy p = PolicyModelHelper.getPolicyForElement(b);
194         WSDLComponent sc = getSTSConfiguration(p);
195         return getSTSServiceProviders((STSConfiguration) sc);
196     }
197
198     public static List JavaDoc<ServiceProvider> getSTSServiceProviders(STSConfiguration stsConfig) {
199         if (stsConfig == null) return null;
200         WSDLModel model = stsConfig.getModel();
201         if (stsConfig != null) {
202             List JavaDoc<ServiceProviders> elems = stsConfig.getExtensibilityElements(ServiceProviders.class);
203             if ((elems != null) && (elems.size() > 0)) {
204                 List JavaDoc<ServiceProvider> sps = elems.get(0).getExtensibilityElements(ServiceProvider.class);
205                 return sps;
206             }
207         }
208         return null;
209     }
210
211     public static String JavaDoc getLifeTime(Binding b, boolean client) {
212         WSDLModel model = b.getModel();
213         Policy p = PolicyModelHelper.getPolicyForElement(b);
214         WSDLComponent sc = null;
215         if (client) {
216             sc = getSCClientConfiguration(p);
217         } else {
218             sc = getSCConfiguration(p);
219         }
220         if (sc != null) {
221             List JavaDoc<LifeTime> elems = sc.getExtensibilityElements(LifeTime.class);
222             if ((elems != null) && (!elems.isEmpty())) {
223                 return elems.get(0).getLifeTime();
224             }
225         }
226         return null;
227     }
228
229     public static String JavaDoc getTimestampTimeout(WSDLComponent b, boolean client) {
230         if (b == null) return null;
231         WSDLModel model = b.getModel();
232         Policy p = PolicyModelHelper.getPolicyForElement(b);
233         if (p == null) return null;
234         Timestamp t = PolicyModelHelper.getTopLevelElement(p, Timestamp.class);
235         return t == null ? null : t.getTimeout();
236     }
237        
238     public static String JavaDoc getPreSTSEndpoint(Binding b) {
239         WSDLModel model = b.getModel();
240         Policy p = PolicyModelHelper.getPolicyForElement(b);
241         PreconfiguredSTS ps = getPreconfiguredSTS(p);
242         if (ps != null) {
243             return ps.getEndpoint();
244         }
245         return null;
246     }
247
248     public static String JavaDoc getPreSTSMetadata(Binding b) {
249         WSDLModel model = b.getModel();
250         Policy p = PolicyModelHelper.getPolicyForElement(b);
251         PreconfiguredSTS ps = getPreconfiguredSTS(p);
252         if (ps != null) {
253             return ps.getMetadata();
254         }
255         return null;
256     }
257
258     public static String JavaDoc getPreSTSNamespace(Binding b) {
259         WSDLModel model = b.getModel();
260         Policy p = PolicyModelHelper.getPolicyForElement(b);
261         PreconfiguredSTS ps = getPreconfiguredSTS(p);
262         if (ps != null) {
263             return ps.getNamespace();
264         }
265         return null;
266     }
267
268     public static String JavaDoc getPreSTSPortName(Binding b) {
269         WSDLModel model = b.getModel();
270         Policy p = PolicyModelHelper.getPolicyForElement(b);
271         PreconfiguredSTS ps = getPreconfiguredSTS(p);
272         if (ps != null) {
273             return ps.getPortName();
274         }
275         return null;
276     }
277
278     public static String JavaDoc getPreSTSServiceName(Binding b) {
279         WSDLModel model = b.getModel();
280         Policy p = PolicyModelHelper.getPolicyForElement(b);
281         PreconfiguredSTS ps = getPreconfiguredSTS(p);
282         if (ps != null) {
283             return ps.getServiceName();
284         }
285         return null;
286     }
287
288     public static String JavaDoc getPreSTSWsdlLocation(Binding b) {
289         WSDLModel model = b.getModel();
290         Policy p = PolicyModelHelper.getPolicyForElement(b);
291         PreconfiguredSTS ps = getPreconfiguredSTS(p);
292         if (ps != null) {
293             return ps.getWsdlLocation();
294         }
295         return null;
296     }
297     
298     public static boolean isRenewExpired(Binding b) {
299         WSDLModel model = b.getModel();
300         Policy p = PolicyModelHelper.getPolicyForElement(b);
301         SCClientConfiguration sc = getSCClientConfiguration(p);
302         if (sc != null) {
303             return sc.getRenewExpiredSCT();
304         }
305         return false;
306     }
307
308     public static boolean isRequireCancel(Binding b) {
309         WSDLModel model = b.getModel();
310         Policy p = PolicyModelHelper.getPolicyForElement(b);
311         SCClientConfiguration sc = getSCClientConfiguration(p);
312         if (sc != null) {
313             return sc.getRequireCancelSCT();
314         }
315         return false;
316     }
317     
318 // public static String getMaxClockSkew(Binding b, boolean client) {
319
// WSDLModel model = b.getModel();
320
// Policy p = PolicyModelHelper.getPolicyForElement(b);
321
// ValidatorConfiguration vc = (ValidatorConfiguration) PolicyModelHelper.getTopLevelElement(p, ValidatorConfiguration.class);
322
// if (vc != null) {
323
// return vc.getMaxClockSkew();
324
// }
325
// return null;
326
// }
327
//
328
// public static String getTimestampFreshness(Binding b, boolean client) {
329
// WSDLModel model = b.getModel();
330
// Policy p = PolicyModelHelper.getPolicyForElement(b);
331
// ValidatorConfiguration vc = (ValidatorConfiguration) PolicyModelHelper.getTopLevelElement(p, ValidatorConfiguration.class);
332
// if (vc != null) {
333
// return vc.getTimestampFreshnessLimit();
334
// }
335
// return null;
336
// }
337

338     public static WSDLComponent getStore(Policy p, boolean trust) {
339         if (trust) {
340             return PolicyModelHelper.getTopLevelElement(p, TrustStore.class);
341         } else {
342             return PolicyModelHelper.getTopLevelElement(p, KeyStore.class);
343         }
344     }
345
346     public static SCClientConfiguration getSCClientConfiguration(Policy p) {
347             return (SCClientConfiguration) PolicyModelHelper.getTopLevelElement(p, SCClientConfiguration.class);
348     }
349     
350     public static PreconfiguredSTS getPreconfiguredSTS(Policy p) {
351             return (PreconfiguredSTS) PolicyModelHelper.getTopLevelElement(p, PreconfiguredSTS.class);
352     }
353
354     public static STSConfiguration getSTSConfiguration(Policy p) {
355             return (STSConfiguration) PolicyModelHelper.getTopLevelElement(p, STSConfiguration.class);
356     }
357
358     public static SCConfiguration getSCConfiguration(Policy p) {
359             return (SCConfiguration) PolicyModelHelper.getTopLevelElement(p, SCConfiguration.class);
360     }
361
362     /** Gets store location value for specified Binding or BindingOperation
363      */

364     public static String JavaDoc getStoreLocation(WSDLComponent b, boolean trust) {
365         if (b == null) return null;
366         WSDLModel model = b.getModel();
367         Policy p = PolicyModelHelper.getPolicyForElement(b);
368         if (p == null) return null;
369         if (trust) {
370             TrustStore ts = (TrustStore) getStore(p, true);
371             return ts == null ? null : ts.getLocation();
372         } else {
373             KeyStore ks = (KeyStore) getStore(p, false);
374             return ks == null ? null : ks.getLocation();
375         }
376     }
377
378     public static String JavaDoc getStoreAlias(WSDLComponent b, boolean trust) {
379         if (b == null) return null;
380         WSDLModel model = b.getModel();
381         Policy p = PolicyModelHelper.getPolicyForElement(b);
382         if (p == null) return null;
383         if (trust) {
384             TrustStore ts = (TrustStore) getStore(p, trust);
385             return (ts != null) ? ts.getPeerAlias() : null;
386         } else {
387             KeyStore ks = (KeyStore) getStore(p, trust);
388             return (ks != null) ? ks.getAlias() : null;
389         }
390     }
391
392     public static String JavaDoc getStoreType(WSDLComponent b, boolean trust) {
393         if (b == null) return null;
394         WSDLModel model = b.getModel();
395         Policy p = PolicyModelHelper.getPolicyForElement(b);
396         if (p == null) return null;
397         if (trust) {
398             TrustStore ts = (TrustStore) getStore(p, trust);
399             return (ts != null) ? ts.getType() : null;
400         } else {
401             KeyStore ks = (KeyStore) getStore(p, trust);
402             return (ks != null) ? ks.getType() : null;
403         }
404     }
405     
406     public static String JavaDoc getTrustSTSAlias(Binding b) {
407         if (b == null) return null;
408         WSDLModel model = b.getModel();
409         Policy p = PolicyModelHelper.getPolicyForElement(b);
410         if (p == null) return null;
411         TrustStore ks = (TrustStore) getStore(p, true);
412         return (ks != null) ? ks.getSTSAlias() : null;
413     }
414
415     public static String JavaDoc getTrustPeerAlias(WSDLComponent b) {
416         if (b == null) return null;
417         WSDLModel model = b.getModel();
418         Policy p = PolicyModelHelper.getPolicyForElement(b);
419         if (p == null) return null;
420         TrustStore ks = (TrustStore) getStore(p, true);
421         return (ks != null) ? ks.getPeerAlias() : null;
422     }
423
424     public static String JavaDoc getValidator(WSDLComponent c, String JavaDoc validatorType) {
425         if (c == null) return null;
426         WSDLModel model = c.getModel();
427         Policy p = PolicyModelHelper.getPolicyForElement(c);
428         if (p == null) return null;
429         ValidatorConfiguration vc = (ValidatorConfiguration) PolicyModelHelper.getTopLevelElement(p, ValidatorConfiguration.class);
430         Validator v = getValidator(validatorType, vc);
431         if (v != null) {
432             return v.getClassname();
433         }
434         return null;
435     }
436     
437     private static Validator getValidator(String JavaDoc type, ValidatorConfiguration vc) {
438         if (vc == null) return null;
439         List JavaDoc<Validator> validators = vc.getExtensibilityElements(Validator.class);
440         for (Validator v : validators) {
441             if (type.equals(v.getName())) {
442                 return v;
443             }
444         }
445         return null;
446     }
447
448     private static LifeTime getLifeTime(WSDLComponent c) {
449         if (c != null) {
450             List JavaDoc<LifeTime> attrs = c.getExtensibilityElements(LifeTime.class);
451             if ((attrs != null) && !(attrs.isEmpty())) {
452                 return attrs.get(0);
453             }
454         }
455         return null;
456     }
457
458     private static Issuer getIssuer(WSDLComponent c) {
459         if (c != null) {
460             List JavaDoc<Issuer> attrs = c.getExtensibilityElements(Issuer.class);
461             if ((attrs != null) && !(attrs.isEmpty())) {
462                 return attrs.get(0);
463             }
464         }
465         return null;
466     }
467     
468     private static Contract getContract(WSDLComponent c) {
469         if (c != null) {
470             List JavaDoc<Contract> attrs = c.getExtensibilityElements(Contract.class);
471             if ((attrs != null) && !(attrs.isEmpty())) {
472                 return attrs.get(0);
473             }
474         }
475         return null;
476     }
477     
478     public static String JavaDoc getDefaultUsername(Binding b) {
479         if (b == null) return null;
480         WSDLModel model = b.getModel();
481         Policy p = PolicyModelHelper.getPolicyForElement(b);
482         if (p == null) return null;
483         CallbackHandlerConfiguration chc = (CallbackHandlerConfiguration) PolicyModelHelper.getTopLevelElement(p, CallbackHandlerConfiguration.class);
484         CallbackHandler ch = getCallbackHandler(CallbackHandler.USERNAME_CBHANDLER, chc);
485         if (ch != null) {
486             return ch.getDefault();
487         }
488         return null;
489     }
490
491     public static String JavaDoc getDefaultPassword(Binding b) {
492         if (b == null) return null;
493         WSDLModel model = b.getModel();
494         Policy p = PolicyModelHelper.getPolicyForElement(b);
495         if (p == null) return null;
496         CallbackHandlerConfiguration chc = (CallbackHandlerConfiguration) PolicyModelHelper.getTopLevelElement(p, CallbackHandlerConfiguration.class);
497         CallbackHandler ch = getCallbackHandler(CallbackHandler.PASSWORD_CBHANDLER, chc);
498         if (ch != null) {
499             return ch.getDefault();
500         }
501         return null;
502     }
503     
504     public static String JavaDoc getCallbackHandler(Binding b, String JavaDoc cbhType) {
505         if (b == null) return null;
506         WSDLModel model = b.getModel();
507         Policy p = PolicyModelHelper.getPolicyForElement(b);
508         if (p == null) return null;
509         CallbackHandlerConfiguration chc = (CallbackHandlerConfiguration) PolicyModelHelper.getTopLevelElement(p, CallbackHandlerConfiguration.class);
510         CallbackHandler ch = getCallbackHandler(cbhType, chc);
511         if (ch != null) {
512             return ch.getClassname();
513         }
514         return null;
515     }
516     
517     private static CallbackHandler getCallbackHandler(String JavaDoc type, CallbackHandlerConfiguration vc) {
518         if (vc == null) return null;
519         List JavaDoc<CallbackHandler> handlers = vc.getExtensibilityElements(CallbackHandler.class);
520         for (CallbackHandler h : handlers) {
521             if (type.equals(h.getName())) {
522                 return h;
523             }
524         }
525         return null;
526     }
527
528     public static String JavaDoc getKeyPassword(WSDLComponent b) {
529         WSDLModel model = b.getModel();
530         Policy p = PolicyModelHelper.getPolicyForElement(b);
531         if (p == null) return null;
532         KeyStore ks = (KeyStore) getStore(p, false);
533         return (ks == null) ? null : ks.getKeyPassword();
534     }
535     
536     public static String JavaDoc getStorePassword(WSDLComponent b, boolean trust) {
537         WSDLModel model = b.getModel();
538         Policy p = PolicyModelHelper.getPolicyForElement(b);
539         if (p == null) return null;
540         if (trust) {
541             TrustStore ts = (TrustStore) getStore(p, trust);
542             return (ts == null) ? null : ts.getStorePassword();
543         } else {
544             KeyStore ks = (KeyStore) getStore(p, trust);
545             return (ks == null) ? null : ks.getStorePassword();
546         }
547     }
548     
549     public static void disableSTS(Binding b) {
550         STSConfiguration stsConfig = getSTSConfiguration(b);
551         if (stsConfig != null) {
552             PolicyModelHelper.removeElement(stsConfig);
553         }
554         PolicyModelHelper.cleanPolicies(b);
555     }
556
557     public static void enableSTS(Binding b) {
558         setSTSContractClass(b, DEFAULT_CONTRACT_CLASS);
559         setSTSLifeTime(b, DEFAULT_LIFETIME);
560     }
561
562     public static boolean isSTSEnabled(Binding b) {
563         STSConfiguration stsConfig = getSTSConfiguration(b);
564         return (stsConfig != null);
565     }
566     
567     public static void setStoreLocation(WSDLComponent b, String JavaDoc value, boolean trust, boolean client) {
568         WSDLModel model = b.getModel();
569         Policy p = PolicyModelHelper.getPolicyForElement(b);
570         boolean isTransaction = model.isIntransaction();
571         if (!isTransaction) {
572             model.startTransaction();
573         }
574         try {
575             if (trust) {
576                 TrustStore ks = (TrustStore) getStore(p, trust);
577                 if (value == null) {
578                     if (ks != null) {
579                         PolicyModelHelper.removeElement(ks);
580                     }
581                     return;
582                 }
583                 if ((p == null) || (ks == null)) {
584                     ks = (TrustStore) createStore(b, trust, client);
585                 }
586                 ks.setLocation(value);
587             } else {
588                 KeyStore ks = (KeyStore) getStore(p, trust);
589                 if (value == null) {
590                     if (ks != null) {
591                         PolicyModelHelper.removeElement(ks);
592                     }
593                     return;
594                 }
595                 if ((p == null) || (ks == null)) {
596                     ks = (KeyStore) createStore(b, trust, client);
597                 }
598                 ks.setLocation(value);
599             }
600         } finally {
601             if (!isTransaction) {
602                 model.endTransaction();
603             }
604         }
605     }
606
607     public static void setKeyStoreAlias(WSDLComponent b, String JavaDoc value, boolean client) {
608         WSDLModel model = b.getModel();
609         Policy p = PolicyModelHelper.getPolicyForElement(b);
610         KeyStore ks = (KeyStore) getStore(p, false);
611         if ((p == null) || (ks == null)) {
612             ks = (KeyStore) createStore(b, false, client);
613         }
614         boolean isTransaction = model.isIntransaction();
615         if (!isTransaction) {
616             model.startTransaction();
617         }
618         try {
619             ks.setAlias(value);
620         } finally {
621             if (!isTransaction) {
622                 model.endTransaction();
623             }
624         }
625     }
626
627     public static void setTrustPeerAlias(WSDLComponent b, String JavaDoc value, boolean client) {
628         WSDLModel model = b.getModel();
629         Policy p = PolicyModelHelper.getPolicyForElement(b);
630         TrustStore ks = (TrustStore) getStore(p, true);
631         if ((p == null) || (ks == null)) {
632             ks = (TrustStore) createStore(b, true, client);
633         }
634         boolean isTransaction = model.isIntransaction();
635         if (!isTransaction) {
636             model.startTransaction();
637         }
638         try {
639             ks.setPeerAlias(value);
640         } finally {
641             if (!isTransaction) {
642                 model.endTransaction();
643             }
644         }
645     }
646     
647     public static void setValidator(WSDLComponent c, String JavaDoc type, String JavaDoc value, boolean client) {
648         WSDLModel model = c.getModel();
649         Policy p = PolicyModelHelper.getPolicyForElement(c);
650         ValidatorConfiguration vc = (ValidatorConfiguration) PolicyModelHelper.getTopLevelElement(p, ValidatorConfiguration.class);
651         
652         if (value == null) {
653             if (vc != null) {
654                 Validator v = getValidator(type, vc);
655                 if (v != null) {
656                     PolicyModelHelper.removeElement(v);
657                 }
658             }
659             return;
660         }
661         
662         if ((p == null) || (vc == null)) {
663             vc = (ValidatorConfiguration) createValidatorConfiguration(c, client);
664         }
665         Validator v = getValidator(type, vc);
666         if (v == null) {
667             v = createValidator(vc, client);
668         }
669         boolean isTransaction = model.isIntransaction();
670         if (!isTransaction) {
671             model.startTransaction();
672         }
673         try {
674             v.setName(type);
675             v.setClassname(value);
676         } finally {
677             if (!isTransaction) {
678                 model.endTransaction();
679             }
680         }
681     }
682
683     public static void setLifeTime(Binding b, String JavaDoc value, boolean client) {
684         WSDLModel model = b.getModel();
685         Policy p = PolicyModelHelper.getPolicyForElement(b);
686         WSDLComponent c = client ? getSCClientConfiguration(p) : getSCConfiguration(p);
687         
688         if (value == null) {
689             if (c != null) {
690                 LifeTime lt = getLifeTime(c);
691                 if (lt != null) {
692                     PolicyModelHelper.removeElement(lt);
693                 }
694             }
695             return;
696         }
697         
698         if ((p == null) || (c == null)) {
699             c = createSCConfiguration(b, client);
700         }
701         LifeTime lt = getLifeTime(c);
702         if (lt == null) {
703             lt = createLifeTime(c, client);
704         }
705         boolean isTransaction = model.isIntransaction();
706         if (!isTransaction) {
707             model.startTransaction();
708         }
709         try {
710             lt.setLifeTime(value);
711         } finally {
712             if (!isTransaction) {
713                 model.endTransaction();
714             }
715         }
716     }
717
718     public static void setTimestampTimeout(Binding b, String JavaDoc value, boolean client) {
719         WSDLModel model = b.getModel();
720         Policy p = PolicyModelHelper.getPolicyForElement(b);
721         WSDLComponent c = PolicyModelHelper.getTopLevelElement(p, Timestamp.class);
722         boolean isTransaction = model.isIntransaction();
723         if (!isTransaction) {
724             model.startTransaction();
725         }
726         try {
727             if ((value == null) && (c != null)) {
728                 PolicyModelHelper.removeElement(c);
729             } else {
730                 if ((p == null) || (c == null)) {
731                     c = createTimestamp(b, client);
732                 }
733                 ((Timestamp)c).setTimeout(value);
734             }
735         } finally {
736             if (!isTransaction) {
737                 model.endTransaction();
738             }
739         }
740     }
741     
742     public static void setSTSLifeTime(Binding b, String JavaDoc value) {
743         WSDLModel model = b.getModel();
744         Policy p = PolicyModelHelper.getPolicyForElement(b);
745         STSConfiguration c = getSTSConfiguration(p);
746         if ((p == null) || (c == null)) {
747             c = createSTSConfiguration(b);
748         }
749         LifeTime lt = getLifeTime(c);
750         if (lt == null) {
751             lt = createSTSLifeTime(c);
752         }
753         boolean isTransaction = model.isIntransaction();
754         if (!isTransaction) {
755             model.startTransaction();
756         }
757         try {
758             lt.setLifeTime(value);
759         } finally {
760             if (!isTransaction) {
761                 model.endTransaction();
762             }
763         }
764     }
765
766     public static void setSTSIssuer(Binding b, String JavaDoc value) {
767         WSDLModel model = b.getModel();
768         Policy p = PolicyModelHelper.getPolicyForElement(b);
769         STSConfiguration c = getSTSConfiguration(p);
770         if ((p == null) || (c == null)) {
771             c = createSTSConfiguration(b);
772         }
773         Issuer i = getIssuer(c);
774         if (i == null) {
775             i = createSTSIssuer(c);
776         }
777         boolean isTransaction = model.isIntransaction();
778         if (!isTransaction) {
779             model.startTransaction();
780         }
781         try {
782             i.setIssuer(value);
783         } finally {
784             if (!isTransaction) {
785                 model.endTransaction();
786             }
787         }
788     }
789     
790     public static void addSTSServiceProvider(STSConfiguration stsConfig, ServiceProviderElement spe) {
791         if ((stsConfig == null) || (spe == null)) return;
792         WSDLModel model = stsConfig.getModel();
793         boolean isTransaction = model.isIntransaction();
794         if (!isTransaction) {
795             model.startTransaction();
796         }
797         try {
798             WSDLComponentFactory wcf = model.getFactory();
799             List JavaDoc<ServiceProviders> sProvidersList = stsConfig.getExtensibilityElements(ServiceProviders.class);
800             ServiceProviders sProviders = null;
801             if ((sProvidersList != null) && (sProvidersList.size() > 0)) {
802                sProviders = sProvidersList.get(0);
803             }
804             if (sProviders == null) {
805                 sProviders = (ServiceProviders)wcf.create(stsConfig, ProprietaryTrustServiceQName.SERVICEPROVIDERS.getQName());
806                 stsConfig.addExtensibilityElement(sProviders);
807             }
808             ServiceProvider sp = (ServiceProvider)wcf.create(sProviders, ProprietaryTrustServiceQName.SERVICEPROVIDER.getQName());
809             sProviders.addExtensibilityElement(sp);
810             sp.setEndpoint(spe.getEndpoint());
811             CertAlias calias = (CertAlias)wcf.create(sp, ProprietaryTrustServiceQName.CERTALIAS.getQName());
812             sp.addExtensibilityElement(calias);
813             calias.setCertAlias(spe.getCertAlias());
814             TokenType ttype = (TokenType)wcf.create(sp, ProprietaryTrustServiceQName.TOKENTYPE.getQName());
815             sp.addExtensibilityElement(ttype);
816
817             String JavaDoc tTypePolicyStr = ComboConstants.ISSUED_TOKENTYPE_SAML11_POLICYSTR;
818             
819             String JavaDoc tTypeShort = spe.getTokenType();
820             if (ComboConstants.ISSUED_TOKENTYPE_SAML20.equals(tTypeShort)) {
821                 tTypePolicyStr = ComboConstants.ISSUED_TOKENTYPE_SAML20_POLICYSTR;
822             }
823             if (ComboConstants.ISSUED_TOKENTYPE_SAML10.equals(tTypeShort)) {
824                 tTypePolicyStr = ComboConstants.ISSUED_TOKENTYPE_SAML10_POLICYSTR;
825             }
826             ttype.setTokenType(tTypePolicyStr);
827         } finally {
828             if (!isTransaction) {
829                 model.endTransaction();
830             }
831         }
832     }
833
834     public static void removeSTSServiceProvider(STSConfiguration stsConfig, ServiceProviderElement spe) {
835         if ((spe == null) || (stsConfig == null)) return;
836         WSDLModel model = stsConfig.getModel();
837         boolean isTransaction = model.isIntransaction();
838         if (!isTransaction) {
839             model.startTransaction();
840         }
841         try {
842             List JavaDoc<ServiceProvider> spList = getSTSServiceProviders(stsConfig);
843             for (ServiceProvider sp : spList) {
844                 String JavaDoc ep = spe.getEndpoint();
845                 if (ep.equals(sp.getEndpoint())) {
846                     if (sp.isInDocumentModel()) {
847                         sp.getParent().removeExtensibilityElement(sp);
848                     }
849                     break;
850                 }
851             }
852         } finally {
853             if (!isTransaction) {
854                 model.endTransaction();
855             }
856         }
857     }
858     
859     public static void setSTSContractClass(Binding b, String JavaDoc value) {
860         WSDLModel model = b.getModel();
861         Policy p = PolicyModelHelper.getPolicyForElement(b);
862         STSConfiguration c = getSTSConfiguration(p);
863         if ((p == null) || (c == null)) {
864             c = createSTSConfiguration(b);
865         }
866         Contract contract = getContract(c);
867         if (contract == null) {
868             contract = createSTSContract(c);
869         }
870         boolean isTransaction = model.isIntransaction();
871         if (!isTransaction) {
872             model.startTransaction();
873         }
874         try {
875             contract.setContract(value);
876         } finally {
877             if (!isTransaction) {
878                 model.endTransaction();
879             }
880         }
881     }
882
883     public static void setSTSEncryptKey(Binding b, boolean enable) {
884         WSDLModel model = b.getModel();
885         Policy p = PolicyModelHelper.getPolicyForElement(b);
886         STSConfiguration sc = getSTSConfiguration(p);
887         if ((p == null) || (sc == null)) {
888             sc = (STSConfiguration) createSTSConfiguration(b);
889         }
890         boolean isTransaction = model.isIntransaction();
891         if (!isTransaction) {
892             model.startTransaction();
893         }
894         try {
895             sc.setEncryptIssuedKey(enable);
896         } finally {
897             if (!isTransaction) {
898                 model.endTransaction();
899             }
900         }
901     }
902     
903
904     public static void setSTSEncryptToken(Binding b, boolean enable) {
905         WSDLModel model = b.getModel();
906         Policy p = PolicyModelHelper.getPolicyForElement(b);
907         STSConfiguration sc = getSTSConfiguration(p);
908         if ((p == null) || (sc == null)) {
909             sc = (STSConfiguration) createSTSConfiguration(b);
910         }
911         boolean isTransaction = model.isIntransaction();
912         if (!isTransaction) {
913             model.startTransaction();
914         }
915         try {
916             sc.setEncryptIssuedToken(enable);
917         } finally {
918             if (!isTransaction) {
919                 model.endTransaction();
920             }
921         }
922     }
923
924     public static void setRequireCancel(Binding b, boolean enable) {
925         WSDLModel model = b.getModel();
926         Policy p = PolicyModelHelper.getPolicyForElement(b);
927         SCClientConfiguration sc = getSCClientConfiguration(p);
928         if ((p == null) || (sc == null)) {
929             sc = (SCClientConfiguration) createSCConfiguration(b, true);
930         }
931         boolean isTransaction = model.isIntransaction();
932         if (!isTransaction) {
933             model.startTransaction();
934         }
935         try {
936             sc.setRequireCancelSCT(enable);
937         } finally {
938             if (!isTransaction) {
939                 model.endTransaction();
940             }
941         }
942     }
943
944     public static void setRenewExpired(Binding b, boolean enable) {
945         WSDLModel model = b.getModel();
946         Policy p = PolicyModelHelper.getPolicyForElement(b);
947         SCClientConfiguration sc = getSCClientConfiguration(p);
948         if ((p == null) || (sc == null)) {
949             sc = (SCClientConfiguration) createSCConfiguration(b, true);
950         }
951         boolean isTransaction = model.isIntransaction();
952         if (!isTransaction) {
953             model.startTransaction();
954         }
955         try {
956             sc.setRenewExpiredSCT(enable);
957         } finally {
958             if (!isTransaction) {
959                 model.endTransaction();
960             }
961         }
962     }
963     
964     public static void setCallbackHandler(Binding b, String JavaDoc type, String JavaDoc value, String JavaDoc defaultVal, boolean client) {
965         WSDLModel model = b.getModel();
966         Policy p = PolicyModelHelper.getPolicyForElement(b);
967         boolean isTransaction = model.isIntransaction();
968         if (!isTransaction) {
969             model.startTransaction();
970         }
971         try {
972             CallbackHandlerConfiguration chc = (CallbackHandlerConfiguration) PolicyModelHelper.getTopLevelElement(p, CallbackHandlerConfiguration.class);
973             if ((p == null) || (chc == null)) {
974                 chc = (CallbackHandlerConfiguration) createCallbackHandlerConfiguration(b, client);
975             }
976             CallbackHandler h = getCallbackHandler(type, chc);
977             if (h == null) {
978                 h = createCallbackHandler(chc, client);
979             }
980             if ((defaultVal == null) && (value == null)) {
981                 chc.removeExtensibilityElement(h);
982                 if (chc.getExtensibilityElements().size() == 0) {
983                     chc.getParent().removeExtensibilityElement(chc);
984                 }
985             } else {
986                 h.setDefault(defaultVal);
987                 h.setName(type);
988                 h.setClassname(value);
989             }
990         } finally {
991             if (!isTransaction) {
992                 model.endTransaction();
993             }
994         }
995     }
996
997     public static void setStoreType(WSDLComponent b, String JavaDoc value, boolean trust, boolean client) {
998         WSDLModel model = b.getModel();
999         Policy p = PolicyModelHelper.getPolicyForElement(b);
1000        boolean isTransaction = model.isIntransaction();
1001        if (!isTransaction) {
1002            model.startTransaction();
1003        }
1004        try {
1005            if (trust) {
1006                TrustStore ks = (TrustStore) getStore(p, trust);
1007                if ((p == null) || (ks == null)) {
1008                    ks = (TrustStore) createStore(b, trust, client);
1009                }
1010                ks.setType(value);
1011            } else {
1012                KeyStore ks = (KeyStore) getStore(p, trust);
1013                if ((p == null) || (ks == null)) {
1014                    ks = (KeyStore) createStore(b, trust, client);
1015                }
1016                ks.setType(value);
1017            }
1018        } finally {
1019            if (!isTransaction) {
1020                model.endTransaction();
1021            }
1022        }
1023    }
1024
1025    public static void setStorePassword(WSDLComponent b, String JavaDoc value, boolean trust, boolean client) {
1026        WSDLModel model = b.getModel();
1027        Policy p = PolicyModelHelper.getPolicyForElement(b);
1028        boolean isTransaction = model.isIntransaction();
1029        if (!isTransaction) {
1030            model.startTransaction();
1031        }
1032        try {
1033            if (trust) {
1034                TrustStore ks = (TrustStore) getStore(p, trust);
1035                if ((p == null) || (ks == null)) {
1036                    ks = (TrustStore) createStore(b, trust, client);
1037                }
1038                ks.setStorePassword(value);
1039            } else {
1040                KeyStore ks = (KeyStore) getStore(p, trust);
1041                if ((p == null) || (ks == null)) {
1042                    ks = (KeyStore) createStore(b, trust, client);
1043                }
1044                ks.setStorePassword(value);
1045            }
1046        } finally {
1047            if (!isTransaction) {
1048                model.endTransaction();
1049            }
1050        }
1051    }
1052
1053    public static void setKeyPassword(WSDLComponent b, String JavaDoc value, boolean client) {
1054        WSDLModel model = b.getModel();
1055        Policy p = PolicyModelHelper.getPolicyForElement(b);
1056        boolean isTransaction = model.isIntransaction();
1057        if (!isTransaction) {
1058            model.startTransaction();
1059        }
1060        try {
1061            KeyStore ks = (KeyStore) getStore(p, false);
1062            if ((p == null) || (ks == null)) {
1063                ks = (KeyStore) createStore(b, false, client);
1064            }
1065            ks.setKeyPassword(value);
1066        } finally {
1067            if (!isTransaction) {
1068                model.endTransaction();
1069            }
1070        }
1071    }
1072    
1073    public static void setPreSTSEndpoint(Binding b, String JavaDoc value) {
1074        WSDLModel model = b.getModel();
1075        Policy p = PolicyModelHelper.getPolicyForElement(b);
1076        PreconfiguredSTS ps = getPreconfiguredSTS(p);
1077        if ((ps == null) || (p == null)) {
1078            ps = createPreconfiguredSTS(b);
1079        }
1080        boolean isTransaction = model.isIntransaction();
1081        if (!isTransaction) {
1082            model.startTransaction();
1083        }
1084        try {
1085            ps.setEndpoint(value);
1086        } finally {
1087            if (!isTransaction) {
1088                model.endTransaction();
1089            }
1090        }
1091    }
1092
1093    public static void setPreSTSMetadata(Binding b, String JavaDoc value) {
1094        WSDLModel model = b.getModel();
1095        Policy p = PolicyModelHelper.getPolicyForElement(b);
1096        PreconfiguredSTS ps = getPreconfiguredSTS(p);
1097        if ((ps == null) || (p == null)) {
1098            ps = createPreconfiguredSTS(b);
1099        }
1100        boolean isTransaction = model.isIntransaction();
1101        if (!isTransaction) {
1102            model.startTransaction();
1103        }
1104        try {
1105            ps.setMetadata(value);
1106        } finally {
1107            if (!isTransaction) {
1108                model.endTransaction();
1109            }
1110        }
1111    }
1112    
1113    public static void setPreSTSNamespace(Binding b, String JavaDoc value) {
1114        WSDLModel model = b.getModel();
1115        Policy p = PolicyModelHelper.getPolicyForElement(b);
1116        PreconfiguredSTS ps = getPreconfiguredSTS(p);
1117        if ((ps == null) || (p == null)) {
1118            ps = createPreconfiguredSTS(b);
1119        }
1120        boolean isTransaction = model.isIntransaction();
1121        if (!isTransaction) {
1122            model.startTransaction();
1123        }
1124        try {
1125            ps.setNamespace(value);
1126        } finally {
1127            if (!isTransaction) {
1128                model.endTransaction();
1129            }
1130        }
1131    }
1132    
1133    public static void setPreSTSServiceName(Binding b, String JavaDoc value) {
1134        WSDLModel model = b.getModel();
1135        Policy p = PolicyModelHelper.getPolicyForElement(b);
1136        PreconfiguredSTS ps = getPreconfiguredSTS(p);
1137        if ((ps == null) || (p == null)) {
1138            ps = createPreconfiguredSTS(b);
1139        }
1140        boolean isTransaction = model.isIntransaction();
1141        if (!isTransaction) {
1142            model.startTransaction();
1143        }
1144        try {
1145            ps.setServiceName(value);
1146        } finally {
1147            if (!isTransaction) {
1148                model.endTransaction();
1149            }
1150        }
1151    }
1152
1153    public static void setPreSTSPortName(Binding b, String JavaDoc value) {
1154        WSDLModel model = b.getModel();
1155        Policy p = PolicyModelHelper.getPolicyForElement(b);
1156        PreconfiguredSTS ps = getPreconfiguredSTS(p);
1157        if ((ps == null) || (p == null)) {
1158            ps = createPreconfiguredSTS(b);
1159        }
1160        boolean isTransaction = model.isIntransaction();
1161        if (!isTransaction) {
1162            model.startTransaction();
1163        }
1164        try {
1165            ps.setPortName(value);
1166        } finally {
1167            if (!isTransaction) {
1168                model.endTransaction();
1169            }
1170        }
1171    }
1172    
1173    public static void setPreSTSWsdlLocation(Binding b, String JavaDoc value) {
1174        WSDLModel model = b.getModel();
1175        Policy p = PolicyModelHelper.getPolicyForElement(b);
1176        PreconfiguredSTS ps = getPreconfiguredSTS(p);
1177        if ((ps == null) || (p == null)) {
1178            ps = createPreconfiguredSTS(b);
1179        }
1180        boolean isTransaction = model.isIntransaction();
1181        if (!isTransaction) {
1182            model.startTransaction();
1183        }
1184        try {
1185            ps.setWsdlLocation(value);
1186        } finally {
1187            if (!isTransaction) {
1188                model.endTransaction();
1189            }
1190        }
1191    }
1192    
1193// public static void setMaxClockSkew(Binding b, String value, boolean client) {
1194
// WSDLModel model = b.getModel();
1195
// Policy p = PolicyModelHelper.getPolicyForElement(b);
1196
// ValidatorConfiguration vc = (ValidatorConfiguration) PolicyModelHelper.getTopLevelElement(p, ValidatorConfiguration.class);
1197
// if ((vc == null) || (p == null)) {
1198
// vc = createValidatorConfiguration(b, client);
1199
// }
1200
// boolean isTransaction = model.isIntransaction();
1201
// if (!isTransaction) {
1202
// model.startTransaction();
1203
// }
1204
// try {
1205
// vc.setMaxClockSkew(value);
1206
// } finally {
1207
// if (!isTransaction) {
1208
// model.endTransaction();
1209
// }
1210
// }
1211
// }
1212

1213// public static void setTimestampFreshness(Binding b, String value, boolean client) {
1214
// WSDLModel model = b.getModel();
1215
// Policy p = PolicyModelHelper.getPolicyForElement(b);
1216
// ValidatorConfiguration vc = (ValidatorConfiguration) PolicyModelHelper.getTopLevelElement(p, ValidatorConfiguration.class);
1217
// if ((vc == null) || (p == null)) {
1218
// vc = createValidatorConfiguration(b, client);
1219
// }
1220
// boolean isTransaction = model.isIntransaction();
1221
// if (!isTransaction) {
1222
// model.startTransaction();
1223
// }
1224
// try {
1225
// vc.setTimestampFreshnessLimit(value);
1226
// } finally {
1227
// if (!isTransaction) {
1228
// model.endTransaction();
1229
// }
1230
// }
1231
// }
1232

1233// public static void setMaxNonceAge(Binding b, String value, boolean client) {
1234
// WSDLModel model = b.getModel();
1235
// Policy p = PolicyModelHelper.getPolicyForElement(b);
1236
// ValidatorConfiguration vc = (ValidatorConfiguration) PolicyModelHelper.getTopLevelElement(p, ValidatorConfiguration.class);
1237
// if ((vc == null) || (p == null)) {
1238
// vc = createValidatorConfiguration(b, client);
1239
// }
1240
// boolean isTransaction = model.isIntransaction();
1241
// if (!isTransaction) {
1242
// model.startTransaction();
1243
// }
1244
// try {
1245
// vc.setMaxNonceAge(value);
1246
// } finally {
1247
// if (!isTransaction) {
1248
// model.endTransaction();
1249
// }
1250
// }
1251
// }
1252

1253    public static WSDLComponent createStore(WSDLComponent b, boolean trust, boolean client) {
1254        WSDLModel model = b.getModel();
1255        Policy p = PolicyModelHelper.getPolicyForElement(b);
1256        if (trust) {
1257            TrustStore ks = (TrustStore) getStore(p, trust);
1258            if (ks == null) {
1259                boolean isTransaction = model.isIntransaction();
1260                if (!isTransaction) {
1261                    model.startTransaction();
1262                }
1263                try {
1264                    WSDLComponentFactory wcf = model.getFactory();
1265                    All all = PolicyModelHelper.createPolicy(b);
1266                    if (client) {
1267                        ks = (TrustStore)wcf.create(all, ProprietarySecurityPolicyQName.TRUSTSTORE.getQName());
1268                    } else {
1269                        ks = (TrustStore)wcf.create(all, ProprietarySecurityPolicyServiceQName.TRUSTSTORE.getQName());
1270                    }
1271                    all.addExtensibilityElement(ks);
1272                    ks.setVisibility(ProprietaryPolicyQName.INVISIBLE);
1273                } finally {
1274                    if (!isTransaction) {
1275                        model.endTransaction();
1276                    }
1277                }
1278                return ks;
1279            }
1280        } else {
1281            KeyStore ks = (KeyStore) getStore(p, trust);
1282            if (ks == null) {
1283                boolean isTransaction = model.isIntransaction();
1284                if (!isTransaction) {
1285                    model.startTransaction();
1286                }
1287                try {
1288                    WSDLComponentFactory wcf = model.getFactory();
1289                    All all = PolicyModelHelper.createPolicy(b);
1290                    if (client) {
1291                        ks = (KeyStore)wcf.create(all, ProprietarySecurityPolicyQName.KEYSTORE.getQName());
1292                    } else {
1293                        ks = (KeyStore)wcf.create(all, ProprietarySecurityPolicyServiceQName.KEYSTORE.getQName());
1294                    }
1295                    all.addExtensibilityElement(ks);
1296                    ks.setVisibility(ProprietaryPolicyQName.INVISIBLE);
1297                } finally {
1298                    if (!isTransaction) {
1299                        model.endTransaction();
1300                    }
1301                }
1302                return ks;
1303            }
1304        }
1305        return null;
1306    }
1307    
1308    public static ValidatorConfiguration createValidatorConfiguration(WSDLComponent c, boolean client) {
1309        WSDLModel model = c.getModel();
1310        Policy p = PolicyModelHelper.getPolicyForElement(c);
1311        ValidatorConfiguration vc = (ValidatorConfiguration) PolicyModelHelper.getTopLevelElement(p, ValidatorConfiguration.class);
1312        if (vc == null) {
1313            boolean isTransaction = model.isIntransaction();
1314            if (!isTransaction) {
1315                model.startTransaction();
1316            }
1317            try {
1318                WSDLComponentFactory wcf = model.getFactory();
1319                All all = PolicyModelHelper.createPolicy(c);
1320                if (client) {
1321                    vc = (ValidatorConfiguration)wcf.create(all, ProprietarySecurityPolicyQName.VALIDATORCONFIGURATION.getQName());
1322                } else {
1323                    vc = (ValidatorConfiguration)wcf.create(all, ProprietarySecurityPolicyServiceQName.VALIDATORCONFIGURATION.getQName());
1324                }
1325                all.addExtensibilityElement(vc);
1326                vc.setVisibility(ProprietaryPolicyQName.INVISIBLE);
1327            } finally {
1328                if (!isTransaction) {
1329                    model.endTransaction();
1330                }
1331            }
1332        }
1333        return vc;
1334    }
1335
1336    public static PreconfiguredSTS createPreconfiguredSTS(Binding b) {
1337        WSDLModel model = b.getModel();
1338        Policy p = PolicyModelHelper.getPolicyForElement(b);
1339        PreconfiguredSTS ps = getPreconfiguredSTS(p);
1340        if (ps == null) {
1341            boolean isTransaction = model.isIntransaction();
1342            if (!isTransaction) {
1343                model.startTransaction();
1344            }
1345            try {
1346                WSDLComponentFactory wcf = model.getFactory();
1347                All all = PolicyModelHelper.createPolicy(b);
1348                ps = (PreconfiguredSTS)wcf.create(all, ProprietaryTrustClientQName.PRECONFIGUREDSTS.getQName());
1349                all.addExtensibilityElement(ps);
1350                ps.setVisibility(ProprietaryPolicyQName.INVISIBLE);
1351            } finally {
1352                if (!isTransaction) {
1353                    model.endTransaction();
1354                }
1355            }
1356        }
1357        return ps;
1358    }
1359
1360    public static STSConfiguration createSTSConfiguration(Binding b) {
1361        WSDLModel model = b.getModel();
1362        Policy p = PolicyModelHelper.getPolicyForElement(b);
1363        STSConfiguration sts = getSTSConfiguration(p);
1364        if (sts == null) {
1365            boolean isTransaction = model.isIntransaction();
1366            if (!isTransaction) {
1367                model.startTransaction();
1368            }
1369            try {
1370                WSDLComponentFactory wcf = model.getFactory();
1371
1372                All all = PolicyModelHelper.createPolicy(b);
1373                sts = (STSConfiguration)wcf.create(all, ProprietaryTrustServiceQName.STSCONFIGURATION.getQName());
1374                all.addExtensibilityElement(sts);
1375                sts.setVisibility(ProprietaryPolicyQName.INVISIBLE);
1376                sts.setEncryptIssuedKey(true);
1377                sts.setEncryptIssuedToken(false);
1378            } finally {
1379                if (!isTransaction) {
1380                    model.endTransaction();
1381                }
1382            }
1383        }
1384        return sts;
1385    }
1386    
1387    public static WSDLComponent createSCConfiguration(Binding b, boolean client) {
1388        WSDLModel model = b.getModel();
1389        Policy p = PolicyModelHelper.getPolicyForElement(b);
1390        WSDLComponent c = client ? getSCClientConfiguration(p) : getSCConfiguration(p);
1391        if (c == null) {
1392            boolean isTransaction = model.isIntransaction();
1393            if (!isTransaction) {
1394                model.startTransaction();
1395            }
1396            try {
1397                WSDLComponentFactory wcf = model.getFactory();
1398
1399                All all = PolicyModelHelper.createPolicy(b);
1400                if (client) {
1401                    c = (SCClientConfiguration)wcf.create(all, ProprietarySCClientQName.SCCLIENTCONFIGURATION.getQName());
1402                    all.addExtensibilityElement((ExtensibilityElement) c);
1403                    ((SCClientConfiguration)c).setVisibility(ProprietaryPolicyQName.INVISIBLE);
1404                } else {
1405                    c = (SCConfiguration)wcf.create(all, ProprietarySCServiceQName.SCCONFIGURATION.getQName());
1406                    all.addExtensibilityElement((ExtensibilityElement) c);
1407                    ((SCConfiguration)c).setVisibility(ProprietaryPolicyQName.INVISIBLE);
1408                }
1409            } finally {
1410                if (!isTransaction) {
1411                    model.endTransaction();
1412                }
1413            }
1414        }
1415        return c;
1416    }
1417
1418    public static WSDLComponent createTimestamp(Binding b, boolean client) {
1419        WSDLModel model = b.getModel();
1420        Policy p = PolicyModelHelper.getPolicyForElement(b);
1421        WSDLComponent c = PolicyModelHelper.getTopLevelElement(p, Timestamp.class);
1422        if (c == null) {
1423            boolean isTransaction = model.isIntransaction();
1424            if (!isTransaction) {
1425                model.startTransaction();
1426            }
1427            try {
1428                WSDLComponentFactory wcf = model.getFactory();
1429                All all = PolicyModelHelper.createPolicy(b);
1430                if (client) {
1431                    c = (Timestamp)wcf.create(all, ProprietarySecurityPolicyQName.TIMESTAMP.getQName());
1432                } else {
1433                    c = (Timestamp)wcf.create(all, ProprietarySecurityPolicyServiceQName.TIMESTAMP.getQName());
1434                }
1435                all.addExtensibilityElement((ExtensibilityElement) c);
1436                ((Timestamp)c).setVisibility(ProprietaryPolicyQName.INVISIBLE);
1437            } finally {
1438                if (!isTransaction) {
1439                    model.endTransaction();
1440                }
1441            }
1442        }
1443        return c;
1444    }
1445    
1446    public static Validator createValidator(ValidatorConfiguration vc, boolean client) {
1447        WSDLModel model = vc.getModel();
1448        Validator v = null;
1449        if (vc != null) {
1450            boolean isTransaction = model.isIntransaction();
1451            if (!isTransaction) {
1452                model.startTransaction();
1453            }
1454            try {
1455                WSDLComponentFactory wcf = model.getFactory();
1456                if (client) {
1457                    v = (Validator)wcf.create(vc, ProprietarySecurityPolicyQName.VALIDATOR.getQName());
1458                } else {
1459                    v = (Validator)wcf.create(vc, ProprietarySecurityPolicyServiceQName.VALIDATOR.getQName());
1460                }
1461                vc.addExtensibilityElement(v);
1462            } finally {
1463                if (!isTransaction) {
1464                    model.endTransaction();
1465                }
1466            }
1467        }
1468        return v;
1469    }
1470
1471    public static LifeTime createLifeTime(WSDLComponent c, boolean client) {
1472        WSDLModel model = c.getModel();
1473        LifeTime lt = null;
1474        if (c != null) {
1475            boolean isTransaction = model.isIntransaction();
1476            if (!isTransaction) {
1477                model.startTransaction();
1478            }
1479            try {
1480                WSDLComponentFactory wcf = model.getFactory();
1481                if (client) {
1482                    lt = (LifeTime)wcf.create(c, ProprietarySCClientQName.LIFETIME.getQName());
1483                } else {
1484                    lt = (LifeTime)wcf.create(c, ProprietarySCServiceQName.LIFETIME.getQName());
1485                }
1486                c.addExtensibilityElement(lt);
1487            } finally {
1488                if (!isTransaction) {
1489                    model.endTransaction();
1490                }
1491            }
1492        }
1493        return lt;
1494    }
1495
1496    public static LifeTime createSTSLifeTime(WSDLComponent c) {
1497        WSDLModel model = c.getModel();
1498        LifeTime lt = null;
1499        if (c != null) {
1500            boolean isTransaction = model.isIntransaction();
1501            if (!isTransaction) {
1502                model.startTransaction();
1503            }
1504            try {
1505                WSDLComponentFactory wcf = model.getFactory();
1506                lt = (LifeTime)wcf.create(c, ProprietaryTrustServiceQName.LIFETIME.getQName());
1507                c.addExtensibilityElement(lt);
1508            } finally {
1509                if (!isTransaction) {
1510                    model.endTransaction();
1511                }
1512            }
1513        }
1514        return lt;
1515    }
1516
1517    public static Issuer createSTSIssuer(WSDLComponent c) {
1518        WSDLModel model = c.getModel();
1519        Issuer i = null;
1520        if (c != null) {
1521            boolean isTransaction = model.isIntransaction();
1522            if (!isTransaction) {
1523                model.startTransaction();
1524            }
1525            try {
1526                WSDLComponentFactory wcf = model.getFactory();
1527                i = (Issuer)wcf.create(c, ProprietaryTrustServiceQName.ISSUER.getQName());
1528                c.addExtensibilityElement(i);
1529            } finally {
1530                if (!isTransaction) {
1531                    model.endTransaction();
1532                }
1533            }
1534        }
1535        return i;
1536    }
1537
1538    public static Contract createSTSContract(WSDLComponent c) {
1539        WSDLModel model = c.getModel();
1540        Contract contract = null;
1541        if (c != null) {
1542            boolean isTransaction = model.isIntransaction();
1543            if (!isTransaction) {
1544                model.startTransaction();
1545            }
1546            try {
1547                WSDLComponentFactory wcf = model.getFactory();
1548                contract = (Contract)wcf.create(c, ProprietaryTrustServiceQName.CONTRACT.getQName());
1549                c.addExtensibilityElement(contract);
1550            } finally {
1551                if (!isTransaction) {
1552                    model.endTransaction();
1553                }
1554            }
1555        }
1556        return contract;
1557    }
1558    
1559    public static CallbackHandlerConfiguration createCallbackHandlerConfiguration(Binding b, boolean client) {
1560        WSDLModel model = b.getModel();
1561        Policy p = PolicyModelHelper.getPolicyForElement(b);
1562        CallbackHandlerConfiguration chc = (CallbackHandlerConfiguration) PolicyModelHelper.getTopLevelElement(p, CallbackHandlerConfiguration.class);
1563        if (chc == null) {
1564            boolean isTransaction = model.isIntransaction();
1565            if (!isTransaction) {
1566                model.startTransaction();
1567            }
1568            try {
1569                WSDLComponentFactory wcf = model.getFactory();
1570
1571                All all = PolicyModelHelper.createPolicy(b);
1572                if (client) {
1573                    chc = (CallbackHandlerConfiguration)wcf.create(all,
1574                            ProprietarySecurityPolicyQName.CALLBACKHANDLERCONFIGURATION.getQName());
1575                } else {
1576                    chc = (CallbackHandlerConfiguration)wcf.create(all,
1577                            ProprietarySecurityPolicyServiceQName.CALLBACKHANDLERCONFIGURATION.getQName());
1578                }
1579                all.addExtensibilityElement(chc);
1580                chc.setVisibility(ProprietaryPolicyQName.INVISIBLE);
1581            } finally {
1582                if (!isTransaction) {
1583                    model.endTransaction();
1584                }
1585            }
1586        }
1587        return chc;
1588    }
1589
1590    public static CallbackHandler createCallbackHandler(CallbackHandlerConfiguration chc, boolean client) {
1591        WSDLModel model = chc.getModel();
1592        CallbackHandler h = null;
1593        if (chc != null) {
1594            boolean isTransaction = model.isIntransaction();
1595            if (!isTransaction) {
1596                model.startTransaction();
1597            }
1598            try {
1599                WSDLComponentFactory wcf = model.getFactory();
1600                if (client) {
1601                    h = (CallbackHandler)wcf.create(chc, ProprietarySecurityPolicyQName.CALLBACKHANDLER.getQName());
1602                } else {
1603                    h = (CallbackHandler)wcf.create(chc, ProprietarySecurityPolicyServiceQName.CALLBACKHANDLER.getQName());
1604                }
1605                chc.addExtensibilityElement(h);
1606            } finally {
1607                if (!isTransaction) {
1608                    model.endTransaction();
1609                }
1610            }
1611        }
1612        return h;
1613    }
1614}
1615
Popular Tags