View | Details | Raw Unified | Return to bug 31288
Collapse All | Expand All

(-)MailSessionFactory.java (-5 / +31 lines)
Lines 21-26 Link Here
21
import java.util.Enumeration;
21
import java.util.Enumeration;
22
import java.util.Hashtable;
22
import java.util.Hashtable;
23
import java.util.Properties;
23
import java.util.Properties;
24
25
import javax.mail.Authenticator;
26
import javax.mail.PasswordAuthentication;
24
import javax.mail.Session;
27
import javax.mail.Session;
25
import javax.naming.Name;
28
import javax.naming.Name;
26
import javax.naming.Context;
29
import javax.naming.Context;
Lines 98-104 Link Here
98
        // can read its default properties without throwing Security
101
        // can read its default properties without throwing Security
99
        // exceptions
102
        // exceptions
100
        return AccessController.doPrivileged( new PrivilegedAction() {
103
        return AccessController.doPrivileged( new PrivilegedAction() {
101
		public Object run() {
104
        public Object run() {
105
                    String password = null;
102
106
103
                    // Create the JavaMail properties we will use
107
                    // Create the JavaMail properties we will use
104
                    Properties props = new Properties();
108
                    Properties props = new Properties();
Lines 109-123 Link Here
109
                        RefAddr attr = (RefAddr) attrs.nextElement();
113
                        RefAddr attr = (RefAddr) attrs.nextElement();
110
                        if ("factory".equals(attr.getType()))
114
                        if ("factory".equals(attr.getType()))
111
                            continue;
115
                            continue;
116
                        if ("password".equals(attr.getType())) {
117
                            password = (String)attr.getContent();
118
                            continue;
119
                        }
112
                        props.put(attr.getType(), (String) attr.getContent());
120
                        props.put(attr.getType(), (String) attr.getContent());
113
                    }
121
                    }
114
122
                    
123
                    Authenticator auth = null;
124
                    
125
                    // Check for authentication
126
                    if (password != null) {
127
                        String user = props.getProperty("mail.smtp.user");
128
                        if (user == null)
129
                            user = props.getProperty("mail.user");
130
                        if (user != null) {
131
                            final PasswordAuthentication pa = new PasswordAuthentication(user, password);
132
                            
133
                            auth = new Authenticator(){
134
                                protected PasswordAuthentication getPasswordAuthentication()
135
                                {
136
                                    return pa;
137
                                }
138
                            };
139
                        }
140
                    }
115
                    // Create and return the new Session object
141
                    // Create and return the new Session object
116
                    Session session = Session.getInstance(props, null);
142
                    Session session = Session.getInstance(props, auth);
117
                    return (session);
143
                    return (session);
118
144
119
		}
145
        }
120
	    } );
146
        } );
121
147
122
    }
148
    }
123
149

Return to bug 31288