Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@www.apache.org Received: (qmail 94240 invoked from network); 23 Mar 2005 18:21:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 Mar 2005 18:21:07 -0000 Received: (qmail 70808 invoked by uid 500); 23 Mar 2005 18:21:01 -0000 Delivered-To: apmail-jakarta-tomcat-dev-archive@jakarta.apache.org Received: (qmail 70522 invoked by uid 500); 23 Mar 2005 18:21:00 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Developers List" Reply-To: "Tomcat Developers List" Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 70496 invoked by uid 500); 23 Mar 2005 18:20:59 -0000 Received: (qmail 70492 invoked by uid 99); 23 Mar 2005 18:20:59 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 23 Mar 2005 10:20:59 -0800 Received: (qmail 33459 invoked by uid 1670); 23 Mar 2005 15:30:57 -0000 Date: 23 Mar 2005 15:30:57 -0000 Message-ID: <20050323153057.33458.qmail@minotaur.apache.org> From: yoavs@apache.org To: jakarta-tomcat-catalina-cvs@apache.org Subject: cvs commit: jakarta-tomcat-catalina/webapps/docs changelog.xml X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N yoavs 2005/03/23 07:30:57 Modified: catalina/src/share/org/apache/naming/factory MailSessionFactory.java webapps/docs changelog.xml Log: Bugzilla 31288. Revision Changes Path 1.3 +35 -4 jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/factory/MailSessionFactory.java Index: MailSessionFactory.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/factory/MailSessionFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MailSessionFactory.java 27 Feb 2004 14:58:54 -0000 1.2 +++ MailSessionFactory.java 23 Mar 2005 15:30:56 -0000 1.3 @@ -21,6 +21,8 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; +import javax.mail.Authenticator; +import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.naming.Name; import javax.naming.Context; @@ -96,7 +98,9 @@ // Create a new Session inside a doPrivileged block, so that JavaMail // can read its default properties without throwing Security - // exceptions + // exceptions. + // + // Bugzilla 31288, 33077: add support for authentication. return AccessController.doPrivileged( new PrivilegedAction() { public Object run() { @@ -104,16 +108,43 @@ Properties props = new Properties(); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.host", "localhost"); + + String password = null; + Enumeration attrs = ref.getAll(); while (attrs.hasMoreElements()) { RefAddr attr = (RefAddr) attrs.nextElement(); - if ("factory".equals(attr.getType())) + if ("factory".equals(attr.getType())) { + continue; + } + + if ("password".equals(attr.getType())) { + password = (String) attr.getContent(); continue; + } + props.put(attr.getType(), (String) attr.getContent()); } + Authenticator auth = null; + if (password != null) { + String user = props.getProperty("mail.smtp.user"); + if(user == null) { + user = props.getProperty("mail.user"); + } + + if(user != null) { + final PasswordAuthentication pa = new PasswordAuthentication(user, password); + auth = new Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return pa; + } + }; + } + } + // Create and return the new Session object - Session session = Session.getInstance(props, null); + Session session = Session.getInstance(props, auth); return (session); } 1.247 +3 -0 jakarta-tomcat-catalina/webapps/docs/changelog.xml Index: changelog.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/changelog.xml,v retrieving revision 1.246 retrieving revision 1.247 diff -u -r1.246 -r1.247 --- changelog.xml 23 Mar 2005 15:17:17 -0000 1.246 +++ changelog.xml 23 Mar 2005 15:30:56 -0000 1.247 @@ -84,6 +84,9 @@ 32938: Allow Salted SHA (SSHA) passwords in JNDIRealm. (yoavs) + + 31288: Allow SMTP authentication for JNDI MailSessionFactory. (yoavs) + --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org