001: package demo.hw_https.common;
002:
003: import java.awt.BorderLayout;
004: import java.awt.GridLayout;
005: import java.awt.event.ActionEvent;
006: import java.awt.event.ActionListener;
007:
008: import javax.swing.JButton;
009: import javax.swing.JDialog;
010: import javax.swing.JFrame;
011: import javax.swing.JLabel;
012: import javax.swing.JPanel;
013: import javax.swing.JPasswordField;
014:
015: import org.objectweb.celtix.bus.configuration.security.SSLClientPolicy;
016: import org.objectweb.celtix.bus.configuration.security.SSLServerPolicy;
017:
018: public final class DemoSecurityConfigurer {
019:
020: public void configure(SSLServerPolicy sslPolicyParam) {
021: PasswordDialog pd = new PasswordDialog();
022: pd.show();
023: String pwd = new String(pd.passwordField.getPassword());
024: sslPolicyParam.setKeystorePassword(pwd);
025: sslPolicyParam.setKeyPassword(pwd);
026: }
027:
028: public void configure(SSLClientPolicy sslPolicyParam) {
029:
030: PasswordDialog pd = new PasswordDialog();
031: pd.show();
032: String pwd = new String(pd.passwordField.getPassword());
033: sslPolicyParam.setKeystorePassword(pwd);
034: sslPolicyParam.setKeyPassword(pwd);
035: }
036:
037: }
038:
039: class PasswordDialog extends JDialog {
040:
041: protected JPasswordField passwordField;
042:
043: private JLabel passwordLabel;
044: private JButton loginBtn;
045:
046: public PasswordDialog() {
047: super ((JFrame) null);
048:
049: loginBtn = new JButton("OK");
050: loginBtn.setMnemonic('o');
051: loginBtn.addActionListener(new ActionListener() {
052: public void actionPerformed(ActionEvent e) {
053: dispose();
054: }
055: });
056:
057: passwordLabel = new JLabel();
058: passwordField = new JPasswordField("", 20);
059:
060: passwordLabel.setText("Password: ");
061: passwordLabel
062: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
063:
064: setTitle("Please enter keystore passord.");
065: setLocation(300, 250);
066: setModal(true);
067: getContentPane().setLayout(new BorderLayout());
068:
069: JPanel topPanel = new JPanel();
070:
071: setSize(400, 140);
072:
073: JPanel labelPanel = new JPanel();
074: labelPanel.setLayout(new GridLayout(2, 1, 20, 20));
075:
076: passwordLabel.setText("Password:");
077: labelPanel.add(passwordLabel);
078:
079: JPanel fieldsPanel = new JPanel();
080: fieldsPanel.setLayout(new GridLayout(2, 1, 20, 20));
081:
082: passwordField.setNextFocusableComponent(loginBtn);
083: fieldsPanel.add(passwordField);
084:
085: JPanel buttonsPanel = new JPanel();
086: GridLayout glo = new GridLayout(1, 2);
087: glo.setHgap(30);
088: buttonsPanel.setLayout(glo);
089: buttonsPanel.add(loginBtn);
090:
091: JPanel bottomPanel = new JPanel();
092: bottomPanel.add(buttonsPanel);
093:
094: topPanel.add(labelPanel, BorderLayout.WEST);
095: topPanel.add(fieldsPanel, BorderLayout.CENTER);
096:
097: JPanel aPanel = new JPanel();
098: aPanel.setLayout(new BorderLayout());
099: aPanel.add(topPanel, BorderLayout.CENTER);
100:
101: getContentPane().add(aPanel, BorderLayout.NORTH);
102: getContentPane().add(bottomPanel, BorderLayout.SOUTH);
103: }
104: }
|