KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > ui > service > profiles > MutualCertificates


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.ui.service.profiles;
21
22 import javax.swing.JCheckBox JavaDoc;
23 import javax.swing.JComboBox JavaDoc;
24 import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants;
25 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.AlgoSuiteModelHelper;
26 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProfilesModelHelper;
27 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.RMModelHelper;
28 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityPolicyModelHelper;
29 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityTokensModelHelper;
30 import org.netbeans.modules.websvc.wsitmodelext.security.BootstrapPolicy;
31 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.InitiatorToken;
32 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.ProtectionToken;
33 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.RecipientToken;
34 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.SecureConversationToken;
35 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
36 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
37
38 /**
39  *
40  * @author Martin Grebac
41  */

42 public class MutualCertificates extends javax.swing.JPanel JavaDoc {
43
44     private boolean inSync = false;
45
46     private WSDLComponent comp;
47     private WSDLModel model;
48     
49     /**
50      * Creates new form MutualCertificates
51      */

52     public MutualCertificates(WSDLComponent comp) {
53         super();
54         initComponents();
55         this.model = comp.getModel();
56         this.comp = comp;
57
58         inSync = true;
59         layoutCombo.removeAllItems();
60         layoutCombo.addItem(ComboConstants.STRICT);
61         layoutCombo.addItem(ComboConstants.LAX);
62         layoutCombo.addItem(ComboConstants.LAXTSFIRST);
63         layoutCombo.addItem(ComboConstants.LAXTSLAST);
64         
65         algoSuiteCombo.removeAllItems();
66         algoSuiteCombo.addItem(ComboConstants.BASIC256);
67         algoSuiteCombo.addItem(ComboConstants.BASIC192);
68         algoSuiteCombo.addItem(ComboConstants.BASIC128);
69         algoSuiteCombo.addItem(ComboConstants.TRIPLEDES);
70         algoSuiteCombo.addItem(ComboConstants.BASIC256RSA15);
71         algoSuiteCombo.addItem(ComboConstants.BASIC192RSA15);
72         algoSuiteCombo.addItem(ComboConstants.BASIC128RSA15);
73         algoSuiteCombo.addItem(ComboConstants.TRIPLEDESRSA15);
74 // algoSuiteCombo.addItem(ComboConstants.BASIC256SHA256);
75
// algoSuiteCombo.addItem(ComboConstants.BASIC192SHA256);
76
// algoSuiteCombo.addItem(ComboConstants.BASIC128SHA256);
77
// algoSuiteCombo.addItem(ComboConstants.TRIPLEDESSHA256);
78
// algoSuiteCombo.addItem(ComboConstants.BASIC256SHA256RSA15);
79
// algoSuiteCombo.addItem(ComboConstants.BASIC192SHA256RSA15);
80
// algoSuiteCombo.addItem(ComboConstants.BASIC128SHA256RSA15);
81
// algoSuiteCombo.addItem(ComboConstants.TRIPLEDESSHA256RSA15);
82

83         inSync = false;
84         
85         sync();
86     }
87     
88     private void sync() {
89         inSync = true;
90
91         WSDLComponent secBinding = null;
92         WSDLComponent topSecBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp);
93         WSDLComponent protTokenKind = SecurityTokensModelHelper.getTokenElement(topSecBinding, ProtectionToken.class);
94         WSDLComponent protToken = SecurityTokensModelHelper.getTokenTypeElement(protTokenKind);
95         
96         boolean secConv = (protToken instanceof SecureConversationToken);
97         
98         if (secConv) {
99             WSDLComponent bootPolicy = SecurityTokensModelHelper.getTokenElement(protToken, BootstrapPolicy.class);
100             secBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(bootPolicy);
101             setChBox(secConvChBox, true);
102             setChBox(derivedKeysChBox, SecurityPolicyModelHelper.isRequireDerivedKeys(protToken));
103             setChBox(encryptSignatureChBox, SecurityPolicyModelHelper.isEncryptSignature(bootPolicy));
104             setChBox(encryptOrderChBox, SecurityPolicyModelHelper.isEncryptBeforeSigning(bootPolicy));
105         } else {
106             secBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp);
107             setChBox(secConvChBox, false);
108             setChBox(encryptSignatureChBox, SecurityPolicyModelHelper.isEncryptSignature(comp));
109             setChBox(encryptOrderChBox, SecurityPolicyModelHelper.isEncryptBeforeSigning(comp));
110         }
111
112         WSDLComponent tokenKind = SecurityTokensModelHelper.getTokenElement(secBinding, RecipientToken.class);
113         WSDLComponent token = SecurityTokensModelHelper.getTokenTypeElement(tokenKind);
114         setChBox(reqDerivedKeys, SecurityPolicyModelHelper.isRequireDerivedKeys(token));
115
116         setCombo(algoSuiteCombo, AlgoSuiteModelHelper.getAlgorithmSuite(secBinding));
117         setCombo(layoutCombo, SecurityPolicyModelHelper.getMessageLayout(secBinding));
118
119         enableDisable();
120         
121         inSync = false;
122     }
123
124     public void setValue(javax.swing.JComponent JavaDoc source) {
125
126         if (inSync) return;
127             
128         WSDLComponent secBinding = null;
129         WSDLComponent topSecBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp);
130         WSDLComponent protTokenKind = SecurityTokensModelHelper.getTokenElement(topSecBinding, ProtectionToken.class);
131         WSDLComponent protToken = SecurityTokensModelHelper.getTokenTypeElement(protTokenKind);
132         
133         boolean secConv = (protToken instanceof SecureConversationToken);
134
135         if (source.equals(secConvChBox)) {
136             ProfilesModelHelper.enableSecureConversation(comp, secConvChBox.isSelected(), ComboConstants.PROF_MSGAUTHSSL);
137         }
138         
139         if (secConv) {
140             WSDLComponent bootPolicy = SecurityTokensModelHelper.getTokenElement(protToken, BootstrapPolicy.class);
141             secBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(bootPolicy);
142             if (source.equals(derivedKeysChBox)) {
143                 SecurityPolicyModelHelper.enableRequireDerivedKeys(protToken, derivedKeysChBox.isSelected());
144             }
145         } else {
146             secBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp);
147         }
148             
149         if (source.equals(encryptSignatureChBox)) {
150             SecurityPolicyModelHelper.enableEncryptSignature(secBinding, encryptSignatureChBox.isSelected());
151             if (secConv) {
152                 SecurityPolicyModelHelper.enableEncryptSignature(topSecBinding, encryptSignatureChBox.isSelected());
153             }
154         }
155         if (source.equals(encryptOrderChBox)) {
156             SecurityPolicyModelHelper.enableEncryptBeforeSigning(secBinding, encryptOrderChBox.isSelected());
157             if (secConv) {
158                 SecurityPolicyModelHelper.enableEncryptBeforeSigning(topSecBinding, encryptOrderChBox.isSelected());
159             }
160         }
161         if (source.equals(layoutCombo)) {
162             SecurityPolicyModelHelper.setLayout(secBinding, (String JavaDoc) layoutCombo.getSelectedItem());
163             if (secConv) {
164                 SecurityPolicyModelHelper.setLayout(topSecBinding, (String JavaDoc) layoutCombo.getSelectedItem());
165             }
166         }
167         if (source.equals(algoSuiteCombo)) {
168             AlgoSuiteModelHelper.setAlgorithmSuite(secBinding, (String JavaDoc) algoSuiteCombo.getSelectedItem());
169             if (secConv) {
170                 AlgoSuiteModelHelper.setAlgorithmSuite(topSecBinding, (String JavaDoc) algoSuiteCombo.getSelectedItem());
171             }
172         }
173         if (source.equals(reqDerivedKeys)) {
174             WSDLComponent tokenKind = SecurityTokensModelHelper.getTokenElement(secBinding, RecipientToken.class);
175             WSDLComponent token = SecurityTokensModelHelper.getTokenTypeElement(tokenKind);
176             SecurityPolicyModelHelper.enableRequireDerivedKeys(token, reqDerivedKeys.isSelected());
177             tokenKind = SecurityTokensModelHelper.getTokenElement(secBinding, InitiatorToken.class);
178             token = SecurityTokensModelHelper.getTokenTypeElement(tokenKind);
179             SecurityPolicyModelHelper.enableRequireDerivedKeys(token, reqDerivedKeys.isSelected());
180             return;
181         }
182         
183         enableDisable();
184     }
185
186     private void enableDisable() {
187         boolean secConvEnabled = secConvChBox.isSelected();
188         derivedKeysChBox.setEnabled(secConvEnabled);
189         boolean rmEnabled = RMModelHelper.isRMEnabled(comp);
190         if (rmEnabled) {
191             secConvChBox.setEnabled(!secConvEnabled);
192         } else {
193             secConvChBox.setEnabled(true);
194         }
195     }
196     
197     private void setCombo(JComboBox JavaDoc combo, String JavaDoc item) {
198         if (item == null) {
199             combo.setSelectedIndex(0);
200         } else {
201             combo.setSelectedItem(item);
202         }
203     }
204
205     private void setCombo(JComboBox JavaDoc combo, boolean second) {
206         combo.setSelectedIndex(second ? 1 : 0);
207     }
208         
209     private void setChBox(JCheckBox JavaDoc chBox, Boolean JavaDoc enable) {
210         if (enable == null) {
211             chBox.setSelected(false);
212         } else {
213             chBox.setSelected(enable);
214         }
215     }
216     
217     /** This method is called from within the constructor to
218      * initialize the form.
219      * WARNING: Do NOT modify this code. The content of this method is
220      * always regenerated by the Form Editor.
221      */

