Kerberos implement graphical callback on missing token

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2073 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2013-03-28 23:06:59 +00:00
parent 98c2e0d933
commit d808c7c453
4 changed files with 135 additions and 1 deletions

View File

@ -19,6 +19,7 @@
package davmail.http;
import davmail.Settings;
import davmail.ui.CredentialPromptDialog;
import org.apache.log4j.Logger;
import org.ietf.jgss.*;
@ -70,7 +71,9 @@ public class KerberosHelper {
BufferedReader inReader = new BufferedReader(new InputStreamReader(System.in));
principal = inReader.readLine();
} else {
// TODO: get username and password from dialog
CredentialPromptDialog credentialPromptDialog = new CredentialPromptDialog(((NameCallback) callbacks[i]).getPrompt());
principal = credentialPromptDialog.getPrincipal();
password = String.valueOf(credentialPromptDialog.getPassword());
}
}
if (principal == null) {

View File

@ -0,0 +1,127 @@
package davmail.ui;
import davmail.BundleMessage;
import davmail.ui.tray.DavGatewayTray;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Prompt for Exchange credential and password.
*/
public class CredentialPromptDialog extends JDialog {
final JTextField principalField = new JTextField(15);
final JPasswordField passwordField = new JPasswordField(15);
protected String principal;
protected char[] password;
/**
* Get user password.
*
* @return user password as char array
*/
public char[] getPassword() {
if (password != null) {
return password.clone();
} else {
return "".toCharArray();
}
}
public String getPrincipal() {
return principal;
}
/**
* Get credentials.
*
* @param prompt Kerberos prompt from callback handler
*/
public CredentialPromptDialog(String prompt) {
setAlwaysOnTop(true);
setTitle(BundleMessage.format("UI_KERBEROS_CREDENTIAL_PROMPT"));
try {
//noinspection Since15
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"));
questionPanel.add(imageLabel);
passwordField.setMaximumSize(passwordField.getPreferredSize());
passwordField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
principal = principalField.getText();
password = passwordField.getPassword();
setVisible(false);
}
});
JPanel credentialPanel = new JPanel(new GridLayout(2, 2));
JLabel promptLabel = new JLabel(" "+prompt.trim());
promptLabel.setHorizontalAlignment(SwingConstants.RIGHT);
promptLabel.setVerticalAlignment(SwingConstants.CENTER);
credentialPanel.add(promptLabel);
principalField.setMaximumSize(principalField.getPreferredSize());
credentialPanel.add(principalField);
JLabel passwordLabel = new JLabel(BundleMessage.format("UI_KERBEROS_PASSWORD_PROMPT"));
passwordLabel.setHorizontalAlignment(SwingConstants.RIGHT);
passwordLabel.setVerticalAlignment(SwingConstants.CENTER);
credentialPanel.add(passwordLabel);
passwordField.setMaximumSize(passwordField.getPreferredSize());
credentialPanel.add(passwordField);
add(questionPanel, BorderLayout.WEST);
add(credentialPanel, 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);
setAlwaysOnTop(true);
setVisible(true);
}
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) {
principal = principalField.getText();
password = passwordField.getPassword();
setVisible(false);
}
});
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
principal = null;
password = null;
setVisible(false);
}
});
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
return buttonPanel;
}
}

View File

@ -141,6 +141,8 @@ UI_ACCEPT_CERTIFICATE=DavMail: Accept certificate ?
UI_ALLOW_REMOTE_CONNECTION=Allow Remote Connections:
UI_ALLOW_REMOTE_CONNECTION_HELP=Allow remote connections to the gateway (server mode)
UI_PASSWORD_PROMPT=DavMail: Enter password
UI_KERBEROS_CREDENTIAL_PROMPT=DavMail: Kerberos credentials
UI_KERBEROS_PASSWORD_PROMPT=Kerberos password:
UI_ANSWER_NO=n
UI_ANSWER_YES=y
UI_BIND_ADDRESS=Bind address:

View File

@ -215,6 +215,8 @@ UI_UNTRUSTED_CERTIFICATE_HTML=<html><b>Le certificat fourni par le serveur n''es
UI_VALID_FROM=Emis le
UI_VALID_UNTIL=Expire le
UI_PASSWORD_PROMPT=DavMail : Entrer le mot de passe
UI_KERBEROS_CREDENTIAL_PROMPT=DavMail : Identifiants Kerberos
UI_KERBEROS_PASSWORD_PROMPT=Mot de passe Kerberos :
UI_PKCS11_LIBRARY_HELP=Chemin de la librarie PKCS11 (carte à puce) (.so or .dll)
UI_PKCS11_LIBRARY=Librairie PKCS11 :
UI_PKCS11_CONFIG_HELP=Configuration PKCS11 complémentaire optionnelle (slot, nssArgs, ...)