1 64 65 package com.jcorporate.expresso.core.misc; 66 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.services.dbobj.Setup; 69 import org.apache.log4j.Logger; 70 71 import javax.mail.Authenticator ; 72 import javax.mail.PasswordAuthentication ; 73 74 75 82 public class EMailAuthenticator 83 extends Authenticator { 84 private String dbName = null; 85 private static Logger log = Logger.getLogger(EMailAuthenticator.class); 86 87 90 public EMailAuthenticator() { 91 super(); 92 } 93 94 100 protected PasswordAuthentication getPasswordAuthentication() { 101 return new PasswordAuthentication (getUser(), getPassword()); 102 } 103 104 107 public void setDBName(String newDBName) { 108 dbName = StringUtil.notNull(newDBName); 109 110 if (dbName.equals("")) { 111 dbName = "default"; 112 } 113 } 114 115 116 private String password = null; 117 private String user = null; 118 119 122 private String getPassword() { 123 String myPassword = password; 124 125 if (myPassword == null) { 126 try { 127 myPassword = Setup.getValue(dbName, "MAILPassword"); 128 } catch (DBException de) { 129 log.error("Unable to read e-mail user info:" + 130 de.getMessage()); 131 } 132 } 133 if (log.isDebugEnabled()) { 134 log.debug("EMailAuthenticator - password=" + myPassword); 135 } 136 137 return myPassword; 138 } 139 140 143 private String getUser() { 144 String myUser = user; 145 146 if (myUser == null) { 147 try { 148 myUser = Setup.getValue(dbName, "MAILUserName"); 149 } catch (DBException de) { 150 log.error("Unable to read e-mail user info:" + 151 de.getMessage()); 152 } 153 } 154 if (log.isDebugEnabled()) { 155 log.debug("EMailAuthenticator - user=" + myUser); 156 } 157 158 return myUser; 159 } 160 161 164 public void setPassword(String newPassword) { 165 password = newPassword; 166 } 167 168 171 public void setUser(String user) { 172 this.user = user; 173 } 174 175 } 176 177 | Popular Tags |