KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > ui > client > KeystorePanel


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.client;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Enumeration JavaDoc;
24 import org.netbeans.api.project.FileOwnerQuery;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
27 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
28 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
29 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
30 import org.netbeans.modules.websvc.wsitconf.ui.StoreFileFilter;
31 import org.netbeans.modules.websvc.wsitconf.util.Util;
32 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.KeyStore;
33 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProprietarySecurityPolicyModelHelper;
34 import org.netbeans.modules.xml.multiview.ui.SectionInnerPanel;
35 import org.netbeans.modules.xml.multiview.ui.SectionView;
36 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme;
37 import org.netbeans.modules.xml.wsdl.model.Binding;
38 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
39 import org.openide.filesystems.FileObject;
40 import org.openide.filesystems.FileUtil;
41 import org.openide.nodes.Node;
42 import org.openide.util.NbBundle;
43 import javax.swing.*;
44 import java.io.File JavaDoc;
45 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
46 import org.netbeans.modules.websvc.wsitconf.spi.SecurityCheckerRegistry;
47 import org.openide.DialogDisplayer;
48 import org.openide.NotifyDescriptor;
49
50 /**
51  *
52  * @author Martin Grebac
53  */

54 public class KeystorePanel extends SectionInnerPanel {
55
56     private static final String JavaDoc PKCS12 = "PKCS12"; //NOI18N
57
private static final String JavaDoc JKS = "JKS"; //NOI18N
58

59     private static final String JavaDoc DEFAULT_PASSWORD="changeit"; //NOI18N
60

61     private WSDLModel model;
62     private Node node;
63     private Binding binding;
64
65     private String JavaDoc keystoreType = JKS;
66     private String JavaDoc truststoreType = JKS;
67     
68     private boolean inSync = false;
69     
70     private Project project;
71     
72     private JaxWsModel jaxwsmodel;
73     
74     public KeystorePanel(SectionView view, WSDLModel model, Node node, Binding binding, JaxWsModel jaxwsmodel) {
75         super(view);
76         this.model = model;
77         this.node = node;
78         this.binding = binding;
79         this.jaxwsmodel = jaxwsmodel;
80         
81         FileObject fo = (FileObject) node.getLookup().lookup(FileObject.class);
82         if (fo != null) project = FileOwnerQuery.getOwner(fo);
83         
84         initComponents();
85
86         keyAliasCombo.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
87         keyAliasLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
88         keyPasswordLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
89         keyPasswordField.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
90         keystoreLocationLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
91         keystoreLocationTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
92         keystorePasswordLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
93         keystorePasswordField.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
94         trustAliasCombo.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
95         trustAliasLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
96         trustPasswordField.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
97         truststoreLocationLbl.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
98         truststoreLocationTextField.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
99         truststorePasswordLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
100
101         addModifier(keystoreLocationTextField);
102         addModifier(keyAliasCombo);
103         addModifier(keystorePasswordField);
104         addModifier(keyPasswordField);
105         addModifier(truststoreLocationTextField);
106         addModifier(trustPasswordField);
107         addModifier(trustAliasCombo);
108
109         sync();
110     }
111
112     private String JavaDoc getKeystoreAlias() {
113         return (String JavaDoc) this.keyAliasCombo.getSelectedItem();
114     }
115
116     private void setKeystoreAlias(String JavaDoc alias) {
117         this.keyAliasCombo.setSelectedItem(alias);
118     }
119     
120     private String JavaDoc getTruststoreAlias() {
121         return (String JavaDoc) this.trustAliasCombo.getSelectedItem();
122     }
123
124     private void setTruststoreAlias(String JavaDoc alias) {
125         this.trustAliasCombo.setSelectedItem(alias);
126     }
127
128     private char[] getCharPassword(boolean trust) {
129         return trust ? trustPasswordField.getPassword() : keystorePasswordField.getPassword();
130     }
131
132     private String JavaDoc getKeyPassword() {
133         return String.valueOf(this.keyPasswordField.getPassword());
134     }
135     
136     private String JavaDoc getKeystorePassword() {
137         return String.valueOf(this.keystorePasswordField.getPassword());
138     }
139
140     private void setKeyPassword(String JavaDoc password) {
141         this.keyPasswordField.setText(password);
142     }
143
144     private void setKeystorePassword(String JavaDoc password) {
145         this.keystorePasswordField.setText(password);
146     }
147
148     private String JavaDoc getTruststorePassword() {
149         return String.valueOf(this.trustPasswordField.getPassword());
150     }
151
152     private void setTruststorePassword(String JavaDoc password) {
153         this.trustPasswordField.setText(password);
154     }
155     
156     private void setKeystorePath(String JavaDoc path) {
157         this.keystoreLocationTextField.setText(path);
158     }
159     
160     private String JavaDoc getKeystorePath() {
161         String JavaDoc path = this.keystoreLocationTextField.getText();
162         if ("".equals(path) || (path == null)) { //NOI18N
163
return null;
164         }
165         return path;
166     }
167
168     private void setTruststorePath(String JavaDoc path) {
169         this.truststoreLocationTextField.setText(path);
170     }
171
172     private String JavaDoc getTruststorePath() {
173         String JavaDoc path = this.truststoreLocationTextField.getText();
174         if ("".equals(path) || (path == null)) { //NOI18N
175
return null;
176         }
177         return path;
178     }
179     
180     public void sync() {
181         inSync = true;
182                 
183         J2eePlatform p = null;
184         JAXWSSupport ws = null;
185         FileObject fo = null;
186         if ((ws != null) && (fo != null)) {
187             Project project = FileOwnerQuery.getOwner(fo);
188             if (project != null) {
189                 J2eeModuleProvider mp = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class);
190                 if (mp != null) {
191                     String JavaDoc instance = mp.getServerInstanceID();
192                     p = Deployment.getDefault().getJ2eePlatform(instance);
193                 }
194             }
195         }
196
197         String JavaDoc keystoreLocation = ProprietarySecurityPolicyModelHelper.getStoreLocation(binding, false);
198         if (keystoreLocation != null) {
199             setKeystorePath(keystoreLocation);
200         } else {
201             setKeystorePath(getServerStoreLocation(false));
202         }
203         
204         String JavaDoc truststoreLocation = ProprietarySecurityPolicyModelHelper.getStoreLocation(binding, true);
205         if (truststoreLocation != null) {
206             setTruststorePath(truststoreLocation);
207         } else {
208             setTruststorePath(getServerStoreLocation(true));
209         }
210        
211         String JavaDoc keyStorePassword = ProprietarySecurityPolicyModelHelper.getStorePassword(binding, false);
212         if (keyStorePassword != null) {
213             setKeystorePassword(keyStorePassword);
214             reloadAliases(false);
215         } else {
216             setKeystorePassword(DEFAULT_PASSWORD);
217         }
218         
219         String JavaDoc trustStorePassword = ProprietarySecurityPolicyModelHelper.getStorePassword(binding,true);
220         if (trustStorePassword != null) {
221             setTruststorePassword(trustStorePassword);
222             reloadAliases(true);
223         } else {
224             setTruststorePassword(DEFAULT_PASSWORD);
225         }
226
227         String JavaDoc keyPassword = ProprietarySecurityPolicyModelHelper.getKeyPassword(binding);
228         if (keyPassword != null) {
229             setKeyPassword(keyPassword);
230         }
231
232         String JavaDoc keyStoreAlias = ProprietarySecurityPolicyModelHelper.getStoreAlias(binding, false);
233         setKeystoreAlias(keyStoreAlias);
234             
235         String JavaDoc truststoreAlias = ProprietarySecurityPolicyModelHelper.getStoreAlias(binding,true);
236         setTruststoreAlias(truststoreAlias);
237         
238         enableDisable();
239         
240         inSync = false;
241     }
242     
243     private String JavaDoc getServerStoreLocation(boolean trust) {
244         String JavaDoc storeLocation = null;
245         J2eeModuleProvider mp = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class);
246         if (mp != null) {
247             String JavaDoc sID = mp.getServerInstanceID();
248             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(sID);
249             File JavaDoc[] keyLocs = null;
250             keyLocs = trust ? j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_TRUSTSTORE_CLIENT) :
251                               j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_KEYSTORE_CLIENT);
252             if ((keyLocs != null) && (keyLocs.length > 0)) {
253                 storeLocation = keyLocs[0].getAbsolutePath();
254             }
255         }
256         return storeLocation;
257     }
258     
259     @Override JavaDoc
260     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc value) {
261         
262         if (inSync) return;
263         
264         if (source.equals(keystoreLocationTextField) ||
265                 source.equals(keyAliasCombo) ||
266                 source.equals(keystorePasswordField) ||
267                 source.equals(keyPasswordField)) {
268             
269             String JavaDoc alias = getKeystoreAlias();
270             if ((alias == null) || (alias.length() == 0)) {
271                 ProprietarySecurityPolicyModelHelper.setKeyStoreAlias(binding, null, true);
272             } else {
273                 ProprietarySecurityPolicyModelHelper.setKeyStoreAlias(binding, alias, true);
274             }
275             
276             String JavaDoc passwd = getKeystorePassword();
277             if ((passwd == null) || (passwd.length() == 0)) {
278                 ProprietarySecurityPolicyModelHelper.setStorePassword(binding, null, false, true);
279             } else {
280                 ProprietarySecurityPolicyModelHelper.setStorePassword(binding, passwd, false, true);
281             }
282
283             String JavaDoc kpasswd = getKeyPassword();
284             if ((kpasswd == null) || (kpasswd.length() == 0)) {
285                 ProprietarySecurityPolicyModelHelper.setKeyPassword(binding, null, true);
286             } else {
287                 ProprietarySecurityPolicyModelHelper.setKeyPassword(binding, kpasswd, true);
288             }
289
290             String JavaDoc loc = getKeystorePath();
291             if ((loc == null) || (loc.length() == 0)) {
292                 ProprietarySecurityPolicyModelHelper.setStoreType(binding, null, false, true);
293                 ProprietarySecurityPolicyModelHelper.setStoreLocation(binding, null, false, true);
294             } else {
295                 ProprietarySecurityPolicyModelHelper.setStoreType(binding, KeyStore.KEYSTORE_TYPE, false, true);
296                 ProprietarySecurityPolicyModelHelper.setStoreLocation(binding, loc, false, true);
297             }
298             
299             return;
300         }
301
302         if (source.equals(truststoreLocationTextField) || source.equals(trustAliasCombo) ||
303                 source.equals(trustPasswordField) ) {
304         
305             String JavaDoc alias = getTruststoreAlias();
306             if ((alias == null) || (alias.length() == 0)) {
307                 ProprietarySecurityPolicyModelHelper.setTrustPeerAlias(binding, null, true);
308             } else {
309                 ProprietarySecurityPolicyModelHelper.setTrustPeerAlias(binding, alias, true);
310             }
311
312             String JavaDoc passwd = getTruststorePassword();
313             if ((passwd == null) || (passwd.length() == 0)) {
314                 ProprietarySecurityPolicyModelHelper.setStorePassword(binding, null, true, true);
315             } else {
316                 ProprietarySecurityPolicyModelHelper.setStorePassword(binding, passwd, true, true);
317             }
318
319             String JavaDoc loc = getTruststorePath();
320             if ((loc == null) || (loc.length() == 0)) {
321                 ProprietarySecurityPolicyModelHelper.setStoreType(binding, null, true, true);
322                 ProprietarySecurityPolicyModelHelper.setStoreLocation(binding, null, true, true);
323             } else {
324                 ProprietarySecurityPolicyModelHelper.setStoreType(binding, KeyStore.KEYSTORE_TYPE, true, true);
325                 ProprietarySecurityPolicyModelHelper.setStoreLocation(binding, loc, true, true);
326             }
327
328             return;
329         }
330         
331         enableDisable();
332     }
333     
334     private void enableDisable() {
335         
336         boolean amSec = SecurityCheckerRegistry.getDefault().isNonWsitSecurityEnabled(node, jaxwsmodel);
337
338         keyAliasLabel.setEnabled(!amSec);
339         keyPasswordField.setEnabled(!amSec);
340         keyPasswordLabel.setEnabled(!amSec);
341         keystoreLocationButton.setEnabled(!amSec);
342         keystoreLocationLabel.setEnabled(!amSec);
343         keystoreLocationTextField.setEnabled(!amSec);
344         keystorePasswordField.setEnabled(!amSec);
345         keystorePasswordLabel.setEnabled(!amSec);
346         loadKeyAliases.setEnabled(!amSec);
347         loadTrustAliases.setEnabled(!amSec);
348         trustAliasCombo.setEnabled(!amSec);
349         trustAliasLabel.setEnabled(!amSec);
350         trustPasswordField.setEnabled(!amSec);
351         truststoreLocationButton.setEnabled(!amSec);
352         truststoreLocationLbl.setEnabled(!amSec);
353         truststoreLocationTextField.setEnabled(!amSec);
354         truststorePasswordLabel.setEnabled(!amSec);
355     }
356     
357     @Override JavaDoc
358     public void documentChanged(javax.swing.text.JTextComponent JavaDoc comp, String JavaDoc value) {
359         enableDisable();
360     }
361
362     @Override JavaDoc
363     public void rollbackValue(javax.swing.text.JTextComponent JavaDoc source) {
364     }
365     
366     @Override JavaDoc
367     protected void endUIChange() {
368     }
369
370     public void linkButtonPressed(Object JavaDoc ddBean, String JavaDoc ddProperty) {
371     }
372
373     public javax.swing.JComponent JavaDoc getErrorComponent(String JavaDoc errorId) {
374         return null;
375     }
376
377     /** This method is called from within the constructor to
378      * initialize the form.
379      * WARNING: Do NOT modify this code. The content of this method is
380      * always regenerated by the Form Editor.
381      */

