ASF Bugzilla – Attachment 12769 Details for
Bug 31288
MailSessionFactory should allow authentication to be configured
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch to add a 'password' property to MailSessionFactory initialisation.
MailSessionFactory-authenticator.patch (text/plain), 2.45 KB, created by
Joseph Walton
on 2004-09-18 23:48:01 UTC
(
hide
)
Description:
Patch to add a 'password' property to MailSessionFactory initialisation.
Filename:
MIME Type:
Creator:
Joseph Walton
Created:
2004-09-18 23:48:01 UTC
Size:
2.45 KB
patch
obsolete
>--- MailSessionFactory.java 18 Sep 2004 23:07:15 -0000 1.1 >+++ MailSessionFactory.java 18 Sep 2004 23:30:25 -0000 1.2 >@@ -21,6 +21,9 @@ > 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; >@@ -98,7 +101,8 @@ > // can read its default properties without throwing Security > // exceptions > return AccessController.doPrivileged( new PrivilegedAction() { >- public Object run() { >+ public Object run() { >+ String password = null; > > // Create the JavaMail properties we will use > Properties props = new Properties(); >@@ -109,15 +113,37 @@ > RefAddr attr = (RefAddr) attrs.nextElement(); > 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; >+ >+ // Check for authentication >+ 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); > >- } >- } ); >+ } >+ } ); > > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 31288
: 12769