1 18 19 package org.apache.jmeter.gui.action; 20 21 import java.awt.event.ActionEvent ; 22 import java.io.File ; 23 import java.util.Collections ; 24 import java.util.HashSet ; 25 import java.util.Set ; 26 27 import javax.swing.JFileChooser ; 28 import javax.swing.filechooser.FileFilter ; 29 30 import org.apache.jmeter.gui.GuiPackage; 31 import org.apache.jmeter.util.JMeterUtils; 32 import org.apache.jmeter.util.SSLManager; 33 34 51 public class SSLManagerCommand implements Command 52 { 53 private static Set commandSet; 54 static { 55 HashSet commands = new HashSet (); 56 commands.add("sslManager"); 57 SSLManagerCommand.commandSet = Collections.unmodifiableSet(commands); 58 } 59 60 private JFileChooser keyStoreChooser; 61 62 67 public void doAction(ActionEvent e) 68 { 69 if (e.getActionCommand().equals("sslManager")) 70 { 71 this.sslManager(); 72 } 73 } 74 75 78 public Set getActionNames() 79 { 80 return SSLManagerCommand.commandSet; 81 } 82 83 88 private void sslManager() 89 { 90 SSLManager.reset(); 91 92 keyStoreChooser = 93 new JFileChooser ( 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 selectedFile = keyStoreChooser.getSelectedFile(); 104 try 105 { 106 JMeterUtils.getJMeterProperties().setProperty( 107 "javax.net.ssl.keyStore", 108 selectedFile.getCanonicalPath()); 109 } 110 catch (Exception e) 111 { 112 } 113 } 114 115 keyStoreChooser = null; 116 SSLManager.getInstance(); 117 } 118 119 122 static private class AcceptPKCS12FileFilter extends FileFilter 123 { 124 129 public String getDescription() 130 { 131 return JMeterUtils.getResString("pkcs12_desc"); 132 } 133 134 140 public boolean accept(File testFile) 141 { 142 return testFile.isDirectory() 143 || testFile.getName().endsWith(".p12") 144 || testFile.getName().endsWith(".P12"); 145 } 146 } 147 } 148 | Popular Tags |