diff --git a/src/java/davmail/http/KerberosHelper.java b/src/java/davmail/http/KerberosHelper.java index bc374018..3e403228 100644 --- a/src/java/davmail/http/KerberosHelper.java +++ b/src/java/davmail/http/KerberosHelper.java @@ -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) { diff --git a/src/java/davmail/ui/CredentialPromptDialog.java b/src/java/davmail/ui/CredentialPromptDialog.java new file mode 100644 index 00000000..276fc253 --- /dev/null +++ b/src/java/davmail/ui/CredentialPromptDialog.java @@ -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; + } + +} diff --git a/src/java/davmailmessages.properties b/src/java/davmailmessages.properties index 0131aa16..b2d81478 100644 --- a/src/java/davmailmessages.properties +++ b/src/java/davmailmessages.properties @@ -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: diff --git a/src/java/davmailmessages_fr.properties b/src/java/davmailmessages_fr.properties index e5c6a397..c6217fde 100644 --- a/src/java/davmailmessages_fr.properties +++ b/src/java/davmailmessages_fr.properties @@ -215,6 +215,8 @@ UI_UNTRUSTED_CERTIFICATE_HTML=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, ...)