382     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
383
private void initComponents() {
384
385         keystoreLocationLabel = new javax.swing.JLabel JavaDoc();
386         truststorePasswordLabel = new javax.swing.JLabel JavaDoc();
387         truststoreLocationLbl = new javax.swing.JLabel JavaDoc();
388         keystorePasswordLabel = new javax.swing.JLabel JavaDoc();
389         keystoreLocationTextField = new javax.swing.JTextField JavaDoc();
390         keystoreLocationButton = new javax.swing.JButton JavaDoc();
391         truststoreLocationTextField = new javax.swing.JTextField JavaDoc();
392         truststoreLocationButton = new javax.swing.JButton JavaDoc();
393         keyAliasLabel = new javax.swing.JLabel JavaDoc();
394         keyPasswordLabel = new javax.swing.JLabel JavaDoc();
395         keyAliasCombo = new javax.swing.JComboBox JavaDoc();
396         trustAliasLabel = new javax.swing.JLabel JavaDoc();
397         trustAliasCombo = new javax.swing.JComboBox JavaDoc();
398         keystorePasswordField = new javax.swing.JPasswordField JavaDoc();
399         keyPasswordField = new javax.swing.JPasswordField JavaDoc();
400         trustPasswordField = new javax.swing.JPasswordField JavaDoc();
401         loadKeyAliases = new javax.swing.JButton JavaDoc();
402         loadTrustAliases = new javax.swing.JButton JavaDoc();
403
404         addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
405             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
406                 formFocusGained(evt);
407             }
408         });
409         addAncestorListener(new javax.swing.event.AncestorListener JavaDoc() {
410             public void ancestorMoved(javax.swing.event.AncestorEvent JavaDoc evt) {
411             }
412             public void ancestorAdded(javax.swing.event.AncestorEvent JavaDoc evt) {
413                 formAncestorAdded(evt);
414             }
415             public void ancestorRemoved(javax.swing.event.AncestorEvent JavaDoc evt) {
416             }
417         });
418
419         keystoreLocationLabel.setLabelFor(keystoreLocationTextField);
420         org.openide.awt.Mnemonics.setLocalizedText(keystoreLocationLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_KeyStoreLocationLabel")); // NOI18N
421

422         truststorePasswordLabel.setLabelFor(trustPasswordField);
423         org.openide.awt.Mnemonics.setLocalizedText(truststorePasswordLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_TrustPasswordLabel")); // NOI18N
424

425         truststoreLocationLbl.setLabelFor(truststoreLocationTextField);
426         org.openide.awt.Mnemonics.setLocalizedText(truststoreLocationLbl, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_TrustStoreLocationLabel")); // NOI18N
427

428         keystorePasswordLabel.setLabelFor(keystorePasswordField);
429         org.openide.awt.Mnemonics.setLocalizedText(keystorePasswordLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_KeystorePasswordLabel")); // NOI18N
430

431         org.openide.awt.Mnemonics.setLocalizedText(keystoreLocationButton, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_KBrowseButton")); // NOI18N
432
keystoreLocationButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
433             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
434                 keystoreLocationButtonActionPerformed(evt);
435             }
436         });
437
438         org.openide.awt.Mnemonics.setLocalizedText(truststoreLocationButton, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_TBrowseButton")); // NOI18N
439
truststoreLocationButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
440             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
441                 truststoreLocationButtonActionPerformed(evt);
442             }
443         });
444
445         keyAliasLabel.setLabelFor(keyAliasCombo);
446         org.openide.awt.Mnemonics.setLocalizedText(keyAliasLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_KeyAliasLabel")); // NOI18N
447

448         keyPasswordLabel.setLabelFor(keyPasswordField);
449         org.openide.awt.Mnemonics.setLocalizedText(keyPasswordLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_KeyPasswordLabel")); // NOI18N
450

451         keyAliasCombo.setEditable(true);
452         keyAliasCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
453             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
454                 keyAliasComboActionPerformed(evt);
455             }
456         });
457         keyAliasCombo.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
458             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
459                 keyAliasComboKeyReleased(evt);
460             }
461         });
462
463         trustAliasLabel.setLabelFor(trustAliasCombo);
464         org.openide.awt.Mnemonics.setLocalizedText(trustAliasLabel, org.openide.util.NbBundle.getMessage(KeystorePanel.class, "LBL_KeyStorePanel_TrustAliasLabel")); // NOI18N
465

