KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > ui > service > subpanels > ValidatorsPanel


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.subpanels;
21
22 import org.netbeans.api.project.Project;
23 import org.netbeans.modules.websvc.wsitconf.WSITEditor;
24 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProprietarySecurityPolicyModelHelper;
25 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.Validator;
26 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme;
27 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
28 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
29 import org.openide.util.NbBundle;
30
31 import javax.swing.*;
32 import javax.swing.filechooser.FileFilter JavaDoc;
33 import java.io.File JavaDoc;
34 import java.util.Set JavaDoc;
35 import org.netbeans.modules.websvc.wsitconf.ui.ClassDialog;
36
37 /**
38  *
39  * @author Martin Grebac
40  */

41 public class ValidatorsPanel extends JPanel {
42
43     private WSDLModel model;
44     private WSDLComponent comp;
45
46     private Project p;
47     
48     private boolean inSync = false;
49         
50     public ValidatorsPanel(WSDLComponent comp, Project p) {
51         super();
52         this.model = comp.getModel();
53         this.comp = comp;
54         this.p = p;
55         
56         initComponents();
57
58         usernameValidatorTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
59         usernameValidatorLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
60         timestampValidatorTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
61         timestampValidatorLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
62         certificateValidatorTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
63         certificateValidatorLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
64         samlValidatorTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
65         samlValidatorLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
66         
67         sync();
68     }
69
70     private String JavaDoc getValidator(String JavaDoc type) {
71         if (Validator.USERNAME_VALIDATOR.equals(type)) return usernameValidatorTextField.getText();
72         if (Validator.TIMESTAMP_VALIDATOR.equals(type)) return timestampValidatorTextField.getText();
73         if (Validator.CERTIFICATE_VALIDATOR.equals(type)) return certificateValidatorTextField.getText();
74         if (Validator.SAML_VALIDATOR.equals(type)) return samlValidatorTextField.getText();
75         return null;
76     }
77
78     private void setValidator(String JavaDoc type, String JavaDoc validator) {
79         if (Validator.USERNAME_VALIDATOR.equals(type)) this.usernameValidatorTextField.setText(validator);
80         if (Validator.TIMESTAMP_VALIDATOR.equals(type)) this.timestampValidatorTextField.setText(validator);
81         if (Validator.CERTIFICATE_VALIDATOR.equals(type)) this.certificateValidatorTextField.setText(validator);
82         if (Validator.SAML_VALIDATOR.equals(type)) this.samlValidatorTextField.setText(validator);
83     }
84     
85     public void sync() {
86         inSync = true;
87                 
88         String JavaDoc usernameValidator = ProprietarySecurityPolicyModelHelper.getValidator(comp, Validator.USERNAME_VALIDATOR);
89         if (usernameValidator != null) {
90             setValidator(Validator.USERNAME_VALIDATOR, usernameValidator);
91         }
92         String JavaDoc timestampValidator = ProprietarySecurityPolicyModelHelper.getValidator(comp, Validator.TIMESTAMP_VALIDATOR);
93         if (timestampValidator != null) {
94             setValidator(Validator.TIMESTAMP_VALIDATOR, timestampValidator);
95         }
96         String JavaDoc certificateValidator = ProprietarySecurityPolicyModelHelper.getValidator(comp, Validator.CERTIFICATE_VALIDATOR);
97         if (certificateValidator != null) {
98             setValidator(Validator.CERTIFICATE_VALIDATOR, certificateValidator);
99         }
100         String JavaDoc samlValidator = ProprietarySecurityPolicyModelHelper.getValidator(comp, Validator.SAML_VALIDATOR);
101         if (samlValidator != null) {
102             setValidator(Validator.SAML_VALIDATOR, samlValidator);
103         }
104         inSync = false;
105     }
106     
107     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc value) {
108         if (source.equals(usernameValidatorTextField)) {
109             String JavaDoc validator = getValidator(Validator.USERNAME_VALIDATOR);
110             if ((validator != null) && (validator.length() == 0)) {
111                 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.USERNAME_VALIDATOR, null, false);
112             } else {
113                 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.USERNAME_VALIDATOR, validator, false);
114             }
115             return;
116         }
117
118         if (source.equals(timestampValidatorTextField)) {
119             String JavaDoc validator = getValidator(Validator.TIMESTAMP_VALIDATOR);
120             if ((validator != null) && (validator.length() == 0)) {
121                 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.TIMESTAMP_VALIDATOR, null, false);
122             } else {
123                 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.TIMESTAMP_VALIDATOR, validator, false);
124             }
125             return;
126         }
127
128         if (source.equals(certificateValidatorTextField)) {
129             String JavaDoc validator = getValidator(Validator.CERTIFICATE_VALIDATOR);
130             if ((validator != null) && (validator.length() == 0)) {
131                 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.CERTIFICATE_VALIDATOR, null, false);
132             } else {
133                 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.CERTIFICATE_VALIDATOR,validator, false);
134             }
135             return;
136         }
137
138         if (source.equals(samlValidatorTextField)) {
139             String JavaDoc validator = getValidator(Validator.SAML_VALIDATOR);
140             if ((validator != null) && (validator.length() == 0)) {
141                 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.SAML_VALIDATOR, null, false);
142             } else {
143                 ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.SAML_VALIDATOR, validator, false);
144             }
145             return;
146         }
147     }
148     
149     private class JavaFileFilter extends FileFilter JavaDoc {
150         private static final String JavaDoc JAVA_EXT = ".java"; //NOI18N
151
public boolean accept(File JavaDoc f) {
152             if ((f != null) && f.exists() && (f.getName() != null) && ((f.getName().contains(JAVA_EXT)) || (f.isDirectory()))) {
153                 return true;
154             }
155             return false;
156         }
157         public String JavaDoc getDescription() {
158             return NbBundle.getMessage(WSITEditor.class, "JAVA_FILE"); //NOI18N
159
}
160     }
161
162     public void storeState() {
163         String JavaDoc usernameV = getValidator(Validator.USERNAME_VALIDATOR);
164         if ((usernameV == null) || (usernameV.length() == 0)) {
165             ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.USERNAME_VALIDATOR, null, false);
166         } else {
167             ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.USERNAME_VALIDATOR, usernameV, false);
168         }
169         
170         String JavaDoc certV = getValidator(Validator.CERTIFICATE_VALIDATOR);
171         if ((certV == null) || (certV.length() == 0)) {
172             ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.CERTIFICATE_VALIDATOR, null, false);
173         } else {
174             ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.CERTIFICATE_VALIDATOR, certV, false);
175         }
176         
177         String JavaDoc timeV = getValidator(Validator.TIMESTAMP_VALIDATOR);
178         if ((timeV == null) || (timeV.length() == 0)) {
179             ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.TIMESTAMP_VALIDATOR, null, false);
180         } else {
181             ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.TIMESTAMP_VALIDATOR, timeV, false);
182         }
183         
184         String JavaDoc samlV = getValidator(Validator.SAML_VALIDATOR);
185         if ((samlV == null) || (samlV.length() == 0)) {
186             ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.SAML_VALIDATOR, null, false);
187         } else {
188             ProprietarySecurityPolicyModelHelper.setValidator(comp, Validator.SAML_VALIDATOR, samlV, false);
189         }
190     }
191     
192     /** This method is called from within the constructor to
193      * initialize the form.
194      * WARNING: Do NOT modify this code. The content of this method is
195      * always regenerated by the Form Editor.
196      */

