001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.websvc.wsitconf.wsdlmodelext;
043:
044: import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants;
045: import org.netbeans.modules.websvc.wsitmodelext.policy.Policy;
046: import org.netbeans.modules.websvc.wsitmodelext.policy.PolicyQName;
047: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.AlgorithmSuite;
048: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.AlgorithmSuiteQName;
049: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic128;
050: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic192;
051: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic256;
052: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic256Sha256;
053: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic256Sha256Rsa15;
054: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.TripleDes;
055: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.TripleDesRsa15;
056: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.TripleDesSha256;
057: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.TripleDesSha256Rsa15;
058: import org.netbeans.modules.xml.wsdl.model.*;
059:
060: import javax.xml.namespace.QName;
061: import java.util.List;
062: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic128Rsa15;
063: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic128Sha256;
064: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic128Sha256Rsa15;
065: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic192Rsa15;
066: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic192Sha256;
067: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic192Sha256Rsa15;
068: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic256Rsa15;
069:
070: /**
071: *
072: * @author Martin Grebac
073: */
074: public class AlgoSuiteModelHelper {
075:
076: /**
077: * Creates a new instance of AlgoSuiteModelHelper
078: */
079: public AlgoSuiteModelHelper() {
080: }
081:
082: public static String getAlgorithmSuite(WSDLComponent comp) {
083: WSDLComponent layout = getAlgorithmSuiteElement(comp);
084: if (layout != null) {
085: if (layout instanceof Basic128)
086: return ComboConstants.BASIC128;
087: if (layout instanceof Basic192)
088: return ComboConstants.BASIC192;
089: if (layout instanceof Basic256)
090: return ComboConstants.BASIC256;
091: if (layout instanceof TripleDes)
092: return ComboConstants.TRIPLEDES;
093: if (layout instanceof Basic256Rsa15)
094: return ComboConstants.BASIC256RSA15;
095: if (layout instanceof Basic192Rsa15)
096: return ComboConstants.BASIC192RSA15;
097: if (layout instanceof Basic128Rsa15)
098: return ComboConstants.BASIC128RSA15;
099: if (layout instanceof TripleDesRsa15)
100: return ComboConstants.TRIPLEDESRSA15;
101: if (layout instanceof Basic256Sha256)
102: return ComboConstants.BASIC256SHA256;
103: if (layout instanceof Basic192Sha256)
104: return ComboConstants.BASIC192SHA256;
105: if (layout instanceof Basic128Sha256)
106: return ComboConstants.BASIC128SHA256;
107: if (layout instanceof TripleDesSha256)
108: return ComboConstants.TRIPLEDESSHA256;
109: if (layout instanceof Basic256Sha256Rsa15)
110: return ComboConstants.BASIC256SHA256RSA15;
111: if (layout instanceof Basic192Sha256Rsa15)
112: return ComboConstants.BASIC192SHA256RSA15;
113: if (layout instanceof Basic128Sha256Rsa15)
114: return ComboConstants.BASIC128SHA256RSA15;
115: if (layout instanceof TripleDesSha256Rsa15)
116: return ComboConstants.TRIPLEDESSHA256RSA15;
117: }
118: return null;
119: }
120:
121: public static WSDLComponent getAlgorithmSuiteElement(
122: WSDLComponent comp) {
123: if ((comp instanceof Binding)
124: || (comp instanceof BindingOperation)) {
125: comp = SecurityPolicyModelHelper
126: .getSecurityBindingTypeElement(comp);
127: }
128: if (comp == null)
129: return null;
130: Policy p = PolicyModelHelper.getTopLevelElement(comp,
131: Policy.class);
132: AlgorithmSuite as = PolicyModelHelper.getTopLevelElement(p,
133: AlgorithmSuite.class);
134: p = PolicyModelHelper.getTopLevelElement(as, Policy.class);
135: if (p != null) {
136: List<ExtensibilityElement> elements = p
137: .getExtensibilityElements();
138: if ((elements != null) && !(elements.isEmpty())) {
139: ExtensibilityElement e = elements.get(0);
140: return e;
141: }
142: }
143: return null;
144: }
145:
146: public static void setAlgorithmSuite(WSDLComponent c,
147: String algoSuite) {
148: WSDLModel model = c.getModel();
149: WSDLComponentFactory wcf = model.getFactory();
150:
151: WSDLComponent topElem = c;
152:
153: boolean isTransaction = model.isIntransaction();
154: if (!isTransaction) {
155: model.startTransaction();
156: }
157:
158: try {
159: QName qnameToCreate = null;
160:
161: if (ComboConstants.BASIC128.equals(algoSuite)) {
162: qnameToCreate = AlgorithmSuiteQName.BASIC128.getQName();
163: } else if (ComboConstants.BASIC192.equals(algoSuite)) {
164: qnameToCreate = AlgorithmSuiteQName.BASIC192.getQName();
165: } else if (ComboConstants.BASIC256.equals(algoSuite)) {
166: qnameToCreate = AlgorithmSuiteQName.BASIC256.getQName();
167: } else if (ComboConstants.TRIPLEDES.equals(algoSuite)) {
168: qnameToCreate = AlgorithmSuiteQName.TRIPLEDES
169: .getQName();
170: } else if (ComboConstants.BASIC128RSA15.equals(algoSuite)) {
171: qnameToCreate = AlgorithmSuiteQName.BASIC128RSA15
172: .getQName();
173: } else if (ComboConstants.BASIC192RSA15.equals(algoSuite)) {
174: qnameToCreate = AlgorithmSuiteQName.BASIC192RSA15
175: .getQName();
176: } else if (ComboConstants.BASIC256RSA15.equals(algoSuite)) {
177: qnameToCreate = AlgorithmSuiteQName.BASIC256RSA15
178: .getQName();
179: } else if (ComboConstants.TRIPLEDESRSA15.equals(algoSuite)) {
180: qnameToCreate = AlgorithmSuiteQName.TRIPLEDESRSA15
181: .getQName();
182: } else if (ComboConstants.BASIC128SHA256.equals(algoSuite)) {
183: qnameToCreate = AlgorithmSuiteQName.BASIC128SHA256
184: .getQName();
185: } else if (ComboConstants.BASIC192SHA256.equals(algoSuite)) {
186: qnameToCreate = AlgorithmSuiteQName.BASIC192SHA256
187: .getQName();
188: } else if (ComboConstants.BASIC256SHA256.equals(algoSuite)) {
189: qnameToCreate = AlgorithmSuiteQName.BASIC256SHA256
190: .getQName();
191: } else if (ComboConstants.TRIPLEDESSHA256.equals(algoSuite)) {
192: qnameToCreate = AlgorithmSuiteQName.TRIPLEDESSHA256
193: .getQName();
194: } else if (ComboConstants.BASIC128SHA256RSA15
195: .equals(algoSuite)) {
196: qnameToCreate = AlgorithmSuiteQName.BASIC128SHA256RSA15
197: .getQName();
198: } else if (ComboConstants.BASIC192SHA256RSA15
199: .equals(algoSuite)) {
200: qnameToCreate = AlgorithmSuiteQName.BASIC192SHA256RSA15
201: .getQName();
202: } else if (ComboConstants.BASIC256SHA256RSA15
203: .equals(algoSuite)) {
204: qnameToCreate = AlgorithmSuiteQName.BASIC256SHA256RSA15
205: .getQName();
206: } else if (ComboConstants.TRIPLEDESSHA256RSA15
207: .equals(algoSuite)) {
208: qnameToCreate = AlgorithmSuiteQName.TRIPLEDESSHA256RSA15
209: .getQName();
210: }
211:
212: AlgorithmSuite suite = PolicyModelHelper.createElement(
213: topElem, AlgorithmSuiteQName.ALGORITHMSUITE
214: .getQName(), AlgorithmSuite.class,
215: !(topElem instanceof Policy));
216:
217: List<Policy> policies = suite
218: .getExtensibilityElements(Policy.class);
219: if ((policies != null) && (!policies.isEmpty())) {
220: for (Policy pol : policies) {
221: suite.removeExtensibilityElement(pol);
222: }
223: }
224: Policy p = PolicyModelHelper.createElement(suite,
225: PolicyQName.POLICY.getQName(), Policy.class, false);
226: ExtensibilityElement e = (ExtensibilityElement) wcf.create(
227: p, qnameToCreate);
228: p.addExtensibilityElement(e);
229: } finally {
230: if (!isTransaction) {
231: model.endTransaction();
232: }
233: }
234: }
235:
236: }
|