net.sf.hermesftp.session.impl
Class FtpSessionContextImpl

java.lang.Object
  extended by net.sf.hermesftp.session.impl.FtpSessionContextImpl
All Implemented Interfaces:
FtpConstants, FtpSessionContext

public class FtpSessionContextImpl
extends java.lang.Object
implements FtpConstants, FtpSessionContext

This class servers as a means of transportation for data shared by a single FTP session. Instances of the FtpSessionContextImpl class are passed to each of the commands while executing a FTP command sequence. The command objects read connection settings and other options from the context. In turn data that may concern the general state of the FTP session can be stored in the context.

Author:
Lars Behnke

Field Summary
 
Fields inherited from interface net.sf.hermesftp.common.FtpConstants
ATTR_CLIENT_NAME, ATTR_DATA_PROT, ATTR_FILE_OFFSET, ATTR_FORCE_UTF8, ATTR_GROUP_DATA, ATTR_LOGIN_TIME, ATTR_RENAME_FILE, ATTR_RESTART_MARKERS, ATTR_SSL, ATTR_USER_DATA, BYTE_LENGTH, BYTE_MASK, DEFAULT_BEAN_RES, DEFAULT_KEYSTORE, DEFAULT_KEYSTORE_PASS, DT_ASCII, DT_BINARY, DT_EBCDIC, HERMES_HOME, MILLI, MODE_BLOCK, MODE_COMPRESS, MODE_STREAM, MODE_ZIP, MSG_GOODBYE, MSG150, MSG200, MSG200_NOTED, MSG200_PBSZ, MSG200_SIZE, MSG200_TYPE, MSG202, MSG211_FEAT_ENTRY, MSG211_FEAT_FOOTER, MSG211_FEAT_HEADER, MSG211_STAT, MSG213_SIZE, MSG213_TIME, MSG214, MSG220, MSG220_WEL, MSG226, MSG227, MSG229, MSG230, MSG234, MSG250, MSG257, MSG331, MSG350, MSG350_REST, MSG421, MSG425, MSG426, MSG431, MSG450, MSG451, MSG500, MSG500_CMD, MSG501, MSG501_PATH, MSG501_SIZE, MSG503, MSG503_USR, MSG504, MSG522, MSG530, MSG530_AUTH, MSG534, MSG536, MSG550, MSG550_COMM, MSG550_EXISTS, MSG550_MSG, MSG550_NOTEMPTY, MSG550_PERM, MSG553, OPT_ALLOWED_PASSIVE_PORTS, OPT_BUFFER_SIZE, OPT_CHARSET_ASCII, OPT_CHARSET_EBCDIC, OPT_EMULATE_UNIX, OPT_FTP_PORT, OPT_IPV4_BLACK_LIST, OPT_IPV6_BLACK_LIST, OPT_MAX_CONNECTIONS, OPT_MAX_DOWNLOAD_RATE, OPT_MAX_IDLE_SECONDS, OPT_MAX_UPLOAD_RATE, OPT_MSG_GOODBYE, OPT_MSG_WELCOME, OPT_REMOTE_DIR, OPT_SSL_ALLOW_EXPLICIT, OPT_SSL_ALLOW_IMPLICIT, OPT_SSL_CIPHER_SUITES, OPT_SSL_FORCE, OPT_SSL_KEYSTORE_FILE, OPT_SSL_KEYSTORE_PASS, OPT_SSL_PORT_IMPLICIT, PRIV_NONE, PRIV_READ, PRIV_READ_WRITE, PRIV_WRITE, PWD, SEPARATOR, SERVER_STATUS_HALTED, SERVER_STATUS_INIT, SERVER_STATUS_READY, SERVER_STATUS_UNDEF, SPACE, STAT_BYTES_DOWNLOADED, STAT_BYTES_UPLOADED, STAT_DOWNLOAD_RATE, STAT_FILES_DOWNLOADED, STAT_FILES_UPLOADED, STAT_UPLOAD_RATE, STRUCT_FILE, STRUCT_RECORD, TYPE_NAMES, WILDCARD
 
