KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > gui > action > SSLManagerCommand


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/SSLManagerCommand.java,v 1.5 2004/02/13 02:40:54 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.gui.action;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.io.File JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import javax.swing.JFileChooser JavaDoc;
28 import javax.swing.filechooser.FileFilter JavaDoc;
29
30 import org.apache.jmeter.gui.GuiPackage;
31 import org.apache.jmeter.util.JMeterUtils;
32 import org.apache.jmeter.util.SSLManager;
33
34 /**
35  * SSL Manager Command. The SSL Manager provides a mechanism to change your
36  * client authentication if required by the server. If you have JSSE 1.0.2
37  * installed, you can select your client identity from a list of installed keys.
38  * You can also change your keystore. JSSE 1.0.2 allows you to export a PKCS#12
39  * key from Netscape 4.04 or higher and use it in a read only format. You must
40  * supply a password that is greater than six characters due to limitations in
41  * the keytool program--and possibly the rest of the system.
42  * <p>
43  * By selecting a *.p12 file as your keystore (your PKCS#12) format file, you
44  * can have a whopping one key keystore. The advantage is that you can test a
45  * connection using the assigned Certificate from a Certificate Authority.
46  * </p>
47  *
48  * @author <a HREF="bloritsch@apache.org">Berin Loritsch</a>
49  * @version CVS $Revision: 1.5 $ $Date: 2004/02/13 02:40:54 $
50  */

51 public class SSLManagerCommand implements Command
52 {
53     private static Set JavaDoc commandSet;
54     static {
55         HashSet JavaDoc commands = new HashSet JavaDoc();
56         commands.add("sslManager");
57         SSLManagerCommand.commandSet = Collections.unmodifiableSet(commands);
58     }
59
60     private JFileChooser JavaDoc keyStoreChooser;
61
62     /**
63      * Handle the "sslmanager" action by displaying the "SSL CLient Manager"
64      * dialog box. The Dialog Box is NOT modal, because those should be avoided
65      * if at all possible.
66      */

67     public void doAction(ActionEvent JavaDoc e)
68     {
69         if (e.getActionCommand().equals("sslManager"))
70         {
71             this.sslManager();
72         }
73     }
74
75     /**
76      * Provide the list of Action names that are available in this command.
77      */

78     public Set JavaDoc getActionNames()
79     {
80         return SSLManagerCommand.commandSet;
81     }
82
83     /**
84      * Called by sslManager button. Raises sslManager dialog. Currently the
85      * sslManager box has the product image and the copyright notice. The
86      * dialog box is centered over the MainFrame.
87      */

88     private void sslManager()
89     {
90         SSLManager.reset();
91
92         keyStoreChooser =
93             new JFileChooser JavaDoc(
94                 JMeterUtils.getJMeterProperties().getProperty("user.dir"));
95         keyStoreChooser.addChoosableFileFilter(new AcceptPKCS12FileFilter());
96         keyStoreChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
97         int retVal =
98             keyStoreChooser.showOpenDialog(
99                 GuiPackage.getInstance().getMainFrame());
100
101         if (JFileChooser.APPROVE_OPTION == retVal)
102         {
103             File JavaDoc selectedFile = keyStoreChooser.getSelectedFile();
104             try
105             {
106                 JMeterUtils.getJMeterProperties().setProperty(
107                     "javax.net.ssl.keyStore",
108                     selectedFile.getCanonicalPath());
109             }
110             catch (Exception JavaDoc e)
111             {
112             }
113         }
114
115         keyStoreChooser = null;
116         SSLManager.getInstance();
117     }
118
119     /**
120      * Internal class to add a PKCS12 file format filter for JFileChooser.
121      */

122     static private class AcceptPKCS12FileFilter extends FileFilter JavaDoc
123     {
124         /**
125          * Get the description that shows up in JFileChooser filter menu.
126          *
127          * @return description
128          */

129         public String JavaDoc getDescription()
130         {
131             return JMeterUtils.getResString("pkcs12_desc");
132         }
133
134         /**
135          * Tests to see if the file ends with "*.p12" or "*.P12".
136          *
137          * @param testfile file to test
138          * @return true if file is accepted, false otherwise
139          */

140         public boolean accept(File JavaDoc testFile)
141         {
142             return testFile.isDirectory()
143                 || testFile.getName().endsWith(".p12")
144                 || testFile.getName().endsWith(".P12");
145         }
146     }
147 }
148
Popular Tags