466         trustAliasCombo.setEditable(true);
467         trustAliasCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
468             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
469                 trustAliasComboActionPerformed(evt);
470             }
471         });
472         trustAliasCombo.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
473             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
474                 trustAliasComboKeyReleased(evt);
475             }
476         });
477
478         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/client/Bundle"); // NOI18N
479
org.openide.awt.Mnemonics.setLocalizedText(loadKeyAliases, bundle.getString("LBL_KLoadKeys")); // NOI18N
480
loadKeyAliases.addActionListener(new java.awt.event.ActionListener JavaDoc() {
481             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
482                 loadKeyAliasesActionPerformed(evt);
483             }
484         });
485
486         org.openide.awt.Mnemonics.setLocalizedText(loadTrustAliases, bundle.getString("LBL_TLoadKeys")); // NOI18N
487
loadTrustAliases.addActionListener(new java.awt.event.ActionListener JavaDoc() {
488             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
489                 loadTrustAliasesActionPerformed(evt);
490             }
491         });
492
493         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
494         this.setLayout(layout);
495         layout.setHorizontalGroup(
496             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
497             .add(layout.createSequentialGroup()
498                 .addContainerGap()
499                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
500                     .add(layout.createSequentialGroup()
501                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
502                             .add(truststorePasswordLabel)
503                             .add(truststoreLocationLbl)
504                             .add(trustAliasLabel))
505                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
506                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
507                             .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
508                                 .add(truststoreLocationTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
509                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
510                                 .add(truststoreLocationButton))
511                             .add(layout.createSequentialGroup()
512                                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
513                                     .add(org.jdesktop.layout.GroupLayout.LEADING, trustAliasCombo, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
514                                     .add(org.jdesktop.layout.GroupLayout.LEADING, trustPasswordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE))
515                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
516                                 .add(loadTrustAliases)
517                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 74, Short.MAX_VALUE))))
518                     .add(layout.createSequentialGroup()
519                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
520                             .add(keystoreLocationLabel)
521                             .add(keystorePasswordLabel)
522                             .add(keyAliasLabel)
523                             .add(keyPasswordLabel))
524                         .add(22, 22, 22)
525                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
526                             .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
527                                 .add(keystoreLocationTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
528                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
529                                 .add(keystoreLocationButton))
530                             .add(layout.createSequentialGroup()
531                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
532                                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
533                                     .add(org.jdesktop.layout.GroupLayout.LEADING, keyPasswordField)
534                                     .add(org.jdesktop.layout.GroupLayout.LEADING, keyAliasCombo, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
535                                     .add(org.jdesktop.layout.GroupLayout.LEADING, keystorePasswordField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE))
536                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
537                                 .add(loadKeyAliases)
538                                 .add(71, 71, 71)))))
539                 .addContainerGap())
540         );
541
542         layout.linkSize(new java.awt.Component JavaDoc[] {keystoreLocationButton, truststoreLocationButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
543
544         layout.setVerticalGroup(
545             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
546             .add(layout.createSequentialGroup()
547                 .addContainerGap()
548                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
549                     .add(keystoreLocationLabel)
550                     .add(keystoreLocationButton)
551                     .add(keystoreLocationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
552                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
553                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
554                     .add(keystorePasswordLabel)
555                     .add(keystorePasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
556                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
557                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
558                     .add(keyAliasLabel)
559                     .add(keyAliasCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
560                     .add(loadKeyAliases))
561                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
562                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
563                     .add(keyPasswordLabel)
564                     .add(keyPasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
565                 .add(49, 49, 49)
566                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
567                     .add(truststoreLocationLbl)
568                     .add(truststoreLocationButton)
569                     .add(truststoreLocationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
570                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
571                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
572                     .add(truststorePasswordLabel)
573                     .add(trustPasswordField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
574                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
575                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
576                     .add(trustAliasLabel)
577                     .add(trustAliasCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
578                     .add(loadTrustAliases))
579                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
580         );
581     }// </editor-fold>//GEN-END:initComponents
582

583 private void formAncestorAdded(javax.swing.event.AncestorEvent JavaDoc evt) {//GEN-FIRST:event_formAncestorAdded
584
enableDisable();
585 }//GEN-LAST:event_formAncestorAdded
586

587 private void formFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_formFocusGained
588
enableDisable();
589 }//GEN-LAST:event_formFocusGained
590

591     private void trustAliasComboKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_trustAliasComboKeyReleased
592
setValue(trustAliasCombo, null);
593     }//GEN-LAST:event_trustAliasComboKeyReleased
594

595     private void trustAliasComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_trustAliasComboActionPerformed
596
setValue(trustAliasCombo, null);
597     }//GEN-LAST:event_trustAliasComboActionPerformed
598

599     private void keyAliasComboKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_keyAliasComboKeyReleased
600
setValue(keyAliasCombo, null);
601     }//GEN-LAST:event_keyAliasComboKeyReleased
602

603     private void keyAliasComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_keyAliasComboActionPerformed
604
setValue(keyAliasCombo, null);
605     }//GEN-LAST:event_keyAliasComboActionPerformed
606

607     private void loadTrustAliasesActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_loadTrustAliasesActionPerformed
608
boolean success = reloadAliases(true);
609         if (!success) {
610             DialogDisplayer.getDefault().notify(
611                     new NotifyDescriptor.Message(NbBundle.getMessage(KeystorePanel.class, "MSG_WrongPassword" //NOI18N
612
)));
613         }
614     }//GEN-LAST:event_loadTrustAliasesActionPerformed
615

616     private void loadKeyAliasesActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_loadKeyAliasesActionPerformed
617
boolean success = reloadAliases(false);
618         if (!success) {
619             DialogDisplayer.getDefault().notify(
620                     new NotifyDescriptor.Message(NbBundle.getMessage(KeystorePanel.class, "MSG_WrongPassword" //NOI18N
621
)));
622         }
623     }//GEN-LAST:event_loadKeyAliasesActionPerformed
624