222     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
223
private void initComponents() {
224
225         secConvChBox = new javax.swing.JCheckBox JavaDoc();
226         derivedKeysChBox = new javax.swing.JCheckBox JavaDoc();
227         algoSuiteLabel = new javax.swing.JLabel JavaDoc();
228         algoSuiteCombo = new javax.swing.JComboBox JavaDoc();
229         layoutLabel = new javax.swing.JLabel JavaDoc();
230         layoutCombo = new javax.swing.JComboBox JavaDoc();
231         encryptSignatureChBox = new javax.swing.JCheckBox JavaDoc();
232         reqDerivedKeys = new javax.swing.JCheckBox JavaDoc();
233         encryptOrderChBox = new javax.swing.JCheckBox JavaDoc();
234
235         org.openide.awt.Mnemonics.setLocalizedText(secConvChBox, org.openide.util.NbBundle.getMessage(MutualCertificates.class, "LBL_SecConvLabel")); // NOI18N
236
secConvChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
237         secConvChBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
238         secConvChBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
239             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
240                 secConvChBoxActionPerformed(evt);
241             }
242         });
243
244         org.openide.awt.Mnemonics.setLocalizedText(derivedKeysChBox, org.openide.util.NbBundle.getMessage(MutualCertificates.class, "LBL_RequireDerivedKeysForSecConv")); // NOI18N
245
derivedKeysChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
246         derivedKeysChBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
247         derivedKeysChBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
248             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
249                 derivedKeysChBoxActionPerformed(evt);
250             }
251         });
252
253         algoSuiteLabel.setLabelFor(algoSuiteCombo);
254         org.openide.awt.Mnemonics.setLocalizedText(algoSuiteLabel, org.openide.util.NbBundle.getMessage(MutualCertificates.class, "LBL_AlgoSuiteLabel")); // NOI18N
255

