org.apache.ftpserver.usermanager
Class DbUserManager

java.lang.Object
  extended by org.apache.ftpserver.usermanager.AbstractUserManager
      extended by org.apache.ftpserver.usermanager.DbUserManager
All Implemented Interfaces:
UserManager

public class DbUserManager
extends AbstractUserManager

This is another database based user manager class. It has been tested in MySQL and Oracle 8i database. The schema file is res/ftp-db.sql All the user attributes are replaced during run-time. So we can use your database schema. Then you need to modify the SQLs in the configuration file.


Field Summary
 
Fields inherited from class org.apache.ftpserver.usermanager.AbstractUserManager
ATTR_ENABLE, ATTR_HOME, ATTR_LOGIN, ATTR_MAX_DOWNLOAD_RATE, ATTR_MAX_IDLE_TIME, ATTR_MAX_LOGIN_NUMBER, ATTR_MAX_LOGIN_PER_IP, ATTR_MAX_UPLOAD_RATE, ATTR_PASSWORD, ATTR_WRITE_PERM
 
Constructor Summary
DbUserManager()
           
 
Method Summary
 User authenticate(Authentication authentication)
          User authentication.
 void configure()
          Configure user manager.
 void delete(java.lang.String name)
          Delete user.
 void dispose()
          Close this user manager.
 boolean doesExist(java.lang.String name)
          User existance check.
 java.lang.String[] getAllUserNames()
          Get all user names from the database.
 javax.sql.DataSource getDataSource()
          Retrive the data source used by the user manager
 java.lang.String getSqlUserAdmin()
          Get the SQL SELECT statement used to find whether an user is admin or not.
 java.lang.String getSqlUserAuthenticate()
          Get the SQL SELECT statement used to authenticate user.
 java.lang.String getSqlUserDelete()
          Get the SQL DELETE statement used to delete an existing user.
 java.lang.String getSqlUserInsert()
          Get the SQL INSERT statement used to add a new user.
 java.lang.String getSqlUserSelect()
          Get the SQL SELECT statement used to select an existing user.
 java.lang.String getSqlUserSelectAll()
          Get the SQL SELECT statement used to select all user ids.
 java.lang.String getSqlUserUpdate()
          Get the SQL UPDATE statement used to update an existing user.
 User getUserByName(java.lang.String name)
          Get the user object.
 boolean isAdmin(java.lang.String login)
           
 void save(User user)
          Save user.
 void setDataSource(javax.sql.DataSource dataSource)
          Set the data source to be used by the user manager
 void setSqlUserAdmin(java.lang.String sql)
          Set the SQL SELECT statement used to find whether an user is admin or not.
 void setSqlUserAuthenticate(java.lang.String sql)
          Set the SQL SELECT statement used to authenticate user.
 void setSqlUserDelete(java.lang.String sql)
          Set the SQL DELETE statement used to delete an existing user.
 void setSqlUserInsert(java.lang.String sql)
          Set the SQL INSERT statement used to add a new user.
 void setSqlUserSelect(java.lang.String sql)
          Set the SQL SELECT statement used to select an existing user.
 void setSqlUserSelectAll(java.lang.String sql)
          Set the SQL SELECT statement used to select all user ids.
 void setSqlUserUpdate(java.lang.String sql)
          Set the SQL UPDATE statement used to update an existing user.
 
Methods inherited from class org.apache.ftpserver.usermanager.AbstractUserManager
getAdminName, setAdmin, setAdminName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbUserManager

public DbUserManager()
Method Detail

getDataSource

public javax.sql.DataSource getDataSource()
Retrive the data source used by the user manager

Returns:
The current data source

setDataSource

public void setDataSource(javax.sql.DataSource dataSource)
Set the data source to be used by the user manager

Parameters:
dataSource - The data source to use

getSqlUserInsert

public java.lang.String getSqlUserInsert()
Get the SQL INSERT statement used to add a new user.

Returns:
The SQL statement

setSqlUserInsert

public void setSqlUserInsert(java.lang.String sql)
Set the SQL INSERT statement used to add a new user. All the dynamic values will be replaced during runtime.

Parameters:
sql - The SQL statement

getSqlUserDelete

public java.lang.String getSqlUserDelete()
Get the SQL DELETE statement used to delete an existing user.

Returns:
The SQL statement

setSqlUserDelete

public void setSqlUserDelete(java.lang.String sql)
Set the SQL DELETE statement used to delete an existing user. All the dynamic values will be replaced during runtime.

Parameters:
sql - The SQL statement

getSqlUserUpdate

public java.lang.String getSqlUserUpdate()
Get the SQL UPDATE statement used to update an existing user.

Returns:
The SQL statement

setSqlUserUpdate

public void setSqlUserUpdate(java.lang.String sql)
Set the SQL UPDATE statement used to update an existing user. All the dynamic values will be replaced during runtime.

Parameters:
sql - The SQL statement

getSqlUserSelect

public java.lang.String getSqlUserSelect()
Get the SQL SELECT statement used to select an existing user.

Returns:
The SQL statement

setSqlUserSelect

public void setSqlUserSelect(java.lang.String sql)
Set the SQL SELECT statement used to select an existing user. All the dynamic values will be replaced during runtime.

Parameters:
sql - The SQL statement

getSqlUserSelectAll

public java.lang.String getSqlUserSelectAll()
Get the SQL SELECT statement used to select all user ids.

Returns:
The SQL statement

setSqlUserSelectAll

public void setSqlUserSelectAll(java.lang.String sql)
Set the SQL SELECT statement used to select all user ids. All the dynamic values will be replaced during runtime.

Parameters:
sql - The SQL statement

getSqlUserAuthenticate

public java.lang.String getSqlUserAuthenticate()
Get the SQL SELECT statement used to authenticate user.

Returns:
The SQL statement

setSqlUserAuthenticate

public void setSqlUserAuthenticate(java.lang.String sql)
Set the SQL SELECT statement used to authenticate user. All the dynamic values will be replaced during runtime.

Parameters:
sql - The SQL statement

getSqlUserAdmin

public java.lang.String getSqlUserAdmin()
Get the SQL SELECT statement used to find whether an user is admin or not.

Returns:
The SQL statement

setSqlUserAdmin

public void setSqlUserAdmin(java.lang.String sql)
Set the SQL SELECT statement used to find whether an user is admin or not. All the dynamic values will be replaced during runtime.

Parameters:
sql - The SQL statement

configure

public void configure()
Configure user manager.


isAdmin

public boolean isAdmin(java.lang.String login)
                throws FtpException
Specified by:
isAdmin in interface UserManager
Overrides:
isAdmin in class AbstractUserManager
Returns:
true if user with this login is administrator
Throws:
FtpException

delete

public void delete(java.lang.String name)
            throws FtpException
Delete user. Delete the row from the table.

Throws:
FtpException

save

public void save(User user)
          throws FtpException
Save user. If new insert a new row, else update the existing row.

Throws:
FtpException

getUserByName

public User getUserByName(java.lang.String name)
                   throws FtpException
Get the user object. Fetch the row from the table.

Throws:
FtpException

doesExist

public boolean doesExist(java.lang.String name)
                  throws FtpException
User existance check.

Throws:
FtpException

getAllUserNames

public java.lang.String[] getAllUserNames()
                                   throws FtpException
Get all user names from the database.

Throws:
FtpException

authenticate

public User authenticate(Authentication authentication)
                  throws AuthenticationFailedException
User authentication.

Throws:
AuthenticationFailedException

dispose

public void dispose()
Close this user manager. Close the database statements and connection.



Copyright © 2003-2008 The Apache Software Foundation. All Rights Reserved.