2.17.2: 2011-06-17

net.sf.basedb.core.authentication
Class POP3Authenticator

java.lang.Object
  extended by net.sf.basedb.core.authentication.POP3Authenticator
All Implemented Interfaces:
Authenticator

public class POP3Authenticator
extends Object
implements Authenticator

This class is an example implementation of the Authenticator interface that authenticates a user against a POP3 server. This means that all users having an email account on a specified mail server are able to log in to base using the same username and password as they use to read their mails.

Example

String host = "mail.thep.lu.se";
String login = "nicklas";
String password = "secret";

Authenticator a = new POP3Authenticator();
a.init(host);
if (a.authenticate(login, password))
{
   // Do some stuff that only nicklas is allowed to do!
}

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2009-04-06 14:52:39 +0200 (Mon, 06 Apr 2009) $

Field Summary
private  String host
          The address or IP-number to the POP3 host.
private  int port
          The POP3 port to use.
 
Constructor Summary
POP3Authenticator()
          Create a new POP3Authenticator object.
 
Method Summary
 AuthenticationInformation authenticate(String login, String password)
          Authenticates a user against the POP3 server.
 void init(String settings)
          Initialises the object.
private  String send(String cmd, BufferedWriter out, BufferedReader in)
          Send cmd to the out buffer.
 boolean supportsExtraInformation()
          Always return FALSE.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

host

private String host
The address or IP-number to the POP3 host.


port

private int port
The POP3 port to use. The default port is 110.

Constructor Detail

POP3Authenticator

public POP3Authenticator()
Create a new POP3Authenticator object.

Method Detail

init

public void init(String settings)
          throws AuthenticationException
Initialises the object. The settings string should be the address or IP-number to the POP3 server. Optionally, the name/number may be followed by a colon (:) and a port number. For example: pop.yourdomain.com or pop.yourdomain.com:110

Specified by:
init in interface Authenticator
Parameters:
settings - The host name with an optional port number
Throws:
AuthenticationException - This exception is thrown if the format of the settings string is invalid. No check is made that the host actually exists and answers at the specified port.

supportsExtraInformation

public boolean supportsExtraInformation()
Always return FALSE.

Specified by:
supportsExtraInformation in interface Authenticator
Returns:
TRUE if additional information is returned, FALSE otherwise.
See Also:
AuthenticationInformation, Authenticator.authenticate(String,String)

authenticate

public AuthenticationInformation authenticate(String login,
                                              String password)
                                       throws UnknownLoginException,
                                              InvalidPasswordException,
                                              AuthenticationException
Authenticates a user against the POP3 server.

Specified by:
authenticate in interface Authenticator
Parameters:
login - The login name of the user
password - The password for the user
Returns:
An AuthenticationInformation object. The id is the same as the login. No extra information is returned.
Throws:
UnknownLoginException - This exception may be thrown if the server doesn't know about the user. It is also possible for an implmentation to throw an AuthenticationException
InvalidPasswordException - This exception may be thrown if the password is invalid. It is also possible for an implementation to throw an AuthenticationException
AuthenticationException - This exception is thrown if the authentication fails

send

private String send(String cmd,
                    BufferedWriter out,
                    BufferedReader in)
             throws Exception
Send cmd to the out buffer. Read a single line of response from the in buffer.

Returns:
The response from the POP server
Throws:
Exception

2.17.2: 2011-06-17