625     private void truststoreLocationButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_truststoreLocationButtonActionPerformed
626
JFileChooser chooser = new JFileChooser();
627         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
628         chooser.setDialogTitle(NbBundle.getMessage(KeystorePanel.class, "LBL_TruststoreBrowse_Title"));
629         chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
630         chooser.setMultiSelectionEnabled(false);
631         chooser.setFileFilter(new StoreFileFilter());
632         File JavaDoc f = new File JavaDoc(truststoreLocationTextField.getText());
633         File JavaDoc dir = null;
634         if ((f != null) && (f.exists())) {
635             if (f.isDirectory()) {
636                 chooser.setCurrentDirectory(f);
637             } else {
638                 chooser.setCurrentDirectory(f.getParentFile());
639             }
640         }
641         if (chooser.showOpenDialog(this)== JFileChooser.APPROVE_OPTION) {
642             File JavaDoc file = chooser.getSelectedFile();
643             if (file != null) {
644                 setTruststorePath(file.getPath());
645                 String JavaDoc extension = FileUtil.getExtension(file.getName());
646                 keystoreType = StoreFileFilter.JKS_EXT.equals(extension) ? JKS : PKCS12;
647                 setValue(truststoreLocationTextField, null);
648             }
649         }
650     }//GEN-LAST:event_truststoreLocationButtonActionPerformed
651

