1 package demo.hw_https.common; 2 3 import java.awt.BorderLayout ; 4 import java.awt.GridLayout ; 5 import java.awt.event.ActionEvent ; 6 import java.awt.event.ActionListener ; 7 8 import javax.swing.JButton ; 9 import javax.swing.JDialog ; 10 import javax.swing.JFrame ; 11 import javax.swing.JLabel ; 12 import javax.swing.JPanel ; 13 import javax.swing.JPasswordField ; 14 15 16 import org.objectweb.celtix.bus.configuration.security.SSLClientPolicy; 17 import org.objectweb.celtix.bus.configuration.security.SSLServerPolicy; 18 19 public final class DemoSecurityConfigurer { 20 21 public void configure(SSLServerPolicy sslPolicyParam) { 22 PasswordDialog pd = new PasswordDialog(); 23 pd.show(); 24 String pwd = new String (pd.passwordField.getPassword()); 25 sslPolicyParam.setKeystorePassword(pwd); 26 sslPolicyParam.setKeyPassword(pwd); 27 } 28 29 public void configure(SSLClientPolicy sslPolicyParam) { 30 31 PasswordDialog pd = new PasswordDialog(); 32 pd.show(); 33 String pwd = new String (pd.passwordField.getPassword()); 34 sslPolicyParam.setKeystorePassword(pwd); 35 sslPolicyParam.setKeyPassword(pwd); 36 } 37 38 } 39 40 41 42 class PasswordDialog extends JDialog { 43 44 protected JPasswordField passwordField; 45 46 private JLabel passwordLabel; 47 private JButton loginBtn; 48 49 50 51 public PasswordDialog() { 52 super((JFrame )null); 53 54 loginBtn = new JButton ("OK"); 55 loginBtn.setMnemonic('o'); 56 loginBtn.addActionListener(new ActionListener () { 57 public void actionPerformed(ActionEvent e) { 58 dispose(); 59 } 60 }); 61 62 63 passwordLabel = new JLabel (); 64 passwordField = new JPasswordField ("", 20); 65 66 passwordLabel.setText("Password: "); 67 passwordLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); 68 69 setTitle("Please enter keystore passord."); 70 setLocation(300, 250); 71 setModal(true); 72 getContentPane().setLayout(new BorderLayout ()); 73 74 JPanel topPanel = new JPanel (); 75 76 setSize(400, 140); 77 78 JPanel labelPanel = new JPanel (); 79 labelPanel.setLayout(new GridLayout (2, 1, 20, 20)); 80 81 passwordLabel.setText("Password:"); 82 labelPanel.add(passwordLabel); 83 84 85 JPanel fieldsPanel = new JPanel (); 86 fieldsPanel.setLayout(new GridLayout (2, 1, 20, 20)); 87 88 passwordField.setNextFocusableComponent(loginBtn); 89 fieldsPanel.add(passwordField); 90 91 JPanel buttonsPanel = new JPanel (); 92 GridLayout glo = new GridLayout (1, 2); 93 glo.setHgap(30); 94 buttonsPanel.setLayout(glo); 95 buttonsPanel.add(loginBtn); 96 97 JPanel bottomPanel = new JPanel (); 98 bottomPanel.add(buttonsPanel); 99 100 topPanel.add(labelPanel, BorderLayout.WEST); 101 topPanel.add(fieldsPanel, BorderLayout.CENTER); 102 103 JPanel aPanel = new JPanel (); 104 aPanel.setLayout(new BorderLayout ()); 105 aPanel.add(topPanel, BorderLayout.CENTER); 106 107 getContentPane().add(aPanel, BorderLayout.NORTH); 108 getContentPane().add(bottomPanel, BorderLayout.SOUTH); 109 } 110 } 111 | Popular Tags |