ecologylab.services.authentication
Class Authenticator<A extends AuthenticationListEntry>

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.services.authentication.Authenticator<A>

public class Authenticator<A extends AuthenticationListEntry>
extends Debug

Encapsulates all authentication actions, so that Servers don't need to. Requires a backend database of users with passwords (an AuthenticationList).

Author:
Zachary O. Toups (toupsz@cs.tamu.edu)

Field Summary
protected  AuthenticationList<A> authList
           
 
Constructor Summary
Authenticator(AuthenticationList<A> source)
          Creates a new Authenticator using the given AuthenticationList as a backend database of usernames and passwords.
 
Method Summary
protected  void add(java.lang.String username, java.lang.String sessionId)
           
 boolean isLoggedIn(java.lang.String username)
          Checks to see if the given username is already logged-in.
 boolean login(A entry, java.lang.String sessionId)
          Attempts to log-in the given AuthenticationListEntry object.
 boolean logout(A entry, java.lang.String sessionId)
          Removes the given username from all authenticated client lists if the IP address matches the one currently stored for the entry.
protected  void remove(java.lang.String username)
           
 void removeBySessionId(java.lang.Object sessionId)
           
 java.util.Set<java.lang.String> usersLoggedIn(A administrator)
          Looks up a list of logged-in users for an administrator.
 int verifyCredentials(A entry)
          Looks up the authentication level, if any, of entry.
 
Methods inherited from class ecologylab.generic.Debug
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

authList

protected AuthenticationList<A extends AuthenticationListEntry> authList
Constructor Detail

Authenticator

public Authenticator(AuthenticationList<A> source)
Creates a new Authenticator using the given AuthenticationList as a backend database of usernames and passwords.

Parameters:
source - - the AuthenticationList of usernames and passwords to use for authentication.
Method Detail

login

public boolean login(A entry,
                     java.lang.String sessionId)
Attempts to log-in the given AuthenticationListEntry object. In order for it to be authenticated, the following MUST be true: 1.) authList must contain a username entry that matches entry.getUsername(). 2.) the entry in authList that matches the username MUST have an identical hashed password. 3.) the username must not already be contained in authedClientsIdToKey (i.e., the username must not already be logged in).

Parameters:
entry - - the AuthenticationListEntry containing a username and password that is attempting to authenticate.
Returns:

verifyCredentials

public int verifyCredentials(A entry)
Looks up the authentication level, if any, of entry. Returns -1 if entry is not authenticatable on this.

Parameters:
entry - - an instance of a subclass of AuthenticationListEntry with a username and password.
Returns:

usersLoggedIn

public java.util.Set<java.lang.String> usersLoggedIn(A administrator)
Looks up a list of logged-in users for an administrator.

Parameters:
administrator - - the username and password of an administrator.
Returns:
if administrator is valid, an ArrayList of usernames for users that are logged-in; else null.

logout

public boolean logout(A entry,
                      java.lang.String sessionId)
Removes the given username from all authenticated client lists if the IP address matches the one currently stored for the entry.

Parameters:
entry -

isLoggedIn

public boolean isLoggedIn(java.lang.String username)
Checks to see if the given username is already logged-in.

Parameters:
username -
Returns:

remove

protected void remove(java.lang.String username)

removeBySessionId

public void removeBySessionId(java.lang.Object sessionId)

add

protected void add(java.lang.String username,
                   java.lang.String sessionId)