197     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
198
private void initComponents() {
199         jToggleButton1 = new javax.swing.JToggleButton JavaDoc();
200         usernameValidatorLabel = new javax.swing.JLabel JavaDoc();
201         timestampValidatorLabel = new javax.swing.JLabel JavaDoc();
202         certificateValidatorLabel = new javax.swing.JLabel JavaDoc();
203         samlValidatorLabel = new javax.swing.JLabel JavaDoc();
204         usernameValidatorTextField = new javax.swing.JTextField JavaDoc();
205         timestampValidatorTextField = new javax.swing.JTextField JavaDoc();
206         certificateValidatorTextField = new javax.swing.JTextField JavaDoc();
207         samlValidatorTextField = new javax.swing.JTextField JavaDoc();
208         usernameValidatorButton = new javax.swing.JButton JavaDoc();
209         timestampValidatorButton = new javax.swing.JButton JavaDoc();
210         certificateValidatorButton = new javax.swing.JButton JavaDoc();
211         samlValidatorButton = new javax.swing.JButton JavaDoc();
212
213         jToggleButton1.setText("jToggleButton1");
214
215         usernameValidatorLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/service/subpanels/Bundle").getString("LBL_ValidatorPanel_UsernameVLabel"));
216
217         timestampValidatorLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/service/subpanels/Bundle").getString("LBL_ValidatorPanel_TimestampVLabel"));
218
219         certificateValidatorLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/service/subpanels/Bundle").getString("LBL_ValidatorPanel_CertificateVLabel"));
220
221         samlValidatorLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/service/subpanels/Bundle").getString("LBL_ValidatorPanel_SAMLVLabel"));
222
223         usernameValidatorButton.setText("Browse...");
224         usernameValidatorButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
225             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
226                 usernameValidatorButtonActionPerformed(evt);
227             }
228         });
229
230         timestampValidatorButton.setText("Browse...");
231         timestampValidatorButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
232             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
233                 timestampValidatorButtonActionPerformed(evt);
234             }
235         });
236
237         certificateValidatorButton.setText("Browse...");
238         certificateValidatorButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
239             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
240                 certificateValidatorButtonActionPerformed(evt);
241             }
242         });
243
244         samlValidatorButton.setText("Browse...");
245         samlValidatorButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
246             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
247                 samlValidatorButtonActionPerformed(evt);
248             }
249         });
250
251         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
252         this.setLayout(layout);
253         layout.setHorizontalGroup(
254             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
255             .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
256                 .addContainerGap()
257                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
258                     .add(layout.createSequentialGroup()
259                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
260                             .add(layout.createSequentialGroup()
261                                 .add(126, 126, 126)
262                                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
263                                     .add(timestampValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
264                                     .add(certificateValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
265                                     .add(usernameValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 266, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
266                                     .add(org.jdesktop.layout.GroupLayout.LEADING, samlValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
267                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
268                                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
269                                     .add(samlValidatorButton)
270                                     .add(certificateValidatorButton)
271                                     .add(timestampValidatorButton)
272                                     .add(usernameValidatorButton)))
273                             .add(timestampValidatorLabel))
274                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 11, Short.MAX_VALUE)
275                         .add(jToggleButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
276                     .add(layout.createSequentialGroup()
277                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
278                             .add(certificateValidatorLabel)
279                             .add(samlValidatorLabel)
280                             .add(usernameValidatorLabel))
281                         .addContainerGap(389, Short.MAX_VALUE))))
282         );
283
284         layout.linkSize(new java.awt.Component JavaDoc[] {certificateValidatorTextField, samlValidatorTextField, timestampValidatorTextField, usernameValidatorTextField}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
285
286         layout.setVerticalGroup(
287             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
288             .add(layout.createSequentialGroup()
289                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
290                     .add(layout.createSequentialGroup()
291                         .add(69, 69, 69)
292                         .add(jToggleButton1))
293                     .add(layout.createSequentialGroup()
294                         .addContainerGap()
295                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
296                             .add(usernameValidatorLabel)
297                             .add(usernameValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
298                             .add(usernameValidatorButton))
299                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
300                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
301                             .add(timestampValidatorLabel)
302                             .add(timestampValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
303                             .add(timestampValidatorButton))
304                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
305                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
306                             .add(certificateValidatorLabel)
307                             .add(certificateValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
308                             .add(certificateValidatorButton))
309                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
310                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
311                             .add(samlValidatorLabel)
312                             .add(samlValidatorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
313                             .add(samlValidatorButton))))
314                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
315         );
316     }// </editor-fold>//GEN-END:initComponents
317