Constructor Summary
FtpSessionContextImpl(FtpServerOptions options, UserManager userManager, java.util.ResourceBundle resourceBundle, FtpEventListener listener)
          Constructor.
 
Method Summary
 boolean authenticate()
          
 void closeSockets()
          Closes all sockets involved in current session.
 java.lang.Object getAttribute(java.lang.String name)
          Returns a sesson attribute.
 java.lang.String getCharset()
          Returns the charset to be used for text output.
 java.io.BufferedReader getClientCmdReader()
          Returns the Reader that is used to read client commands.
 java.io.PrintWriter getClientResponseWriter()
          Returns the writer that is used to respond to client requests.
 java.net.Socket getClientSocket()
          Returns the client communication socket.
 java.util.Date getCreationTime()
          Date/time the session context was created.
 SocketProvider getDataSocketProvider()
          Returns the object that provides the socket that is used for file transfer.
 int getDataType()
          Returns the current data type (ASCII, BINARY, EPBCDIC).
 FtpEventListener getEventListener()
          Returns the instance that listens to session events.
 int getMaxDownloadRate()
          Returns the maximum transfer rate (download stream) in KB/s.
 int getMaxUploadRate()
          Returns the maximum transfer rate (upload stream) in KB/s.
 java.lang.Integer getNextPassivePort()
          Returns the next available port from a user defined list of passive ports.
 java.lang.String getOption(java.lang.String key)
          Returns the value of an server option.
 FtpServerOptions getOptions()
          
 java.lang.String getPassword()
          Gets the user's password.
 int getPermission(java.lang.String path)
          Gets the user's permission on the passed path.
 java.lang.String getRemoteDir()
          Gets the current remote directory.
 java.lang.String getRemoteRelDir()
          Gets the relative path, with respect to the FTP root path.
 java.lang.String getRes(java.lang.String id)
          Returns a named resource from a resource bundle.
 java.util.Map<java.lang.String,java.lang.Long> getSessionStatistics()
          Returns the session statistics.
 int getStorageStructure()
          Returns the storage structure (File, Record).
 int getTransmissionMode()
          Returns the transmission mode (Stream, Block, Compressed).
 java.lang.String getUser()
          Returns the login name of the user.
 UserData getUserData()
          Returns data about the current user.
 UserManager getUserManager()
          Returns the user manager.
 boolean isAuthenticated()
          Checks whether user was successfully authenticated.
 void resetCredentials()
          Resets the user's credentials and unflags the authentication.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Sets a session attribute.
 void setClientSocket(java.net.Socket clientSocket)
          Sets the client communication socket.
 void setCreationTime(java.util.Date creationTime)
          Date/time the session context was created.
 void setDataSocketProvider(SocketProvider provider)
          Sets the provider that provides the socket that is used in file transfer.
 void setDataType(int dataType)
          Sets the current data type.
 void setPassword(java.lang.String password)
          Sets the user's password.
 void setRemoteDir(java.lang.String remoteDir)
          Sets the remote directory of the user's session.
 void setStorageStructure(int storageStructure)
          Sets the storage structure (File, Record).
 void setTransmissionMode(int transmissionMode)
          Sets the transmission mode (Stream, Block, Compressed).
 void setUser(java.lang.String user)
          Sets the login name of the user.
 void updateAverageStat(java.lang.String avgKey, int value)
          Updates the upload or download transfer rate taking the passed value into account.
 void updateIncrementalStat(java.lang.String countKey, long value)
          Increases a particular resource consumption by the passed value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FtpSessionContextImpl

public FtpSessionContextImpl(FtpServerOptions options,
                             UserManager userManager,
                             java.util.ResourceBundle resourceBundle,
                             FtpEventListener listener)
Constructor.

Parameters:
options - The server options.
userManager - The user manager.
resourceBundle - The resource bundle that containts messages and texts.
listener - The listener that is informed on session events.
Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Returns a sesson attribute.

Specified by:
getAttribute in interface FtpSessionContext
Parameters:
name - Name of the attribute.
Returns:
Value of the attribute.

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Sets a session attribute.

