5d1e9f8f3160b209b488244992549fb22c301661
[utils] / crawler / kiss / src / org / wamblee / crawler / kiss / notification / UsernamePasswordAuthenticator.java
1 /**
2  * Copyright (c) 2005 UPS_SCS NL
3  *  
4  */
5 package org.wamblee.crawler.kiss.notification;
6
7 import javax.mail.Authenticator;
8 import javax.mail.PasswordAuthentication;
9
10 /**
11  * Authenticator to supply username and password to the mail server (if needed).
12  * 
13  */
14 public class UsernamePasswordAuthenticator extends Authenticator {
15
16     private String _username;
17
18     private String _password;
19
20     /**
21      * Constructs the authenticator.
22      * 
23      * @param aUsername
24      *            User name.
25      * @param aPassword
26      *            Password.
27      */
28     public UsernamePasswordAuthenticator(String aUsername, String aPassword) {
29         _username = aUsername;
30         _password = aPassword;
31     }
32
33     /*
34      * (non-Javadoc)
35      * 
36      * @see javax.mail.Authenticator#getPasswordAuthentication()
37      */
38     @Override
39     protected PasswordAuthentication getPasswordAuthentication() {
40         if (_username == null) {
41             return null;
42         }
43         return new PasswordAuthentication(_username, _password);
44     }
45 }