You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-commits@incubator.apache.org by ng...@apache.org on 2007/02/07 20:02:17 UTC
svn commit: r504666 - in /incubator/ftpserver/trunk/core/src:
java/org/apache/ftpserver/usermanager/PropertiesUserManager.java
test/users.gen
Author: ngn
Date: Wed Feb 7 12:02:17 2007
New Revision: 504666
URL: http://svn.apache.org/viewvc?view=rev&rev=504666
Log:
Lowercased property names used in the users file (with backwards compability handling in place)
Improved JavaDoc
Modified:
incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java
incubator/ftpserver/trunk/core/src/test/users.gen
Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java?view=diff&rev=504666&r1=504665&r2=504666
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/usermanager/PropertiesUserManager.java Wed Feb 7 12:02:17 2007
@@ -47,7 +47,8 @@
public
class PropertiesUserManager extends AbstractUserManager {
- private final static String PREFIX = "FtpServer.user.";
+ private final static String DEPRECATED_PREFIX = "FtpServer.user.";
+ private final static String PREFIX = "ftpserver.user.";
private Log log;
@@ -55,6 +56,8 @@
private File userDataFile = new File("./res/user.gen");
private boolean isPasswordEncrypt = true;
private String adminName = "admin";
+
+ private boolean isConfigured = false;
/**
@@ -64,16 +67,49 @@
log = factory.getInstance(getClass());
}
+ /**
+ * Set the file used to store and read users. Must be set before
+ * {@link #configure()} is called.
+ * @param propFile A file containing users
+ */
public void setPropFile(File propFile) {
+ if(isConfigured) {
+ throw new IllegalStateException("Must be called before configure()");
+ }
+
this.userDataFile = propFile;
}
+
+ /**
+ * If true is returned, passwords will be stored as hashes rather
+ * than in clear text. Default is true.
+ * @return True if passwords are stored as hashes.
+ */
+ public boolean isEncryptPassword() {
+ return isPasswordEncrypt;
+ }
- public void setPropPasswordEncrypt(boolean encryptPassword) {
+ /**
+ * If set to true, passwords will be stored as a
+ * hash to ensure that it can not be retrived from the
+ * user file.
+ * Must be set before {@link #configure()} is called.
+ * @param encryptPassword True to store a hash of the passwords,
+ * false to store the passwords in clear text.
+ */
+ public void setEncryptPasswords(boolean encryptPassword) {
+ if(isConfigured) {
+ throw new IllegalStateException("Must be called before configure()");
+ }
+
this.isPasswordEncrypt = encryptPassword;
}
- public void setAdmin(String adminName) {
- this.adminName = adminName;
+ /**
+ * @deprecated Use {@link #setEncryptPasswords(boolean)}
+ */
+ public void setPropPasswordEncrypt(boolean encryptPassword) {
+ setEncryptPasswords(encryptPassword);
}
/**
@@ -81,6 +117,7 @@
*/
public void configure() throws FtpException {
try {
+ isConfigured = true;
File dir = userDataFile.getParentFile();
if( (!dir.exists()) && (!dir.mkdirs()) ) {
String dirName = dir.getAbsolutePath();
@@ -88,18 +125,60 @@
}
userDataFile.createNewFile();
userDataProp = new BaseProperties(userDataFile);
+
+ convertDeprecatedPropertyNames();
}
catch(IOException ex) {
log.fatal("PropertiesUserManager.configure()", ex);
throw new FtpException("PropertiesUserManager.configure()", ex);
}
}
+
+ private void convertDeprecatedPropertyNames() throws FtpException {
+ Enumeration keys = userDataProp.propertyNames();
+
+ boolean doSave = false;
+
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+
+ if(key.startsWith(DEPRECATED_PREFIX)) {
+ String newKey = PREFIX + key.substring(DEPRECATED_PREFIX.length());
+ userDataProp.setProperty(newKey, userDataProp.getProperty(key));
+ userDataProp.remove(key);
+
+ doSave = true;
+ }
+ }
+
+ if(doSave) {
+ saveUserData();
+ }
+ }
/**
* Get the admin name.
*/
public String getAdminName() {
return adminName;
+ }
+
+ /**
+ * Set the name to use as the administrator of the server.
+ * The default value is "admin".
+ * @param adminName The administrator user name
+ */
+ public void setAdminName(String adminName) {
+ this.adminName = adminName;
+ }
+
+ /**
+ * Set the name to use as the administrator of the server
+ * @param adminName The administrator user name
+ * @deprecated Use {@link #setAdminName(String)} instead
+ */
+ public void setAdmin(String adminName) {
+ this.adminName = adminName;
}
/**
Modified: incubator/ftpserver/trunk/core/src/test/users.gen
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/users.gen?view=diff&rev=504666&r1=504665&r2=504666
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/users.gen (original)
+++ incubator/ftpserver/trunk/core/src/test/users.gen Wed Feb 7 12:02:17 2007
@@ -1,46 +1,28 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-FtpServer.user.admin.maxloginnumber=0
-FtpServer.user.admin.downloadrate=0
-FtpServer.user.admin.enableflag=true
-FtpServer.user.admin.homedirectory=./test-tmp/ftproot
-FtpServer.user.admin.maxloginperip=0
-FtpServer.user.admin.idletime=0
-FtpServer.user.admin.userpassword=admin
-FtpServer.user.admin.writepermission=true
-FtpServer.user.admin.uploadrate=0
-
-FtpServer.user.anonymous.enableflag=true
-FtpServer.user.anonymous.maxloginnumber=20
-FtpServer.user.anonymous.writepermission=false
-FtpServer.user.anonymous.downloadrate=4800
-FtpServer.user.anonymous.uploadrate=4800
-FtpServer.user.anonymous.idletime=300
-FtpServer.user.anonymous.userpassword=
-FtpServer.user.anonymous.homedirectory=./test-tmp/ftproot
-FtpServer.user.anonymous.maxloginperip=2
-
-FtpServer.user.testuser1.homedirectory=./test-tmp/ftproot
-FtpServer.user.testuser1.userpassword=password
-FtpServer.user.testuser1.maxloginnumber=3
-FtpServer.user.testuser1.writepermission=true
-
-FtpServer.user.testuser2.homedirectory=./test-tmp/ftproot
-FtpServer.user.testuser2.userpassword=password
-FtpServer.user.testuser2.maxloginperip=2
-FtpServer.user.testuser2.writepermission=true
+#Generated file - don't edit (please)
+#Wed Feb 07 20:58:22 CET 2007
+ftpserver.user.anonymous.writepermission=false
+ftpserver.user.anonymous.maxloginnumber=20
+ftpserver.user.anonymous.enableflag=true
+ftpserver.user.anonymous.userpassword=
+ftpserver.user.admin.homedirectory=./test-tmp/ftproot
+ftpserver.user.admin.maxloginperip=0
+ftpserver.user.anonymous.homedirectory=./test-tmp/ftproot
+ftpserver.user.anonymous.idletime=300
+ftpserver.user.admin.idletime=0
+ftpserver.user.admin.enableflag=true
+ftpserver.user.testuser2.userpassword=password
+ftpserver.user.testuser2.writepermission=true
+ftpserver.user.testuser1.homedirectory=./test-tmp/ftproot
+ftpserver.user.anonymous.uploadrate=4800
+ftpserver.user.testuser2.homedirectory=./test-tmp/ftproot
+ftpserver.user.admin.maxloginnumber=0
+ftpserver.user.testuser2.maxloginperip=2
+ftpserver.user.testuser1.maxloginnumber=3
+ftpserver.user.admin.uploadrate=0
+ftpserver.user.anonymous.maxloginperip=2
+ftpserver.user.admin.userpassword=admin
+ftpserver.user.testuser1.writepermission=true
+ftpserver.user.admin.downloadrate=0
+ftpserver.user.anonymous.downloadrate=4800
+ftpserver.user.testuser1.userpassword=password
+ftpserver.user.admin.writepermission=true