652     private void keystoreLocationButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_keystoreLocationButtonActionPerformed
653
JFileChooser chooser = new JFileChooser();
654         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
655         chooser.setDialogTitle(NbBundle.getMessage(KeystorePanel.class, "LBL_KeystoreBrowse_Title"));
656         chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
657         chooser.setMultiSelectionEnabled(false);
658         chooser.setFileFilter(new StoreFileFilter());
659         File JavaDoc f = new File JavaDoc(truststoreLocationTextField.getText());
660         File JavaDoc dir = null;
661         if ((f != null) && (f.exists())) {
662             if (f.isDirectory()) {
663                 chooser.setCurrentDirectory(f);
664             } else {
665                 chooser.setCurrentDirectory(f.getParentFile());
666             }
667         }
668         if (chooser.showOpenDialog(this)== JFileChooser.APPROVE_OPTION) {
669             File JavaDoc file = chooser.getSelectedFile();
670             if (file != null) {
671                 setKeystorePath(file.getPath());
672                 String JavaDoc extension = FileUtil.getExtension(file.getName());
673                 truststoreType = StoreFileFilter.JKS_EXT.equals(extension) ? JKS : PKCS12;
674                 setValue(keystoreLocationTextField, null);
675             }
676         }
677     }//GEN-LAST:event_keystoreLocationButtonActionPerformed
678

