hammant 2004/07/27 13:16:44
Modified: src/java/org/apache/ftpserver ConnectionService.java
FtpConfig.java FtpStatistics.java
src/java/org/apache/ftpserver/remote RemoteHandler.java
src/java/org/apache/ftpserver/usermanager
AbstractUserManager.java DbUserManager.java
LdapUserManager.java PropertiesUserManager.java
UserManagerInterface.java
Added: src/java/org/apache/ftpserver AbstractFtpConfig.java
AvalonConnectionMonitor.java AvalonFileMonitor.java
AvalonFtpRemoteHandlerMonitor.java
FtpConfigBean.java UserManagerException.java
src/java/org/apache/ftpserver/remote RemoteFtpConfig.java
src/java/org/apache/ftpserver/interfaces
FtpConnectionMonitor.java FtpFileMonitor.java
FtpRemoteHandlerMonitor.java
Log:
Some component refactorings. Including allowing this puppy to run without
Avalon (optional) according to CDI
Revision Changes Path
1.2 +25 -16
incubator-ftpserver/src/java/org/apache/ftpserver/ConnectionService.java
Index: ConnectionService.java
===================================================================
RCS file:
/home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/ConnectionService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConnectionService.java 31 Mar 2003 06:50:02 -0000 1.1
+++ ConnectionService.java 27 Jul 2004 20:16:42 -0000 1.2
@@ -66,6 +66,7 @@
import org.apache.ftpserver.util.Message;
import org.apache.ftpserver.interfaces.FtpConnectionObserver;
import org.apache.ftpserver.interfaces.SpyConnectionInterface;
+import org.apache.ftpserver.interfaces.FtpConnectionMonitor;
import org.apache.ftpserver.usermanager.User;
import org.apache.ftpserver.usermanager.UserManagerInterface;
@@ -78,7 +79,8 @@
class ConnectionService {
private FtpConnectionObserver mObserver;
- private FtpConfig mConfig;
+ private AbstractFtpConfig mConfig;
+ private FtpConnectionMonitor ftpConnectionMonitor;
private Timer mTimer;
private Vector mConList;
@@ -86,8 +88,9 @@
/**
* Constructor. Start scheduler job.
*/
- public ConnectionService(FtpConfig cfg) throws Exception {
+ public ConnectionService(AbstractFtpConfig cfg, FtpConnectionMonitor
ftpConnectionMonitor) throws UserManagerException {
mConfig = cfg;
+ this.ftpConnectionMonitor = ftpConnectionMonitor;
mConList = new Vector();
// default users creation
@@ -106,13 +109,13 @@
/**
* Create default users (admin/anonymous) if necessary
*/
- private void createDefaultUsers() throws Exception {
+ private void createDefaultUsers() throws UserManagerException {
UserManagerInterface userManager = mConfig.getUserManager();
// create admin user
String adminName = userManager.getAdminName();
if(!userManager.doesExist(adminName)) {
- mConfig.getLogger().info("Creating user " + adminName);
+ ftpConnectionMonitor.creatingUser(adminName);
User adminUser = new User();
adminUser.setName(adminName);
adminUser.setPassword(adminName);
@@ -127,7 +130,7 @@
// create anonymous user
if(!userManager.doesExist(FtpUser.ANONYMOUS)) {
- mConfig.getLogger().info("Creating user " + FtpUser.ANONYMOUS);
+ ftpConnectionMonitor.creatingUser(FtpUser.ANONYMOUS);
User anonUser = new User();
anonUser.setName(FtpUser.ANONYMOUS);
anonUser.setPassword("");
@@ -141,6 +144,7 @@
}
}
+
/**
* It returns a list of all the currently connected users.
*/
@@ -200,7 +204,7 @@
UserManagerInterface userManager = mConfig.getUserManager();
boolean bAnonymous = thisUser.getIsAnonymous();
if ( !(bAnonymous || userManager.authenticate(user, password)) ) {
- mConfig.getLogger().warn("Authentication failed - " + user);
+ ftpConnectionMonitor.authFailed(user);
return false;
}
@@ -226,13 +230,14 @@
if( !createHome(thisUser) ) {
return false;
}
- mConfig.getLogger().info("User login - " +
thisUser.getClientAddress().getHostAddress() + " - " + thisUser.getName());
+ ftpConnectionMonitor.userLogin(thisUser);
// update global statistics
mConfig.getStatistics().setLogin(thisUser.getIsAnonymous());
return true;
}
+
/**
* Close ftp connection for this session id.
*/
@@ -322,7 +327,7 @@
if( (anonNbr>=maxAnonLogins) || (totalNbr>=maxLogins) ) {
return false;
}
- mConfig.getLogger().info("Anonymous connection - " +
thisUser.getClientAddress().getHostAddress() + " - " + thisUser.getPassword());
+ ftpConnectionMonitor.anonConnection(thisUser);
}
else {
if(totalNbr>=maxLogins) {
@@ -341,20 +346,20 @@
File userHome = new File(
user.getVirtualDirectory().getRootDirectory() );
if( userHome.exists() ) {
if( !userHome.isDirectory() ) {
- mConfig.getLogger().warn("User home (" +
userHome.getAbsolutePath() + ") for user " + user.getName() + " is not a
directory.");
+ ftpConnectionMonitor.userHomeNotADir(userHome, user);
return false;
}
}
else {
if( mConfig.isCreateHome() ) {
- mConfig.getLogger().info("Creating home (" +
userHome.getAbsolutePath() + ") for user " + user.getName());
+ ftpConnectionMonitor.creatingHome(userHome, user);
if( !userHome.mkdirs() ) {
- mConfig.getLogger().warn("Cannot create home (" +
userHome.getAbsolutePath() + ") for user " + user.getName());
+ ftpConnectionMonitor.cannotCreateHome(userHome, user);
return false;
}
}
else {
- mConfig.getLogger().warn("Cannot find home (" +
userHome.getAbsolutePath() + ") for user " + user.getName());
+ ftpConnectionMonitor.cannotFindHome(userHome, user);
return false;
}
}
@@ -363,6 +368,7 @@
}
+
/**
* New connection has been established - not yet logged-in.
*/
@@ -379,7 +385,7 @@
newUser.setMaxIdleTime(mConfig.getDefaultIdleTime());
newUser.getVirtualDirectory().setRootDirectory(mConfig.getDefaultRoot());
newCon.setObserver(mObserver);
- mConfig.getLogger().info("New connection from " +
newUser.getClientAddress().getHostAddress());
+ ftpConnectionMonitor.newConnectionFrom(newUser);
// notify observer about a new connection
final FtpConnectionObserver observer = mObserver;
@@ -397,6 +403,7 @@
}
+
/**
* Set connection spy object
*/
@@ -464,7 +471,7 @@
// remove inactive users
for( Iterator userIt=inactiveUserList.iterator(); userIt.hasNext();
) {
FtpUser user = (FtpUser)userIt.next();
- mConfig.getLogger().info("Removing idle user " + user);
+ ftpConnectionMonitor.removingIdleUser(user);
closeConnection(user.getSessionId());
}
@@ -474,10 +481,11 @@
userManager.reload();
}
catch(Exception ex) {
- mConfig.getLogger().error("ConnectionService.timerTask()", ex);
+ ftpConnectionMonitor.timerError(ex);
}
}
+
/**
* Dispose connection service. If logs out all the connected
* users and stops the cleaner thread.
@@ -496,5 +504,6 @@
mTimer = null;
}
}
+
}
1.3 +8 -211
incubator-ftpserver/src/java/org/apache/ftpserver/FtpConfig.java
Index: FtpConfig.java
===================================================================
RCS file:
/home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/FtpConfig.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FtpConfig.java 25 Oct 2003 19:49:52 -0000 1.2
+++ FtpConfig.java 27 Jul 2004 20:16:42 -0000 1.3
@@ -80,44 +80,13 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Rana Bhattacharyya</a>
*/
public
-class FtpConfig {
+class FtpConfig extends AbstractFtpConfig {
- private FtpStatus mStatus = null;
- private ConnectionService mConService = null;
- private IpRestrictorInterface mIpRestrictor = null;
- private UserManagerInterface mUserManager = null;
-
- private InetAddress mServerAddress = null;
- private InetAddress mSelfAddress = null;
-
- private Configuration mConf = null;
- private Context mContext = null;
- private Logger mLogger = null;
-
- private FtpStatistics mStatistics = null;
-
- private RemoteHandler mRemoteHandler = null;
-
- private int miServerPort;
- private int miDataPort[][];
- private int miRmiPort;
- private int miMaxLogin;
- private int miAnonLogin;
- private int miPollInterval;
- private int miDefaultIdle;
- private boolean mbAnonAllowed;
- private boolean mbCreateHome;
- private boolean mbRemoteAdminAllowed;
- private File mDefaultRoot;
- private AsyncMessageQueue mQueue;
+ protected Configuration mConf = null;
+ protected Context mContext = null;
+ protected Logger mLogger = null;
- /**
- * Default constructor - first step.
- */
public FtpConfig() throws IOException {
- mStatus = new FtpStatus();
- mQueue = new AsyncMessageQueue();
- mQueue.setMaxSize(4096);
}
/**
@@ -255,10 +224,10 @@
mServerAddress = mSelfAddress;
}
- mStatistics = new FtpStatistics(this);
- mConService = new ConnectionService(this);
+ mStatistics = new FtpStatistics(this, new
AvalonFileMonitor(getLogger()));
+ mConService = new ConnectionService(this, new
AvalonConnectionMonitor(getLogger()));
if (mbRemoteAdminAllowed) {
- mRemoteHandler = new RemoteHandler(this);
+ mRemoteHandler = new RemoteHandler(this, new
AvalonFtpRemoteHandlerMonitor(getLogger()));
}
}
@@ -321,178 +290,6 @@
return mLogger;
}
- /**
- * Get server port.
- */
- public int getServerPort() {
- return miServerPort;
- }
-
- /**
- * Get context
- */
- public Context getContext() {
- return mContext;
- }
-
- /**
- * Get configuration
- */
- public Configuration getConfiguration() {
- return mConf;
- }
-
- /**
- * Get server bind address.
- */
- public InetAddress getServerAddress() {
- return mServerAddress;
- }
-
- /**
- * Get self address
- */
- public InetAddress getSelfAddress() {
- return mSelfAddress;
- }
-
- /**
- * Check annonymous login support.
- */
- public boolean isAnonymousLoginAllowed() {
- return mbAnonAllowed;
- }
-
- /**
- * Get ftp status resource.
- */
- public FtpStatus getStatus() {
- return mStatus;
- }
-
- /**
- * Get connection service.
- */
- public ConnectionService getConnectionService() {
- return mConService;
- }
-
- /**
- * Get user manager.
- */
- public UserManagerInterface getUserManager() {
- return mUserManager;
- }
-
- /**
- * Get maximum number of connections.
- */
- public int getMaxConnections() {
- return miMaxLogin;
- }
-
- /**
- * Get maximum number of anonymous connections.
- */
- public int getMaxAnonymousLogins() {
- if(!isAnonymousLoginAllowed()) {
- return 0;
- }
- return miAnonLogin;
- }
-
- /**
- * Get poll interval in seconds.
- */
- public int getSchedulerInterval() {
- return miPollInterval;
- }
-
- /**
- * Get default idle time in seconds.
- */
- public int getDefaultIdleTime() {
- return miDefaultIdle;
- }
-
- /**
- * Get default root directory
- */
- public File getDefaultRoot() {
- return mDefaultRoot;
- }
-
- /**
- * Create user home directory if not exist during login
- */
- public boolean isCreateHome() {
- return mbCreateHome;
- }
-
- /**
- * Get rmi port
- */
- public int getRemoteAdminPort() {
- return miRmiPort;
- }
-
- /**
- * Is remote admin allowed
- */
- public boolean isRemoteAdminAllowed() {
- return mbRemoteAdminAllowed;
- }
-
- /**
- * Get base directory
- */
- public File getBaseDirectory() {
- File baseDir = null;
- try {
- baseDir = (File) mContext.get("app.home");
- }
- catch (ContextException ex) {
- mLogger.warn("Unable to retrieve application base directory",
ex);
- }
- return baseDir;
- }
-
- /**
- * Get IP restrictor object.
- */
- public IpRestrictorInterface getIpRestrictor() {
- return mIpRestrictor;
- }
-
- /**
- * Get global statistics object.
- */
- public FtpStatistics getStatistics() {
- return mStatistics;
- }
-
- /**
- * Get message queue
- */
- public AsyncMessageQueue getMessageQueue() {
- return mQueue;
- }
-
-
- /**
- * Get the system name.
- */
- public String getSystemName() {
- String systemName = System.getProperty("os.name");
- if(systemName == null) {
- systemName = "UNKNOWN";
- }
- else {
- systemName = systemName.toUpperCase();
- systemName = systemName.replace(' ', '-');
- }
- return systemName;
- }
/**
* Close this config and all the related resources. Ftp server
1.2 +12 -6
incubator-ftpserver/src/java/org/apache/ftpserver/FtpStatistics.java
Index: FtpStatistics.java
===================================================================
RCS file:
/home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/FtpStatistics.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FtpStatistics.java 31 Mar 2003 06:50:02 -0000 1.1
+++ FtpStatistics.java 27 Jul 2004 20:16:42 -0000 1.2
@@ -61,6 +61,7 @@
import org.apache.ftpserver.util.Message;
import org.apache.ftpserver.interfaces.FtpStatisticsListener;
import org.apache.ftpserver.interfaces.FtpFileListener;
+import org.apache.ftpserver.interfaces.FtpFileMonitor;
/**
* This class encapsulates all the global statistics.
@@ -72,7 +73,8 @@
private FtpStatisticsListener mListener = null;
private FtpFileListener mFileListener = null;
- private FtpConfig mConfig = null;
+ private AbstractFtpConfig mConfig = null;
+ private FtpFileMonitor ftpFileMonitor;
private Date mStartTime = new Date();
@@ -95,8 +97,9 @@
/**
* Default constructor.
*/
- public FtpStatistics(FtpConfig cfg) {
+ public FtpStatistics(AbstractFtpConfig cfg, FtpFileMonitor
ftpFileMonitor) {
mConfig = cfg;
+ this.ftpFileMonitor = ftpFileMonitor;
}
@@ -193,28 +196,31 @@
void setUpload(File fl, FtpUser user, long sz) {
++miNbrUpload;
mlBytesUpload += sz;
- mConfig.getLogger().info("File upload : " + user.getName() + " - " +
fl.getAbsolutePath());
+ ftpFileMonitor.fileUploaded(user, fl);
notifyUpload(fl, user);
}
+
/**
* Increment download count.
*/
void setDownload(File fl, FtpUser user, long sz) {
++miNbrDownload;
mlBytesDownload += sz;
- mConfig.getLogger().info("File download : " + user.getName() + " - "
+ fl.getAbsolutePath());
+ ftpFileMonitor.fileDownloaded(user, fl);
notifyDownload(fl, user);
}
+
/**
* Increment delete count.
*/
void setDelete(File fl, FtpUser user) {
++miNbrDelete;
- mConfig.getLogger().info("File delete : " + user.getName() + " - " +
fl.getAbsolutePath());
+ ftpFileMonitor.fileDeleted(user, fl);
notifyDelete(fl, user);
}
+
/**
* New login.
1.1
incubator-ftpserver/src/java/org/apache/ftpserver/AbstractFtpConfig.java
Index: AbstractFtpConfig.java
===================================================================
package org.apache.ftpserver;
import org.apache.ftpserver.ip.IpRestrictorInterface;
import org.apache.ftpserver.remote.RemoteHandler;
import org.apache.ftpserver.usermanager.UserManagerInterface;
import org.apache.ftpserver.util.AsyncMessageQueue;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
/**
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class AbstractFtpConfig {
protected FtpStatus mStatus = null;
protected ConnectionService mConService = null;
protected IpRestrictorInterface mIpRestrictor = null;
protected UserManagerInterface mUserManager = null;
protected InetAddress mServerAddress = null;
protected InetAddress mSelfAddress = null;
protected FtpStatistics mStatistics = null;
protected RemoteHandler mRemoteHandler = null;
protected int miServerPort;
protected int miDataPort[][];
protected int miRmiPort;
protected int miMaxLogin;
protected int miAnonLogin;
protected int miPollInterval;
protected int miDefaultIdle;
protected boolean mbAnonAllowed;
protected boolean mbCreateHome;
protected boolean mbRemoteAdminAllowed;
protected File mDefaultRoot;
protected AsyncMessageQueue mQueue;
protected File baseDir;
/**
* Default constructor - first step.
*/
public AbstractFtpConfig() throws IOException {
mStatus = new FtpStatus();
mQueue = new AsyncMessageQueue();
mQueue.setMaxSize(4096);
}
/**
* Get server port.
*/
public final int getServerPort() {
return miServerPort;
}
/**
* Get server bind address.
*/
public final InetAddress getServerAddress() {
return mServerAddress;
}
/**
* Get self address
*/
public final InetAddress getSelfAddress() {
return mSelfAddress;
}
/**
* Check annonymous login support.
*/
public final boolean isAnonymousLoginAllowed() {
return mbAnonAllowed;
}
/**
* Get ftp status resource.
*/
public final FtpStatus getStatus() {
return mStatus;
}
/**
* Get connection service.
*/
public final ConnectionService getConnectionService() {
return mConService;
}
/**
* Get user manager.
*/
public final UserManagerInterface getUserManager() {
return mUserManager;
}
/**
* Get maximum number of connections.
*/
public final int getMaxConnections() {
return miMaxLogin;
}
/**
* Get maximum number of anonymous connections.
*/
public final int getMaxAnonymousLogins() {
if(!isAnonymousLoginAllowed()) {
return 0;
}
return miAnonLogin;
}
/**
* Get poll interval in seconds.
*/
public final int getSchedulerInterval() {
return miPollInterval;
}
/**
* Get default idle time in seconds.
*/
public final int getDefaultIdleTime() {
return miDefaultIdle;
}
/**
* Get default root directory
*/
public final File getDefaultRoot() {
return mDefaultRoot;
}
/**
* Create user home directory if not exist during login
*/
public final boolean isCreateHome() {
return mbCreateHome;
}
/**
* Get rmi port
*/
public final int getRemoteAdminPort() {
return miRmiPort;
}
/**
* Is remote admin allowed
*/
public final boolean isRemoteAdminAllowed() {
return mbRemoteAdminAllowed;
}
/**
* Get base directory
*/
public final File getBaseDirectory() {
return baseDir;
}
/**
* Get IP restrictor object.
*/
public final IpRestrictorInterface getIpRestrictor() {
return mIpRestrictor;
}
/**
* Get global statistics object.
*/
public final FtpStatistics getStatistics() {
return mStatistics;
}
/**
* Get message queue
*/
public final AsyncMessageQueue getMessageQueue() {
return mQueue;
}
/**
* Get the system name.
*/
public final String getSystemName() {
String systemName = System.getProperty("os.name");
if(systemName == null) {
systemName = "UNKNOWN";
}
else {
systemName = systemName.toUpperCase();
systemName = systemName.replace(' ', '-');
}
return systemName;
}
}
1.1
incubator-ftpserver/src/java/org/apache/ftpserver/AvalonConnectionMonitor.java
Index: AvalonConnectionMonitor.java
===================================================================
package org.apache.ftpserver;
import org.apache.ftpserver.interfaces.FtpConnectionMonitor;
import org.apache.avalon.framework.logger.Logger;
import java.io.File;
/**
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class AvalonConnectionMonitor implements FtpConnectionMonitor {
Logger logger;
public AvalonConnectionMonitor(Logger logger) {
this.logger = logger;
}
public void timerError(Exception ex) {
logger.error("ConnectionService.timerTask()", ex);
}
public void removingIdleUser(FtpUser user) {
logger.info("Removing idle user " + user);
}
public void newConnectionFrom(final FtpUser newUser) {
logger.info("New connection from " +
newUser.getClientAddress().getHostAddress());
}
public void cannotFindHome(File userHome, FtpUser user) {
logger.warn("Cannot find home (" + userHome.getAbsolutePath() + ")
for user " + user.getName());
}
public void cannotCreateHome(File userHome, FtpUser user) {
logger.warn("Cannot create home (" + userHome.getAbsolutePath() + ")
for user " + user.getName());
}
public void creatingHome(File userHome, FtpUser user) {
logger.info("Creating home (" + userHome.getAbsolutePath() + ") for
user " + user.getName());
}
public void userHomeNotADir(File userHome, FtpUser user) {
logger.warn("User home (" + userHome.getAbsolutePath() + ") for user
" + user.getName() + " is not a directory.");
}
public void anonConnection(FtpUser thisUser) {
logger.info("Anonymous connection - " +
thisUser.getClientAddress().getHostAddress() + " - " + thisUser.getPassword());
}
public void userLogin(final FtpUser thisUser) {
logger.info("User login - " +
thisUser.getClientAddress().getHostAddress() + " - " + thisUser.getName());
}
public void authFailed(String user) {
logger.warn("Authentication failed - " + user);
}
public void creatingUser(String adminName) {
logger.info("Creating user " + adminName);
}
}
1.1
incubator-ftpserver/src/java/org/apache/ftpserver/AvalonFileMonitor.java
Index: AvalonFileMonitor.java
===================================================================
package org.apache.ftpserver;
import org.apache.ftpserver.interfaces.FtpFileMonitor;
import org.apache.avalon.framework.logger.Logger;
import java.io.File;
/**
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class AvalonFileMonitor implements FtpFileMonitor {
Logger logger;
public AvalonFileMonitor(Logger logger) {
this.logger = logger;
}
public void fileUploaded(FtpUser user, File fl) {
logger.info("File upload : " + user.getName() + " - " +
fl.getAbsolutePath());
}
public void fileDownloaded(FtpUser user, File fl) {
logger.info("File download : " + user.getName() + " - " +
fl.getAbsolutePath());
}
public void fileDeleted(FtpUser user, File fl) {
logger.info("File delete : " + user.getName() + " - " +
fl.getAbsolutePath());
}
}
1.1
incubator-ftpserver/src/java/org/apache/ftpserver/AvalonFtpRemoteHandlerMonitor.java
Index: AvalonFtpRemoteHandlerMonitor.java
===================================================================
package org.apache.ftpserver;
import org.apache.ftpserver.interfaces.FtpRemoteHandlerMonitor;
import org.apache.avalon.framework.logger.Logger;
/**
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class AvalonFtpRemoteHandlerMonitor implements FtpRemoteHandlerMonitor
{
Logger logger;
public AvalonFtpRemoteHandlerMonitor(Logger logger) {
this.logger = logger;
}
public void remoteAdminLoginRequestError(Exception ex) {
logger.error("RemoteHandler.login()", ex);
}
public void remoteLoginAdminRequest(String clientHost) {
logger.info("Remote admin login request from " + clientHost);
}
public void remoteAdminLogout() {
logger.info("Remote Admin Logout");
}
public void remoteAdminClose() {
logger.info("Remote Admin Close");
}
public void remoteAdminTimeout() {
logger.info("Remote admin timeout");
}
}
1.1
incubator-ftpserver/src/java/org/apache/ftpserver/FtpConfigBean.java
Index: FtpConfigBean.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "FtpServer", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: FtpConfigBean.java,v 1.1 2004/07/27 20:16:42 hammant Exp $
*/
package org.apache.ftpserver;
import org.apache.ftpserver.ip.IpRestrictorInterface;
import org.apache.ftpserver.remote.RemoteHandler;
import org.apache.ftpserver.usermanager.UserManagerInterface;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.StringTokenizer;
import java.rmi.RemoteException;
/**
* Ftp configuration class. It has all ftp server configuration
* parameters. This is not hot-editable. parameters will be loaded
* once during server startup. We can add our own config parameters.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rana Bhattacharyya</a>
*/
public
class FtpConfigBean extends AbstractFtpConfig {
public FtpConfigBean(IpRestrictorInterface ipRestrictorInterface,
UserManagerInterface userManagerInterface) throws IOException,
UserManagerException {
mUserManager = userManagerInterface;
mIpRestrictor = ipRestrictorInterface;
miServerPort = 21;
mDefaultRoot = new File("/");
miDefaultIdle = 300;
mbRemoteAdminAllowed = true;
miRmiPort = java.rmi.registry.Registry.REGISTRY_PORT;
miPollInterval = 120;
miAnonLogin = 10;
mbAnonAllowed = true;
miMaxLogin = 20;
setDefaultDataPool("0");
setConfiguration();
}
public void setServerHost(String serverHost) throws UnknownHostException {
if (serverHost != null) {
mServerAddress = InetAddress.getByName(serverHost);
}
}
public void setServerPort(int port) {
miServerPort = port;
}
/**
* Set configuration - fifth step.
*/
public void setConfiguration() throws UnknownHostException,
UserManagerException, RemoteException {
// get host addresses
if (mSelfAddress == null) {
mSelfAddress = InetAddress.getLocalHost();
}
if(mServerAddress == null) {
mServerAddress = mSelfAddress;
}
//TODO - not Avalon monitors
mStatistics = new FtpStatistics(this, new AvalonFileMonitor(null));
mConService = new ConnectionService(this, new
AvalonConnectionMonitor(null));
if (mbRemoteAdminAllowed) {
mRemoteHandler = new RemoteHandler(this, new
AvalonFtpRemoteHandlerMonitor(null));
}
}
private void setDefaultDataPool(String dataPort) {
// get data port number
StringTokenizer st = new StringTokenizer(dataPort, ", \t\n\r\f");
miDataPort = new int[st.countTokens()][2];
for(int i=0; i<miDataPort.length; i++) {
miDataPort[i][0] = Integer.parseInt(st.nextToken());
miDataPort[i][1] = 0;
}
}
public void setDefaultRoot(String defaultRoot) {
mDefaultRoot = new File(defaultRoot);
}
public void setDefaultIdle(int idleTime) {
miDefaultIdle = idleTime;
}
public void setCreateUserHome(boolean setit) {
mbCreateHome = setit;
}
public void setRemoteAdminAllowed(boolean allowed) {
mbRemoteAdminAllowed = allowed;
}
public void setRmiPort(int port) {
miRmiPort = port;
}
public void setPollInterval(int interval) {
miPollInterval = interval;
}
public void setMaxAnonLogins(int max) {
miAnonLogin = max;
}
public void setAnonLoginsAllowed(boolean allowed) {
mbAnonAllowed = allowed;
}
public void setMaxLogin(int max) {
miMaxLogin = max;
}
/**
* Get data port. Data port number zero (0) means that
* any available port will be used.
*/
public int getDataPort() {
synchronized(miDataPort) {
int dataPort = -1;
int loopTimes = 2;
Thread currThread = Thread.currentThread();
while( (dataPort==-1) && (--loopTimes >= 0) &&
(!currThread.isInterrupted()) ) {
// search for a free port
for(int i=0; i<miDataPort.length; i++) {
if(miDataPort[i][1] == 0) {
if(miDataPort[i][0] != 0) {
miDataPort[i][1] = 1;
}
dataPort = miDataPort[i][0];
break;
}
}
// no available free port - wait for the release notification
if(dataPort == -1) {
try {
miDataPort.wait();
}
catch(InterruptedException ex) {
}
}
}
return dataPort;
}
}
/**
* Release data port
*/
public void releaseDataPort(int port) {
synchronized(miDataPort) {
for(int i=0; i<miDataPort.length; i++) {
if(miDataPort[i][0] == port) {
miDataPort[i][1] = 0;
break;
}
}
miDataPort.notify();
}
}
/**
* Close this config and all the related resources. Ftp server
* <code>FtpServer.stop()</code> method will call this method.
*/
public void dispose() {
// close remote handler
if (mRemoteHandler != null) {
mRemoteHandler.dispose();
mRemoteHandler = null;
}
// close connection service
if(mConService != null) {
mConService.dispose();
mConService = null;
}
// close message queue
if (mQueue != null) {
mQueue.stop();
mQueue = null;
}
}
}
1.1
incubator-ftpserver/src/java/org/apache/ftpserver/UserManagerException.java
Index: UserManagerException.java
===================================================================
package org.apache.ftpserver;
/**
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class UserManagerException extends Exception{
public UserManagerException(Throwable cause) {
super(cause);
}
}
1.2 +27 -18
incubator-ftpserver/src/java/org/apache/ftpserver/remote/RemoteHandler.java
Index: RemoteHandler.java
===================================================================
RCS file:
/home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/remote/RemoteHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RemoteHandler.java 31 Mar 2003 06:50:26 -0000 1.1
+++ RemoteHandler.java 27 Jul 2004 20:16:43 -0000 1.2
@@ -56,17 +56,18 @@
*/
package org.apache.ftpserver.remote;
+import org.apache.ftpserver.AbstractFtpConfig;
+import org.apache.ftpserver.interfaces.FtpRemoteHandlerMonitor;
+import org.apache.ftpserver.remote.interfaces.FtpConfigInterface;
+import org.apache.ftpserver.remote.interfaces.RemoteHandlerInterface;
+import org.apache.ftpserver.usermanager.UserManagerInterface;
+
import java.rmi.RemoteException;
-import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.UID;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.server.Unreferenced;
-import java.rmi.server.UID;
-
-import org.apache.ftpserver.usermanager.User;
-import org.apache.ftpserver.usermanager.UserManagerInterface;
-import org.apache.ftpserver.remote.interfaces.FtpConfigInterface;
-import org.apache.ftpserver.remote.interfaces.RemoteHandlerInterface;
/**
* Ftp server remote admin adapter. This is the starting point of remote
admin.
@@ -76,14 +77,16 @@
public
class RemoteHandler implements RemoteHandlerInterface, Unreferenced {
- private FtpConfig mFtpConfig;
+ private RemoteFtpConfig mFtpConfig;
private String mstAdminSession;
private Registry mRegistry;
+ private FtpRemoteHandlerMonitor ftpRemoteHandlerMonitor;
/**
* Constructor - set the actual user config object
*/
- public RemoteHandler(org.apache.ftpserver.FtpConfig config) throws
RemoteException {
+ public RemoteHandler(AbstractFtpConfig config, FtpRemoteHandlerMonitor
ftpRemoteHandlerMonitor) throws RemoteException {
+ this.ftpRemoteHandlerMonitor = ftpRemoteHandlerMonitor;
// open registry
int rmiPort = config.getRemoteAdminPort();
@@ -101,7 +104,7 @@
UnicastRemoteObject.exportObject(this);
mRegistry.rebind(BIND_NAME, this);
- mFtpConfig = new FtpConfig(config);
+ mFtpConfig = new RemoteFtpConfig(config);
}
/**
@@ -109,10 +112,11 @@
*/
public synchronized String login(String id, String password) throws
Exception {
try {
- mFtpConfig.getConfig().getLogger().info("Remote admin login
request from " + UnicastRemoteObject.getClientHost());
+ String clientHost = UnicastRemoteObject.getClientHost();
+ ftpRemoteHandlerMonitor.remoteLoginAdminRequest(clientHost);
}
catch(Exception ex) {
-
mFtpConfig.getConfig().getLogger().error("RemoteHandler.login()", ex);
+ ftpRemoteHandlerMonitor.remoteAdminLoginRequestError(ex);
}
// data validation
@@ -138,15 +142,17 @@
}
try {
- mFtpConfig.getConfig().getLogger().info("Remote admin login from
" + UnicastRemoteObject.getClientHost());
+ String clientHost = UnicastRemoteObject.getClientHost();
+ ftpRemoteHandlerMonitor.remoteLoginAdminRequest(clientHost);
}
catch(Exception ex) {
-
mFtpConfig.getConfig().getLogger().error("RemoteHandler.login()", ex);
+ ftpRemoteHandlerMonitor.remoteAdminLoginRequestError(ex);
}
mstAdminSession = new UID().toString();
return mstAdminSession;
}
+
/**
* Remote admin logout
*/
@@ -154,7 +160,7 @@
if( (sessId == null) || (!sessId.equals(mstAdminSession)) ) {
return false;
}
- mFtpConfig.getConfig().getLogger().info("Remote admin logout");
+ ftpRemoteHandlerMonitor.remoteAdminLogout();
resetObservers();
mstAdminSession = null;
return true;
@@ -187,7 +193,7 @@
* Close the remote handler
*/
public void dispose() {
- mFtpConfig.getConfig().getLogger().info("Closing remote handler...");
+ ftpRemoteHandlerMonitor.remoteAdminClose();
resetObservers();
try {
if (mRegistry != null) {
@@ -203,7 +209,10 @@
* Unreferenced - admin user idle timeout
*/
public synchronized void unreferenced() {
- mFtpConfig.getConfig().getLogger().info("Remote admin timeout");
+ ftpRemoteHandlerMonitor.remoteAdminTimeout();
logout(mstAdminSession);
}
+
+
+
}
1.1
incubator-ftpserver/src/java/org/apache/ftpserver/remote/RemoteFtpConfig.java
Index: RemoteFtpConfig.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Incubator", "FtpServer", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: RemoteFtpConfig.java,v 1.1 2004/07/27 20:16:43 hammant Exp $
*/
package org.apache.ftpserver.remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.net.InetAddress;
import org.apache.ftpserver.remote.interfaces.FtpConfigInterface;
import org.apache.ftpserver.remote.interfaces.IpRestrictorInterface;
import org.apache.ftpserver.remote.interfaces.ConnectionServiceInterface;
import org.apache.ftpserver.remote.interfaces.UserManagerInterface;
import org.apache.ftpserver.remote.interfaces.FtpStatisticsInterface;
import org.apache.ftpserver.AbstractFtpConfig;
/**
* Ftp configuration remote adapter. It is used by remote admin GUI.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rana Bhattacharyya</a>
*/
public
class RemoteFtpConfig implements FtpConfigInterface {
private AbstractFtpConfig mConfig;
private IpRestrictor mIpRestrictor;
private UserManager mUserManager;
private ConnectionService mConService;
private FtpStatistics mStatistics;
/**
* Constructor - sets the actual config object.
*/
public RemoteFtpConfig(AbstractFtpConfig config) throws RemoteException {
mConfig = config;
mIpRestrictor = new IpRestrictor(config.getIpRestrictor());
mUserManager = new UserManager(config.getUserManager());
mConService = new ConnectionService(config.getConnectionService());
mStatistics = new FtpStatistics(config.getStatistics());
UnicastRemoteObject.exportObject(this);
}
/**
* Get config
*/
public AbstractFtpConfig getConfig() {
return mConfig;
}
/**
* Get user manager
*/
public UserManagerInterface getUserManager() {
return mUserManager;
}
/**
* Get IP restrictor object.
*/
public IpRestrictorInterface getIpRestrictor() {
return mIpRestrictor;
}
/**
* Get server bind address.
*/
public InetAddress getServerAddress() {
return mConfig.getServerAddress();
}
/**
* Get address string
*/
public String getAddressString() {
return mConfig.getSelfAddress().toString();
}
/**
* Get server port.
*/
public int getServerPort() {
return mConfig.getServerPort();
}
/**
* Check annonymous login support.
*/
public boolean isAnonymousLoginAllowed() {
return mConfig.isAnonymousLoginAllowed();
}
/**
* Get the connection handler
*/
public ConnectionServiceInterface getConnectionService() {
return mConService;
}
/**
* Get maximum number of connections.
*/
public int getMaxConnections() {
return mConfig.getMaxConnections();
}
/**
* Get maximum number of anonymous connections.
*/
public int getMaxAnonymousLogins() {
return mConfig.getMaxAnonymousLogins();
}
/**
* Get poll interval in seconds.
*/
public int getSchedulerInterval() {
return mConfig.getSchedulerInterval();
}
/**
* Get default idle time in seconds.
*/
public int getDefaultIdleTime() {
return mConfig.getDefaultIdleTime();
}
/**
* Get default root directory
*/
public String getDefaultRoot() {
return mConfig.getDefaultRoot().getAbsolutePath();
}
/**
* Get global statistics object.
*/
public FtpStatisticsInterface getStatistics() {
return mStatistics;
}
/**
* Get rmi port
*/
public int getRemoteAdminPort() {
return mConfig.getRemoteAdminPort();
}
/**
* Is remote admin allowed
*/
public boolean isRemoteAdminAllowed() {
return mConfig.isRemoteAdminAllowed();
}
/**
* Get base directory
*/
public String getBaseDirectory() {
return mConfig.getBaseDirectory().getAbsolutePath();
}
}
1.3 +3 -2
incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/AbstractUserManager.java
Index: AbstractUserManager.java
===================================================================
RCS file:
/home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/AbstractUserManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractUserManager.java 25 Oct 2003 19:49:52 -0000 1.2
+++ AbstractUserManager.java 27 Jul 2004 20:16:43 -0000 1.3
@@ -72,6 +72,7 @@
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
+import org.apache.ftpserver.UserManagerException;
/**
* Abstract user manager class.
@@ -135,7 +136,7 @@
/**
* Reload user data - dummy implementation.
*/
- public void reload() throws Exception {
+ public void reload() throws UserManagerException {
}
/**
1.3 +49 -49
incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/DbUserManager.java
Index: DbUserManager.java
===================================================================
RCS file:
/home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/DbUserManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DbUserManager.java 23 Jun 2003 16:34:26 -0000 1.2
+++ DbUserManager.java 27 Jul 2004 20:16:43 -0000 1.3
@@ -69,6 +69,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.ftpserver.util.StringUtils;
+import org.apache.ftpserver.UserManagerException;
/**
* This is another database based user manager class. I have
@@ -96,15 +97,6 @@
/**
- * Instantiate user manager - default constructor.
- *
- * @param cfg Ftp config object.
- */
- public DbUserManager() throws Exception {
- }
-
-
- /**
* Set configuration - open database connection
*/
public void configure(Configuration conf) throws ConfigurationException {
@@ -175,51 +167,59 @@
/**
* Delete user. Delete the row from the table.
*/
- public synchronized void delete(String name) throws SQLException {
- HashMap map = new HashMap();
- map.put(User.ATTR_LOGIN, name);
- String sql = StringUtils.replaceString(mDelUserStmt, map);
-
- prepareDbConnection();
- Statement stmt = mDbConnection.createStatement();
- stmt.executeUpdate(sql);
- stmt.close();
+ public synchronized void delete(String name) throws UserManagerException
{
+ try {
+ HashMap map = new HashMap();
+ map.put(User.ATTR_LOGIN, name);
+ String sql = StringUtils.replaceString(mDelUserStmt, map);
+
+ prepareDbConnection();
+ Statement stmt = mDbConnection.createStatement();
+ stmt.executeUpdate(sql);
+ stmt.close();
+ } catch (SQLException e) {
+ throw new UserManagerException(e);
+ }
}
/**
* Save user. If new insert a new row, else update the existing row.
*/
- public synchronized void save(User user) throws SQLException {
-
- // null value check
- if(user.getName() == null) {
- throw new NullPointerException("User name is null.");
- }
-
- prepareDbConnection();
-
- HashMap map = new HashMap();
- map.put(User.ATTR_LOGIN, user.getName());
- map.put(User.ATTR_PASSWORD, getPassword(user));
- map.put(User.ATTR_HOME,
user.getVirtualDirectory().getRootDirectory());
- map.put(User.ATTR_ENABLE, String.valueOf(user.getEnabled()));
- map.put(User.ATTR_WRITE_PERM,
String.valueOf(user.getVirtualDirectory().getWritePermission()));
- map.put(User.ATTR_MAX_IDLE_TIME, new Long(user.getMaxIdleTime()));
- map.put(User.ATTR_MAX_UPLOAD_RATE, new
Integer(user.getMaxUploadRate()));
- map.put(User.ATTR_MAX_DOWNLOAD_RATE, new
Integer(user.getMaxDownloadRate()));
-
- String sql = null;
- if( !doesExist(user.getName()) ) {
- sql = StringUtils.replaceString(mInsUserStmt, map);
- }
- else {
- sql = StringUtils.replaceString(mUpdUserStmt, map);
- }
-
- Statement stmt = mDbConnection.createStatement();
- stmt.executeUpdate(sql);
- stmt.close();
+ public synchronized void save(User user) throws UserManagerException {
+
+ try {
+ // null value check
+ if(user.getName() == null) {
+ throw new NullPointerException("User name is null.");
+ }
+
+ prepareDbConnection();
+
+ HashMap map = new HashMap();
+ map.put(User.ATTR_LOGIN, user.getName());
+ map.put(User.ATTR_PASSWORD, getPassword(user));
+ map.put(User.ATTR_HOME,
user.getVirtualDirectory().getRootDirectory());
+ map.put(User.ATTR_ENABLE, String.valueOf(user.getEnabled()));
+ map.put(User.ATTR_WRITE_PERM,
String.valueOf(user.getVirtualDirectory().getWritePermission()));
+ map.put(User.ATTR_MAX_IDLE_TIME, new
Long(user.getMaxIdleTime()));
+ map.put(User.ATTR_MAX_UPLOAD_RATE, new
Integer(user.getMaxUploadRate()));
+ map.put(User.ATTR_MAX_DOWNLOAD_RATE, new
Integer(user.getMaxDownloadRate()));
+
+ String sql = null;
+ if( !doesExist(user.getName()) ) {
+ sql = StringUtils.replaceString(mInsUserStmt, map);
+ }
+ else {
+ sql = StringUtils.replaceString(mUpdUserStmt, map);
+ }
+
+ Statement stmt = mDbConnection.createStatement();
+ stmt.executeUpdate(sql);
+ stmt.close();
+ } catch (SQLException e) {
+ throw new UserManagerException(e);
+ }
}
1.3 +19 -10
incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/LdapUserManager.java
Index: LdapUserManager.java
===================================================================
RCS file:
/home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/LdapUserManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LdapUserManager.java 23 Jun 2003 16:33:59 -0000 1.2
+++ LdapUserManager.java 27 Jul 2004 20:16:43 -0000 1.3
@@ -77,6 +77,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.ftpserver.util.StringUtils;
+import org.apache.ftpserver.UserManagerException;
/**
* Ldap based user manager class. Tested using Netscape Directory Server 4.1.
@@ -292,12 +293,16 @@
/**
* Save user
*/
- public synchronized void save(User user) throws NamingException {
- if (doesExist(user.getName())) {
- update(user);
- }
- else {
- add(user);
+ public synchronized void save(User user) throws UserManagerException {
+ try {
+ if (doesExist(user.getName())) {
+ update(user);
+ }
+ else {
+ add(user);
+ }
+ } catch (NamingException e) {
+ throw new UserManagerException(e);
}
}
@@ -385,9 +390,13 @@
/**
* Delete user
*/
- public synchronized void delete(String userName) throws NamingException {
- String dn = getDN(userName);
- mAdminContext.unbind(dn);
+ public synchronized void delete(String userName) throws
UserManagerException {
+ try {
+ String dn = getDN(userName);
+ mAdminContext.unbind(dn);
+ } catch (NamingException e) {
+ throw new UserManagerException(e);
+ }
}
1.4 +71 -66
incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java
Index: PropertiesUserManager.java
===================================================================
RCS file:
/home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PropertiesUserManager.java 25 Oct 2003 19:49:52 -0000 1.3
+++ PropertiesUserManager.java 27 Jul 2004 20:16:43 -0000 1.4
@@ -74,6 +74,7 @@
import org.apache.ftpserver.util.IoUtils;
import org.apache.ftpserver.util.BaseProperties;
import org.apache.ftpserver.util.EncryptUtils;
+import org.apache.ftpserver.UserManagerException;
/**
* Properties file based <code>UserManager</code>
@@ -97,14 +98,6 @@
private long mlLastModified;
/**
- * Instantiate user manager - default constructor.
- *
- * @param cfg Ftp config object.
- */
- public PropertiesUserManager() throws Exception {
- }
-
- /**
* Set application context
*/
public void contextualize(Context context) throws ContextException {
@@ -139,33 +132,37 @@
/**
* Save user data. Store the properties.
*/
- public synchronized void save(User usr) throws IOException {
+ public synchronized void save(User usr) throws UserManagerException {
- // null value check
- if(usr.getName() == null) {
- throw new NullPointerException("User name is null.");
- }
- String thisPrefix = PREFIX + usr.getName() + '.';
-
- // set other properties
- mUserData.setProperty(thisPrefix + User.ATTR_PASSWORD,
getPassword(usr));
- mUserData.setProperty(thisPrefix + User.ATTR_HOME,
usr.getVirtualDirectory().getRootDirectory());
- mUserData.setProperty(thisPrefix + User.ATTR_ENABLE,
usr.getEnabled());
- mUserData.setProperty(thisPrefix + User.ATTR_WRITE_PERM,
usr.getVirtualDirectory().getWritePermission());
- mUserData.setProperty(thisPrefix + User.ATTR_MAX_IDLE_TIME,
usr.getMaxIdleTime());
- mUserData.setProperty(thisPrefix + User.ATTR_MAX_UPLOAD_RATE,
usr.getMaxUploadRate());
- mUserData.setProperty(thisPrefix + User.ATTR_MAX_DOWNLOAD_RATE,
usr.getMaxDownloadRate());
-
- // save user data
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(mUserDataFile);
- mUserData.store(fos, "Generated file - don't edit (please)");
- mlLastModified = mUserDataFile.lastModified();
- }
- finally {
- IoUtils.close(fos);
- }
+ try {
+ // null value check
+ if(usr.getName() == null) {
+ throw new NullPointerException("User name is null.");
+ }
+ String thisPrefix = PREFIX + usr.getName() + '.';
+
+ // set other properties
+ mUserData.setProperty(thisPrefix + User.ATTR_PASSWORD,
getPassword(usr));
+ mUserData.setProperty(thisPrefix + User.ATTR_HOME,
usr.getVirtualDirectory().getRootDirectory());
+ mUserData.setProperty(thisPrefix + User.ATTR_ENABLE,
usr.getEnabled());
+ mUserData.setProperty(thisPrefix + User.ATTR_WRITE_PERM,
usr.getVirtualDirectory().getWritePermission());
+ mUserData.setProperty(thisPrefix + User.ATTR_MAX_IDLE_TIME,
usr.getMaxIdleTime());
+ mUserData.setProperty(thisPrefix + User.ATTR_MAX_UPLOAD_RATE,
usr.getMaxUploadRate());
+ mUserData.setProperty(thisPrefix + User.ATTR_MAX_DOWNLOAD_RATE,
usr.getMaxDownloadRate());
+
+ // save user data
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(mUserDataFile);
+ mUserData.store(fos, "Generated file - don't edit (please)");
+ mlLastModified = mUserDataFile.lastModified();
+ }
+ finally {
+ IoUtils.close(fos);
+ }
+ } catch (IOException e) {
+ throw new UserManagerException(e);
+ }
}
@@ -173,32 +170,36 @@
* Delete an user. Removes all this user entries from the properties.
* After removing the corresponding from the properties, save the data.
*/
- public synchronized void delete(String usrName) throws IOException {
+ public synchronized void delete(String usrName) throws
UserManagerException {
- // remove entries from properties
- String thisPrefix = PREFIX + usrName + '.';
- Enumeration propNames = mUserData.propertyNames();
- ArrayList remKeys = new ArrayList();
- while(propNames.hasMoreElements()) {
- String thisKey = propNames.nextElement().toString();
- if(thisKey.startsWith(thisPrefix)) {
- remKeys.add(thisKey);
+ try {
+ // remove entries from properties
+ String thisPrefix = PREFIX + usrName + '.';
+ Enumeration propNames = mUserData.propertyNames();
+ ArrayList remKeys = new ArrayList();
+ while(propNames.hasMoreElements()) {
+ String thisKey = propNames.nextElement().toString();
+ if(thisKey.startsWith(thisPrefix)) {
+ remKeys.add(thisKey);
+ }
+ }
+ Iterator remKeysIt = remKeys.iterator();
+ while (remKeysIt.hasNext()) {
+ mUserData.remove(remKeysIt.next().toString());
}
- }
- Iterator remKeysIt = remKeys.iterator();
- while (remKeysIt.hasNext()) {
- mUserData.remove(remKeysIt.next().toString());
- }
- // save user data
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(mUserDataFile);
- mUserData.store(fos, "Generated file - don't edit (please)");
- mlLastModified = mUserDataFile.lastModified();
- }
- finally {
- IoUtils.close(fos);
+ // save user data
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(mUserDataFile);
+ mUserData.store(fos, "Generated file - don't edit (please)");
+ mlLastModified = mUserDataFile.lastModified();
+ }
+ finally {
+ IoUtils.close(fos);
+ }
+ } catch (IOException e) {
+ throw new UserManagerException(e);
}
}
@@ -304,14 +305,18 @@
/**
* Reload the user data if necessary
*/
- public synchronized void reload() throws Exception {
- long lastModified = mUserDataFile.lastModified();
- if (lastModified > mlLastModified) {
- FileInputStream fis = new FileInputStream(mUserDataFile);
- mUserData.load(fis);
- fis.close();
- mlLastModified = lastModified;
- getLogger().info("File modified - loading " +
mUserDataFile.getAbsolutePath());
+ public synchronized void reload() throws UserManagerException {
+ try {
+ long lastModified = mUserDataFile.lastModified();
+ if (lastModified > mlLastModified) {
+ FileInputStream fis = new FileInputStream(mUserDataFile);
+ mUserData.load(fis);
+ fis.close();
+ mlLastModified = lastModified;
+ getLogger().info("File modified - loading " +
mUserDataFile.getAbsolutePath());
+ }
+ } catch (IOException e) {
+ throw new UserManagerException(e);
}
}
1.2 +7 -5
incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/UserManagerInterface.java
Index: UserManagerInterface.java
===================================================================
RCS file:
/home/cvs/incubator-ftpserver/src/java/org/apache/ftpserver/usermanager/UserManagerInterface.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UserManagerInterface.java 31 Mar 2003 06:50:26 -0000 1.1
+++ UserManagerInterface.java 27 Jul 2004 20:16:43 -0000 1.2
@@ -56,6 +56,8 @@
*/
package org.apache.ftpserver.usermanager;
+import org.apache.ftpserver.UserManagerException;
+
import java.util.List;
/**
@@ -74,14 +76,14 @@
* Save the user. If a new user, create it else update the
* existing user.
*/
- void save(User user) throws Exception;
+ void save(User user) throws UserManagerException;
/**
* Delete the user from the system.
*
- * @param name name of the user to be deleted.
+ * @param userName name of the user to be deleted.
*/
- void delete(String userName) throws Exception;
+ void delete(String userName) throws UserManagerException;
/**
* Get user by name.
@@ -108,7 +110,7 @@
/**
* Load the user data again
*/
- void reload() throws Exception;
+ void reload() throws UserManagerException;
/**
* Get admin user name
1.1
incubator-ftpserver/src/java/org/apache/ftpserver/interfaces/FtpConnectionMonitor.java
Index: FtpConnectionMonitor.java
===================================================================
package org.apache.ftpserver.interfaces;
import org.apache.ftpserver.FtpUser;
import java.io.File;
/**
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public interface FtpConnectionMonitor {
void timerError(Exception ex);
void removingIdleUser(FtpUser user);
void newConnectionFrom(final FtpUser newUser);
void cannotFindHome(File userHome, FtpUser user);
void cannotCreateHome(File userHome, FtpUser user);
void creatingHome(File userHome, FtpUser user);
void userHomeNotADir(File userHome, FtpUser user);
void anonConnection(FtpUser thisUser);
void userLogin(final FtpUser thisUser);
void authFailed(String user);
void creatingUser(String adminName);
}
1.1
incubator-ftpserver/src/java/org/apache/ftpserver/interfaces/FtpFileMonitor.java
Index: FtpFileMonitor.java
===================================================================
package org.apache.ftpserver.interfaces;
import org.apache.ftpserver.FtpUser;
import java.io.File;
/**
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public interface FtpFileMonitor {
void fileUploaded(FtpUser user, File fl);
void fileDownloaded(FtpUser user, File fl);
void fileDeleted(FtpUser user, File fl);
}
1.1
incubator-ftpserver/src/java/org/apache/ftpserver/interfaces/FtpRemoteHandlerMonitor.java
Index: FtpRemoteHandlerMonitor.java
===================================================================
package org.apache.ftpserver.interfaces;
/**
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public interface FtpRemoteHandlerMonitor {
void remoteAdminLoginRequestError(Exception ex);
void remoteLoginAdminRequest(String clientHost);
void remoteAdminLogout();
void remoteAdminClose();
void remoteAdminTimeout();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]