1 16 17 package org.apache.taglibs.mailer; 18 19 import java.awt.*; 20 import java.awt.event.ActionEvent ; 21 import java.awt.event.ActionListener ; 22 import javax.mail.Authenticator ; 23 import javax.mail.PasswordAuthentication ; 24 25 35 public class MailAuthenticator extends Authenticator { 36 39 protected String m_user = null; 40 43 protected String m_password = null; 44 45 49 public MailAuthenticator(String user, String password) { 50 super(); 51 m_user = user; 52 m_password = password; 53 } 54 55 59 public MailAuthenticator() { 60 super(); 61 } 62 63 72 protected PasswordAuthentication getPasswordAuthentication() { 73 74 if (m_user != null && m_password != null) { 75 return new PasswordAuthentication (m_user, m_password); 76 } 77 78 final Dialog dialog = new Dialog(new Frame("Login"), 79 "Please Login to the mail server", true); 80 dialog.setBounds(200, 200, 200, 100); 81 dialog.setLayout(new GridLayout (0, 1)); 82 Label label = new Label(getRequestingPrompt()); 83 dialog.add (label); 84 TextField username = new TextField(); 85 username.setBackground (Color.white); 86 dialog.add (username); 87 TextField password = new TextField(); 88 password.setEchoChar ('*'); 89 password.setBackground (Color.white); 90 dialog.add (password); 91 Button button = new Button ("OK"); 92 dialog.add (button); 93 button.addActionListener (new ActionListener () { 94 public void actionPerformed (ActionEvent e) { 95 dialog.dispose(); 96 } 97 }); 98 dialog.pack(); 99 dialog.setVisible(true); 100 return new PasswordAuthentication (username.getText(), 101 password.getText()); 102 } 103 } 104 | Popular Tags |