318     private void samlValidatorButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_samlValidatorButtonActionPerformed
319
if (p != null) {
320             ClassDialog classDialog = new ClassDialog(p, "com.sun.xml.wss.impl.callback.SAMLAssertionValidator"); //NOI18N
321
classDialog.show();
322             if (classDialog.okButtonPressed()) {
323                 Set JavaDoc<String JavaDoc> selectedClasses = classDialog.getSelectedClasses();
324                 for (String JavaDoc selectedClass : selectedClasses) {
325                     setValidator(Validator.SAML_VALIDATOR, selectedClass);
326                     break;
327                 }
328             }
329         }
330     }//GEN-LAST:event_samlValidatorButtonActionPerformed
331

332     private void certificateValidatorButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_certificateValidatorButtonActionPerformed
333
if (p != null) {
334             ClassDialog classDialog = new ClassDialog(p, "com.sun.xml.wss.impl.callback.CertificateValidationCallback.CertificateValidator"); //NOI18N
335
classDialog.show();
336             if (classDialog.okButtonPressed()) {
337                 Set JavaDoc<String JavaDoc> selectedClasses = classDialog.getSelectedClasses();
338                 for (String JavaDoc selectedClass : selectedClasses) {
339                     setValidator(Validator.CERTIFICATE_VALIDATOR, selectedClass);
340                     break;
341                 }
342             }
343         }
344     }//GEN-LAST:event_certificateValidatorButtonActionPerformed
345

