2009-07-21 04:39:18 -04:00
|
|
|
/*
|
|
|
|
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
|
|
|
* Copyright (C) 2009 Mickael Guessant
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
2009-06-17 12:27:31 -04:00
|
|
|
package davmail.ui;
|
|
|
|
|
|
|
|
import davmail.BundleMessage;
|
|
|
|
import davmail.ui.tray.DavGatewayTray;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
2012-01-26 05:28:39 -05:00
|
|
|
import javax.swing.border.EmptyBorder;
|
|
|
|
import javax.swing.border.LineBorder;
|
2009-06-17 12:27:31 -04:00
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get smartcard password
|
|
|
|
*/
|
|
|
|
public class PasswordPromptDialog extends JDialog {
|
|
|
|
final JPasswordField passwordField = new JPasswordField(20);
|
|
|
|
protected char[] password;
|
|
|
|
|
2009-09-17 05:22:19 -04:00
|
|
|
/**
|
|
|
|
* Get user password.
|
|
|
|
*
|
|
|
|
* @return user password as char array
|
|
|
|
*/
|
2009-06-17 12:27:31 -04:00
|
|
|
public char[] getPassword() {
|
2009-11-23 04:53:04 -05:00
|
|
|
if (password != null) {
|
|
|
|
return password.clone();
|
|
|
|
} else {
|
|
|
|
return "".toCharArray();
|
|
|
|
}
|
2009-06-17 12:27:31 -04:00
|
|
|
}
|
|
|
|
|
2009-09-17 05:22:19 -04:00
|
|
|
/**
|
|
|
|
* Get smartcard password.
|
|
|
|
*
|
|
|
|
* @param prompt password prompt from PKCS11 module
|
|
|
|
*/
|
2009-06-17 12:27:31 -04:00
|
|
|
public PasswordPromptDialog(String prompt) {
|
2012-01-26 05:15:10 -05:00
|
|
|
this(prompt, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get smartcard password.
|
|
|
|
*
|
|
|
|
* @param prompt password prompt from PKCS11 module
|
|
|
|
* @param captchaImage ISA filter pinsafe image
|
|
|
|
*/
|
|
|
|
public PasswordPromptDialog(String prompt, Image captchaImage) {
|
2009-06-17 12:27:31 -04:00
|
|
|
setAlwaysOnTop(true);
|
|
|
|
|
|
|
|
setTitle(BundleMessage.format("UI_PASSWORD_PROMPT"));
|
|
|
|
try {
|
|
|
|
setIconImage(DavGatewayTray.getFrameIcon());
|
|
|
|
} catch (NoSuchMethodError error) {
|
|
|
|
DavGatewayTray.debug(new BundleMessage("LOG_UNABLE_TO_SET_ICON_IMAGE"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JPanel questionPanel = new JPanel();
|
|
|
|
questionPanel.setLayout(new BoxLayout(questionPanel, BoxLayout.Y_AXIS));
|
|
|
|
JLabel imageLabel = new JLabel();
|
|
|
|
imageLabel.setIcon(UIManager.getIcon("OptionPane.questionIcon"));
|
|
|
|
imageLabel.setText(prompt);
|
|
|
|
questionPanel.add(imageLabel);
|
|
|
|
|
|
|
|
passwordField.setMaximumSize(passwordField.getPreferredSize());
|
|
|
|
passwordField.addActionListener(new ActionListener() {
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
password = passwordField.getPassword();
|
2010-08-06 19:07:21 -04:00
|
|
|
setVisible(false);
|
2009-06-17 12:27:31 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
JPanel passwordPanel = new JPanel();
|
|
|
|
passwordPanel.setLayout(new BoxLayout(passwordPanel, BoxLayout.Y_AXIS));
|
2012-01-26 05:15:10 -05:00
|
|
|
if (captchaImage != null) {
|
|
|
|
JLabel captchaLabel = new JLabel(new ImageIcon(captchaImage));
|
|
|
|
captchaLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
2012-01-26 05:28:39 -05:00
|
|
|
captchaLabel.setBorder(new EmptyBorder(10,10,10,10));
|
2012-01-26 05:15:10 -05:00
|
|
|
passwordPanel.add(captchaLabel);
|
|
|
|
}
|
2009-06-17 12:27:31 -04:00
|
|
|
passwordPanel.add(passwordField);
|
2012-01-26 05:15:10 -05:00
|
|
|
|
2009-06-17 12:27:31 -04:00
|
|
|
add(questionPanel, BorderLayout.NORTH);
|
|
|
|
add(passwordPanel, BorderLayout.CENTER);
|
|
|
|
add(getButtonPanel(), BorderLayout.SOUTH);
|
|
|
|
setModal(true);
|
|
|
|
|
|
|
|
pack();
|
|
|
|
// center frame
|
|
|
|
setLocation(getToolkit().getScreenSize().width / 2 -
|
|
|
|
getSize().width / 2,
|
|
|
|
getToolkit().getScreenSize().height / 2 -
|
|
|
|
getSize().height / 2);
|
|
|
|
setVisible(true);
|
2011-10-02 17:49:39 -04:00
|
|
|
toFront();
|
2009-06-17 12:27:31 -04:00
|
|
|
requestFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected JPanel getButtonPanel() {
|
|
|
|
JPanel buttonPanel = new JPanel();
|
|
|
|
JButton okButton = new JButton(BundleMessage.format("UI_BUTTON_OK"));
|
|
|
|
JButton cancelButton = new JButton(BundleMessage.format("UI_BUTTON_CANCEL"));
|
|
|
|
okButton.addActionListener(new ActionListener() {
|
|
|
|
public void actionPerformed(ActionEvent evt) {
|
|
|
|
password = passwordField.getPassword();
|
2010-08-06 19:07:21 -04:00
|
|
|
setVisible(false);
|
2009-06-17 12:27:31 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
cancelButton.addActionListener(new ActionListener() {
|
|
|
|
public void actionPerformed(ActionEvent evt) {
|
|
|
|
password = null;
|
2010-08-06 19:07:21 -04:00
|
|
|
setVisible(false);
|
2009-06-17 12:27:31 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
buttonPanel.add(okButton);
|
|
|
|
buttonPanel.add(cancelButton);
|
|
|
|
return buttonPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|