679     private boolean reloadAliases(boolean trust) {
680         JComboBox combo = trust ? trustAliasCombo : keyAliasCombo;
681         String JavaDoc path = trust ? getTruststorePath() : getKeystorePath();
682         String JavaDoc type = trust ? truststoreType : keystoreType;
683         Enumeration JavaDoc<String JavaDoc> aliases;
684         try {
685             aliases = Util.getAliases(path, getCharPassword(trust), truststoreType);
686         } catch (IOException JavaDoc ex) {
687             ex.printStackTrace();
688             return false;
689         }
690         combo.removeAllItems();
691         if (aliases != null) {
692             combo.addItem(""); //NOI18N
693
while (aliases.hasMoreElements()){
694                 String JavaDoc alias = aliases.nextElement();
695                 combo.addItem(alias);
696             }
697             if (combo.getItemCount() > 1) {
698                 combo.setSelectedIndex(1);
699             }
700         }
701         return true;
702     }
703         
704     // Variables declaration - do not modify//GEN-BEGIN:variables
705
private javax.swing.JComboBox JavaDoc keyAliasCombo;
706     private javax.swing.JLabel JavaDoc keyAliasLabel;
707     private javax.swing.JPasswordField JavaDoc keyPasswordField;
708     private javax.swing.JLabel JavaDoc keyPasswordLabel;
709     private javax.swing.JButton JavaDoc keystoreLocationButton;
710     private javax.swing.JLabel JavaDoc keystoreLocationLabel;
711     private javax.swing.JTextField JavaDoc keystoreLocationTextField;
712     private javax.swing.JPasswordField JavaDoc keystorePasswordField;
713     private javax.swing.JLabel JavaDoc keystorePasswordLabel;
714     private javax.swing.JButton JavaDoc loadKeyAliases;
715     private javax.swing.JButton JavaDoc loadTrustAliases;
716     private javax.swing.JComboBox JavaDoc trustAliasCombo;
717     private javax.swing.JLabel JavaDoc trustAliasLabel;
718     private javax.swing.JPasswordField JavaDoc trustPasswordField;
719     private javax.swing.JButton JavaDoc truststoreLocationButton;
720     private javax.swing.JLabel JavaDoc truststoreLocationLbl;
721     private javax.swing.JTextField JavaDoc truststoreLocationTextField;
722     private javax.swing.JLabel JavaDoc truststorePasswordLabel;
723     // End of variables declaration//GEN-END:variables
724

725 }
726
Popular Tags