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 1997-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.ui.service.profiles;
043:
044: import java.awt.Dialog;
045: import java.io.IOException;
046: import java.util.logging.Level;
047: import java.util.logging.Logger;
048: import javax.swing.JPanel;
049: import javax.swing.undo.UndoManager;
050: import org.netbeans.api.java.project.JavaProjectConstants;
051: import org.netbeans.api.project.Project;
052: import org.netbeans.api.project.ProjectUtils;
053: import org.netbeans.api.project.SourceGroup;
054: import org.netbeans.api.project.Sources;
055: import org.netbeans.modules.websvc.wsitconf.spi.features.ClientDefaultsFeature;
056: import org.netbeans.modules.websvc.wsitconf.spi.features.ServiceDefaultsFeature;
057: import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants;
058: import org.netbeans.modules.websvc.wsitconf.util.UndoCounter;
059: import org.netbeans.modules.websvc.wsitconf.wizard.SamlCallbackCreator;
060: import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProfilesModelHelper;
061: import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProprietarySecurityPolicyModelHelper;
062: import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityTokensModelHelper;
063: import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.CallbackHandler;
064: import org.netbeans.modules.xml.wsdl.model.Binding;
065: import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
066: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
067: import org.openide.DialogDescriptor;
068: import org.openide.DialogDisplayer;
069: import org.openide.filesystems.FileObject;
070:
071: /**
072: * Transport Security Profile definition
073: *
074: * @author Martin Grebac
075: */
076: public class SAMLAuthorizationOverSSLProfile extends ProfileBase
077: implements ClientDefaultsFeature, ServiceDefaultsFeature {
078:
079: private static final String PKGNAME = "samlcb";
080:
081: public int getId() {
082: return 50;
083: }
084:
085: public String getDisplayName() {
086: return ComboConstants.PROF_SAMLSSL;
087: }
088:
089: public String getDescription() {
090: return ComboConstants.PROF_SAMLSSL_INFO;
091: }
092:
093: /**
094: * Called when the profile is selected in the combo box.
095: */
096: @Override
097: public void profileSelected(WSDLComponent component,
098: boolean updateServiceUrl) {
099: ProfilesModelHelper.setSecurityProfile(component,
100: getDisplayName(), updateServiceUrl);
101: }
102:
103: /**
104: * Should return true if the profile is set on component, false otherwise
105: */
106: public boolean isCurrentProfile(WSDLComponent component) {
107: return getDisplayName().equals(
108: ProfilesModelHelper.getWSITSecurityProfile(component));
109: }
110:
111: @Override()
112: public void displayConfig(WSDLComponent component,
113: UndoManager undoManager) {
114: UndoCounter undoCounter = new UndoCounter();
115: WSDLModel model = component.getModel();
116:
117: model.addUndoableEditListener(undoCounter);
118:
119: JPanel profConfigPanel = new SAMLAuthorizationOverSSL(component);
120: DialogDescriptor dlgDesc = new DialogDescriptor(
121: profConfigPanel, getDisplayName());
122: Dialog dlg = DialogDisplayer.getDefault().createDialog(dlgDesc);
123:
124: dlg.setVisible(true);
125: if (dlgDesc.getValue() == DialogDescriptor.CANCEL_OPTION) {
126: for (int i = 0; i < undoCounter.getCounter(); i++) {
127: if (undoManager.canUndo()) {
128: undoManager.undo();
129: }
130: }
131: }
132:
133: model.removeUndoableEditListener(undoCounter);
134: }
135:
136: @Override
137: public boolean isProfileSupported(Project p,
138: WSDLComponent component, boolean sts) {
139: return true;
140: }
141:
142: public void setClientDefaults(WSDLComponent component,
143: WSDLComponent serviceBinding, Project p) {
144: ProprietarySecurityPolicyModelHelper.setStoreLocation(
145: component, null, false, true);
146: ProprietarySecurityPolicyModelHelper.setStoreLocation(
147: component, null, true, true);
148: ProprietarySecurityPolicyModelHelper
149: .removeCallbackHandlerConfiguration((Binding) component);
150:
151: FileObject targetFolder = null;
152:
153: Sources sources = ProjectUtils.getSources(p);
154: SourceGroup[] sourceGroups = sources
155: .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
156: if ((sourceGroups != null) && (sourceGroups.length > 0)) {
157: targetFolder = sourceGroups[0].getRootFolder();
158: }
159:
160: SamlCallbackCreator samlCreator = new SamlCallbackCreator();
161: String samlVersion = getSamlVersion((Binding) serviceBinding);
162: String cbName = "SamlCallbackHandler";
163:
164: if (targetFolder != null) {
165: if (targetFolder.getFileObject(PKGNAME) == null) {
166: try {
167: targetFolder = targetFolder.createFolder(PKGNAME);
168: } catch (IOException ex) {
169: Logger.getLogger("global").log(Level.SEVERE, null,
170: ex);
171: }
172: } else {
173: targetFolder = targetFolder.getFileObject(PKGNAME);
174: }
175: if (ComboConstants.SAML_V2011.equals(samlVersion)) {
176: cbName = "Saml20SVCallbackHandler";
177: if (targetFolder.getFileObject(cbName, "java") == null) {
178: samlCreator.generateSamlCBHandler(targetFolder,
179: cbName, SamlCallbackCreator.SV,
180: SamlCallbackCreator.SAML20);
181: }
182: } else {
183: cbName = "Saml11SVCallbackHandler";
184: if (targetFolder.getFileObject(cbName, "java") == null) {
185: samlCreator.generateSamlCBHandler(targetFolder,
186: cbName, SamlCallbackCreator.SV,
187: SamlCallbackCreator.SAML11);
188: }
189: }
190: }
191: ProprietarySecurityPolicyModelHelper.setCallbackHandler(
192: (Binding) component, CallbackHandler.SAML_CBHANDLER,
193: PKGNAME + "." + cbName, null, true);
194:
195: }
196:
197: public void setServiceDefaults(WSDLComponent component, Project p) {
198: ProprietarySecurityPolicyModelHelper.setStoreLocation(
199: component, null, false, false);
200: ProprietarySecurityPolicyModelHelper.setStoreLocation(
201: component, null, true, false);
202: }
203:
204: public boolean isServiceDefaultSetupUsed(WSDLComponent component,
205: Project p) {
206: return true;
207: }
208:
209: public boolean isClientDefaultSetupUsed(WSDLComponent component,
210: Binding serviceBinding, Project p) {
211: String samlVersion = getSamlVersion(serviceBinding);
212: String cbName = null;
213:
214: if (ComboConstants.SAML_V2011.equals(samlVersion)) {
215: cbName = "Saml20SVCallbackHandler";
216: } else {
217: cbName = "Saml11SVCallbackHandler";
218: }
219:
220: String cbHandler = ProprietarySecurityPolicyModelHelper
221: .getCallbackHandler((Binding) component,
222: CallbackHandler.SAML_CBHANDLER);
223: if ((PKGNAME + "." + cbName).equals(cbHandler)) {
224: return true;
225: }
226: return false;
227: }
228:
229: private String getSamlVersion(Binding serviceBinding) {
230: WSDLComponent tokenKind = SecurityTokensModelHelper
231: .getSupportingToken(serviceBinding,
232: SecurityTokensModelHelper.SIGNED_SUPPORTING);
233: WSDLComponent token = SecurityTokensModelHelper
234: .getTokenTypeElement(tokenKind);
235: return SecurityTokensModelHelper.getTokenProfileVersion(token);
236: }
237:
238: }
|