346     private void timestampValidatorButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_timestampValidatorButtonActionPerformed
347
if (p != null) {
348             ClassDialog classDialog = new ClassDialog(p, "com.sun.xml.wss.impl.callback.TimestampValidationCallback.TimestampValidator"); //NOI18N
349
classDialog.show();
350             if (classDialog.okButtonPressed()) {
351                 Set JavaDoc<String JavaDoc> selectedClasses = classDialog.getSelectedClasses();
352                 for (String JavaDoc selectedClass : selectedClasses) {
353                     setValidator(Validator.TIMESTAMP_VALIDATOR, selectedClass);
354                     break;
355                 }
356             }
357         }
358     }//GEN-LAST:event_timestampValidatorButtonActionPerformed
359

360     private void usernameValidatorButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_usernameValidatorButtonActionPerformed
361
if (p != null) {
362             ClassDialog classDialog = new ClassDialog(p, "com.sun.xml.wss.impl.callback.PasswordValidationCallback.PasswordValidator"); //NOI18N
363
classDialog.show();
364             if (classDialog.okButtonPressed()) {
365                 Set JavaDoc<String JavaDoc> selectedClasses = classDialog.getSelectedClasses();
366                 for (String JavaDoc selectedClass : selectedClasses) {
367                     setValidator(Validator.USERNAME_VALIDATOR, selectedClass);
368                     break;
369                 }
370             }
371         }
372     }//GEN-LAST:event_usernameValidatorButtonActionPerformed
373

374     // Variables declaration - do not modify//GEN-BEGIN:variables
375
private javax.swing.JButton JavaDoc certificateValidatorButton;
376     private javax.swing.JLabel JavaDoc certificateValidatorLabel;
377     private javax.swing.JTextField JavaDoc certificateValidatorTextField;
378     private javax.swing.JToggleButton JavaDoc jToggleButton1;
379     private javax.swing.JButton JavaDoc samlValidatorButton;
380     private javax.swing.JLabel JavaDoc samlValidatorLabel;
381     private javax.swing.JTextField JavaDoc samlValidatorTextField;
382     private javax.swing.JButton JavaDoc timestampValidatorButton;
383     private javax.swing.JLabel JavaDoc timestampValidatorLabel;
384     private javax.swing.JTextField JavaDoc timestampValidatorTextField;
385     private javax.swing.JButton JavaDoc usernameValidatorButton;
386     private javax.swing.JLabel JavaDoc usernameValidatorLabel;
387     private javax.swing.JTextField JavaDoc usernameValidatorTextField;
388     // End of variables declaration//GEN-END:variables
389

390 }
391
Popular Tags