Specified by:
setAttribute in interface FtpSessionContext
Parameters:
name - Name of the attribute.
value - Value of the attribute.

getOptions

public FtpServerOptions getOptions()

Specified by:
getOptions in interface FtpSessionContext
Returns:
The static server options as read from the configuration file.

getOption

public java.lang.String getOption(java.lang.String key)
Returns the value of an server option.

Specified by:
getOption in interface FtpSessionContext
Parameters:
key - The option name.
Returns:
The value.

getPassword

public java.lang.String getPassword()
Gets the user's password.

Specified by:
getPassword in interface FtpSessionContext
Returns:
The user's password.

setPassword

public void setPassword(java.lang.String password)
Sets the user's password.

Specified by:
setPassword in interface FtpSessionContext
Parameters:
password - The users password.

getRemoteDir

public java.lang.String getRemoteDir()
Gets the current remote directory.

Specified by:
getRemoteDir in interface FtpSessionContext
Returns:
The remote directory.

getRemoteRelDir

public java.lang.String getRemoteRelDir()
Gets the relative path, with respect to the FTP root path.

Specified by:
getRemoteRelDir in interface FtpSessionContext
Returns:
The path.

setRemoteDir

public void setRemoteDir(java.lang.String remoteDir)
Sets the remote directory of the user's session.

Specified by:
setRemoteDir in interface FtpSessionContext
Parameters:
remoteDir - The directory to set.

getUser

public java.lang.String getUser()
Returns the login name of the user.

Specified by:
getUser in interface FtpSessionContext
Returns:
The name.

setUser

public void setUser(java.lang.String user)
Sets the login name of the user.

Specified by:
setUser in interface FtpSessionContext
Parameters:
user - The user name.

getEventListener

public FtpEventListener getEventListener()
Returns the instance that listens to session events.

Specified by:
getEventListener in interface FtpSessionContext
Returns:
The session listener.

getRes

public java.lang.String getRes(java.lang.String id)
Returns a named resource from a resource bundle.

Specified by:
getRes in interface FtpSessionContext
Parameters:
id - The name of the resource.
Returns:
The resource.

isAuthenticated

public boolean isAuthenticated()
Checks whether user was successfully authenticated.

Specified by:
isAuthenticated in interface FtpSessionContext
Returns:
True, user is authenticated.

getDataType

public int getDataType()
Returns the current data type (ASCII, BINARY, EPBCDIC).

Specified by:
getDataType in interface FtpSessionContext
Returns:
The data type.

setDataType

public void setDataType(int dataType)
Sets the current data type.

Specified by:
setDataType in interface FtpSessionContext
Parameters:
dataType - The data type.

getStorageStructure

public int getStorageStructure()
Returns the storage structure (File, Record).

Specified by:
getStorageStructure in interface FtpSessionContext
Returns:
The storage structure.

setStorageStructure

public void setStorageStructure(int storageStructure)
Sets the storage structure (File, Record).

Specified by:
setStorageStructure in interface FtpSessionContext
Parameters:
storageStructure - The storage structure..

getTransmissionMode

public int getTransmissionMode()
Returns the transmission mode (Stream, Block, Compressed).

Specified by:
getTransmissionMode in interface FtpSessionContext
Returns:
The transmission mode.

setTransmissionMode

public void setTransmissionMode(int transmissionMode)
Sets the transmission mode (Stream, Block, Compressed).

Specified by:
setTransmissionMode in interface FtpSessionContext
Parameters:
transmissionMode - The transmission mode.

getDataSocketProvider

public SocketProvider getDataSocketProvider()
Returns the object that provides the socket that is used for file transfer.

Specified by:
getDataSocketProvider in interface FtpSessionContext
Returns:
The socket provider.

setDataSocketProvider

public void setDataSocketProvider(SocketProvider provider)
Sets the provider that provides the socket that is used in file transfer.

Specified by:
setDataSocketProvider in interface FtpSessionContext
Parameters:
provider - The socket provider.

getClientSocket

