KickJava   Java API By Example, From Geeks To Geeks.

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


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.SecurityPolicyModelHelper;
27 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityTokensModelHelper;
28 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.HttpsToken;
29 import org.netbeans.modules.websvc.wsitmodelext.security.tokens.TransportToken;
30 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
31 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
32
33 /**
34  *
35  * @author Martin Grebac
36  */

37 public class TransportSecurity extends javax.swing.JPanel JavaDoc {
38
39     private boolean inSync = false;
40
41     private WSDLComponent comp;
42     private WSDLModel model;
43     
44     /**
45      * Creates new form TransportSecurity
46      */

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

78         inSync = false;
79         sync();
80     }
81     
82     private void sync() {
83         inSync = true;
84
85         WSDLComponent secBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp);
86         WSDLComponent tokenKind = SecurityTokensModelHelper.getTokenElement(secBinding, TransportToken.class);
87         HttpsToken token = (HttpsToken) SecurityTokensModelHelper.getTokenTypeElement(tokenKind);
88         if (token instanceof HttpsToken) {
89             setChBox(requireCertificateChBox, SecurityTokensModelHelper.isRequireClientCertificate((HttpsToken) token));
90         }
91
92         setCombo(algoSuiteCombo, AlgoSuiteModelHelper.getAlgorithmSuite(secBinding));
93       
94         setCombo(layoutCombo, SecurityPolicyModelHelper.getMessageLayout(comp));
95         
96         inSync = false;
97     }
98
99     public void setValue(javax.swing.JComponent JavaDoc source) {
100
101         if (inSync) return;
102
103         WSDLComponent secBinding = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp);
104
105         if (source.equals(requireCertificateChBox)) {
106             WSDLComponent tokenKind = SecurityTokensModelHelper.getTokenElement(secBinding, TransportToken.class);
107             HttpsToken token = (HttpsToken) SecurityTokensModelHelper.getTokenTypeElement(tokenKind);
108             SecurityTokensModelHelper.setRequireClientCertificate(token, requireCertificateChBox.isSelected());
109         }
110         if (source.equals(layoutCombo)) {
111             SecurityPolicyModelHelper.setLayout(secBinding, (String JavaDoc) layoutCombo.getSelectedItem());
112         }
113         if (source.equals(algoSuiteCombo)) {
114             AlgoSuiteModelHelper.setAlgorithmSuite(secBinding, (String JavaDoc) algoSuiteCombo.getSelectedItem());
115         }
116     }
117
118     private void setCombo(JComboBox JavaDoc combo, String JavaDoc item) {
119         if (item == null) {
120             combo.setSelectedIndex(0);
121         } else {
122             combo.setSelectedItem(item);
123         }
124     }
125
126     private void setChBox(JCheckBox JavaDoc chBox, Boolean JavaDoc enable) {
127         if (enable == null) {
128             chBox.setSelected(false);
129         } else {
130             chBox.setSelected(enable);
131         }
132     }
133     
134     /** This method is called from within the constructor to
135      * initialize the form.
136      * WARNING: Do NOT modify this code. The content of this method is
137      * always regenerated by the Form Editor.
138      */

139     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
140
private void initComponents() {
141
142         requireCertificateChBox = new javax.swing.JCheckBox JavaDoc();
143         algoSuiteLabel = new javax.swing.JLabel JavaDoc();
144         algoSuiteCombo = new javax.swing.JComboBox JavaDoc();
145         layoutLabel = new javax.swing.JLabel JavaDoc();
146         layoutCombo = new javax.swing.JComboBox JavaDoc();
147
148         org.openide.awt.Mnemonics.setLocalizedText(requireCertificateChBox, org.openide.util.NbBundle.getMessage(TransportSecurity.class, "LBL_RequireClientCertificate")); // NOI18N
149
requireCertificateChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
150         requireCertificateChBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
151         requireCertificateChBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
152             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
153                 requireCertificateChBoxActionPerformed(evt);
154             }
155         });
156
157         algoSuiteLabel.setLabelFor(algoSuiteCombo);
158         org.openide.awt.Mnemonics.setLocalizedText(algoSuiteLabel, org.openide.util.NbBundle.getMessage(TransportSecurity.class, "LBL_AlgoSuiteLabel")); // NOI18N
159

160         algoSuiteCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
161             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
162                 algoSuiteComboActionPerformed(evt);
163             }
164         });
165
166         layoutLabel.setLabelFor(layoutCombo);
167         org.openide.awt.Mnemonics.setLocalizedText(layoutLabel, org.openide.util.NbBundle.getMessage(TransportSecurity.class, "LBL_LayoutLabel")); // NOI18N
168

169         layoutCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
170             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
171                 layoutComboActionPerformed(evt);
172             }
173         });
174
175         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
176         this.setLayout(layout);
177         layout.setHorizontalGroup(
178             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
179             .add(layout.createSequentialGroup()
180                 .addContainerGap()
181                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
182                     .add(layout.createSequentialGroup()
183                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
184                             .add(layoutLabel)
185                             .add(algoSuiteLabel))
186                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
187                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
188                             .add(algoSuiteCombo, 0, 133, Short.MAX_VALUE)
189                             .add(layoutCombo, 0, 133, Short.MAX_VALUE)))
190                     .add(requireCertificateChBox))
191                 .addContainerGap())
192         );
193
194         layout.linkSize(new java.awt.Component JavaDoc[] {algoSuiteCombo, layoutCombo}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
195
196         layout.setVerticalGroup(
197             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
198             .add(layout.createSequentialGroup()
199                 .addContainerGap()
200                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
201                     .add(algoSuiteLabel)
202                     .add(algoSuiteCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
203                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
204                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
205                     .add(layoutLabel)
206                     .add(layoutCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
207                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
208                 .add(requireCertificateChBox)
209                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
210         );
211
212         layout.linkSize(new java.awt.Component JavaDoc[] {algoSuiteCombo, layoutCombo}, org.jdesktop.layout.GroupLayout.VERTICAL);
213
214     }// </editor-fold>//GEN-END:initComponents
215

216     private void layoutComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_layoutComboActionPerformed
217
setValue(layoutCombo);
218     }//GEN-LAST:event_layoutComboActionPerformed
219

220     private void algoSuiteComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_algoSuiteComboActionPerformed
221
setValue(algoSuiteCombo);
222     }//GEN-LAST:event_algoSuiteComboActionPerformed
223

224     private void requireCertificateChBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_requireCertificateChBoxActionPerformed
225
setValue(requireCertificateChBox);
226     }//GEN-LAST:event_requireCertificateChBoxActionPerformed
227

228     // Variables declaration - do not modify//GEN-BEGIN:variables
229
private javax.swing.JComboBox JavaDoc algoSuiteCombo;
230     private javax.swing.JLabel JavaDoc algoSuiteLabel;
231     private javax.swing.JComboBox JavaDoc layoutCombo;
232     private javax.swing.JLabel JavaDoc layoutLabel;
233     private javax.swing.JCheckBox JavaDoc requireCertificateChBox;
234     // End of variables declaration//GEN-END:variables
235

236 }
237
Popular Tags