256         algoSuiteCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
257             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
258                 algoSuiteComboActionPerformed(evt);
259             }
260         });
261
262         layoutLabel.setLabelFor(layoutCombo);
263         org.openide.awt.Mnemonics.setLocalizedText(layoutLabel, org.openide.util.NbBundle.getMessage(MutualCertificates.class, "LBL_LayoutLabel")); // NOI18N
264

265         layoutCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
266             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
267                 layoutComboActionPerformed(evt);
268             }
269         });
270
271         org.openide.awt.Mnemonics.setLocalizedText(encryptSignatureChBox, org.openide.util.NbBundle.getMessage(MutualCertificates.class, "LBL_EncryptSignatureLabel")); // NOI18N
272
encryptSignatureChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
273         encryptSignatureChBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
274         encryptSignatureChBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
275             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
276                 encryptSignatureChBox(evt);
277             }
278         });
279
280         org.openide.awt.Mnemonics.setLocalizedText(reqDerivedKeys, org.openide.util.NbBundle.getMessage(MutualCertificates.class, "LBL_RequireDerivedKeys")); // NOI18N
281
reqDerivedKeys.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
282         reqDerivedKeys.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
283         reqDerivedKeys.addActionListener(new java.awt.event.ActionListener JavaDoc() {
284             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
285                 reqDerivedKeysActionPerformed(evt);
286             }
287         });
288
289         org.openide.awt.Mnemonics.setLocalizedText(encryptOrderChBox, org.openide.util.NbBundle.getMessage(MutualCertificates.class, "LBL_EncryptOrderLabel")); // NOI18N
290
encryptOrderChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
291         encryptOrderChBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
292         encryptOrderChBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
293             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
294                 encryptOrderChBoxActionPerformed(evt);
295             }
296         });
297
298         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
299         this.setLayout(layout);
300         layout.setHorizontalGroup(
301             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
302             .add(layout.createSequentialGroup()
303                 .addContainerGap()
304                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
305                     .add(reqDerivedKeys)
306                     .add(secConvChBox)
307                     .add(derivedKeysChBox)
308                     .add(encryptSignatureChBox)
309                     .add(encryptOrderChBox)
310                     .add(layout.createSequentialGroup()
311                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
312                             .add(layoutLabel)
313                             .add(algoSuiteLabel))
314                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
315                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
316                             .add(layoutCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
317                             .add(algoSuiteCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
318                 .addContainerGap())
319         );
320
321         layout.linkSize(new java.awt.Component JavaDoc[] {algoSuiteCombo, layoutCombo}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
322
323         layout.setVerticalGroup(
324             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
325             .add(layout.createSequentialGroup()
326                 .addContainerGap()
327                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
328                     .add(algoSuiteLabel)
329                     .add(algoSuiteCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
330                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
331                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
332                     .add(layoutLabel)
333                     .add(layoutCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
334                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
335                 .add(reqDerivedKeys)
336                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
337                 .add(secConvChBox)
338                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
339                 .add(derivedKeysChBox)
340                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
341                 .add(encryptSignatureChBox)
342                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
343                 .add(encryptOrderChBox)
344                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
345         );
346
347         layout.linkSize(new java.awt.Component JavaDoc[] {algoSuiteCombo, layoutCombo}, org.jdesktop.layout.GroupLayout.VERTICAL);
348
349     }// </editor-fold>//GEN-END:initComponents
350

351     private void encryptOrderChBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_encryptOrderChBoxActionPerformed
352
setValue(encryptOrderChBox);
353     }//GEN-LAST:event_encryptOrderChBoxActionPerformed
354

355     private void reqDerivedKeysActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_reqDerivedKeysActionPerformed
356
setValue(reqDerivedKeys);
357     }//GEN-LAST:event_reqDerivedKeysActionPerformed
358

359     private void derivedKeysChBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_derivedKeysChBoxActionPerformed
360
setValue(derivedKeysChBox);
361     }//GEN-LAST:event_derivedKeysChBoxActionPerformed
362

363     private void secConvChBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_secConvChBoxActionPerformed
364
setValue(secConvChBox);
365     }//GEN-LAST:event_secConvChBoxActionPerformed
366

367     private void encryptSignatureChBox(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_encryptSignatureChBox
368
setValue(encryptSignatureChBox);
369     }//GEN-LAST:event_encryptSignatureChBox
370

371     private void layoutComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_layoutComboActionPerformed
372
setValue(layoutCombo);
373     }//GEN-LAST:event_layoutComboActionPerformed
374

375     private void algoSuiteComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_algoSuiteComboActionPerformed
376
setValue(algoSuiteCombo);
377     }//GEN-LAST:event_algoSuiteComboActionPerformed
378

379     // Variables declaration - do not modify//GEN-BEGIN:variables
380
private javax.swing.JComboBox JavaDoc algoSuiteCombo;
381     private javax.swing.JLabel JavaDoc algoSuiteLabel;
382     private javax.swing.JCheckBox JavaDoc derivedKeysChBox;
383     private javax.swing.JCheckBox JavaDoc encryptOrderChBox;
384     private javax.swing.JCheckBox JavaDoc encryptSignatureChBox;
385     private javax.swing.JComboBox JavaDoc layoutCombo;
386     private javax.swing.JLabel JavaDoc layoutLabel;
387     private javax.swing.JCheckBox JavaDoc reqDerivedKeys;
388     private javax.swing.JCheckBox JavaDoc secConvChBox;
389     // End of variables declaration//GEN-END:variables
390

391 }
392
Popular Tags