org.apache.ftpserver.usermanager.impl
Class DbUserManager

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

public class DbUserManager
extends AbstractUserManager

Internal class, do not use directly. 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.

Version:
$Rev: 729495 $, $Date: 2008-12-26 14:34:39 +0100 (Fri, 26 Dec 2008) $
Author:
The Apache MINA Project (dev@mina.apache.org)

Field Summary
 
Fields inherited from class org.apache.ftpserver.usermanager.impl.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(javax.sql.DataSource dataSource, java.lang.String selectAllStmt, java.lang.String selectUserStmt, java.lang.String insertUserStmt, java.lang.String updateUserStmt, java.lang.String deleteUserStmt, java.lang.String authenticateStmt, java.lang.String isAdminStmt, PasswordEncryptor passwordEncryptor, java.lang.String adminName)
          Internal constructor, do not use directly.
 
Method Summary
 User authenticate(Authentication authentication)
          User authentication.
protected  java.sql.Connection createConnection()
          Open connection to database.
 void delete(java.lang.String name)
          Delete user.
 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)
          Check if the user is admin.
 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.impl.AbstractUserManager
getAdminName, getPasswordEncryptor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbUserManager

public DbUserManager(javax.sql.DataSource dataSource,
                     java.lang.String selectAllStmt,
                     java.lang.String selectUserStmt,
                     java.lang.String insertUserStmt,
                     java.lang.String updateUserStmt,
                     java.lang.String deleteUserStmt,
                     java.lang.String authenticateStmt,
                     java.lang.String isAdminStmt,
                     PasswordEncryptor passwordEncryptor,
                     java.lang.String adminName)
Internal constructor, do not use directly. Use DbUserManagerFactory instead.

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

isAdmin

public boolean isAdmin(java.lang.String login)
                throws FtpException
Description copied from interface: UserManager
Check if the user is admin.

Specified by:
isAdmin in interface UserManager
Overrides:
isAdmin in class AbstractUserManager
Parameters:
login - The name of the User to check
Returns:
true if user with this login is administrator
Throws:
FtpException - when the UserManager can't fulfill the request.

createConnection

protected java.sql.Connection createConnection()
                                        throws java.sql.SQLException
Open connection to database.

Throws:
java.sql.SQLException

delete

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

Parameters:
name - The name of the User to delete
Throws:
FtpException - when the UserManager can't fulfill the request.

save

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

Parameters:
user - the Uset to save
Throws:
FtpException - when the UserManager can't fulfill the request.

getUserByName

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

Parameters:
name - the name to search for.
Returns:
the user with the specified name, or null if a such user does not exist.
Throws:
FtpException - when the UserManager can't fulfill the request.

doesExist

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

Parameters:
name - the name of the user to check.
Returns:
true if the user exist, false otherwise.
Throws:
FtpException

getAllUserNames

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

Returns:
an array of username strings, note that the result should never be null, if there is no users the result is an empty array.
Throws:
FtpException - when the UserManager can't fulfill the request.

authenticate

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

Parameters:
authentication - The Authentication that proves the users identity
Returns:
the authenticated account.
Throws:
AuthenticationFailedException


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.