ecologylab.services.distributed.server
Class DoubleThreadedAuthNIOServer<A extends AuthenticationListEntry>

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.services.distributed.impl.NIOServerBase
          extended by ecologylab.services.distributed.server.DoubleThreadedNIOServer
              extended by ecologylab.services.distributed.server.DoubleThreadedAuthNIOServer<A>
All Implemented Interfaces:
StartAndStoppable, Authenticatable<A>, AuthLogging, AuthMessages, AuthServerRegistryObjects, NetworkingConstants, ServerConstants, SessionObjects, Shutdownable, NIOServerFrontend, java.lang.Runnable

public class DoubleThreadedAuthNIOServer<A extends AuthenticationListEntry>
extends DoubleThreadedNIOServer
implements AuthServerRegistryObjects, AuthMessages, AuthLogging, Authenticatable<A>

An authenticating server that uses NIO and two threads (one for handling IO, the other for handling interfacing with messages). Any clients attempting to communicate with this server must either first provide a Login request, or otherwise have previously been logged in; otherwise, no requests are processed from the client.

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

Field Summary
protected  Authenticator<A> authenticator
           
 
Fields inherited from class ecologylab.services.distributed.server.DoubleThreadedNIOServer
maxPacketSize
 
Fields inherited from class ecologylab.services.distributed.impl.NIOServerBase
registry, translationSpace
 
Fields inherited from interface ecologylab.services.authentication.registryobjects.AuthServerRegistryObjects
MAIN_AUTHENTICATABLE
 
Fields inherited from interface ecologylab.services.authentication.messages.AuthMessages
LOGIN_FAILED_LOGGEDIN, LOGIN_FAILED_NO_IP_SUPPLIED, LOGIN_FAILED_PASSWORD, LOGIN_SUCCESSFUL, LOGOUT_FAILED_IP_MISMATCH, LOGOUT_FAILED_NOT_LOGGEDIN, LOGOUT_SUCCESSFUL, REQUEST_FAILED_NOT_AUTHENTICATED
 
Fields inherited from interface ecologylab.services.distributed.common.ServerConstants
GARBAGE_CONNECTION_CLEANUP_TIMEOUT, MAX_CONNECTIONS, MAXIMUM_TRANSMISSION_ERRORS
 
Fields inherited from interface ecologylab.services.distributed.common.NetworkingConstants
CHARACTER_ENCODING, CONTENT_LENGTH_STRING, CONTENT_LENGTH_STRING_LENGTH, ENCODER, HTTP_HEADER_LINE_DELIMITER, HTTP_HEADER_TERMINATOR, MAX_HTTP_HEADER_LENGTH, MAX_PACKET_SIZE_BYTES, MAX_PACKET_SIZE_CHARACTERS, UNIQUE_IDENTIFIER_STRING
 
Fields inherited from interface ecologylab.services.distributed.common.SessionObjects
BROWSER_SERVICES_CLIENT, BROWSER_SERVICES_TRANSLATIONS, LOGGING, MAIN_SHUTDOWNABLE, MAIN_START_AND_STOPPABLE, TOP_LEVEL
 
Constructor Summary
protected DoubleThreadedAuthNIOServer(int portNumber, java.net.InetAddress[] inetAddress, TranslationSpace requestTranslationSpace, Scope objectRegistry, int idleConnectionTimeout, int maxPacketSize, AuthenticationList authList)
           
 
Method Summary
 void addAuthenticationListener(AuthenticationListener authListener)
           
 void addLoggingListener(Logging log)
           
 void fireLoggingEvent(AuthenticationOp op)
           
protected  void fireLoginEvent(java.lang.String username, java.lang.String sessionId)
           
protected  void fireLogoutEvent(java.lang.String username, java.lang.String sessionId)
           
protected  AbstractClientManager generateContextManager(java.lang.Object sessionId, java.nio.channels.SelectionKey sk, TranslationSpace translationSpace, Scope registry)
          Hook method to allow changing the ContextManager to enable specific extra functionality.
static DoubleThreadedAuthNIOServer getInstance(int portNumber, java.net.InetAddress[] inetAddress, TranslationSpace requestTranslationSpace, Scope objectRegistry, int idleConnectionTimeout, int maxPacketSize, AuthenticationList authList)
          This is the actual way to create an instance of this.
static DoubleThreadedAuthNIOServer getInstance(int portNumber, java.net.InetAddress[] inetAddress, TranslationSpace requestTranslationSpace, Scope objectRegistry, int idleConnectionTimeout, int maxPacketSize, java.lang.String authListFilename)
          This is the actual way to create an instance of this.
 AbstractClientManager invalidate(java.lang.Object sessionId, boolean permanent)
          Ensure that the user associated with sc has been logged out of the authenticator, then call super.invalidate().
 boolean isLoggedIn(java.lang.String username)
          Indicates whether or not the supplied username is currently logged-in to the system.
 boolean login(A entry, java.lang.String sessionId)
          Determines whether a user can log in (based on the content of entry and its originating IP address (address)).
 boolean logout(A entry, java.lang.String sessionId)
          Logs the user out of the system (based on the content of entry and its originating IP address (address)).
 
