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.identity.profile.ui;
043:
044: import javax.swing.JComponent;
045: import org.netbeans.modules.identity.profile.api.configurator.ProviderConfigurator;
046: import org.netbeans.modules.identity.profile.api.configurator.Configurator.AccessMethod;
047: import org.netbeans.modules.identity.profile.api.configurator.ConfiguratorException;
048: import org.netbeans.modules.identity.profile.api.configurator.ProviderConfigurator.Configurable;
049: import org.netbeans.modules.identity.profile.api.configurator.ProviderConfigurator.Type;
050: import org.netbeans.modules.identity.profile.api.configurator.SecurityMechanism;
051: import org.netbeans.modules.identity.profile.api.configurator.SecurityMechanismHelper;
052: import org.netbeans.modules.identity.profile.ui.support.J2eeProjectHelper;
053: import org.netbeans.modules.identity.server.manager.api.ServerManager;
054: import org.netbeans.modules.xml.multiview.ui.SectionNodeInnerPanel;
055: import org.netbeans.modules.xml.multiview.ui.SectionNodeView;
056: import org.openide.util.NbBundle;
057:
058: /**
059: * Visual panel for the WSC security panel.
060: *
061: * Created on April 14, 2006, 3:03 PM
062: *
063: * @author ptliu
064: */
065: public class WSPSecurityPanel extends SectionNodeInnerPanel {
066:
067: private static final String URN = "urn:"; //NOI18N
068:
069: private ProviderConfigurator configurator;
070: private J2eeProjectHelper helper;
071: private boolean disabled = false;
072:
073: /** Creates new form WSPSecurityPanel */
074: public WSPSecurityPanel(SectionNodeView view,
075: J2eeProjectHelper helper) {
076: super (view);
077: initComponents();
078:
079: errorLabel.setText(""); //NOI18N
080:
081: this .helper = helper;
082:
083: try {
084: configurator = ProviderConfigurator.getConfigurator(helper
085: .getServiceDescriptionName(), Type.WSP,
086: AccessMethod.FILE, helper.getConfigPath(), helper
087: .getServerID());
088: } catch (ConfiguratorException ex) {
089: errorLabel.setText(ex.getMessage());
090: disabled = true;
091: }
092:
093: if (!disabled) {
094: if (helper.isSecurityEnabled()) {
095: enableSecurityCB.setSelected(true);
096: } else {
097: enableSecurityCB.setSelected(false);
098: }
099:
100: configurator.addModifier(Configurable.SECURITY_MECH,
101: requestSecMechCB, configurator.getSecMechHelper()
102: .getAllWSPSecurityMechanisms());
103: //(helper.getVersion() == Version.VERSION_1_4) ?
104: // SecurityMechanismHelper.getDefault().getAllWSPSecurityMechanisms() :
105: //SecurityMechanismHelper.getDefault().getAllMessageLevelSecurityMechanisms());
106:
107: }
108:
109: updateVisualState();
110: }
111:
112: public JComponent getErrorComponent(String errorId) {
113: return null;
114: }
115:
116: public void setValue(JComponent source, Object value) {
117:
118: }
119:
120: public void linkButtonPressed(Object ddBean, String ddProperty) {
121:
122: }
123:
124: private void updateVisualState() {
125: if (disabled) {
126: disableAll();
127: enableSecurityCB.setEnabled(false);
128: return;
129: }
130:
131: if (helper.isWsitSecurityEnabled()) {
132: //System.out.println("wsit enabled");
133: enableSecurityCB.setEnabled(false);
134: errorLabel.setText(NbBundle.getMessage(
135: WSCSecurityPanel.class, "MSG_WsitEnabled"));
136: } else {
137: //System.out.println("wsit disabled");
138: enableSecurityCB.setEnabled(true);
139: errorLabel.setText(""); //NOI18N
140: }
141:
142: if (enableSecurityCB.isSelected()
143: && enableSecurityCB.isEnabled()) {
144: secMechLabel.setEnabled(true);
145: requestLabel.setEnabled(true);
146: requestSecMechCB.setEnabled(true);
147: userNameInfoLabel.setEnabled(true);
148: certSettingsLabel.setEnabled(true);
149: certSettingsInfoLabel.setEnabled(true);
150:
151: certSettingsInfoLabel.setBackground(javax.swing.UIManager
152: .getDefaults().getColor("Label.background")); //NOI18N
153: certSettingsInfoLabel.setForeground(javax.swing.UIManager
154: .getDefaults().getColor("Label.foreground")); //NOI18N
155: } else {
156: secMechLabel.setEnabled(false);
157: requestLabel.setEnabled(false);
158: requestSecMechCB.setEnabled(false);
159: userNameInfoLabel.setEnabled(false);
160: certSettingsLabel.setEnabled(false);
161: certSettingsInfoLabel.setEnabled(false);
162:
163: certSettingsInfoLabel.setBackground(javax.swing.UIManager
164: .getDefaults().getColor("Label.disabledShadow")); //NOI18N
165: certSettingsInfoLabel
166: .setForeground(javax.swing.UIManager.getDefaults()
167: .getColor("Label.disabledForeground")); //NOI18N
168: }
169:
170: SecurityMechanism secMech = (SecurityMechanism) requestSecMechCB
171: .getSelectedItem();
172:
173: if (secMech.isPasswordCredentialRequired()
174: && requestSecMechCB.isEnabled()) {
175: userNameInfoLabel.setVisible(true);
176: } else {
177: userNameInfoLabel.setVisible(false);
178: }
179: }
180:
181: private void disableAll() {
182: secMechLabel.setEnabled(false);
183: requestLabel.setEnabled(false);
184: requestSecMechCB.setEnabled(false);
185: userNameInfoLabel.setEnabled(false);
186: certSettingsLabel.setEnabled(false);
187: certSettingsInfoLabel.setEnabled(false);
188:
189: certSettingsInfoLabel.setBackground(javax.swing.UIManager
190: .getDefaults().getColor("Label.disabledShadow")); //NOI18N
191: certSettingsInfoLabel.setForeground(javax.swing.UIManager
192: .getDefaults().getColor("Label.disabledForeground")); //NOI18N
193:
194: userNameInfoLabel.setVisible(false);
195: }
196:
197: public void save() {
198: if (!disabled) {
199: if (enableSecurityCB.isSelected()) {
200: configurator.save();
201:
202: SecurityMechanism secMech = (SecurityMechanism) configurator
203: .getValue(Configurable.SECURITY_MECH);
204: helper.enableWSPSecurity(secMech.getName());
205: } else {
206: helper.disableWSPSecurity();
207: configurator.disable();
208: configurator.save();
209: }
210: }
211:
212: configurator.close();
213: helper.clearTransientState();
214: }
215:
216: public void cancel() {
217: configurator.close();
218: helper.clearTransientState();
219: }
220:
221: /** This method is called from within the constructor to
222: * initialize the form.
223: * WARNING: Do NOT modify this code. The content of this method is
224: * always regenerated by the Form Editor.
225: */
226: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
227: private void initComponents() {
228:
229: jTabbedPane1 = new javax.swing.JTabbedPane();
230: enableSecurityCB = new javax.swing.JCheckBox();
231: secMechLabel = new javax.swing.JLabel();
232: requestLabel = new javax.swing.JLabel();
233: userNameInfoLabel = new javax.swing.JLabel();
234: requestSecMechCB = new javax.swing.JComboBox();
235: certSettingsInfoLabel = new javax.swing.JLabel();
236: certSettingsLabel = new javax.swing.JLabel();
237: jSeparator1 = new javax.swing.JSeparator();
238: errorLabel = new javax.swing.JLabel();
239:
240: addFocusListener(new java.awt.event.FocusAdapter() {
241: public void focusGained(java.awt.event.FocusEvent evt) {
242: formFocusGained(evt);
243: }
244: });
245: addAncestorListener(new javax.swing.event.AncestorListener() {
246: public void ancestorMoved(
247: javax.swing.event.AncestorEvent evt) {
248: }
249:
250: public void ancestorAdded(
251: javax.swing.event.AncestorEvent evt) {
252: formAncestorAdded(evt);
253: }
254:
255: public void ancestorRemoved(
256: javax.swing.event.AncestorEvent evt) {
257: }
258: });
259:
260: java.util.ResourceBundle bundle = java.util.ResourceBundle
261: .getBundle("org/netbeans/modules/identity/profile/ui/Bundle"); // NOI18N
262: org.openide.awt.Mnemonics.setLocalizedText(enableSecurityCB,
263: bundle.getString("LBL_EnableSecurity")); // NOI18N
264: enableSecurityCB.setBorder(javax.swing.BorderFactory
265: .createEmptyBorder(0, 0, 0, 0));
266: enableSecurityCB.setMargin(new java.awt.Insets(0, 0, 0, 0));
267: enableSecurityCB.setOpaque(false);
268: enableSecurityCB
269: .addActionListener(new java.awt.event.ActionListener() {
270: public void actionPerformed(
271: java.awt.event.ActionEvent evt) {
272: enableSecurityCBActionPerformed(evt);
273: }
274: });
275:
276: secMechLabel
277: .setText(bundle.getString("LBL_SecurityMechanisms")); // NOI18N
278:
279: requestLabel.setLabelFor(requestSecMechCB);
280: org.openide.awt.Mnemonics.setLocalizedText(requestLabel, bundle
281: .getString("LBL_Request")); // NOI18N
282:
283: userNameInfoLabel.setText(bundle.getString("MSG_UserNameInfo")); // NOI18N
284:
285: requestSecMechCB
286: .addActionListener(new java.awt.event.ActionListener() {
287: public void actionPerformed(
288: java.awt.event.ActionEvent evt) {
289: requestSecMechCBActionPerformed(evt);
290: }
291: });
292:
293: certSettingsInfoLabel.setText(bundle
294: .getString("MSG_CertificateSettingsInfo")); // NOI18N
295: certSettingsInfoLabel.setFocusable(false);
296:
297: certSettingsLabel.setText(bundle
298: .getString("LBL_CertificateSettings")); // NOI18N
299:
300: errorLabel.setForeground(new java.awt.Color(255, 0, 0));
301: errorLabel.setText("Error:");
302:
303: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
304: this );
305: this .setLayout(layout);
306: layout
307: .setHorizontalGroup(layout
308: .createParallelGroup(
309: org.jdesktop.layout.GroupLayout.LEADING)
310: .add(
311: org.jdesktop.layout.GroupLayout.TRAILING,
312: layout
313: .createSequentialGroup()
314: .add(
315: layout
316: .createParallelGroup(
317: org.jdesktop.layout.GroupLayout.TRAILING)
318: .add(
319: org.jdesktop.layout.GroupLayout.LEADING,
320: layout
321: .createSequentialGroup()
322: .add(
323: 20,
324: 20,
325: 20)
326: .add(
327: certSettingsInfoLabel,
328: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
329: 379,
330: Short.MAX_VALUE))
331: .add(
332: org.jdesktop.layout.GroupLayout.LEADING,
333: layout
334: .createSequentialGroup()
335: .add(
336: 30,
337: 30,
338: 30)
339: .add(
340: userNameInfoLabel,
341: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
342: 369,
343: Short.MAX_VALUE))
344: .add(
345: org.jdesktop.layout.GroupLayout.LEADING,
346: layout
347: .createSequentialGroup()
348: .addContainerGap()
349: .add(
350: layout
351: .createParallelGroup(
352: org.jdesktop.layout.GroupLayout.LEADING)
353: .add(
354: enableSecurityCB)
355: .add(
356: secMechLabel)
357: .add(
358: layout
359: .createSequentialGroup()
360: .add(
361: 10,
362: 10,
363: 10)
364: .add(
365: requestLabel)
366: .addPreferredGap(
367: org.jdesktop.layout.LayoutStyle.RELATED)
368: .add(
369: requestSecMechCB,
370: 0,
371: 321,
372: Short.MAX_VALUE))))
373: .add(
374: org.jdesktop.layout.GroupLayout.LEADING,
375: layout
376: .createSequentialGroup()
377: .addContainerGap()
378: .add(
379: jSeparator1,
380: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
381: 387,
382: Short.MAX_VALUE))
383: .add(
384: org.jdesktop.layout.GroupLayout.LEADING,
385: layout
386: .createSequentialGroup()
387: .addContainerGap()
388: .add(
389: certSettingsLabel))
390: .add(
391: org.jdesktop.layout.GroupLayout.LEADING,
392: layout
393: .createSequentialGroup()
394: .addContainerGap()
395: .add(
396: errorLabel)))
397: .addContainerGap()));
398: layout
399: .setVerticalGroup(layout
400: .createParallelGroup(
401: org.jdesktop.layout.GroupLayout.LEADING)
402: .add(
403: layout
404: .createSequentialGroup()
405: .addContainerGap()
406: .add(enableSecurityCB)
407: .addPreferredGap(
408: org.jdesktop.layout.LayoutStyle.RELATED)
409: .add(secMechLabel)
410: .addPreferredGap(
411: org.jdesktop.layout.LayoutStyle.RELATED)
412: .add(
413: layout
414: .createParallelGroup(
415: org.jdesktop.layout.GroupLayout.BASELINE)
416: .add(
417: requestLabel)
418: .add(
419: requestSecMechCB,
420: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
421: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
422: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
423: .addPreferredGap(
424: org.jdesktop.layout.LayoutStyle.RELATED)
425: .add(userNameInfoLabel)
426: .addPreferredGap(
427: org.jdesktop.layout.LayoutStyle.RELATED)
428: .add(certSettingsLabel)
429: .addPreferredGap(
430: org.jdesktop.layout.LayoutStyle.RELATED)
431: .add(certSettingsInfoLabel)
432: .addPreferredGap(
433: org.jdesktop.layout.LayoutStyle.RELATED)
434: .add(
435: jSeparator1,
436: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
437: 10,
438: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
439: .addPreferredGap(
440: org.jdesktop.layout.LayoutStyle.RELATED)
441: .add(errorLabel)
442: .addContainerGap(
443: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
444: Short.MAX_VALUE)));
445: }// </editor-fold>//GEN-END:initComponents
446:
447: private void formFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusGained
448: // TODO add your handling code here:
449: updateVisualState();
450: }//GEN-LAST:event_formFocusGained
451:
452: private void formAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_formAncestorAdded
453: // TODO add your handling code here:
454: //requestFocusInWindow();
455: }//GEN-LAST:event_formAncestorAdded
456:
457: private void requestSecMechCBActionPerformed(
458: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_requestSecMechCBActionPerformed
459: // TODO add your handling code here:
460: updateVisualState();
461:
462: SecurityMechanism secMech = (SecurityMechanism) requestSecMechCB
463: .getSelectedItem();
464:
465: if (secMech.isLiberty()) {
466: configurator.setValue(Configurable.SERVICE_TYPE, URN
467: + helper.getEndpointURI().get(0));
468: } else {
469: configurator.setValue(Configurable.SERVICE_TYPE, null);
470: }
471: }//GEN-LAST:event_requestSecMechCBActionPerformed
472:
473: private void enableSecurityCBActionPerformed(
474: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enableSecurityCBActionPerformed
475: // TODO add your handling code here:
476: if (enableSecurityCB.isSelected()) {
477: configurator.enable();
478: helper.setTransientState(true);
479: } else {
480: configurator.disable();
481: helper.setTransientState(false);
482: }
483:
484: updateVisualState();
485: }//GEN-LAST:event_enableSecurityCBActionPerformed
486:
487: // Variables declaration - do not modify//GEN-BEGIN:variables
488: private javax.swing.JLabel certSettingsInfoLabel;
489: private javax.swing.JLabel certSettingsLabel;
490: private javax.swing.JCheckBox enableSecurityCB;
491: private javax.swing.JLabel errorLabel;
492: private javax.swing.JSeparator jSeparator1;
493: private javax.swing.JTabbedPane jTabbedPane1;
494: private javax.swing.JLabel requestLabel;
495: private javax.swing.JComboBox requestSecMechCB;
496: private javax.swing.JLabel secMechLabel;
497: private javax.swing.JLabel userNameInfoLabel;
498: // End of variables declaration//GEN-END:variables
499:
500: }
|