001 /** 002 * 003 */ 004 package org.hackystat.sensorbase.mailer; 005 006 import javax.mail.PasswordAuthentication; 007 import static org.hackystat.sensorbase.server.ServerProperties.SMTP_SERVER_USER; 008 import static org.hackystat.sensorbase.server.ServerProperties.SMTP_SERVER_PASS; 009 010 /** 011 * @author Martin Imme 012 * 013 * This class provides access to a username/password combination to the 014 * SMTP Server in order to use SFTP with authentication. The password 015 * has to be stored in the new properties SMTP_SERVER_USER and 016 * SMTP_SERVER_PASS If this property is empty, anonymous access is used. 017 * 018 */ 019 public class SmtpAuthenticator extends javax.mail.Authenticator { 020 021 /** 022 * Constructor to the class. 023 */ 024 public SmtpAuthenticator() { 025 super(); 026 } 027 028 029 /** 030 * Created and returns a PasswordAuthentication Object which 031 * contains the username/password combination for the authentication process. 032 * 033 * @return PasswordAuthentication the PasswordAuthentication Object 034 * 035 * @see javax.mail.Authenticator#getPasswordAuthentication() 036 */ 037 @Override 038 protected PasswordAuthentication getPasswordAuthentication() { 039 PasswordAuthentication passwordAuthentication = new PasswordAuthentication( 040 System.getProperty(SMTP_SERVER_USER), 041 System.getProperty(SMTP_SERVER_PASS)); 042 043 return passwordAuthentication; 044 } 045 046 }