public java.net.Socket getClientSocket()
Returns the client communication socket.

Specified by:
getClientSocket in interface FtpSessionContext
Returns:
The socket.

setClientSocket

public void setClientSocket(java.net.Socket clientSocket)
                     throws java.io.IOException
Sets the client communication socket.

Specified by:
setClientSocket in interface FtpSessionContext
Parameters:
clientSocket - The socket.
Throws:
java.io.IOException - Thrown if socket is invalid.

getClientResponseWriter

public java.io.PrintWriter getClientResponseWriter()
Returns the writer that is used to respond to client requests.

Specified by:
getClientResponseWriter in interface FtpSessionContext
Returns:
Response writer.

getClientCmdReader

public java.io.BufferedReader getClientCmdReader()
Returns the Reader that is used to read client commands.

Specified by:
getClientCmdReader in interface FtpSessionContext
Returns:
The reader.

getPermission

public int getPermission(java.lang.String path)
Gets the user's permission on the passed path.

Specified by:
getPermission in interface FtpSessionContext
Parameters:
path - The path to check the permission on.
Returns:
The permission value.

getUserManager

public UserManager getUserManager()
Returns the user manager.

Specified by:
getUserManager in interface FtpSessionContext
Returns:
The user manager.

authenticate

public boolean authenticate()

Specified by:
authenticate in interface FtpSessionContext
Returns:
True, if successful.

getUserData

public UserData getUserData()
Returns data about the current user.

Specified by:
getUserData in interface FtpSessionContext
Returns:
The user data.

resetCredentials

public void resetCredentials()
Resets the user's credentials and unflags the authentication.

Specified by:
resetCredentials in interface FtpSessionContext

closeSockets

public void closeSockets()
Closes all sockets involved in current session.

Specified by:
closeSockets in interface FtpSessionContext

getCharset

public java.lang.String getCharset()
Returns the charset to be used for text output.

Specified by:
getCharset in interface FtpSessionContext
Returns:
The name of the charset.

getNextPassivePort

public java.lang.Integer getNextPassivePort()
Returns the next available port from a user defined list of passive ports. If no port list was configured, 0 is returned. The port 0 makes a the system decide which port to use.

Specified by:
getNextPassivePort in interface FtpSessionContext
Returns:
The port for passive data transfer.

getCreationTime

public java.util.Date getCreationTime()
Date/time the session context was created.

Specified by:
getCreationTime in interface FtpSessionContext
Returns:
The creation time.

setCreationTime

public void setCreationTime(java.util.Date creationTime)
Date/time the session context was created.

Specified by:
setCreationTime in interface FtpSessionContext
Parameters:
creationTime - The creation time.

getSessionStatistics

public java.util.Map<java.lang.String,java.lang.Long> getSessionStatistics()
Returns the session statistics.

Specified by:
getSessionStatistics in interface FtpSessionContext
Returns:
The statistics.

getMaxDownloadRate

public int getMaxDownloadRate()
Returns the maximum transfer rate (download stream) in KB/s.

Specified by:
getMaxDownloadRate in interface FtpSessionContext
Returns:
The rate.

getMaxUploadRate

public int getMaxUploadRate()
Returns the maximum transfer rate (upload stream) in KB/s.

Specified by:
getMaxUploadRate in interface FtpSessionContext
Returns:
The rate.

updateIncrementalStat

public void updateIncrementalStat(java.lang.String countKey,
                                  long value)
                           throws FtpQuotaException
Increases a particular resource consumption by the passed value.

Specified by:
updateIncrementalStat in interface FtpSessionContext
Parameters:
countKey - The name of the statistic.
value - The value
Throws:
FtpQuotaException - Thrown if a resource limit has been reached.

updateAverageStat

public void updateAverageStat(java.lang.String avgKey,
                              int value)
Updates the upload or download transfer rate taking the passed value into account.

Specified by:
updateAverageStat in interface FtpSessionContext
Parameters:
avgKey - The name of the statistic.
value - The value


Copyright © 2005-2007 Lars Behnke. All Rights Reserved.