You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ng...@apache.org on 2008/11/11 00:14:01 UTC
svn commit: r712867 - in /mina/ftpserver/trunk/core: ./
src/main/java/org/apache/ftpserver/config/spring/
src/main/java/org/apache/ftpserver/usermanager/
src/main/java/org/apache/ftpserver/usermanager/impl/
src/main/resources/org/apache/ftpserver/confi...
Author: ngn
Date: Mon Nov 10 15:14:01 2008
New Revision: 712867
URL: http://svn.apache.org/viewvc?rev=712867&view=rev
Log:
Allow setting the users file as a URL so ensure it will work in OSGi
Modified:
mina/ftpserver/trunk/core/pom.xml
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/UserManagerBeanDefinitionParser.java
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/PropertiesUserManagerFactory.java
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/impl/PropertiesUserManager.java
mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/config/spring/ftpserver-1.0.xsd
Modified: mina/ftpserver/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/pom.xml?rev=712867&r1=712866&r2=712867&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/pom.xml (original)
+++ mina/ftpserver/trunk/core/pom.xml Mon Nov 10 15:14:01 2008
@@ -56,7 +56,6 @@
</testResources>
<plugins>
<plugin>
- <!-- This is still very much work in progress -->
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.1</version>
@@ -82,7 +81,7 @@
org.apache.ftpserver.message.impl, org.apache.ftpserver.ssl.impl,
org.apache.ftpserver.usermanager.impl,
org.apache.ftpserver.util</Private-Package>
- <Import-Package>
+ <Import-Package>
org.springframework.beans.factory.config;resolution:=optional;version="2.5",
org.springframework.beans.factory.support;resolution:=optional;version="2.5",
org.springframework.beans.factory.xml;resolution:=optional;version="2.5",
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/UserManagerBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/UserManagerBeanDefinitionParser.java?rev=712867&r1=712866&r2=712867&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/UserManagerBeanDefinitionParser.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/UserManagerBeanDefinitionParser.java Mon Nov 10 15:14:01 2008
@@ -76,7 +76,12 @@
}
if (factoryClass == PropertiesUserManagerFactory.class) {
- factoryBuilder.addPropertyValue("file", element.getAttribute("file"));
+ if (StringUtils.hasText(element.getAttribute("file"))) {
+ factoryBuilder.addPropertyValue("file", element.getAttribute("file"));
+ }
+ if (StringUtils.hasText(element.getAttribute("url"))) {
+ factoryBuilder.addPropertyValue("url", element.getAttribute("url"));
+ }
} else {
Element dsElm = SpringUtil.getChildElement(element,
FtpServerNamespaceHandler.FTPSERVER_NS, "data-source");
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/PropertiesUserManagerFactory.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/PropertiesUserManagerFactory.java?rev=712867&r1=712866&r2=712867&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/PropertiesUserManagerFactory.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/PropertiesUserManagerFactory.java Mon Nov 10 15:14:01 2008
@@ -20,6 +20,7 @@
package org.apache.ftpserver.usermanager;
import java.io.File;
+import java.net.URL;
import org.apache.ftpserver.ftplet.UserManager;
import org.apache.ftpserver.usermanager.impl.PropertiesUserManager;
@@ -32,21 +33,28 @@
*/
public class PropertiesUserManagerFactory implements UserManagerFactory {
-
-
private String adminName = "admin";
-
+
private File userDataFile;
-
+
+ private URL userDataURL;
+
private PasswordEncryptor passwordEncryptor = new Md5PasswordEncryptor();
/**
* Creates a {@link PropertiesUserManager} instance based on the provided configuration
*/
public UserManager createUserManager() {
- return new PropertiesUserManager(passwordEncryptor, userDataFile, adminName);
+ if (userDataURL != null) {
+ return new PropertiesUserManager(passwordEncryptor, userDataURL,
+ adminName);
+ } else {
+
+ return new PropertiesUserManager(passwordEncryptor, userDataFile,
+ adminName);
+ }
}
-
+
/**
* Get the admin name.
* @return The admin user name
@@ -65,7 +73,7 @@
public void setAdminName(String adminName) {
this.adminName = adminName;
}
-
+
/**
* Retrieve the file used to load and store users
* @return The file
@@ -84,17 +92,33 @@
this.userDataFile = propFile;
}
+ /**
+ * Retrieve the URL used to load and store users
+ * @return The {@link URL}
+ */
+ public URL getUrl() {
+ return userDataURL;
+ }
+
+ /**
+ * Set the URL used to store and read users.
+ *
+ * @param userDataURL
+ * A {@link URL} containing users
+ */
+ public void setUrl(URL userDataURL) {
+ this.userDataURL = userDataURL;
+ }
/**
* Retrieve the password encryptor used by user managers created by this factory
* @return The password encryptor. Default to {@link Md5PasswordEncryptor}
* if no other has been provided
- */
+ */
public PasswordEncryptor getPasswordEncryptor() {
return passwordEncryptor;
}
-
/**
* Set the password encryptor to use by user managers created by this factory
* @param passwordEncryptor The password encryptor
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/impl/PropertiesUserManager.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/impl/PropertiesUserManager.java?rev=712867&r1=712866&r2=712867&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/impl/PropertiesUserManager.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/usermanager/impl/PropertiesUserManager.java Mon Nov 10 15:14:01 2008
@@ -24,6 +24,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
@@ -133,7 +134,6 @@
public PropertiesUserManager(PasswordEncryptor passwordEncryptor,
File userDataFile, String adminName) {
super(adminName, passwordEncryptor);
- this.userDataFile = userDataFile;
try {
userDataProp = new BaseProperties();
@@ -142,6 +142,8 @@
LOG.debug("File configured, will try loading");
if(userDataFile.exists()) {
+ this.userDataFile = userDataFile;
+
LOG.debug("File found on file system");
FileInputStream fis = null;
try {
@@ -173,11 +175,41 @@
} catch (IOException e) {
throw new FtpServerConfigurationException(
"Error loading user data file : "
- + userDataFile.getAbsolutePath(), e);
+ + userDataFile, e);
}
}
/**
+ * Internal constructor, do not use directly. Use {@link PropertiesUserManagerFactory} instead.
+ */
+ public PropertiesUserManager(PasswordEncryptor passwordEncryptor,
+ URL userDataPath, String adminName) {
+ super(adminName, passwordEncryptor);
+
+ try {
+ userDataProp = new BaseProperties();
+
+ if (userDataPath != null) {
+ LOG.debug("URL configured, will try loading");
+
+ InputStream is = null;
+
+ is = userDataPath.openStream();
+
+ try {
+ userDataProp.load(is);
+ } finally {
+ IoUtils.close(is);
+ }
+ }
+ } catch (IOException e) {
+ throw new FtpServerConfigurationException(
+ "Error loading user data resource : "
+ + userDataPath, e);
+ }
+ }
+
+ /**
* Retrive the file backing this user manager
* @return The file
*/
Modified: mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/config/spring/ftpserver-1.0.xsd
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/config/spring/ftpserver-1.0.xsd?rev=712867&r1=712866&r2=712867&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/config/spring/ftpserver-1.0.xsd (original)
+++ mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/config/spring/ftpserver-1.0.xsd Mon Nov 10 15:14:01 2008
@@ -162,7 +162,8 @@
<!-- Element used to configure a file based user manager -->
<xs:element name="file-user-manager">
<xs:complexType>
- <xs:attribute name="file" use="required" type="xs:string" />
+ <xs:attribute name="file" type="xs:string" />
+ <xs:attribute name="url" type="xs:string" />
<xs:attribute name="encrypt-passwords">
<xs:simpleType>
<xs:restriction base="xs:string">