com.Prominic.jFTPd
Class FTPUserListSecuritySource

java.lang.Object
  extended by com.Prominic.jFTPd.FTPSecuritySource
      extended by com.Prominic.jFTPd.FTPUserListSecuritySource
All Implemented Interfaces:
java.lang.Runnable

public class FTPUserListSecuritySource
extends FTPSecuritySource
implements java.lang.Runnable

This class implements a security source based on the users.dat file. It was initially used to force users to stay in their home directory (they are not allowed to access directories outside the home directories) but all the canXXXXXXX methods return true because a java policy is in place to limit their access and a single method in FTPConnection handles the check. This class is now helpfull for only reading the users.dat file.

Author:
Iulian

Field Summary
static int BASIC_FORMAT
          users.dat format for very old jFTPd releases (backwards compatibility).
private  int currentFormat
           
private static boolean DEBUG
           
private  java.lang.String defaultGroup
           
private  java.lang.String defaultMask
           
private  java.lang.String defaultOwner
           
private  java.lang.String defaultReadAccess
           
protected static java.lang.String FIELD_DELIMITER
           
static int OWNERGROUP_FORMAT
          users.dat format for current jFTPd release.
(package private)  long updateInterval
           
(package private)  java.lang.Thread updaterThread
           
protected  java.lang.String userFilename
           
protected  java.util.Hashtable userTable
           
 
Fields inherited from class com.Prominic.jFTPd.FTPSecuritySource
ANONYMOUS_USERNAME
 
Constructor Summary
FTPUserListSecuritySource(java.lang.String filename, int format)
          Creates a security source based on the users.dat file.
 
