true
if the server is stopped
*/
boolean isStopped();
@@ -60,8 +61,8 @@ public interface FtpServer {
/**
* Is the server suspended
+ *
* @return true
if the server is suspended
*/
boolean isSuspended();
-
}
diff --git a/core/src/main/java/org/apache/ftpserver/Version.java b/core/src/main/java/org/apache/ftpserver/Version.java
index db7c4512..eefac9ba 100644
--- a/core/src/main/java/org/apache/ftpserver/Version.java
+++ b/core/src/main/java/org/apache/ftpserver/Version.java
@@ -24,31 +24,33 @@
import java.io.UncheckedIOException;
import java.util.Properties;
-import org.apache.ftpserver.util.IoUtils;
-
/**
* Provides the version of this release of FtpServer
*
* @author Apache MINA Project
*/
public class Version {
+ /**
+ * A private constructor: this class should not be instanciated
+ */
+ private Version() {
+ // Nothing to do
+ }
/**
* Get the version of this FtpServer
+ *
* @return The current version
*/
public static String getVersion() {
- Properties props = new Properties();
- InputStream in = null;
-
- try {
- in = Version.class.getClassLoader().getResourceAsStream("org/apache/ftpserver/ftpserver.properties");
+ try (InputStream in = Version.class.getClassLoader().
+ getResourceAsStream("org/apache/ftpserver/ftpserver.properties")) {
+ Properties props = new Properties();
props.load(in);
+
return props.getProperty("ftpserver.version");
} catch (IOException e) {
throw new UncheckedIOException("Failed to read version", e);
- } finally {
- IoUtils.close(in);
}
}
}
diff --git a/core/src/main/java/org/apache/ftpserver/command/AbstractCommand.java b/core/src/main/java/org/apache/ftpserver/command/AbstractCommand.java
index bdfd0da8..840abcb4 100644
--- a/core/src/main/java/org/apache/ftpserver/command/AbstractCommand.java
+++ b/core/src/main/java/org/apache/ftpserver/command/AbstractCommand.java
@@ -26,5 +26,8 @@
* @author Apache MINA Project
*/
public abstract class AbstractCommand implements Command {
-
+ /** potected constructor */
+ protected AbstractCommand() {
+ // Nothing to do
+ }
}
diff --git a/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java b/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java
index 5e7af9d8..ec54868b 100644
--- a/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java
+++ b/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java
@@ -164,13 +164,19 @@ public class CommandFactoryFactory {
/** A flag indicating of we have non-default commands */
private boolean useDefaultCommands = true;
+ /**
+ * Create a CommandFactoryFactory instance
+ */
+ public CommandFactoryFactory() {
+ // Nothing to do
+ }
+
/**
* Create an {@link CommandFactory} based on the configuration on the factory.
*
* @return The {@link CommandFactory}
*/
public CommandFactory createCommandFactory() {
-
Map* Formats files according to the LIST specification * * @author Apache MINA Project */ public class LISTFileFormater implements FileFormater { - + /** The delimiter, default to space */ private static final char DELIM = ' '; - private static final char[] NEWLINE = { '\r', '\n' }; - /** - * @see FileFormater#format(FtpFile) - * + * Create a LISTFileFormater insance + */ + public LISTFileFormater() { + // Nothing to do + } + /** * {@inheritDoc} */ public String format(FtpFile file) { @@ -58,7 +61,7 @@ public String format(FtpFile file) { sb.append(getLastModified(file)); sb.append(DELIM); sb.append(file.getName()); - sb.append(NEWLINE); + sb.append(StringUtils.NEWLINE); return sb.toString(); } @@ -69,13 +72,17 @@ public String format(FtpFile file) { private String getLength(FtpFile file) { String initStr = " "; long sz = 0; + if (file.isFile()) { sz = file.getSize(); } + String szStr = String.valueOf(sz); + if (szStr.length() > initStr.length()) { return szStr; } + return initStr.substring(0, initStr.length() - szStr.length()) + szStr; } @@ -97,6 +104,7 @@ private char[] getPermission(FtpFile file) { permission[1] = file.isReadable() ? 'r' : '-'; permission[2] = file.isWritable() ? 'w' : '-'; permission[3] = file.isDirectory() ? 'x' : '-'; + return permission; } } diff --git a/core/src/main/java/org/apache/ftpserver/command/impl/listing/ListArgument.java b/core/src/main/java/org/apache/ftpserver/command/impl/listing/ListArgument.java index 6370b851..cd8574e1 100644 --- a/core/src/main/java/org/apache/ftpserver/command/impl/listing/ListArgument.java +++ b/core/src/main/java/org/apache/ftpserver/command/impl/listing/ListArgument.java @@ -20,7 +20,7 @@ /** * Internal class, do not use directly. - * + *
* Contains the parsed argument for a list command (e.g. LIST or NLST) * * @author Apache MINA Project @@ -34,16 +34,16 @@ public class ListArgument { private final char[] options; /** - * @param file - * The file path including the directory - * @param pattern - * A regular expression pattern that files must match - * @param options - * List options, such as -la + * Create a ListArgument instance + * + * @param file The file path including the directory + * @param pattern A regular expression pattern that files must match + * @param options List options, such as -la */ public ListArgument(String file, String pattern, char[] options) { this.file = file; this.pattern = pattern; + if (options == null) { this.options = new char[0]; } else { @@ -94,5 +94,4 @@ public boolean hasOption(char option) { public String getFile() { return file; } - } diff --git a/core/src/main/java/org/apache/ftpserver/command/impl/listing/ListArgumentParser.java b/core/src/main/java/org/apache/ftpserver/command/impl/listing/ListArgumentParser.java index 57ec0232..62bbe0de 100644 --- a/core/src/main/java/org/apache/ftpserver/command/impl/listing/ListArgumentParser.java +++ b/core/src/main/java/org/apache/ftpserver/command/impl/listing/ListArgumentParser.java @@ -22,21 +22,25 @@ /** * Internal class, do not use directly. - * + *
* Parses a list argument (e.g. for LIST or NLST) into a {@link ListArgument} * * @author Apache MINA Project */ public class ListArgumentParser { + /** + * A private constructor + */ + private ListArgumentParser() { + // Nothing to do + } /** * Parse the argument * - * @param argument - * The argument string + * @param argument The argument string * @return The parsed argument - * @throws IllegalArgumentException - * If the argument string is incorrectly formated + * @throws IllegalArgumentException If the argument string is incorrectly formated */ public static ListArgument parse(String argument) { String file = "./"; @@ -49,6 +53,7 @@ public static ListArgument parse(String argument) { StringBuilder optionsSb = new StringBuilder(4); StringBuilder fileSb = new StringBuilder(16); StringTokenizer st = new StringTokenizer(argument, " ", true); + while (st.hasMoreTokens()) { String token = st.nextToken(); @@ -73,10 +78,12 @@ public static ListArgument parse(String argument) { if (fileSb.length() != 0) { file = fileSb.toString(); } + options = optionsSb.toString(); } int slashIndex = file.lastIndexOf('/'); + if (slashIndex == -1) { if (containsPattern(file)) { pattern = file; @@ -91,8 +98,7 @@ public static ListArgument parse(String argument) { } if (containsPattern(file)) { - throw new IllegalArgumentException( - "Directory path can not contain regular expression"); + throw new IllegalArgumentException("Directory path can not contain regular expression"); } } @@ -104,8 +110,6 @@ public static ListArgument parse(String argument) { } private static boolean containsPattern(String file) { - return file.indexOf('*') > -1 || file.indexOf('?') > -1 - || file.indexOf('[') > -1; - + return file.indexOf('*') > -1 || file.indexOf('?') > -1 || file.indexOf('[') > -1; } } diff --git a/core/src/main/java/org/apache/ftpserver/command/impl/listing/MLSTFileFormater.java b/core/src/main/java/org/apache/ftpserver/command/impl/listing/MLSTFileFormater.java index f212eff7..711356f0 100644 --- a/core/src/main/java/org/apache/ftpserver/command/impl/listing/MLSTFileFormater.java +++ b/core/src/main/java/org/apache/ftpserver/command/impl/listing/MLSTFileFormater.java @@ -20,26 +20,26 @@ import org.apache.ftpserver.ftplet.FtpFile; import org.apache.ftpserver.util.DateUtils; +import org.apache.ftpserver.util.StringUtils; /** * Internal class, do not use directly. - * + *
* Formats files according to the MLST specification * * @author Apache MINA Project */ public class MLSTFileFormater implements FileFormater { + /** The default types */ + private static final String[] DEFAULT_TYPES = new String[] { "Size", "Modify", "Type" }; - private static final String[] DEFAULT_TYPES = new String[] { "Size", - "Modify", "Type" }; - - private static final char[] NEWLINE = { '\r', '\n' }; - + /** The selected types default value */ private String[] selectedTypes = DEFAULT_TYPES; /** - * @param selectedTypes - * The types to show in the formated file + * Create an instance + * + * @param selectedTypes The types to show in the formated file */ public MLSTFileFormater(String[] selectedTypes) { if (selectedTypes != null) { @@ -48,60 +48,62 @@ public MLSTFileFormater(String[] selectedTypes) { } /** - * @see FileFormater#format(FtpFile) - * * {@inheritDoc} */ public String format(FtpFile file) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < selectedTypes.length; ++i) { - String type = selectedTypes[i]; - if (type.equalsIgnoreCase("size")) { - sb.append("Size="); - sb.append(String.valueOf(file.getSize())); - sb.append(';'); - } else if (type.equalsIgnoreCase("modify")) { - String timeStr = DateUtils.getFtpDate(file.getLastModified()); - sb.append("Modify="); - sb.append(timeStr); - sb.append(';'); - } else if (type.equalsIgnoreCase("type")) { - if (file.isFile()) { - sb.append("Type=file;"); - } else if (file.isDirectory()) { - sb.append("Type=dir;"); - } - } else if (type.equalsIgnoreCase("perm")) { - sb.append("Perm="); - if (file.isReadable()) { + for (String selectedType:selectedTypes) { + switch (selectedType.toUpperCase()) { + case "SIZE": + sb.append("Size="); + sb.append(String.valueOf(file.getSize())); + sb.append(';'); + break; + + case "MODIFY": + String timeStr = DateUtils.getFtpDate(file.getLastModified()); + sb.append("Modify="); + sb.append(timeStr); + sb.append(';'); + break; + + case "TYPE": if (file.isFile()) { - sb.append('r'); + sb.append("Type=file;"); } else if (file.isDirectory()) { - sb.append('e'); - sb.append('l'); + sb.append("Type=dir;"); } - } - if (file.isWritable()) { - if (file.isFile()) { - sb.append('a'); - sb.append('d'); - sb.append('f'); - sb.append('w'); - } else if (file.isDirectory()) { - sb.append('f'); - sb.append('p'); - sb.append('c'); - sb.append('m'); + + break; + + default: + sb.append("Perm="); + + if (file.isReadable()) { + if (file.isFile()) { + sb.append('r'); + } else if (file.isDirectory()) { + sb.append("el"); + } + } + + if (file.isWritable()) { + if (file.isFile()) { + sb.append("adfw"); + } else if (file.isDirectory()) { + sb.append("fpcm"); + } } - } - sb.append(';'); + + sb.append(';'); + break; } } + sb.append(' '); sb.append(file.getName()); - - sb.append(NEWLINE); + sb.append(StringUtils.NEWLINE); return sb.toString(); } diff --git a/core/src/main/java/org/apache/ftpserver/command/impl/listing/NLSTFileFormater.java b/core/src/main/java/org/apache/ftpserver/command/impl/listing/NLSTFileFormater.java index 692bb63e..8320decd 100644 --- a/core/src/main/java/org/apache/ftpserver/command/impl/listing/NLSTFileFormater.java +++ b/core/src/main/java/org/apache/ftpserver/command/impl/listing/NLSTFileFormater.java @@ -19,27 +19,28 @@ package org.apache.ftpserver.command.impl.listing; import org.apache.ftpserver.ftplet.FtpFile; +import org.apache.ftpserver.util.StringUtils; /** * Internal class, do not use directly. - * + *
* Formats files according to the NLST specification
*
* @author Apache MINA Project
*/
public class NLSTFileFormater implements FileFormater {
-
- private static final char[] NEWLINE = { '\r', '\n' };
+ /** Public constructor */
+ public NLSTFileFormater() {
+ // Nothing to do
+ }
/**
- * @see FileFormater#format(FtpFile)
- *
* {@inheritDoc}
*/
public String format(FtpFile file) {
StringBuilder sb = new StringBuilder();
sb.append(file.getName());
- sb.append(NEWLINE);
+ sb.append(StringUtils.NEWLINE);
return sb.toString();
}
diff --git a/core/src/main/java/org/apache/ftpserver/command/impl/listing/RegexFileFilter.java b/core/src/main/java/org/apache/ftpserver/command/impl/listing/RegexFileFilter.java
index eda113eb..0bcefae9 100644
--- a/core/src/main/java/org/apache/ftpserver/command/impl/listing/RegexFileFilter.java
+++ b/core/src/main/java/org/apache/ftpserver/command/impl/listing/RegexFileFilter.java
@@ -58,8 +58,6 @@ public RegexFileFilter(String regex, FileFilter wrappedFilter) {
}
/**
- * @see FileFilter#accept(FtpFile)
- *
* {@inheritDoc}
*/
public boolean accept(FtpFile file) {
diff --git a/core/src/main/java/org/apache/ftpserver/command/impl/listing/VisibleFileFilter.java b/core/src/main/java/org/apache/ftpserver/command/impl/listing/VisibleFileFilter.java
index 20f39bf4..58d66413 100644
--- a/core/src/main/java/org/apache/ftpserver/command/impl/listing/VisibleFileFilter.java
+++ b/core/src/main/java/org/apache/ftpserver/command/impl/listing/VisibleFileFilter.java
@@ -28,7 +28,7 @@
* @author Apache MINA Project
*/
public class VisibleFileFilter implements FileFilter {
-
+ /** The wrapped filter */
private final FileFilter wrappedFilter;
/**
@@ -41,16 +41,13 @@ public VisibleFileFilter() {
/**
* Constructor with a wrapped filter, allows for chaining filters
*
- * @param wrappedFilter
- * The {@link FileFilter} to wrap
+ * @param wrappedFilter The {@link FileFilter} to wrap
*/
public VisibleFileFilter(FileFilter wrappedFilter) {
this.wrappedFilter = wrappedFilter;
}
/**
- * @see FileFilter#accept(FtpFile)
- *
* {@inheritDoc}
*/
public boolean accept(FtpFile file) {
diff --git a/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java b/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java
index e1700428..5c8cff4a 100644
--- a/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java
+++ b/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java
@@ -37,8 +37,13 @@
*
* @author Apache MINA Project
*/
-public class CommandFactoryBeanDefinitionParser extends
- AbstractSingleBeanDefinitionParser {
+public class CommandFactoryBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
+ /**
+ * A CommandFactoryBeanDefinitionParser constrcutor
+ */
+ public CommandFactoryBeanDefinitionParser() {
+ super();
+ }
/**
* {@inheritDoc}
@@ -52,10 +57,8 @@ protected Class extends CommandFactory> getBeanClass(final Element element) {
* {@inheritDoc}
*/
@Override
- protected void doParse(final Element element,
- final ParserContext parserContext,
- final BeanDefinitionBuilder builder) {
-
+ protected void doParse(final Element element, final ParserContext parserContext,
+ final BeanDefinitionBuilder builder) {
BeanDefinitionBuilder factoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(CommandFactoryFactory.class);
ManagedMap commands = new ManagedMap();
@@ -64,16 +67,14 @@ protected void doParse(final Element element,
for (Element commandElm : childs) {
String name = commandElm.getAttribute("name");
- Object bean = SpringUtil.parseSpringChildElement(commandElm,
- parserContext, builder);
+ Object bean = SpringUtil.parseSpringChildElement(commandElm, parserContext, builder);
commands.put(name, bean);
}
factoryBuilder.addPropertyValue("commandMap", commands);
if (StringUtils.hasText(element.getAttribute("use-default"))) {
- factoryBuilder.addPropertyValue("useDefaultCommands", Boolean
- .valueOf(element.getAttribute("use-default")));
+ factoryBuilder.addPropertyValue("useDefaultCommands", Boolean.valueOf(element.getAttribute("use-default")));
}
BeanDefinition factoryDefinition = factoryBuilder.getBeanDefinition();
@@ -85,6 +86,5 @@ protected void doParse(final Element element,
// set the factory on the listener bean
builder.getRawBeanDefinition().setFactoryBeanName(factoryId);
builder.getRawBeanDefinition().setFactoryMethodName("createCommandFactory");
-
}
}
diff --git a/core/src/main/java/org/apache/ftpserver/config/spring/FileSystemBeanDefinitionParser.java b/core/src/main/java/org/apache/ftpserver/config/spring/FileSystemBeanDefinitionParser.java
index a35db35d..b09a8dc8 100644
--- a/core/src/main/java/org/apache/ftpserver/config/spring/FileSystemBeanDefinitionParser.java
+++ b/core/src/main/java/org/apache/ftpserver/config/spring/FileSystemBeanDefinitionParser.java
@@ -32,15 +32,19 @@
*
* @author Apache MINA Project
*/
-public class FileSystemBeanDefinitionParser extends
- AbstractSingleBeanDefinitionParser {
+public class FileSystemBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
+ /**
+ * Create a FileSystemBeanDefinitionParser instance
+ */
+ public FileSystemBeanDefinitionParser() {
+ super();
+ }
/**
* {@inheritDoc}
*/
@Override
- protected Class extends FileSystemFactory> getBeanClass(
- final Element element) {
+ protected Class extends FileSystemFactory> getBeanClass(final Element element) {
return NativeFileSystemFactory.class;
}
@@ -48,16 +52,14 @@ protected Class extends FileSystemFactory> getBeanClass(
* {@inheritDoc}
*/
@Override
- protected void doParse(final Element element,
- final ParserContext parserContext,
+ protected void doParse(final Element element, final ParserContext parserContext,
final BeanDefinitionBuilder builder) {
if (StringUtils.hasText(element.getAttribute("case-insensitive"))) {
- builder.addPropertyValue("caseInsensitive", Boolean
- .valueOf(element.getAttribute("case-insensitive")));
+ builder.addPropertyValue("caseInsensitive", Boolean.valueOf(element.getAttribute("case-insensitive")));
}
+
if (StringUtils.hasText(element.getAttribute("create-home"))) {
- builder.addPropertyValue("createHome", Boolean
- .valueOf(element.getAttribute("create-home")));
+ builder.addPropertyValue("createHome", Boolean.valueOf(element.getAttribute("create-home")));
}
}
}
diff --git a/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java b/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java
index 02de6b30..b85de028 100644
--- a/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java
+++ b/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java
@@ -44,11 +44,16 @@
*
* @author Apache MINA Project
*/
-public class ListenerBeanDefinitionParser extends
- AbstractSingleBeanDefinitionParser {
+public class ListenerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
+ /** Class logger */
+ private final Logger LOG = LoggerFactory.getLogger(ListenerBeanDefinitionParser.class);
- private final Logger LOG = LoggerFactory
- .getLogger(ListenerBeanDefinitionParser.class);
+ /**
+ * Create a ListenerBeanDefinitionParser instance
+ */
+ public ListenerBeanDefinitionParser() {
+ super();
+ }
/**
* {@inheritDoc}
@@ -65,15 +70,14 @@ protected Class> getBeanClass(final Element element) {
protected void doParse(final Element element,
final ParserContext parserContext,
final BeanDefinitionBuilder builder) {
-
BeanDefinitionBuilder factoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(ListenerFactory.class);
if (StringUtils.hasText(element.getAttribute("port"))) {
- factoryBuilder.addPropertyValue("port", Integer.valueOf(element
- .getAttribute("port")));
+ factoryBuilder.addPropertyValue("port", Integer.valueOf(element.getAttribute("port")));
}
SslConfiguration ssl = parseSsl(element);
+
if (ssl != null) {
factoryBuilder.addPropertyValue("sslConfiguration", ssl);
}
@@ -84,23 +88,24 @@ protected void doParse(final Element element,
factoryBuilder.addPropertyValue("dataConnectionConfiguration", dc);
if (StringUtils.hasText(element.getAttribute("idle-timeout"))) {
- factoryBuilder.addPropertyValue("idleTimeout", SpringUtil.parseInt(
- element, "idle-timeout", 300));
+ factoryBuilder.addPropertyValue("idleTimeout", SpringUtil.parseInt(element, "idle-timeout", 300));
}
- String localAddress = SpringUtil.parseStringFromInetAddress(element,
- "local-address");
+ String localAddress = SpringUtil.parseStringFromInetAddress(element, "local-address");
+
if (localAddress != null) {
factoryBuilder.addPropertyValue("serverAddress", localAddress);
}
- factoryBuilder.addPropertyValue("implicitSsl", SpringUtil.parseBoolean(
- element, "implicit-ssl", false));
+
+ factoryBuilder.addPropertyValue("implicitSsl", SpringUtil.parseBoolean( element, "implicit-ssl", false));
Element blacklistElm = SpringUtil.getChildElement(element,
FtpServerNamespaceHandler.FTPSERVER_NS, "blacklist");
+
if (blacklistElm != null) {
LOG.warn("Element 'blacklist' is deprecated, and may be removed in a future release. "
+ "Please use 'remote-ip-filter' instead. ");
+
try {
RemoteIpFilter remoteIpFilter = new RemoteIpFilter(IpFilterType.DENY,
blacklistElm.getTextContent());
@@ -114,18 +119,20 @@ protected void doParse(final Element element,
Element remoteIpFilterElement = SpringUtil.getChildElement(element,
FtpServerNamespaceHandler.FTPSERVER_NS, "remote-ip-filter");
+
if (remoteIpFilterElement != null) {
if (blacklistElm != null) {
throw new FtpServerConfigurationException(
"Element 'remote-ip-filter' may not be used when 'blacklist' element is specified. ");
}
+
String filterType = remoteIpFilterElement.getAttribute("type");
+
try {
RemoteIpFilter remoteIpFilter = new RemoteIpFilter(IpFilterType
.parse(filterType), remoteIpFilterElement
.getTextContent());
- factoryBuilder
- .addPropertyValue("sessionFilter", remoteIpFilter);
+ factoryBuilder.addPropertyValue("sessionFilter", remoteIpFilter);
} catch (UnknownHostException e) {
throw new IllegalArgumentException(
"Invalid IP address or subnet in the 'remote-ip-filter' element");
@@ -145,38 +152,38 @@ protected void doParse(final Element element,
}
private SslConfiguration parseSsl(final Element parent) {
- Element sslElm = SpringUtil.getChildElement(parent,
- FtpServerNamespaceHandler.FTPSERVER_NS, "ssl");
+ Element sslElm = SpringUtil.getChildElement(parent, FtpServerNamespaceHandler.FTPSERVER_NS, "ssl");
if (sslElm != null) {
SslConfigurationFactory ssl = new SslConfigurationFactory();
Element keyStoreElm = SpringUtil.getChildElement(sslElm,
FtpServerNamespaceHandler.FTPSERVER_NS, "keystore");
+
if (keyStoreElm != null) {
ssl.setKeystoreFile(SpringUtil.parseFile(keyStoreElm, "file"));
- ssl.setKeystorePassword(SpringUtil.parseString(keyStoreElm,
- "password"));
+ ssl.setKeystorePassword(SpringUtil.parseString(keyStoreElm, "password"));
String type = SpringUtil.parseString(keyStoreElm, "type");
+
if (type != null) {
ssl.setKeystoreType(type);
}
- String keyAlias = SpringUtil.parseString(keyStoreElm,
- "key-alias");
+ String keyAlias = SpringUtil.parseString(keyStoreElm, "key-alias");
+
if (keyAlias != null) {
ssl.setKeyAlias(keyAlias);
}
- String keyPassword = SpringUtil.parseString(keyStoreElm,
- "key-password");
+ String keyPassword = SpringUtil.parseString(keyStoreElm, "key-password");
+
if (keyPassword != null) {
ssl.setKeyPassword(keyPassword);
}
- String algorithm = SpringUtil.parseString(keyStoreElm,
- "algorithm");
+ String algorithm = SpringUtil.parseString(keyStoreElm, "algorithm");
+
if (algorithm != null) {
ssl.setKeystoreAlgorithm(algorithm);
}
@@ -184,32 +191,32 @@ private SslConfiguration parseSsl(final Element parent) {
Element trustStoreElm = SpringUtil.getChildElement(sslElm,
FtpServerNamespaceHandler.FTPSERVER_NS, "truststore");
+
if (trustStoreElm != null) {
- ssl.setTruststoreFile(SpringUtil.parseFile(trustStoreElm,
- "file"));
- ssl.setTruststorePassword(SpringUtil.parseString(trustStoreElm,
- "password"));
+ ssl.setTruststoreFile(SpringUtil.parseFile(trustStoreElm, "file"));
+ ssl.setTruststorePassword(SpringUtil.parseString(trustStoreElm, "password"));
String type = SpringUtil.parseString(trustStoreElm, "type");
+
if (type != null) {
ssl.setTruststoreType(type);
}
- String algorithm = SpringUtil.parseString(trustStoreElm,
- "algorithm");
+ String algorithm = SpringUtil.parseString(trustStoreElm, "algorithm");
+
if (algorithm != null) {
ssl.setTruststoreAlgorithm(algorithm);
}
}
- String clientAuthStr = SpringUtil.parseString(sslElm,
- "client-authentication");
+ String clientAuthStr = SpringUtil.parseString(sslElm, "client-authentication");
+
if (clientAuthStr != null) {
ssl.setClientAuthentication(clientAuthStr);
}
- String enabledCiphersuites = SpringUtil.parseString(sslElm,
- "enabled-ciphersuites");
+ String enabledCiphersuites = SpringUtil.parseString(sslElm, "enabled-ciphersuites");
+
if (enabledCiphersuites != null) {
ssl.setEnabledCipherSuites(enabledCiphersuites.split(" "));
}
@@ -224,7 +231,6 @@ private SslConfiguration parseSsl(final Element parent) {
} else {
return null;
}
-
}
private DataConnectionConfiguration parseDataConnection(
@@ -233,7 +239,6 @@ private DataConnectionConfiguration parseDataConnection(
DataConnectionConfigurationFactory dc = new DataConnectionConfigurationFactory();
if (element != null) {
-
dc.setImplicitSsl(SpringUtil.parseBoolean(element, "implicit-ssl", false));
// data con config element available
@@ -248,16 +253,14 @@ private DataConnectionConfiguration parseDataConnection(
Element activeElm = SpringUtil.getChildElement(element,
FtpServerNamespaceHandler.FTPSERVER_NS, "active");
+
if (activeElm != null) {
- dc.setActiveEnabled(SpringUtil.parseBoolean(activeElm, "enabled",
- true));
- dc.setActiveIpCheck(SpringUtil.parseBoolean(activeElm,
- "ip-check", false));
- dc.setActiveLocalPort(SpringUtil.parseInt(activeElm,
- "local-port", 0));
-
- String localAddress = SpringUtil.parseStringFromInetAddress(
- activeElm, "local-address");
+ dc.setActiveEnabled(SpringUtil.parseBoolean(activeElm, "enabled", true));
+ dc.setActiveIpCheck(SpringUtil.parseBoolean(activeElm, "ip-check", false));
+ dc.setActiveLocalPort(SpringUtil.parseInt(activeElm, "local-port", 0));
+
+ String localAddress = SpringUtil.parseStringFromInetAddress( activeElm, "local-address");
+
if (localAddress != null) {
dc.setActiveLocalAddress(localAddress);
}
@@ -265,25 +268,27 @@ private DataConnectionConfiguration parseDataConnection(
Element passiveElm = SpringUtil.getChildElement(element,
FtpServerNamespaceHandler.FTPSERVER_NS, "passive");
+
if (passiveElm != null) {
- String address = SpringUtil.parseStringFromInetAddress(passiveElm,
- "address");
+ String address = SpringUtil.parseStringFromInetAddress(passiveElm, "address");
+
if (address != null) {
dc.setPassiveAddress(address);
}
- String externalAddress = SpringUtil.parseStringFromInetAddress(
- passiveElm, "external-address");
+ String externalAddress = SpringUtil.parseStringFromInetAddress( passiveElm, "external-address");
+
if (externalAddress != null) {
dc.setPassiveExternalAddress(externalAddress);
}
String ports = SpringUtil.parseString(passiveElm, "ports");
+
if (ports != null) {
dc.setPassivePorts(ports);
}
- dc.setPassiveIpCheck(SpringUtil.parseBoolean(passiveElm,
- "ip-check", false));
+
+ dc.setPassiveIpCheck(SpringUtil.parseBoolean(passiveElm, "ip-check", false));
}
} else {
// no data conn config element, do we still have SSL config from the
@@ -296,5 +301,4 @@ private DataConnectionConfiguration parseDataConnection(
return dc.createDataConnectionConfiguration();
}
-
}
diff --git a/core/src/main/java/org/apache/ftpserver/config/spring/ServerBeanDefinitionParser.java b/core/src/main/java/org/apache/ftpserver/config/spring/ServerBeanDefinitionParser.java
index 033268ea..07731821 100644
--- a/core/src/main/java/org/apache/ftpserver/config/spring/ServerBeanDefinitionParser.java
+++ b/core/src/main/java/org/apache/ftpserver/config/spring/ServerBeanDefinitionParser.java
@@ -44,8 +44,13 @@
*
* @author Apache MINA Project
*/
-public class ServerBeanDefinitionParser extends
- AbstractSingleBeanDefinitionParser {
+public class ServerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
+ /**
+ * Create a ServerBeanDefinitionParser instance
+ */
+ public ServerBeanDefinitionParser() {
+ super();
+ }
/**
* {@inheritDoc}
@@ -66,50 +71,61 @@ protected void doParse(final Element element,
BeanDefinitionBuilder factoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(FtpServerFactory.class);
List
* File system view based on native file system. Here the root directory will be
* user virtual root (/).
*
@@ -41,7 +41,6 @@
public class NativeFileSystemView implements FileSystemView {
private final Logger LOG = LoggerFactory.getLogger(NativeFileSystemView.class);
-
// the root directory will always end with '/'.
private String rootDir;
@@ -57,6 +56,9 @@ public class NativeFileSystemView implements FileSystemView {
/**
* Constructor - internal do not use directly, use {@link NativeFileSystemFactory} instead
+ *
+ * @param user The current user
+ * @throws FtpException Actually, never thrown... To be removed!
*/
protected NativeFileSystemView(User user) throws FtpException {
this(user, false);
@@ -139,20 +141,22 @@ public FtpFile getFile(String file) {
public boolean changeWorkingDirectory(String dir) {
// not a directory - return false
- dir = getPhysicalName(rootDir, currDir, dir,
- caseInsensitive);
+ dir = getPhysicalName(rootDir, currDir, dir, caseInsensitive);
File dirObj = new File(dir);
+
if (!dirObj.isDirectory()) {
return false;
}
// strip user root and add last '/' if necessary
dir = dir.substring(rootDir.length() - 1);
+
if (dir.charAt(dir.length() - 1) != '/') {
dir = dir + '/';
}
currDir = dir;
+
return true;
}
@@ -173,20 +177,15 @@ public void dispose() {
* Get the physical canonical file name. It works like
* File.getCanonicalPath().
*
- * @param rootDir
- * The root directory.
- * @param currDir
- * The current directory. It will always be with respect to the
- * root directory.
- * @param fileName
- * The input file name.
- * @return The return string will always begin with the root directory. It
- * will never be null.
+ * @param rootDir The root directory.
+ * @param currDir The current directory. It will always be with respect to the root directory.
+ * @param fileName The input file name.
+ * @param caseInsensitive Tells if the file name case sensitivity should be considered or not
+ * @return The return string will always begin with the root directory. It will never be null.
*/
protected String getPhysicalName(final String rootDir,
final String currDir, final String fileName,
final boolean caseInsensitive) {
-
// normalize root dir
String normalizedRootDir = normalizeSeparateChar(rootDir);
normalizedRootDir = appendSlash(normalizedRootDir);
@@ -212,6 +211,7 @@ protected String getPhysicalName(final String rootDir,
// replace ., ~ and ..
// in this loop resArg will never end with '/'
StringTokenizer st = new StringTokenizer(normalizedFileName, "/");
+
while (st.hasMoreTokens()) {
String tok = st.nextToken();
@@ -222,6 +222,7 @@ protected String getPhysicalName(final String rootDir,
// .. => parent directory (if not root)
if (result.startsWith(normalizedRootDir)) {
int slashIndex = result.lastIndexOf('/');
+
if (slashIndex != -1) {
result = result.substring(0, slashIndex);
}
@@ -235,8 +236,7 @@ protected String getPhysicalName(final String rootDir,
if (caseInsensitive) {
// we're case insensitive, find a directory with the name, ignoring casing
- File[] matches = new File(result)
- .listFiles(new NameEqualsFileFilter(tok, true));
+ File[] matches = new File(result).listFiles(new NameEqualsFileFilter(tok, true));
if (matches != null && matches.length > 0) {
// found a file matching tok, replace tok for get the right casing
@@ -316,6 +316,7 @@ private String normalize(String path, String defaultPath) {
path = normalizeSeparateChar(path);
path = prependSlash(appendSlash(path));
+
return path;
}
}
diff --git a/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java b/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
index 2237ab52..3ec1ec96 100644
--- a/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
+++ b/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
@@ -60,12 +60,17 @@ public class NativeFtpFile implements FtpFile {
/**
* Constructor, internal do not use directly.
+ *
+ * @param fileName The file name
+ * @param file The file itself
+ * @param user The user
*/
protected NativeFtpFile(final String fileName, final File file,
final User user) {
if (fileName == null) {
throw new IllegalArgumentException("fileName can not be null");
}
+
if (file == null) {
throw new IllegalArgumentException("file can not be null");
}
diff --git a/core/src/main/java/org/apache/ftpserver/ftpletcontainer/impl/DefaultFtpletContainer.java b/core/src/main/java/org/apache/ftpserver/ftpletcontainer/impl/DefaultFtpletContainer.java
index 8fa98d97..00de5bef 100644
--- a/core/src/main/java/org/apache/ftpserver/ftpletcontainer/impl/DefaultFtpletContainer.java
+++ b/core/src/main/java/org/apache/ftpserver/ftpletcontainer/impl/DefaultFtpletContainer.java
@@ -37,24 +37,32 @@
/**
* Internal class, do not use directly.
- *
+ *
* This ftplet calls other ftplet methods and returns appropriate return value.
- *
+ *
* Internal class, do not use directly.
*
* @author Apache MINA Project
*/
public class DefaultFtpletContainer implements FtpletContainer {
+ /** The class logger */
+ private final Logger LOG = LoggerFactory.getLogger(DefaultFtpletContainer.class);
- private final Logger LOG = LoggerFactory
- .getLogger(DefaultFtpletContainer.class);
-
+ /** The contained FtpLets */
private final Map
* We can get the FTP data connection using this class. It uses either PORT or PASV command.
*
* @author Apache MINA Project
@@ -71,6 +71,12 @@ public class IODataConnectionFactory implements ServerDataConnectionFactory {
FtpIoSession session;
+ /**
+ * Create a IODataConnectionFactory instance
+ *
+ * @param serverContext The FTP server context
+ * @param session The FTP session
+ */
public IODataConnectionFactory(final FtpServerContext serverContext, final FtpIoSession session) {
this.session = session;
this.serverContext = serverContext;
diff --git a/core/src/main/java/org/apache/ftpserver/impl/LocalizedFtpReply.java b/core/src/main/java/org/apache/ftpserver/impl/LocalizedFtpReply.java
index 6a5bf7bb..dc17e19c 100644
--- a/core/src/main/java/org/apache/ftpserver/impl/LocalizedFtpReply.java
+++ b/core/src/main/java/org/apache/ftpserver/impl/LocalizedFtpReply.java
@@ -30,7 +30,17 @@
* @author Apache MINA Project
*/
public class LocalizedFtpReply extends DefaultFtpReply {
-
+ /**
+ * Provide a localized message
+ *
+ * @param session the FTP session for which a reply is to be sent
+ * @param request the FTP request object
+ * @param context the FTP server context
+ * @param code the reply code
+ * @param subId the ID of the sub message
+ * @param basicMsg the basic message
+ * @return the translated message
+ */
public static LocalizedFtpReply translate(FtpIoSession session, FtpRequest request,
FtpServerContext context, int code, String subId, String basicMsg) {
String msg = FtpReplyTranslator.translateMessage(session, request, context, code, subId,
@@ -42,10 +52,8 @@ public static LocalizedFtpReply translate(FtpIoSession session, FtpRequest reque
/**
* Creates a new instance of
* The max upload rate permission
*
* @author Apache MINA Project
@@ -35,34 +35,32 @@ public class ConcurrentLoginPermission implements Authority {
private final int maxConcurrentLoginsPerIP;
- public ConcurrentLoginPermission(int maxConcurrentLogins,
- int maxConcurrentLoginsPerIP) {
+ /**
+ * Create an instance
+ *
+ * @param maxConcurrentLogins The maximum number of concurren logins
+ * @param maxConcurrentLoginsPerIP The maximum number of concurren logins per IP
+ */
+ public ConcurrentLoginPermission(int maxConcurrentLogins, int maxConcurrentLoginsPerIP) {
this.maxConcurrentLogins = maxConcurrentLogins;
this.maxConcurrentLoginsPerIP = maxConcurrentLoginsPerIP;
}
/**
- * @see Authority#authorize(AuthorizationRequest)
- *
* {@inheritDoc}
*/
public AuthorizationRequest authorize(AuthorizationRequest request) {
if (request instanceof ConcurrentLoginRequest) {
ConcurrentLoginRequest concurrentLoginRequest = (ConcurrentLoginRequest) request;
- if (maxConcurrentLogins != 0
- && maxConcurrentLogins < concurrentLoginRequest
- .getConcurrentLogins()) {
+ if (maxConcurrentLogins != 0 && maxConcurrentLogins < concurrentLoginRequest.getConcurrentLogins()) {
return null;
} else if (maxConcurrentLoginsPerIP != 0
- && maxConcurrentLoginsPerIP < concurrentLoginRequest
- .getConcurrentLoginsFromThisIP()) {
+ && maxConcurrentLoginsPerIP < concurrentLoginRequest.getConcurrentLoginsFromThisIP()) {
return null;
} else {
- concurrentLoginRequest
- .setMaxConcurrentLogins(maxConcurrentLogins);
- concurrentLoginRequest
- .setMaxConcurrentLoginsPerIP(maxConcurrentLoginsPerIP);
+ concurrentLoginRequest.setMaxConcurrentLogins(maxConcurrentLogins);
+ concurrentLoginRequest.setMaxConcurrentLoginsPerIP(maxConcurrentLoginsPerIP);
return concurrentLoginRequest;
}
@@ -72,8 +70,6 @@ public AuthorizationRequest authorize(AuthorizationRequest request) {
}
/**
- * @see Authority#canAuthorize(AuthorizationRequest)
- *
* {@inheritDoc}
*/
public boolean canAuthorize(AuthorizationRequest request) {
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/impl/ConcurrentLoginRequest.java b/core/src/main/java/org/apache/ftpserver/usermanager/impl/ConcurrentLoginRequest.java
index f173f02c..34465271 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/impl/ConcurrentLoginRequest.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/impl/ConcurrentLoginRequest.java
@@ -23,7 +23,7 @@
/**
* Internal class, do not use directly.
- *
+ *
* Class representing a request to log in a number of concurrent times
*
* @author Apache MINA Project
@@ -39,11 +39,12 @@ public class ConcurrentLoginRequest implements AuthorizationRequest {
private int maxConcurrentLoginsPerIP = 0;
/**
- * @param concurrentLogins
- * @param concurrentLoginsFromThisIP
+ * Create a ConcurrentLoginRequest instance
+ *
+ * @param concurrentLogins Number of concurrent logins
+ * @param concurrentLoginsFromThisIP Number of concurrent logins for this IP address
*/
- public ConcurrentLoginRequest(int concurrentLogins,
- int concurrentLoginsFromThisIP) {
+ public ConcurrentLoginRequest(int concurrentLogins, int concurrentLoginsFromThisIP) {
super();
this.concurrentLogins = concurrentLogins;
this.concurrentLoginsFromThisIP = concurrentLoginsFromThisIP;
@@ -81,8 +82,7 @@ public int getMaxConcurrentLogins() {
/**
* Set the maximum allowed concurrent logins for this user
*
- * @param maxConcurrentLogins
- * Set max allowed concurrent connections
+ * @param maxConcurrentLogins Set max allowed concurrent connections
*/
void setMaxConcurrentLogins(int maxConcurrentLogins) {
this.maxConcurrentLogins = maxConcurrentLogins;
@@ -102,8 +102,7 @@ public int getMaxConcurrentLoginsPerIP() {
/**
* Set the maximum allowed concurrent logins per IP for this user
*
- * @param maxConcurrentLoginsPerIP
- * Set max allowed concurrent connections per IP
+ * @param maxConcurrentLoginsPerIP Set max allowed concurrent connections per IP
*/
void setMaxConcurrentLoginsPerIP(int maxConcurrentLoginsPerIP) {
this.maxConcurrentLoginsPerIP = maxConcurrentLoginsPerIP;
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/impl/DbUserManager.java b/core/src/main/java/org/apache/ftpserver/usermanager/impl/DbUserManager.java
index 908cec36..37b691b7 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/impl/DbUserManager.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/impl/DbUserManager.java
@@ -55,7 +55,7 @@
* @author Apache MINA Project
*/
public class DbUserManager extends AbstractUserManager {
-
+ /** The class logger */
private final Logger LOG = LoggerFactory.getLogger(DbUserManager.class);
private String insertUserStmt;
@@ -124,8 +124,7 @@ public DataSource getDataSource() {
/**
* Set the data source to be used by the user manager
*
- * @param dataSource
- * The data source to use
+ * @param dataSource The data source to use
*/
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
@@ -144,8 +143,7 @@ public String getSqlUserInsert() {
* Set the SQL INSERT statement used to add a new user. All the dynamic
* values will be replaced during runtime.
*
- * @param sql
- * The SQL statement
+ * @param sql The SQL statement
*/
public void setSqlUserInsert(String sql) {
insertUserStmt = sql;
@@ -164,8 +162,7 @@ public String getSqlUserDelete() {
* Set the SQL DELETE statement used to delete an existing user. All the
* dynamic values will be replaced during runtime.
*
- * @param sql
- * The SQL statement
+ * @param sql The SQL statement
*/
public void setSqlUserDelete(String sql) {
deleteUserStmt = sql;
@@ -184,8 +181,7 @@ public String getSqlUserUpdate() {
* Set the SQL UPDATE statement used to update an existing user. All the
* dynamic values will be replaced during runtime.
*
- * @param sql
- * The SQL statement
+ * @param sql The SQL statement
*/
public void setSqlUserUpdate(String sql) {
updateUserStmt = sql;
@@ -224,8 +220,7 @@ public String getSqlUserSelectAll() {
* Set the SQL SELECT statement used to select all user ids. All the dynamic
* values will be replaced during runtime.
*
- * @param sql
- * The SQL statement
+ * @param sql The SQL statement
*/
public void setSqlUserSelectAll(String sql) {
selectAllStmt = sql;
@@ -244,8 +239,7 @@ public String getSqlUserAuthenticate() {
* Set the SQL SELECT statement used to authenticate user. All the dynamic
* values will be replaced during runtime.
*
- * @param sql
- * The SQL statement
+ * @param sql The SQL statement
*/
public void setSqlUserAuthenticate(String sql) {
authenticateStmt = sql;
@@ -265,8 +259,7 @@ public String getSqlUserAdmin() {
* Set the SQL SELECT statement used to find whether an user is admin or
* not. All the dynamic values will be replaced during runtime.
*
- * @param sql
- * The SQL statement
+ * @param sql The SQL statement
*/
public void setSqlUserAdmin(String sql) {
isAdminStmt = sql;
@@ -290,7 +283,8 @@ public boolean isAdmin(String login) throws FtpException {
// execute query
try (Statement stmt = createConnection().createStatement();
- ResultSet rs = stmt.executeQuery(sql)) {
+ ResultSet rs = stmt.executeQuery(sql)) {
+
return rs.next();
} catch (SQLException ex) {
LOG.error("DbUserManager.isAdmin()", ex);
@@ -300,6 +294,9 @@ public boolean isAdmin(String login) throws FtpException {
/**
* Open connection to database.
+ *
+ * @return The oepned connection
+ * @throws SQLException If the connection can't be created
*/
protected Connection createConnection() throws SQLException {
Connection connection = dataSource.getConnection();
@@ -310,8 +307,6 @@ protected Connection createConnection() throws SQLException {
/**
- * Delete user. Delete the row from the table.
- *
* {@inheritDoc}
*/
public void delete(String name) throws FtpException {
@@ -331,8 +326,6 @@ public void delete(String name) throws FtpException {
}
/**
- * Save user. If new insert a new row, else update the existing row.
- *
* {@inheritDoc}
*/
public void save(User user) throws FtpException {
@@ -432,6 +425,7 @@ private BaseUser selectUserByName(String name) throws SQLException {
// execute query
try (Statement stmt = createConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
+
// populate user object
BaseUser thisUser = null;
@@ -464,13 +458,10 @@ private BaseUser selectUserByName(String name) throws SQLException {
}
/**
- * Get the user object. Fetch the row from the table.
- *
* {@inheritDoc}
*/
public User getUserByName(String name) throws FtpException {
try {
-
BaseUser user = selectUserByName(name);
if (user != null) {
@@ -486,8 +477,6 @@ public User getUserByName(String name) throws FtpException {
}
/**
- * User existance check.
- *
* {@inheritDoc}
*/
public boolean doesExist(String name) throws FtpException {
@@ -500,6 +489,7 @@ public boolean doesExist(String name) throws FtpException {
// execute query
try (Statement stmt = createConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
+
return rs.next();
} catch (SQLException ex) {
LOG.error("DbUserManager.doesExist()", ex);
@@ -508,8 +498,6 @@ public boolean doesExist(String name) throws FtpException {
}
/**
- * Get all user names from the database.
- *
* {@inheritDoc}
*/
public String[] getAllUserNames() throws FtpException {
@@ -535,8 +523,6 @@ public String[] getAllUserNames() throws FtpException {
}
/**
- * User authentication.
- *
* {@inheritDoc}
*/
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
@@ -563,6 +549,7 @@ public User authenticate(Authentication authentication) throws AuthenticationFai
// execute query
try (Statement stmt = createConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
+
if (rs.next()) {
try {
String storedPassword = rs.getString(ATTR_PASSWORD);
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/impl/TransferRatePermission.java b/core/src/main/java/org/apache/ftpserver/usermanager/impl/TransferRatePermission.java
index fea29c52..058d01a7 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/impl/TransferRatePermission.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/impl/TransferRatePermission.java
@@ -24,7 +24,7 @@
/**
* Internal class, do not use directly.
- *
+ *
* The max upload rate permission
*
* @author Apache MINA Project
@@ -35,14 +35,18 @@ public class TransferRatePermission implements Authority {
private int maxUploadRate;
+ /**
+ * Create a TransferRatePermission istance
+ *
+ * @param maxDownloadRate Maximum download rate
+ * @param maxUploadRate Maximum upload rate
+ */
public TransferRatePermission(int maxDownloadRate, int maxUploadRate) {
this.maxDownloadRate = maxDownloadRate;
this.maxUploadRate = maxUploadRate;
}
/**
- * @see Authority#authorize(AuthorizationRequest)
- *
* {@inheritDoc}
*/
public AuthorizationRequest authorize(AuthorizationRequest request) {
@@ -59,8 +63,6 @@ public AuthorizationRequest authorize(AuthorizationRequest request) {
}
/**
- * @see Authority#canAuthorize(AuthorizationRequest)
- *
* {@inheritDoc}
*/
public boolean canAuthorize(AuthorizationRequest request) {
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/impl/TransferRateRequest.java b/core/src/main/java/org/apache/ftpserver/usermanager/impl/TransferRateRequest.java
index 857a22de..7c9bf269 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/impl/TransferRateRequest.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/impl/TransferRateRequest.java
@@ -24,17 +24,28 @@
/**
* Internal class, do not use directly.
*
+ *
* Request for getting the maximum allowed transfer rates for a user
*
* @author Apache MINA Project
*/
public class TransferRateRequest implements AuthorizationRequest {
-
+ /** Max download rate for a user */
private int maxDownloadRate = 0;
+ /** Max upload rate for a user */
private int maxUploadRate = 0;
/**
+ * Public constructor
+ */
+ public TransferRateRequest() {
+ // Nothing to do
+ }
+
+ /**
+ * Get the user maximum download rate
+ *
* @return the maxDownloadRate
*/
public int getMaxDownloadRate() {
@@ -42,14 +53,17 @@ public int getMaxDownloadRate() {
}
/**
- * @param maxDownloadRate
- * the maxDownloadRate to set
+ * Set the user maximum download rate
+ *
+ * @param maxDownloadRate the maxDownloadRate to set
*/
public void setMaxDownloadRate(int maxDownloadRate) {
this.maxDownloadRate = maxDownloadRate;
}
/**
+ * Get the user maximum upload rate
+ *
* @return the maxUploadRate
*/
public int getMaxUploadRate() {
@@ -57,11 +71,11 @@ public int getMaxUploadRate() {
}
/**
- * @param maxUploadRate
- * the maxUploadRate to set
+ * Set the user maximum upload rate
+ *
+ * @param maxUploadRate the maxUploadRate to set
*/
public void setMaxUploadRate(int maxUploadRate) {
this.maxUploadRate = maxUploadRate;
}
-
}
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/impl/UserMetadata.java b/core/src/main/java/org/apache/ftpserver/usermanager/impl/UserMetadata.java
index eb9694ab..1255fe7a 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/impl/UserMetadata.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/impl/UserMetadata.java
@@ -24,17 +24,25 @@
/**
* Internal class, do not use directly.
- *
+ *
* User metadata used during authentication
*
* @author Apache MINA Project
*/
public class UserMetadata {
-
+ /** The array of certificates up to the CA */
private Certificate[] certificateChain;
+ /** The user address */
private InetAddress inetAddress;
+ /**
+ * Public constructor
+ */
+ public UserMetadata() {
+ // Nothing to do
+ }
+
/**
* Retrive the certificate chain used for an SSL connection.
*
@@ -52,8 +60,7 @@ public Certificate[] getCertificateChain() {
/**
* Set the certificate chain
*
- * @param certificateChain
- * The certificate chain to set
+ * @param certificateChain The certificate chain to set
*/
public void setCertificateChain(final Certificate[] certificateChain) {
if (certificateChain != null) {
@@ -75,11 +82,9 @@ public InetAddress getInetAddress() {
/**
* Set the remote IP adress of the client
*
- * @param inetAddress
- * The client IP adress
+ * @param inetAddress The client IP adress
*/
public void setInetAddress(final InetAddress inetAddress) {
this.inetAddress = inetAddress;
}
-
}
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/impl/WritePermission.java b/core/src/main/java/org/apache/ftpserver/usermanager/impl/WritePermission.java
index e32f624a..87f547c1 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/impl/WritePermission.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/impl/WritePermission.java
@@ -44,16 +44,13 @@ public WritePermission() {
* Construct a write permission for a file or directory relative to the user
* home directory
*
- * @param permissionRoot
- * The file or directory
+ * @param permissionRoot The file or directory
*/
public WritePermission(final String permissionRoot) {
this.permissionRoot = permissionRoot;
}
/**
- * @see Authority#authorize(AuthorizationRequest)
- *
* {@inheritDoc}
*/
public AuthorizationRequest authorize(final AuthorizationRequest request) {
@@ -73,8 +70,6 @@ public AuthorizationRequest authorize(final AuthorizationRequest request) {
}
/**
- * @see Authority#canAuthorize(AuthorizationRequest)
- *
* {@inheritDoc}
*/
public boolean canAuthorize(final AuthorizationRequest request) {
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/impl/WriteRequest.java b/core/src/main/java/org/apache/ftpserver/usermanager/impl/WriteRequest.java
index 0ac8acd5..5540a638 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/impl/WriteRequest.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/impl/WriteRequest.java
@@ -44,7 +44,7 @@ public WriteRequest() {
* Request write access to a file or directory relative to the user home
* directory
*
- * @param file
+ * @param file The file to which we want write access
*/
public WriteRequest(final String file) {
this.file = file;
diff --git a/core/src/main/java/org/apache/ftpserver/util/ClassUtils.java b/core/src/main/java/org/apache/ftpserver/util/ClassUtils.java
index 42352566..5d8a3822 100644
--- a/core/src/main/java/org/apache/ftpserver/util/ClassUtils.java
+++ b/core/src/main/java/org/apache/ftpserver/util/ClassUtils.java
@@ -26,16 +26,20 @@
*
*/
public class ClassUtils {
+ /**
+ * Private constructor
+ */
+ private ClassUtils() {
+ // Nothing to do
+ }
/**
* Checks if a class is a subclass of a class with the specified name. Used
* as an instanceOf without having to load the class, useful when trying to
* check for classes that might not be available in the runtime JRE.
*
- * @param clazz
- * The class to check
- * @param className
- * The class name to look for in the super classes
+ * @param clazz The class to check
+ * @param className The class name to look for in the super classes
* @return
* Encodes and decodes socket addresses (IP and port) from and to the format
* used with for example the PORT and PASV command
*
* @author Apache MINA Project
*/
public class SocketAddressEncoder {
+ /**
+ * Public constructor
+ */
+ public SocketAddressEncoder() {
+ // Nothinhg to do
+ }
private static int convertAndValidateNumber(String s) {
int i = Integer.parseInt(s);
+
if (i < 0) {
throw new IllegalArgumentException("Token can not be less than 0");
} else if (i > 255) {
- throw new IllegalArgumentException(
- "Token can not be larger than 255");
+ throw new IllegalArgumentException("Token can not be larger than 255");
}
return i;
}
- public static InetSocketAddress decode(String str)
- throws UnknownHostException {
+ /**
+ * Decode an address
+ *
+ * @param str The string containing the address to decode
+ * @return The decodd address
+ * @throws UnknownHostException If the host is unkown
+ */
+ public static InetSocketAddress decode(String str) throws UnknownHostException {
StringTokenizer st = new StringTokenizer(str, ",");
+
if (st.countTokens() != 6) {
throw new IllegalInetAddressException("Illegal amount of tokens");
}
StringBuilder sb = new StringBuilder();
+
try {
sb.append(convertAndValidateNumber(st.nextToken()));
sb.append('.');
@@ -70,6 +84,7 @@ public static InetSocketAddress decode(String str)
// get data server port
int dataPort = 0;
+
try {
int hi = convertAndValidateNumber(st.nextToken());
int lo = convertAndValidateNumber(st.nextToken());
@@ -81,11 +96,16 @@ public static InetSocketAddress decode(String str)
return new InetSocketAddress(dataAddr, dataPort);
}
+ /**
+ * Encode the address
+ *
+ * @param address The address to encode
+ * @return The encoded address
+ */
public static String encode(InetSocketAddress address) {
InetAddress servAddr = address.getAddress();
int servPort = address.getPort();
- return servAddr.getHostAddress().replace('.', ',') + ','
- + (servPort >> 8) + ',' + (servPort & 0xFF);
- }
+ return servAddr.getHostAddress().replace('.', ',') + ',' + (servPort >> 8) + ',' + (servPort & 0xFF);
+ }
}
diff --git a/core/src/main/java/org/apache/ftpserver/util/StringUtils.java b/core/src/main/java/org/apache/ftpserver/util/StringUtils.java
index dc5083dc..3d530fa2 100644
--- a/core/src/main/java/org/apache/ftpserver/util/StringUtils.java
+++ b/core/src/main/java/org/apache/ftpserver/util/StringUtils.java
@@ -29,6 +29,9 @@
* @author Apache MINA Project
*/
public class StringUtils {
+ /** Newline characters */
+ public static final char[] NEWLINE = { '\r', '\n' };
+
/**
* @deprecated Do not instantiate.
*/
diff --git a/core/src/test/java/org/apache/ftpserver/ssl/ExplicitSecurityTestTemplate.java b/core/src/test/java/org/apache/ftpserver/ssl/ExplicitSecurityTestTemplate.java
index fa65f2d3..62d9b8f3 100644
--- a/core/src/test/java/org/apache/ftpserver/ssl/ExplicitSecurityTestTemplate.java
+++ b/core/src/test/java/org/apache/ftpserver/ssl/ExplicitSecurityTestTemplate.java
@@ -180,12 +180,8 @@ public void testReceiveEmptyFile() throws Exception {
File file = new File(ROOT_DIR, "foo");
file.createNewFile();
- InputStream is = null;
- try {
- is = client.retrieveFileStream(file.getName());
+ try (InputStream is = client.retrieveFileStream(file.getName())) {
assertEquals(-1, is.read(new byte[1024]));
- } finally {
- IoUtils.close(is);
}
}
}
diff --git a/core/src/test/java/org/apache/ftpserver/ssl/SSLTestTemplate.java b/core/src/test/java/org/apache/ftpserver/ssl/SSLTestTemplate.java
index 49dea047..0d48de4e 100644
--- a/core/src/test/java/org/apache/ftpserver/ssl/SSLTestTemplate.java
+++ b/core/src/test/java/org/apache/ftpserver/ssl/SSLTestTemplate.java
@@ -132,14 +132,8 @@ protected FTPSClient createFTPClient() throws Exception {
protected abstract String getAuthValue();
protected void writeDataToFile(File file, byte[] data) throws IOException {
- FileOutputStream fos = null;
-
- try {
- fos = new FileOutputStream(file);
-
+ try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(data);
- } finally {
- IoUtils.close(fos);
}
}
diff --git a/core/src/test/java/org/apache/ftpserver/test/TestUtil.java b/core/src/test/java/org/apache/ftpserver/test/TestUtil.java
index 9723c085..b931b574 100644
--- a/core/src/test/java/org/apache/ftpserver/test/TestUtil.java
+++ b/core/src/test/java/org/apache/ftpserver/test/TestUtil.java
@@ -167,36 +167,20 @@ public static InetAddress findNonLocalhostIp() throws Exception {
return null;
}
- public static void writeDataToFile(File file, byte[] data)
- throws IOException {
- FileOutputStream fos = null;
-
- try {
- fos = new FileOutputStream(file);
-
+ public static void writeDataToFile(File file, byte[] data) throws IOException {
+ try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(data);
- } finally {
- IoUtils.close(fos);
}
}
- public static void assertFileEqual(byte[] expected, File file)
- throws Exception {
- ByteArrayOutputStream baos = null;
- FileInputStream fis = null;
-
- try {
- baos = new ByteArrayOutputStream();
- fis = new FileInputStream(file);
-
+ public static void assertFileEqual(byte[] expected, File file) throws Exception {
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ FileInputStream fis = new FileInputStream(file)) {
IoUtils.copy(fis, baos, 1024);
byte[] actual = baos.toByteArray();
assertArraysEqual(expected, actual);
- } finally {
- IoUtils.close(fis);
- IoUtils.close(baos);
}
}
false
+ */
public boolean isSingleton() {
return false;
}
-
}
diff --git a/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/DataConnectionConfigurationFactoryBean.java b/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/DataConnectionConfigurationFactoryBean.java
index aab77936..d8db2ae9 100644
--- a/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/DataConnectionConfigurationFactoryBean.java
+++ b/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/DataConnectionConfigurationFactoryBean.java
@@ -32,17 +32,31 @@
* @see DataConnectionConfigurationFactory
*/
public class DataConnectionConfigurationFactoryBean extends DataConnectionConfigurationFactory implements FactoryBean {
+ /**
+ * Create a DataConnectionConfigurationFactoryBean
+ */
+ public DataConnectionConfigurationFactoryBean() {
+ // Nothing to do
+ }
+ /**
+ * {@inheritDoc}
+ */
public Object getObject() throws Exception {
return createDataConnectionConfiguration();
}
+ /**
+ * {@inheritDoc}
+ */
public Class> getObjectType() {
return DataConnectionConfiguration.class;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isSingleton() {
return false;
}
-
}
diff --git a/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/FtpServerFactoryBean.java b/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/FtpServerFactoryBean.java
index 0a9661ca..72e6ecd5 100644
--- a/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/FtpServerFactoryBean.java
+++ b/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/FtpServerFactoryBean.java
@@ -32,17 +32,32 @@
* @see FtpServerFactory
*/
public class FtpServerFactoryBean extends FtpServerFactory implements FactoryBean {
+ /**
+ * Create a FtpServerFactoryBean instance
+ */
+ public FtpServerFactoryBean() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Object getObject() throws Exception {
return createServer();
}
+ /**
+ * {@inheritDoc}
+ */
public Class> getObjectType() {
return FtpServer.class;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isSingleton() {
return false;
}
-
}
diff --git a/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/ListenerFactoryBean.java b/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/ListenerFactoryBean.java
index 64687dfe..3ed39521 100644
--- a/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/ListenerFactoryBean.java
+++ b/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/ListenerFactoryBean.java
@@ -32,17 +32,31 @@
* @see ListenerFactory
*/
public class ListenerFactoryBean extends ListenerFactory implements FactoryBean {
+ /**
+ * Create a ListenerFactoryBean instance
+ */
+ public ListenerFactoryBean() {
+ super();
+ }
+ /**
+ * {@inheritDoc}
+ */
public Object getObject() throws Exception {
return createListener();
}
+ /**
+ * {@inheritDoc}
+ */
public Class> getObjectType() {
return Listener.class;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isSingleton() {
return false;
}
-
}
diff --git a/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/SslConfigurationFactoryBean.java b/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/SslConfigurationFactoryBean.java
index f3a5ae0c..249975a2 100644
--- a/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/SslConfigurationFactoryBean.java
+++ b/core/src/main/java/org/apache/ftpserver/config/spring/factorybeans/SslConfigurationFactoryBean.java
@@ -32,6 +32,12 @@
* @see SslConfigurationFactory
*/
public class SslConfigurationFactoryBean extends SslConfigurationFactory implements FactoryBean {
+ /**
+ * Create a SslConfigurationFactoryBean instance
+ */
+ public SslConfigurationFactoryBean() {
+ // Nothing tp do
+ }
public Object getObject() throws Exception {
return createSslConfiguration();
diff --git a/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java b/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java
index 49d4c347..960e57a1 100644
--- a/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java
+++ b/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/NativeFileSystemFactory.java
@@ -35,12 +35,20 @@
* @author Apache MINA Project
*/
public class NativeFileSystemFactory implements FileSystemFactory {
+ /** The class logger */
private final Logger LOG = LoggerFactory.getLogger(NativeFileSystemFactory.class);
private boolean createHome;
private boolean caseInsensitive;
+ /**
+ * Create a NativeFileSystemFactory instance
+ */
+ public NativeFileSystemFactory() {
+ // Nothing to do
+ }
+
/**
* Should the home directories be created automatically
*
diff --git a/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFileSystemView.java b/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFileSystemView.java
index d14b96a6..f08f5141 100644
--- a/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFileSystemView.java
+++ b/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFileSystemView.java
@@ -32,7 +32,7 @@
/**
* Internal class, do not use directly.
- *
+ *
+ *
+ */
public DefaultConnectionConfig() {
this(true, 500, 10, 10, 3, 0);
}
@@ -90,5 +102,4 @@ public boolean isAnonymousLoginEnabled() {
public int getMaxThreads() {
return maxThreads;
}
-
}
diff --git a/core/src/main/java/org/apache/ftpserver/impl/DefaultDataConnectionConfiguration.java b/core/src/main/java/org/apache/ftpserver/impl/DefaultDataConnectionConfiguration.java
index c5406039..03620718 100644
--- a/core/src/main/java/org/apache/ftpserver/impl/DefaultDataConnectionConfiguration.java
+++ b/core/src/main/java/org/apache/ftpserver/impl/DefaultDataConnectionConfiguration.java
@@ -189,8 +189,6 @@ public SslConfiguration getSslConfiguration() {
}
/**
- * @see org.apache.ftpserver.DataConnectionConfiguration#isImplicitSsl()
- *
* {@inheritDoc}
*/
public boolean isImplicitSsl() {
diff --git a/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpHandler.java b/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpHandler.java
index 3afe06bd..f8829c78 100644
--- a/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpHandler.java
+++ b/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpHandler.java
@@ -53,6 +53,15 @@ public class DefaultFtpHandler implements FtpHandler {
private Listener listener;
+ /**
+ * Create a DefaultFtpHandler instance
+ */
+ public DefaultFtpHandler() {
+ // Nothing to do
+ }
+
+ /**
+ * {@inheritDoc} */
public void init(final FtpServerContext context, final Listener listener) {
this.context = context;
this.listener = listener;
diff --git a/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpServer.java b/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpServer.java
index 0bbb6b55..8443f27f 100644
--- a/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpServer.java
+++ b/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpServer.java
@@ -66,7 +66,7 @@ public DefaultFtpServer(final FtpServerContext serverContext) {
/**
* Start the server. Open a new listener thread.
- * @throws FtpException
+ * @throws FtpException If the server failed to start
*/
public void start() throws FtpException {
if (serverContext == null) {
@@ -185,8 +185,6 @@ public void resume() {
}
/**
- * Is the server suspended
- *
* {@inheritDoc}
*/
public boolean isSuspended() {
@@ -196,7 +194,7 @@ public boolean isSuspended() {
/**
* Get the root server context.
*
- * {@inheritDoc}
+ * @return The FTP Server context
*/
public FtpServerContext getServerContext() {
return serverContext;
diff --git a/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpServerContext.java b/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpServerContext.java
index 9708d262..1c0a02a1 100644
--- a/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpServerContext.java
+++ b/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpServerContext.java
@@ -65,14 +65,19 @@ public class DefaultFtpServerContext implements FtpServerContext {
/** The FTP messages per language */
private MessageResource messageResource = new MessageResourceFactory().createMessageResource();
+ /** The user manager */
private UserManager userManager = new PropertiesUserManagerFactory().createUserManager();
+ /** The file system factory */
private FileSystemFactory fileSystemManager = new NativeFileSystemFactory();
+ /** The FtpLet container */
private FtpletContainer ftpletContainer = new DefaultFtpletContainer();
+ /** The FTP statistics */
private FtpStatistics statistics = new DefaultFtpStatistics();
+ /** The comand factory */
private CommandFactory commandFactory = new CommandFactoryFactory().createCommandFactory();
/** The connection configuration */
@@ -81,7 +86,10 @@ public class DefaultFtpServerContext implements FtpServerContext {
/** The declared listeners for this context */
private Maptrue
500
ms10
10
3
0
LocalizedFtpReply
.
*
- * @param code
- * the reply code
- * @param message
- * the reply text
+ * @param code the reply code
+ * @param message the reply text
*/
public LocalizedFtpReply(int code, String message) {
super(code, message);
diff --git a/core/src/main/java/org/apache/ftpserver/impl/PassivePorts.java b/core/src/main/java/org/apache/ftpserver/impl/PassivePorts.java
index a27bbc74..f61c097c 100644
--- a/core/src/main/java/org/apache/ftpserver/impl/PassivePorts.java
+++ b/core/src/main/java/org/apache/ftpserver/impl/PassivePorts.java
@@ -77,6 +77,7 @@ private static SetSslConfiguration
.
*
* @return the socket factory that can be used to create sockets using this SslConfiguration
.
- * @throws GeneralSecurityException
- * if any error occurs while creating the socket factory.
+ * @throws GeneralSecurityException if any error occurs while creating the socket factory.
*
*/
SSLSocketFactory getSocketFactory() throws GeneralSecurityException;
@@ -46,7 +46,7 @@ public interface SslConfiguration {
* Return the SSL context for this configuration
*
* @return The {@link SSLContext}
- * @throws GeneralSecurityException
+ * @throws GeneralSecurityException If we got an error trying to get the SSL context
*/
SSLContext getSSLContext() throws GeneralSecurityException;
@@ -56,7 +56,7 @@ public interface SslConfiguration {
* @param protocol
* The protocol, SSL or TLS must be supported
* @return The {@link SSLContext}
- * @throws GeneralSecurityException
+ * @throws GeneralSecurityException If we got an error trying to get the SSL context
*/
SSLContext getSSLContext(String protocol) throws GeneralSecurityException;
diff --git a/core/src/main/java/org/apache/ftpserver/ssl/SslConfigurationFactory.java b/core/src/main/java/org/apache/ftpserver/ssl/SslConfigurationFactory.java
index 4fb4a832..d50c59b1 100644
--- a/core/src/main/java/org/apache/ftpserver/ssl/SslConfigurationFactory.java
+++ b/core/src/main/java/org/apache/ftpserver/ssl/SslConfigurationFactory.java
@@ -31,7 +31,6 @@
import org.apache.ftpserver.FtpServerConfigurationException;
import org.apache.ftpserver.ssl.impl.DefaultSslConfiguration;
-import org.apache.ftpserver.util.IoUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +40,7 @@
* @author Apache MINA Project
*/
public class SslConfigurationFactory {
-
+ /** Class logger */
private final Logger LOG = LoggerFactory.getLogger(SslConfigurationFactory.class);
private File keystoreFile = new File("./res/.keystore");
@@ -70,6 +69,13 @@ public class SslConfigurationFactory {
private String[] enabledCipherSuites;
+ /**
+ * A SslConfigurationFactory constructor
+ */
+ public SslConfigurationFactory() {
+ // Nothing to do
+ }
+
/**
* The key store file used by this configuration
*
@@ -322,27 +328,26 @@ public void setTruststoreAlgorithm(String trustStoreAlgorithm) {
private KeyStore loadStore(File storeFile, String storeType, String storePass)
throws IOException, GeneralSecurityException {
- InputStream fin = null;
- try {
+
if (storeFile.exists()) {
- LOG.debug("Trying to load store from file");
- fin = new FileInputStream(storeFile);
- } else {
- LOG.debug("Trying to load store from classpath");
- fin = getClass().getClassLoader().getResourceAsStream(storeFile.getPath());
+ LOG.debug("Trying to load store from file");
- if (fin == null) {
- throw new FtpServerConfigurationException("Key store could not be loaded from " + storeFile.getPath());
- }
- }
+ try (InputStream fin = new FileInputStream(storeFile)) {
+ KeyStore store = KeyStore.getInstance(storeType);
+ store.load(fin, storePass.toCharArray());
- KeyStore store = KeyStore.getInstance(storeType);
- store.load(fin, storePass.toCharArray());
+ return store;
+ }
+ } else {
+ LOG.debug("Trying to load store from classpath");
- return store;
- } finally {
- IoUtils.close(fin);
- }
+ try (InputStream fin = getClass().getClassLoader().getResourceAsStream(storeFile.getPath())) {
+ KeyStore store = KeyStore.getInstance(storeType);
+ store.load(fin, storePass.toCharArray());
+
+ return store;
+ }
+ }
}
/**
@@ -420,7 +425,7 @@ public String[] getEnabledCipherSuites() {
* Set the allowed cipher suites, note that the exact list of supported cipher suites differs between JRE
* implementations.
*
- * @param enabledCipherSuites
+ * @param enabledCipherSuites The set of enabled ciphers
*/
public void setEnabledCipherSuites(String[] enabledCipherSuites) {
if (enabledCipherSuites != null) {
diff --git a/core/src/main/java/org/apache/ftpserver/ssl/impl/DefaultSslConfiguration.java b/core/src/main/java/org/apache/ftpserver/ssl/impl/DefaultSslConfiguration.java
index bae0fbf6..0caa5b43 100644
--- a/core/src/main/java/org/apache/ftpserver/ssl/impl/DefaultSslConfiguration.java
+++ b/core/src/main/java/org/apache/ftpserver/ssl/impl/DefaultSslConfiguration.java
@@ -123,8 +123,9 @@ public SSLContext getSSLContext(String enabledProtocol) throws GeneralSecurityEx
/**
* @deprecated Use {@link #getEnabledProtocol()}
+ * Get the enabled protocol
*
- * {@inheritDoc}
+ * @return The enabled protocol
*/
public String getEnabledProtoco() {
return getEnabledProtocol();
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/ClearTextPasswordEncryptor.java b/core/src/main/java/org/apache/ftpserver/usermanager/ClearTextPasswordEncryptor.java
index c8d7824b..2f61f3e9 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/ClearTextPasswordEncryptor.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/ClearTextPasswordEncryptor.java
@@ -28,8 +28,14 @@
* @author Apache MINA Project
*/
public class ClearTextPasswordEncryptor implements PasswordEncryptor {
+ /** A ClearTextPasswordEncryptor constructor */
+ public ClearTextPasswordEncryptor() {
+ // Nothing to do
+ }
+
/**
* Returns the clear text password
+ *
* @param password The password to encrypt
* @return The encrypted password
*/
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/DbUserManagerFactory.java b/core/src/main/java/org/apache/ftpserver/usermanager/DbUserManagerFactory.java
index e50bdf15..83149b57 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/DbUserManagerFactory.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/DbUserManagerFactory.java
@@ -31,7 +31,6 @@
* @author Apache MINA Project
*/
public class DbUserManagerFactory implements UserManagerFactory {
-
private String adminName = "admin";
private String insertUserStmt;
@@ -52,6 +51,13 @@ public class DbUserManagerFactory implements UserManagerFactory {
private PasswordEncryptor passwordEncryptor = new Md5PasswordEncryptor();
+ /**
+ * Create a DbUserManagerFactory instance
+ */
+ public DbUserManagerFactory() {
+ // Nothing to do
+ }
+
public UserManager createUserManager() {
if (dataSource == null) {
throw new FtpServerConfigurationException(
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/Md5PasswordEncryptor.java b/core/src/main/java/org/apache/ftpserver/usermanager/Md5PasswordEncryptor.java
index 01739495..f59a201f 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/Md5PasswordEncryptor.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/Md5PasswordEncryptor.java
@@ -29,6 +29,12 @@
* @author Apache MINA Project
*/
public class Md5PasswordEncryptor implements PasswordEncryptor {
+ /**
+ * Create a Md5PasswordEncryptor instance
+ */
+ public Md5PasswordEncryptor() {
+ // Nothing to do
+ }
/**
* Hashes the password using MD5
@@ -46,6 +52,7 @@ public boolean matches(String passwordToCheck, String storedPassword) {
if (storedPassword == null) {
throw new NullPointerException("storedPassword can not be null");
}
+
if (passwordToCheck == null) {
throw new NullPointerException("passwordToCheck can not be null");
}
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/PropertiesUserManagerFactory.java b/core/src/main/java/org/apache/ftpserver/usermanager/PropertiesUserManagerFactory.java
index fb4777f8..f0e63725 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/PropertiesUserManagerFactory.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/PropertiesUserManagerFactory.java
@@ -38,6 +38,13 @@ public class PropertiesUserManagerFactory implements UserManagerFactory {
private URL userDataURL;
+ /**
+ * Create a PropertiesUserManagerFactory instance
+ */
+ public PropertiesUserManagerFactory() {
+ // Nothing to do
+ }
+
/**
* The default password encryption method. It's a one way mechanism, ie
* a password is *never* unencrypted.
@@ -78,6 +85,7 @@ public void setAdminName(String adminName) {
/**
* Retrieve the file used to load and store users
+ *
* @return The file
*/
public File getFile() {
@@ -87,8 +95,7 @@ public File getFile() {
/**
* Set the file used to store and read users.
*
- * @param propFile
- * A file containing users
+ * @param propFile A file containing users
*/
public void setFile(File propFile) {
this.userDataFile = propFile;
@@ -96,6 +103,7 @@ public void setFile(File propFile) {
/**
* Retrieve the URL used to load and store users
+ *
* @return The {@link URL}
*/
public URL getUrl() {
@@ -105,8 +113,7 @@ public URL getUrl() {
/**
* Set the URL used to store and read users.
*
- * @param userDataURL
- * A {@link URL} containing users
+ * @param userDataURL A {@link URL} containing users
*/
public void setUrl(URL userDataURL) {
this.userDataURL = userDataURL;
@@ -114,6 +121,7 @@ public void setUrl(URL 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
*/
@@ -123,6 +131,7 @@ public PasswordEncryptor getPasswordEncryptor() {
/**
* Set the password encryptor to use by user managers created by this factory
+ *
* @param passwordEncryptor The password encryptor
*/
public void setPasswordEncryptor(PasswordEncryptor passwordEncryptor) {
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/SaltedPasswordEncryptor.java b/core/src/main/java/org/apache/ftpserver/usermanager/SaltedPasswordEncryptor.java
index 8a52ba85..b449c463 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/SaltedPasswordEncryptor.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/SaltedPasswordEncryptor.java
@@ -35,17 +35,25 @@
* @author Apache MINA Project
*/
public class SaltedPasswordEncryptor implements PasswordEncryptor {
-
private SecureRandom rnd = new SecureRandom();
private static final int MAX_SEED = 99999999;
private static final int HASH_ITERATIONS = 1000;
+ /**
+ * Create a SaltedPasswordEncryptor instance
+ */
+ public SaltedPasswordEncryptor() {
+ // Nothing to do
+ }
+
private String encrypt(String password, String salt) {
String hash = salt + password;
+
for (int i = 0; i < HASH_ITERATIONS; i++) {
hash = EncryptUtils.encryptMD5(hash);
}
+
return salt + ":" + hash;
}
@@ -68,6 +76,7 @@ public boolean matches(String passwordToCheck, String storedPassword) {
if (storedPassword == null) {
throw new NullPointerException("storedPassword can not be null");
}
+
if (passwordToCheck == null) {
throw new NullPointerException("passwordToCheck can not be null");
}
@@ -84,5 +93,4 @@ public boolean matches(String passwordToCheck, String storedPassword) {
return PasswordUtil.secureCompareFast(encrypt(passwordToCheck, storedSalt).toLowerCase(),
storedPassword.toLowerCase());
}
-
}
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/Sha1PasswordEncryptor.java b/core/src/main/java/org/apache/ftpserver/usermanager/Sha1PasswordEncryptor.java
index 9a292743..5eadf06d 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/Sha1PasswordEncryptor.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/Sha1PasswordEncryptor.java
@@ -30,9 +30,16 @@
* @author Apache MINA Project
*/
public class Sha1PasswordEncryptor implements PasswordEncryptor {
+ /**
+ * Create a Sha1PasswordEncryptor instance
+ */
+ public Sha1PasswordEncryptor() {
+ // Nothing to do
+ }
/**
* Hashes the password using SHA-1
+ *
* @param password The password to encrypt
* @return The encrypted password
*/
@@ -47,6 +54,7 @@ public boolean matches(String passwordToCheck, String storedPassword) {
if (storedPassword == null) {
throw new NullPointerException("storedPassword can not be null");
}
+
if (passwordToCheck == null) {
throw new NullPointerException("passwordToCheck can not be null");
}
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/Sha256PasswordEncryptor.java b/core/src/main/java/org/apache/ftpserver/usermanager/Sha256PasswordEncryptor.java
index fda69cb7..059f68ba 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/Sha256PasswordEncryptor.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/Sha256PasswordEncryptor.java
@@ -29,9 +29,16 @@
* @author Apache MINA Project
*/
public class Sha256PasswordEncryptor implements PasswordEncryptor {
+ /**
+ * Create a Sha256PasswordEncryptor instance
+ */
+ public Sha256PasswordEncryptor() {
+ // Nothing to do
+ }
/**
* Hashes the password using SHA-256
+ *
* @param password The password to encrypt
* @return The encrypted password
*/
@@ -46,6 +53,7 @@ public boolean matches(String passwordToCheck, String storedPassword) {
if (storedPassword == null) {
throw new NullPointerException("storedPassword can not be null");
}
+
if (passwordToCheck == null) {
throw new NullPointerException("passwordToCheck can not be null");
}
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/Sha512PasswordEncryptor.java b/core/src/main/java/org/apache/ftpserver/usermanager/Sha512PasswordEncryptor.java
index 503d2dd8..44fa2560 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/Sha512PasswordEncryptor.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/Sha512PasswordEncryptor.java
@@ -29,9 +29,16 @@
* @author Apache MINA Project
*/
public class Sha512PasswordEncryptor implements PasswordEncryptor {
+ /**
+ * Create a Sha512PasswordEncryptor instance
+ */
+ public Sha512PasswordEncryptor() {
+ // Nothing to do
+ }
/**
* Hashes the password using SHA-512
+ *
* @param password The password to encrypt
* @return The encrypted password
*/
@@ -46,6 +53,7 @@ public boolean matches(String passwordToCheck, String storedPassword) {
if (storedPassword == null) {
throw new NullPointerException("storedPassword can not be null");
}
+
if (passwordToCheck == null) {
throw new NullPointerException("passwordToCheck can not be null");
}
diff --git a/core/src/main/java/org/apache/ftpserver/usermanager/UserFactory.java b/core/src/main/java/org/apache/ftpserver/usermanager/UserFactory.java
index eaa353ab..1144ebc1 100644
--- a/core/src/main/java/org/apache/ftpserver/usermanager/UserFactory.java
+++ b/core/src/main/java/org/apache/ftpserver/usermanager/UserFactory.java
@@ -45,8 +45,17 @@ public class UserFactory {
private Listtrue
if the user is enabled (allowed to log in)
*/
public boolean isEnabled() {
@@ -135,6 +153,7 @@ public boolean isEnabled() {
/**
* Get the enabled status for users created by this factory
+ *
* @param isEnabled true if the user should be enabled (allowed to log in)
*/
public void setEnabled(boolean isEnabled) {
@@ -143,6 +162,7 @@ public void setEnabled(boolean isEnabled) {
/**
* Get the authorities for users created by this factory
+ *
* @return The authorities
*/
public List extends Authority> getAuthorities() {
@@ -151,6 +171,7 @@ public List extends Authority> getAuthorities() {
/**
* Set the authorities for users created by this factory
+ *
* @param authorities The authorities
*/
public void setAuthorities(Listtrue
if the class extends a class by the specified name.
*/
public static boolean extendsClass(final Class> clazz, String className) {
@@ -45,9 +49,11 @@ public static boolean extendsClass(final Class> clazz, String className) {
if (superClass.getName().equals(className)) {
return true;
}
+
superClass = superClass.getSuperclass();
}
+
return false;
}
}
diff --git a/core/src/main/java/org/apache/ftpserver/util/DateUtils.java b/core/src/main/java/org/apache/ftpserver/util/DateUtils.java
index c2aced1e..0a89ae13 100644
--- a/core/src/main/java/org/apache/ftpserver/util/DateUtils.java
+++ b/core/src/main/java/org/apache/ftpserver/util/DateUtils.java
@@ -35,26 +35,31 @@
* @author Apache MINA Project
*/
public class DateUtils {
-
private static final TimeZone TIME_ZONE_UTC = TimeZone.getTimeZone("UTC");
private static final String[] MONTHS = { "Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+ /**
+ * A private constructor
+ */
+ private DateUtils() {
+ // Nothing to do
+ }
+
/*
* Creates the DateFormat object used to parse/format
* dates in FTP format.
*/
private static final ThreadLocalBufferedInputStream
.
@@ -60,14 +65,15 @@ public class IoUtils {
* @param in The incoming InputStream
* @return A BufferedInputStream
*/
- public static final BufferedInputStream getBufferedInputStream(
- InputStream in) {
+ public static final BufferedInputStream getBufferedInputStream(InputStream in) {
BufferedInputStream bin = null;
+
if (in instanceof java.io.BufferedInputStream) {
bin = (BufferedInputStream) in;
} else {
bin = new BufferedInputStream(in);
}
+
return bin;
}
@@ -77,14 +83,15 @@ public static final BufferedInputStream getBufferedInputStream(
* @param out The incoming OutputStream
* @return A BufferedOutputStream
*/
- public static final BufferedOutputStream getBufferedOutputStream(
- OutputStream out) {
+ public static final BufferedOutputStream getBufferedOutputStream(OutputStream out) {
BufferedOutputStream bout = null;
+
if (out instanceof java.io.BufferedOutputStream) {
bout = (BufferedOutputStream) out;
} else {
bout = new BufferedOutputStream(out);
}
+
return bout;
}
@@ -96,11 +103,13 @@ public static final BufferedOutputStream getBufferedOutputStream(
*/
public static final BufferedReader getBufferedReader(Reader reader) {
BufferedReader buffered = null;
+
if (reader instanceof java.io.BufferedReader) {
buffered = (BufferedReader) reader;
} else {
buffered = new BufferedReader(reader);
}
+
return buffered;
}
@@ -112,11 +121,13 @@ public static final BufferedReader getBufferedReader(Reader reader) {
*/
public static final BufferedWriter getBufferedWriter(Writer wr) {
BufferedWriter bw = null;
+
if (wr instanceof java.io.BufferedWriter) {
bw = (BufferedWriter) wr;
} else {
bw = new BufferedWriter(wr);
}
+
return bw;
}
@@ -128,13 +139,15 @@ public static final BufferedWriter getBufferedWriter(Writer wr) {
*/
public static final File getUniqueFile(File oldFile) {
File newFile = oldFile;
+
while (true) {
if (!newFile.exists()) {
break;
}
- newFile = new File(oldFile.getAbsolutePath() + '.'
- + Math.abs(RANDOM_GEN.nextLong()));
+
+ newFile = new File(oldFile.getAbsolutePath() + '.' + Math.abs(RANDOM_GEN.nextLong()));
}
+
return newFile;
}
@@ -142,6 +155,7 @@ public static final File getUniqueFile(File oldFile) {
* No exception InputStream
close method.
*
* @param is The InputStream to close
+ * @deprecated Use try-with-resources instead
*/
public static final void close(InputStream is) {
if (is != null) {
@@ -156,6 +170,7 @@ public static final void close(InputStream is) {
* No exception OutputStream
close method.
*
* @param os The OutputStream to close
+ * @deprecated Use try-with-resources instead
*/
public static final void close(OutputStream os) {
if (os != null) {
@@ -170,6 +185,7 @@ public static final void close(OutputStream os) {
* No exception java.io.Reader
close method.
*
* @param rd The Reader to close
+ * @deprecated Use try-with-resources instead
*/
public static final void close(Reader rd) {
if (rd != null) {
@@ -184,6 +200,7 @@ public static final void close(Reader rd) {
* No exception java.io.Writer
close method.
*
* @param wr The Writer to close
+ * @deprecated Use try-with-resources instead
*/
public static final void close(Writer wr) {
if (wr != null) {
@@ -202,6 +219,7 @@ public static final void close(Writer wr) {
*/
public static final String getStackTrace(Throwable ex) {
String result = "";
+
if (ex != null) {
try {
StringWriter sw = new StringWriter();
@@ -214,6 +232,7 @@ public static final String getStackTrace(Throwable ex) {
e.printStackTrace();
}
}
+
return result;
}
@@ -225,10 +244,10 @@ public static final String getStackTrace(Throwable ex) {
* @param bufferSize Size of internal buffer to use.
* @throws IOException If the copy failed
*/
- public static final void copy(Reader input, Writer output, int bufferSize)
- throws IOException {
+ public static final void copy(Reader input, Writer output, int bufferSize) throws IOException {
char[] buffer = new char[bufferSize];
int n = 0;
+
while ((n = input.read(buffer)) != -1) {
output.write(buffer, 0, n);
}
@@ -242,10 +261,10 @@ public static final void copy(Reader input, Writer output, int bufferSize)
* @param bufferSize Size of internal buffer to use.
* @throws IOException If the copy failed
*/
- public static final void copy(InputStream input, OutputStream output,
- int bufferSize) throws IOException {
+ public static final void copy(InputStream input, OutputStream output, int bufferSize) throws IOException {
byte[] buffer = new byte[bufferSize];
int n = 0;
+
while ((n = input.read(buffer)) != -1) {
output.write(buffer, 0, n);
}
@@ -261,6 +280,7 @@ public static final void copy(InputStream input, OutputStream output,
public static final String readFully(Reader reader) throws IOException {
StringWriter writer = new StringWriter();
copy(reader, writer, 1024);
+
return writer.toString();
}
@@ -275,9 +295,16 @@ public static final String readFully(InputStream input) throws IOException {
StringWriter writer = new StringWriter();
InputStreamReader reader = new InputStreamReader(input);
copy(reader, writer, 1024);
+
return writer.toString();
}
+ /**
+ * Delete a file
+ *
+ * @param file The file to delete
+ * @throws IOException If the deletion failed
+ */
public static final void delete(File file) throws IOException {
if (file.isDirectory()) {
deleteDir(file);
@@ -311,10 +338,12 @@ private static void deleteFile(File file) throws IOException {
if (OS.isFamilyWindows()) {
System.gc();
}
+
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
+
if (!file.delete()) {
throw new IOException("Failed to delete file: " + file);
}
diff --git a/core/src/main/java/org/apache/ftpserver/util/OS.java b/core/src/main/java/org/apache/ftpserver/util/OS.java
index b8b1f717..c1bfd405 100644
--- a/core/src/main/java/org/apache/ftpserver/util/OS.java
+++ b/core/src/main/java/org/apache/ftpserver/util/OS.java
@@ -29,37 +29,49 @@
* @author Apache MINA Project
*/
public final class OS {
+ /** OS/400 */
private static final String FAMILY_OS_400 = "os/400";
+ /** Z/OS */
private static final String FAMILY_Z_OS = "z/os";
+ /** WIN9x */
private static final String FAMILY_WIN9X = "win9x";
+ /** OpenVMS */
private static final String FAMILY_OPENVMS = "openvms";
+ /** Unix */
private static final String FAMILY_UNIX = "unix";
+ /** Tandem */
private static final String FAMILY_TANDEM = "tandem";
+ /** MAC */
private static final String FAMILY_MAC = "mac";
+ /** MS/DOS */
private static final String FAMILY_DOS = "dos";
+ /** NetWare */
private static final String FAMILY_NETWARE = "netware";
+ /** OS/2 */
private static final String FAMILY_OS_2 = "os/2";
+ /** Windows */
private static final String FAMILY_WINDOWS = "windows";
- private static final String OS_NAME = System.getProperty("os.name")
- .toLowerCase(Locale.US);
+ /** The OS name */
+ private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.US);
- private static final String OS_ARCH = System.getProperty("os.arch")
- .toLowerCase(Locale.US);
+ /** The OS architecture */
+ private static final String OS_ARCH = System.getProperty("os.arch").toLowerCase(Locale.US);
- private static final String OS_VERSION = System.getProperty("os.version")
- .toLowerCase(Locale.US);
+ /** The OS version */
+ private static final String OS_VERSION = System.getProperty("os.version").toLowerCase(Locale.US);
+ /** The OS path separator */
private static final String PATH_SEP = System.getProperty("path.separator");
/**
@@ -84,54 +96,108 @@ private OS() {
* true
if the OS matches
*/
private static boolean isFamily(final String family) {
return isOs(family, null, null, null);
}
+ /**
+ * Tells if the underlaying OS is MS/DOS
+ *
+ * @return true
if the underlaying OS is MS/DOS
+ */
public static boolean isFamilyDOS() {
return isFamily(FAMILY_DOS);
}
+ /**
+ * Tells if the underlaying OS is MAC
+ *
+ * @return true
if the underlaying OS is MAC
+ */
public static boolean isFamilyMac() {
return isFamily(FAMILY_MAC);
}
+ /**
+ * Tells if the underlaying OS is NetWare
+ *
+ * @return true
if the underlaying OS is NetWare
+ */
public static boolean isFamilyNetware() {
return isFamily(FAMILY_NETWARE);
}
+ /**
+ * Tells if the underlaying OS is OS/2
+ *
+ * @return true
if the underlaying OS is OS/2
+ */
public static boolean isFamilyOS2() {
return isFamily(FAMILY_OS_2);
}
+ /**
+ * Tells if the underlaying OS is Tandem
+ *
+ * @return true
if the underlaying OS is Tandem
+ */
public static boolean isFamilyTandem() {
return isFamily(FAMILY_TANDEM);
}
+ /**
+ * Tells if the underlaying OS is Unix
+ *
+ * @return true
if the underlaying OS is Unix
+ */
public static boolean isFamilyUnix() {
return isFamily(FAMILY_UNIX);
}
+ /**
+ * Tells if the underlaying OS is Windows
+ *
+ * @return true
if the underlaying OS is Windows
+ */
public static boolean isFamilyWindows() {
return isFamily(FAMILY_WINDOWS);
}
+ /**
+ * Tells if the underlaying OS is Win9x
+ *
+ * @return true
if the underlaying OS is Win9x
+ */
public static boolean isFamilyWin9x() {
return isFamily(FAMILY_WIN9X);
}
+ /**
+ * Tells if the underlaying OS is Z/OS
+ *
+ * @return true
if the underlaying OS is Z/OS
+ */
public static boolean isFamilyZOS() {
return isFamily(FAMILY_Z_OS);
}
+ /**
+ * Tells if the underlaying OS is OS/400
+ *
+ * @return true
if the underlaying OS is OS/400
+ */
public static boolean isFamilyOS400() {
return isFamily(FAMILY_OS_400);
}
+ /**
+ * Tells if the underlaying OS is OpenVMS
+ *
+ * @return true
if the underlaying OS is OpenVMS
+ */
public static boolean isFamilyOpenVms() {
return isFamily(FAMILY_OPENVMS);
}
@@ -139,8 +205,7 @@ public static boolean isFamilyOpenVms() {
/**
* Determines if the OS on which Ant is executing matches the given OS name.
*
- * @param name
- * the OS name to check for
+ * @param name the OS name to check for
* @return true
if the OS matches
*/
public static boolean isName(final String name) {
@@ -151,8 +216,7 @@ public static boolean isName(final String name) {
* Determines if the OS on which Ant is executing matches the given OS
* architecture.
*
- * @param arch
- * the OS architecture to check for
+ * @param arch the OS architecture to check for
* @return true
if the OS matches
*/
public static boolean isArch(final String arch) {
@@ -163,8 +227,7 @@ public static boolean isArch(final String arch) {
* Determines if the OS on which Ant is executing matches the given OS
* version.
*
- * @param version
- * the OS version to check for
+ * @param version the OS version to check for
* @return true
if the OS matches
*/
public static boolean isVersion(final String version) {
@@ -175,18 +238,13 @@ public static boolean isVersion(final String version) {
* Determines if the OS on which Ant is executing matches the given OS
* family, name, architecture and version
*
- * @param family
- * The OS family
- * @param name
- * The OS name
- * @param arch
- * The OS architecture
- * @param version
- * The OS version
+ * @param family The OS family
+ * @param name The OS name
+ * @param arch The OS architecture
+ * @param version The OS version
* @return true
if the OS matches
*/
- public static boolean isOs(final String family, final String name,
- final String arch, final String version) {
+ public static boolean isOs(final String family, final String name, final String arch, final String version) {
boolean retValue = false;
if (family != null || name != null || arch != null || version != null) {
@@ -197,53 +255,77 @@ public static boolean isOs(final String family, final String name,
boolean isVersion = true;
if (family != null) {
- if (family.equals(FAMILY_WINDOWS)) {
- isFamily = OS_NAME.indexOf(FAMILY_WINDOWS) > -1;
- } else if (family.equals(FAMILY_OS_2)) {
- isFamily = OS_NAME.indexOf(FAMILY_OS_2) > -1;
- } else if (family.equals(FAMILY_NETWARE)) {
- isFamily = OS_NAME.indexOf(FAMILY_NETWARE) > -1;
- } else if (family.equals(FAMILY_DOS)) {
- isFamily = PATH_SEP.equals(";")
- && !isFamily(FAMILY_NETWARE);
- } else if (family.equals(FAMILY_MAC)) {
- isFamily = OS_NAME.indexOf(FAMILY_MAC) > -1;
- } else if (family.equals(FAMILY_TANDEM)) {
- isFamily = OS_NAME.indexOf("nonstop_kernel") > -1;
- } else if (family.equals(FAMILY_UNIX)) {
- isFamily = PATH_SEP.equals(":")
+ switch (family) {
+ case FAMILY_WINDOWS:
+ isFamily = OS_NAME.indexOf(FAMILY_WINDOWS) > -1;
+ break;
+
+ case FAMILY_OS_2:
+ isFamily = OS_NAME.indexOf(FAMILY_OS_2) > -1;
+ break;
+
+ case FAMILY_NETWARE:
+ isFamily = OS_NAME.indexOf(FAMILY_NETWARE) > -1;
+ break;
+
+ case FAMILY_DOS:
+ isFamily = PATH_SEP.equals(";") && !isFamily(FAMILY_NETWARE);
+ break;
+
+ case FAMILY_MAC:
+ isFamily = OS_NAME.indexOf(FAMILY_MAC) > -1;
+ break;
+
+ case FAMILY_TANDEM:
+ isFamily = OS_NAME.indexOf("nonstop_kernel") > -1;
+ break;
+
+ case FAMILY_UNIX:
+ isFamily = PATH_SEP.equals(":")
&& !isFamily(FAMILY_OPENVMS)
&& (!isFamily(FAMILY_MAC) || OS_NAME.endsWith("x"));
- } else if (family.equals(FAMILY_WIN9X)) {
- isFamily = isFamily(FAMILY_WINDOWS)
+ break;
+
+ case FAMILY_WIN9X:
+ isFamily = isFamily(FAMILY_WINDOWS)
&& (OS_NAME.indexOf("95") >= 0
|| OS_NAME.indexOf("98") >= 0
|| OS_NAME.indexOf("me") >= 0 || OS_NAME
.indexOf("ce") >= 0);
- } else if (family.equals(FAMILY_Z_OS)) {
- isFamily = OS_NAME.indexOf(FAMILY_Z_OS) > -1
- || OS_NAME.indexOf("os/390") > -1;
- } else if (family.equals(FAMILY_OS_400)) {
- isFamily = OS_NAME.indexOf(FAMILY_OS_400) > -1;
- } else if (family.equals(FAMILY_OPENVMS)) {
- isFamily = OS_NAME.indexOf(FAMILY_OPENVMS) > -1;
- } else {
- throw new IllegalArgumentException(
- "Don\'t know how to detect os family \"" + family
- + "\"");
+ break;
+
+ case FAMILY_Z_OS:
+ isFamily = OS_NAME.indexOf(FAMILY_Z_OS) > -1 || OS_NAME.indexOf("os/390") > -1;
+ break;
+
+ case FAMILY_OS_400:
+ isFamily = OS_NAME.indexOf(FAMILY_OS_400) > -1;
+ break;
+
+ case FAMILY_OPENVMS:
+ isFamily = OS_NAME.indexOf(FAMILY_OPENVMS) > -1;
+ break;
+
+ default:
+ throw new IllegalArgumentException("Don\'t know how to detect os family \"" + family + "\"");
}
}
+
if (name != null) {
isName = name.equals(OS_NAME);
}
+
if (arch != null) {
isArch = arch.equals(OS_ARCH);
}
+
if (version != null) {
isVersion = version.equals(OS_VERSION);
}
+
retValue = isFamily && isName && isArch && isVersion;
}
+
return retValue;
}
}
diff --git a/core/src/main/java/org/apache/ftpserver/util/PasswordUtil.java b/core/src/main/java/org/apache/ftpserver/util/PasswordUtil.java
index 511cbf7c..dea1916f 100644
--- a/core/src/main/java/org/apache/ftpserver/util/PasswordUtil.java
+++ b/core/src/main/java/org/apache/ftpserver/util/PasswordUtil.java
@@ -19,7 +19,19 @@
package org.apache.ftpserver.util;
+/**
+ * Utility class for password management
+ *
+ * @author Apache MINA Project
+ */
public class PasswordUtil {
+ /**
+ * A private constructor
+ */
+ private PasswordUtil() {
+ // Nothing to do
+ }
+
/**
* Securely compares two strings up to a maximum number of characters in a way
* that obscures the password length from timing attacks
diff --git a/core/src/main/java/org/apache/ftpserver/util/SocketAddressEncoder.java b/core/src/main/java/org/apache/ftpserver/util/SocketAddressEncoder.java
index 771e6919..b4125466 100644
--- a/core/src/main/java/org/apache/ftpserver/util/SocketAddressEncoder.java
+++ b/core/src/main/java/org/apache/ftpserver/util/SocketAddressEncoder.java
@@ -26,34 +26,48 @@
/**
* Internal class, do not use directly.
- *
+ *