Methods inherited from class ecologylab.services.distributed.server.DoubleThreadedNIOServer
addressToAddresses, getInstance, getInstance, isRunning, processRead, restoreContextManagerFromSessionId, run, shutdown, start, stop
 
Methods inherited from class ecologylab.services.distributed.impl.NIOServerBase
composeTranslations, composeTranslations, generateBackend, getBackend, getRegistry, getTranslationSpace
 
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

authenticator

protected Authenticator<A extends AuthenticationListEntry> authenticator
Constructor Detail

DoubleThreadedAuthNIOServer

protected DoubleThreadedAuthNIOServer(int portNumber,
                                      java.net.InetAddress[] inetAddress,
                                      TranslationSpace requestTranslationSpace,
                                      Scope objectRegistry,
                                      int idleConnectionTimeout,
                                      int maxPacketSize,
                                      AuthenticationList authList)
                               throws java.io.IOException,
                                      java.net.BindException
Parameters:
portNumber -
inetAddress -
translationSpace -
objectRegistry -
Throws:
java.io.IOException
java.net.BindException
Method Detail

getInstance

public static DoubleThreadedAuthNIOServer getInstance(int portNumber,
                                                      java.net.InetAddress[] inetAddress,
                                                      TranslationSpace requestTranslationSpace,
                                                      Scope objectRegistry,
                                                      int idleConnectionTimeout,
                                                      int maxPacketSize,
                                                      java.lang.String authListFilename)
This is the actual way to create an instance of this.

Parameters:
portNumber -
translationSpace -
objectRegistry -
authListFilename - - a file name indicating the location of the authentication list; this should be an XML file of an AuthenticationList object.
Returns:
A server instance, or null if it was not possible to open a ServerSocket on the port on this machine.

getInstance

public static DoubleThreadedAuthNIOServer getInstance(int portNumber,
                                                      java.net.InetAddress[] inetAddress,
                                                      TranslationSpace requestTranslationSpace,
                                                      Scope objectRegistry,
                                                      int idleConnectionTimeout,
                                                      int maxPacketSize,
                                                      AuthenticationList authList)
This is the actual way to create an instance of this.

Parameters:
portNumber -
translationSpace -
objectRegistry -
authList - - the AuthorizationList object to be used to determine possible users.
Returns:
A server instance, or null if it was not possible to open a ServerSocket on the port on this machine.

generateContextManager

protected AbstractClientManager generateContextManager(java.lang.Object sessionId,
                                                       java.nio.channels.SelectionKey sk,
                                                       TranslationSpace translationSpace,
                                                       Scope registry)
Description copied from class: DoubleThreadedNIOServer
Hook method to allow changing the ContextManager to enable specific extra functionality.

Overrides:
generateContextManager in class DoubleThreadedNIOServer
Parameters:
sessionId -
translationSpace -
registry -
Returns:

addLoggingListener

public void addLoggingListener(Logging log)
Specified by:
addLoggingListener in interface AuthLogging
See Also:
AuthLogging.addLoggingListener(ecologylab.services.logging.Logging)

addAuthenticationListener

public void addAuthenticationListener(AuthenticationListener authListener)

fireLogoutEvent

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

fireLoginEvent

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

fireLoggingEvent

public void fireLoggingEvent(AuthenticationOp op)
Specified by:
fireLoggingEvent in interface AuthLogging

logout

public boolean logout(A entry,
                      java.lang.String sessionId)
Description copied from interface: Authenticatable
Logs the user out of the system (based on the content of entry and its originating IP address (address)). Handles necessary bookkeeping (such as a list of authenticated clients).

Specified by:
logout in interface Authenticatable<A extends AuthenticationListEntry>
Parameters:
entry - the information about the user attempting to log out (username / password, etc.).
Returns:
true if the user successfully logged out, false otherwise. This method may return false if the user was never logged in, or if the attempt appears to be a spoof.

isLoggedIn

public boolean isLoggedIn(java.lang.String username)
Description copied from interface: Authenticatable
Indicates whether or not the supplied username is currently logged-in to the system.

Specified by:
isLoggedIn in interface Authenticatable<A extends AuthenticationListEntry>
Parameters:
username - the username to check.
Returns:

login

public boolean login(A entry,
                     java.lang.String sessionId)
Description copied from interface: Authenticatable
Determines whether a user can log in (based on the content of entry and its originating IP address (address)). Handles any necessary bookkeeping (such as a list of authenticated clients).

Specified by:
login in interface Authenticatable<A extends AuthenticationListEntry>
Parameters:
entry - the information about the user attempting to log in (username / password, etc.).
sessionId - the session id for the connected socket.
Returns:
true if the user successfully logged in, false otherwise.

invalidate

public AbstractClientManager invalidate(java.lang.Object sessionId,
                                        boolean permanent)
Ensure that the user associated with sc has been logged out of the authenticator, then call super.invalidate().

Specified by:
invalidate in interface NIOServerFrontend
Overrides:
invalidate in class DoubleThreadedNIOServer
permanent - - indicates whether the NIOServerFrontend should destroy the context manager object associated with the given connection.
Returns:
the ContextManager object associated with sc that has been removed from the system.
See Also:
ecologylab.services.distributed.server.DoubleThreadedNIOServer#invalidate(java.lang.Object, ecologylab.services.distributed.impl.NIOServerBackend, java.nio.channels.SocketChannel)