Method Summary
 boolean canDelete(FTPUser user, java.lang.String path)
          Implement this if the given user can delete the specified path.
 boolean canDownload(FTPUser user, java.lang.String path)
          Implement this if the given user can download from the specified path.
 boolean canRename(FTPUser user, java.lang.String frompath, java.lang.String topath)
          Implement this if the given user can rename the specified path.
 boolean canUpload(FTPUser user, java.lang.String path)
          Implement this if the given user can upload to the specified path.
 java.lang.String getDefaultGroup()
          Returns the default group for all the jFTPd users (this is needed when a user doesn't have its group specified in the users.dat file).
 java.lang.String getDefaultMask()
          Returns the default file mask for all the jFTPd users (this is needed when a user doesn't have its file mask specified in the users.dat file).
 java.lang.String getDefaultOwner()
          Returns the default owner for the files of all the jFTPd users (this is needed when a user doesn't have its files owner specified in the users.dat file).
 java.lang.String getDefaultReadAccess()
          Returns the default read access specified in the configuration file.
 boolean isAnonymousUsername(java.lang.String username)
          Checks if the user is anonymous as well as if the ANONYMOUS_USERNAME is defined in the users.dat file.
protected  java.util.Hashtable readUsersFromStream(java.io.InputStream in)
          Reads the users list from a stream (which is the users.dat file).
 void run()
          Starts this thread.
(package private)  void setCurrentFormat(int newCurrentFormat)
          Sets the users.dat format (basic or ownergroup).
 void setDefaultGroup(java.lang.String newDefaultGroup)
          Sets the default group for files belonging to the current user.
 void setDefaultMask(java.lang.String newDefaultMask)
          Sets the default file mask for files belonging to the current user.
 void setDefaultOwner(java.lang.String newDefaultOwner)
          Sets the default owner for files belonging to the current user.
 void setDefaultReadAccess(java.lang.String newDefaultReadAccess)
          Sets the default read access for files belonging to the current user.
 void startUpdating(long t)
          Starts FTPUserListSecuritySource as a thread which will run at the given interval and reread the users.dat file.
 void stopUpdating()
          Stops the updater thread.
 void updateUserList()
          Reads the users.dat file from disk and builds up the internal user hashtable.
 FTPUser userWithUsernameAndPassword(java.lang.String username, java.lang.String password)
          Creates an FTPUser based on the username and password.
 
Methods inherited from class com.Prominic.jFTPd.FTPSecuritySource
isValidEmail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values

FIELD_DELIMITER

protected static final java.lang.String FIELD_DELIMITER
See Also:
Constant Field Values

userFilename

protected java.lang.String userFilename

userTable

protected java.util.Hashtable userTable

updaterThread

java.lang.Thread updaterThread

updateInterval

long updateInterval

BASIC_FORMAT

public static int BASIC_FORMAT
users.dat format for very old jFTPd releases (backwards compatibility).


OWNERGROUP_FORMAT

public static int OWNERGROUP_FORMAT
users.dat format for current jFTPd release.


currentFormat

private int currentFormat

defaultOwner

private java.lang.String defaultOwner

defaultReadAccess

private java.lang.String defaultReadAccess

defaultGroup

private java.lang.String defaultGroup

defaultMask

private java.lang.String defaultMask
Constructor Detail

FTPUserListSecuritySource

public FTPUserListSecuritySource(java.lang.String filename,
                                 int format)
                          throws java.io.IOException
Creates a security source based on the users.dat file.

Parameters:
filename - - path to users.dat file.
format - - whether the format is a basic one (for very old jFTPd releases) or an advanced one.
Throws:
java.io.IOException
Method Detail

canDelete

public boolean canDelete(FTPUser user,
                         java.lang.String path)
Description copied from class: FTPSecuritySource
Implement this if the given user can delete the specified path.

Specified by:
canDelete in class FTPSecuritySource
Parameters:
user - - user
path - - path to be deleted
Returns:
- always returns true.

canDownload

public boolean canDownload(FTPUser user,
                           java.lang.String path)
Description copied from class: FTPSecuritySource
Implement this if the given user can download from the specified path.

Specified by:
canDownload in class FTPSecuritySource
Parameters:
user - - user
path - - path
Returns:
- always returns true.

canRename

public boolean canRename(FTPUser user,
                         java.lang.String frompath,
                         java.lang.String topath)
Description copied from class: FTPSecuritySource
Implement this if the given user can rename the specified path.

Specified by:
canRename in class FTPSecuritySource
Parameters:
user - - user
frompath - - path to be renamed
topath - - new path
Returns:
- always returns true.

canUpload

public boolean canUpload(FTPUser user,
                         java.lang.String path)
Description copied from class: FTPSecuritySource
Implement this if the given user can upload to the specified path.

Specified by:
canUpload in class FTPSecuritySource
Parameters:
user - - user
path - - path where upload should be done
Returns:
- always returns true.

getDefaultGroup

public java.lang.String getDefaultGroup()
Returns the default group for all the jFTPd users (this is needed when a user doesn't have its group specified in the users.dat file). Creation date: (25-Apr-02 16:51:06)

Returns:
java.lang.String - default user group.

getDefaultMask

public java.lang.String getDefaultMask()
Returns the default file mask for all the jFTPd users (this is needed when a user doesn't have its file mask specified in the users.dat file).

Returns:
java.lang.String - the file mask

getDefaultOwner

public java.lang.String getDefaultOwner()
Returns the default owner for the files of all the jFTPd users (this is needed when a user doesn't have its files owner specified in the users.dat file).

Returns:
java.lang.String - files owner

getDefaultReadAccess

public java.lang.String getDefaultReadAccess()
Returns the default read access specified in the configuration file.

Returns:
java.lang.String - default read access.

isAnonymousUsername

public boolean isAnonymousUsername(java.lang.String username)
Checks if the user is anonymous as well as if the ANONYMOUS_USERNAME is defined in the users.dat file.

Overrides:
isAnonymousUsername in class FTPSecuritySource
Parameters:
username - - username
Returns:
true if the user is anonymous and if anonymous users are allowed to access the server.

readUsersFromStream

protected java.util.Hashtable readUsersFromStream(java.io.InputStream in)
                                           throws java.io.IOException
Reads the users list from a stream (which is the users.dat file). This class creates the hashtable with the each user's virtual directories, and creates an FTPUser for each user. All are put in a hashtable and returned.

Parameters:
in - - stream with users list
Returns:
- a Hashtable with all the users defined in the configuration file.
Throws:
java.io.IOException

run

public void run()
Starts this thread. Each time the updated thread will run this thread, the users.dat il get reread (so jFTPd updates its users on the fly, no need for server restart). Update is given by "updateInterval"

Specified by:
run in interface java.lang.Runnable

setCurrentFormat

void setCurrentFormat(int newCurrentFormat)
Sets the users.dat format (basic or ownergroup).

Parameters:
newCurrentFormat - int - new format.

setDefaultGroup

public void setDefaultGroup(java.lang.String newDefaultGroup)
Sets the default group for files belonging to the current user.

Parameters:
newDefaultGroup - java.lang.String

setDefaultMask

public void setDefaultMask(java.lang.String newDefaultMask)
Sets the default file mask for files belonging to the current user. Creation date: (25-Apr-02 16:50:45)

Parameters:
newDefaultOwner - java.lang.String

setDefaultOwner

public void setDefaultOwner(java.lang.String newDefaultOwner)
Sets the default owner for files belonging to the current user. Creation date: (25-Apr-02 16:50:45)

Parameters:
newDefaultOwner - java.lang.String

setDefaultReadAccess

public void setDefaultReadAccess(java.lang.String newDefaultReadAccess)
Sets the default read access for files belonging to the current user.

Parameters:
newDefaultReadAccess - java.lang.String

startUpdating

public void startUpdating(long t)
Starts FTPUserListSecuritySource as a thread which will run at the given interval and reread the users.dat file.

Parameters:
t - - interval.

stopUpdating

public void stopUpdating()
Stops the updater thread.


updateUserList

public void updateUserList()
Reads the users.dat file from disk and builds up the internal user hashtable.


userWithUsernameAndPassword

public FTPUser userWithUsernameAndPassword(java.lang.String username,
                                           java.lang.String password)
Description copied from class: FTPSecuritySource
Creates an FTPUser based on the username and password. The informations are read from the users.dat file.

Specified by:
userWithUsernameAndPassword in class FTPSecuritySource
Parameters:
username - - username
password - - password.
Returns:
an FTPUser corresponding to the given username and password. Returns null if the username is unknown or the password is invalid.