Repository: mina-sshd Updated Branches: refs/heads/master 9521dfa27 -> 9dbd66ea9
Fixed some calls to Objects.toString() to invoke Objects.toString(o, null) Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/a5bf6cab Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/a5bf6cab Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/a5bf6cab Branch: refs/heads/master Commit: a5bf6cabf9a1aaa21e6ee9506f0ba64eeba18953 Parents: 9521dfa Author: Lyor Goldstein <[email protected]> Authored: Tue Jul 28 08:18:18 2015 +0300 Committer: Lyor Goldstein <[email protected]> Committed: Tue Jul 28 08:18:18 2015 +0300 ---------------------------------------------------------------------- .../AbstractResourceKeyPairProvider.java | 9 ++-- .../apache/sshd/common/util/Transformer.java | 5 +- .../apache/sshd/common/util/buffer/Buffer.java | 9 ++-- .../sshd/server/subsystem/sftp/SftpHelper.java | 6 +-- .../server/subsystem/sftp/SftpSubsystem.java | 48 ++++++++++---------- .../sshd/common/cipher/BuiltinCiphersTest.java | 2 +- 6 files changed, 41 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a5bf6cab/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/AbstractResourceKeyPairProvider.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/AbstractResourceKeyPairProvider.java b/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/AbstractResourceKeyPairProvider.java index ee65334..259b6bc 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/AbstractResourceKeyPairProvider.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/AbstractResourceKeyPairProvider.java @@ -34,6 +34,7 @@ import java.util.TreeSet; import org.apache.sshd.common.config.keys.FilePasswordProvider; import org.apache.sshd.common.util.GenericUtils; +import org.apache.sshd.common.util.ValidateUtils; /** * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> @@ -41,10 +42,10 @@ import org.apache.sshd.common.util.GenericUtils; public abstract class AbstractResourceKeyPairProvider<R> extends AbstractKeyPairProvider { private FilePasswordProvider passwordFinder; - /* + /* * NOTE: the map is case insensitive even for Linux, as it is (very) bad * practice to have 2 key files that differ from one another only in their - * case... + * case... */ private final Map<String, KeyPair> cacheMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); @@ -74,7 +75,7 @@ public abstract class AbstractResourceKeyPairProvider<R> extends AbstractKeyPair } for (Object r : resources) { - String resourceKey = Objects.toString(r); + String resourceKey = ValidateUtils.checkNotNullAndNotEmpty(Objects.toString(r, null), "No resource key value"); if (cacheMap.containsKey(resourceKey)) { continue; } @@ -114,7 +115,7 @@ public abstract class AbstractResourceKeyPairProvider<R> extends AbstractKeyPair } protected KeyPair doLoadKey(R resource) throws IOException, GeneralSecurityException { - String resourceKey = Objects.toString(resource); + String resourceKey = ValidateUtils.checkNotNullAndNotEmpty(Objects.toString(resource, null), "No resource string value"); KeyPair kp; synchronized (cacheMap) { // check if lucky enough to have already loaded this file http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a5bf6cab/sshd-core/src/main/java/org/apache/sshd/common/util/Transformer.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/Transformer.java b/sshd-core/src/main/java/org/apache/sshd/common/util/Transformer.java index 73e2233..96adbc1 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/Transformer.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/Transformer.java @@ -28,12 +28,13 @@ public interface Transformer<I, O> { // TODO in JDK-8 replace this with Function /** - * Invokes {@link Objects#toString(Object)} on the argument + * Invokes {@link Objects#toString(Object, String)} on the argument + * with {@code null} as the value to return if argument is {@code null} */ Transformer<Object, String> TOSTRING = new Transformer<Object, String>() { @Override public String transform(Object input) { - return Objects.toString(input); + return Objects.toString(input, null); } }; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a5bf6cab/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java index 9cf4d92..106d9cd 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java @@ -58,6 +58,7 @@ import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.Int2IntFunction; import org.apache.sshd.common.util.Readable; import org.apache.sshd.common.util.SecurityUtils; +import org.apache.sshd.common.util.Transformer; /** * Provides an abstract message buffer for encoding SSH messages @@ -493,7 +494,7 @@ public abstract class Buffer implements Readable { } /** - * Encodes the {@link Objects#toString(Object)} value of each member. + * Encodes the {@link Transformer#TOSTRING} value of each member. * * @param objects The objects to be encoded in the buffer - OK if * {@code null}/empty @@ -506,7 +507,7 @@ public abstract class Buffer implements Readable { } /** - * Encodes the {@link Objects#toString(Object)} value of each member + * Encodes the {@link Transformer#TOSTRING} value of each member * * @param objects The objects to be encoded in the buffer - OK if * {@code null}/empty @@ -526,7 +527,7 @@ public abstract class Buffer implements Readable { } for (Object o : objects) { - putString(Objects.toString(o), charset); + putString(Transformer.TOSTRING.transform(o), charset); } } @@ -535,7 +536,7 @@ public abstract class Buffer implements Readable { } public void putString(String string, Charset charset) { - putBytes(string.getBytes(charset)); + putBytes(GenericUtils.isEmpty(string) ? GenericUtils.EMPTY_BYTE_ARRAY : string.getBytes(charset)); } public void putMPInt(BigInteger bi) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a5bf6cab/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpHelper.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpHelper.java b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpHelper.java index 060bb88..502b9d5 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpHelper.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpHelper.java @@ -126,7 +126,7 @@ import static org.apache.sshd.common.subsystem.sftp.SftpConstants.S_IXUSR; * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public final class SftpHelper { - + private SftpHelper() { throw new UnsupportedOperationException("No instance allowed"); } @@ -199,8 +199,8 @@ public final class SftpHelper { buffer.putLong(size.longValue()); } if ((flags & SSH_FILEXFER_ATTR_OWNERGROUP) != 0) { - buffer.putString(Objects.toString(attributes.get("owner"))); - buffer.putString(Objects.toString(attributes.get("group"))); + buffer.putString(Objects.toString(attributes.get("owner"), null)); + buffer.putString(Objects.toString(attributes.get("group"), null)); } if ((flags & SSH_FILEXFER_ATTR_PERMISSIONS) != 0) { buffer.putInt(attributesToPermissions(isReg, isDir, isLnk, perms)); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a5bf6cab/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java index 5d5092f..6d304a4 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java @@ -218,7 +218,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna /** * Force the use of a max. packet length - especially for {@link #doReadDir(Buffer, int)} * and {@link #doRead(Buffer, int)} methods - * + * * @see #DEFAULT_MAX_PACKET_LENGTH */ public static final String MAX_PACKET_LENGTH_PROP = "sftp-max-packet-length"; @@ -393,7 +393,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna public void setFileSystem(FileSystem fileSystem) { if (fileSystem != this.fileSystem) { this.fileSystem = fileSystem; - + Iterable<Path> roots = ValidateUtils.checkNotNull(fileSystem.getRootDirectories(), "No root directories"); Iterator<Path> available = ValidateUtils.checkNotNull(roots.iterator(), "No roots iterator"); ValidateUtils.checkTrue(available.hasNext(), "No available root"); @@ -720,7 +720,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna /* * To quote http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt section 9.1.2: - * + * * If ACE4_READ_DATA was not included when the file was opened, * the server MUST return STATUS_PERMISSION_DENIED. */ @@ -730,10 +730,10 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } } else { path = resolveFile(target); - + /* * To quote http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt section 9.1.2: - * + * * If 'check-file-name' refers to a SSH_FILEXFER_TYPE_SYMLINK, the * target should be opened. */ @@ -891,7 +891,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna /* * To quote http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt section 9.1.1: - * + * * The handle MUST be a file handle, and ACE4_READ_DATA MUST * have been included in the desired-access when the file * was opened @@ -944,7 +944,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna /* * To quote http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt section 9.1.1: - * + * * If this is a zero length string, the client does not have the * data, and is requesting the hash for reasons other than comparing * with a local file. The server MAY return SSH_FX_OP_UNSUPPORTED in @@ -966,10 +966,10 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna if (hashMatches) { /* * Need to re-initialize the digester due to the Javadoc: - * + * * "The digest method can be called once for a given number * of updates. After digest has been called, the MessageDigest - * object is reset to its initialized state." + * object is reset to its initialized state." */ if (effectiveLength > 0L) { digest = BuiltinDigests.md5.create(); @@ -1471,10 +1471,10 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna if (version < SFTP_V6) { /* * See http://www.openssh.com/txt/draft-ietf-secsh-filexfer-02.txt: - * + * * The SSH_FXP_REALPATH request can be used to have the server * canonicalize any given path name to an absolute path. - * + * * See also SSHD-294 */ result = doRealPathV345(id, path, options); @@ -2345,9 +2345,9 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna /* * As per the spec: - * + * * The server will respond with a SSH_FXP_NAME packet containing only - * one name and a dummy attributes value. + * one name and a dummy attributes value. */ SftpHelper.writeAttrs(version, buffer, Collections.<String, Object>emptyMap()); send(buffer); @@ -2428,7 +2428,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna private String getLongName(Path f, Map<String, ?> attributes) throws IOException { String username; if (attributes.containsKey("owner")) { - username = Objects.toString(attributes.get("owner")); + username = Objects.toString(attributes.get("owner"), null); } else { username = "owner"; } @@ -2441,7 +2441,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } String group; if (attributes.containsKey("group")) { - group = Objects.toString(attributes.get("group")); + group = Objects.toString(attributes.get("group"), null); } else { group = "group"; } @@ -2480,7 +2480,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna int count = nrm.getNameCount(); /* * According to the javadoc: - * + * * The number of elements in the path, or 0 if this path only * represents a root component */ @@ -2620,11 +2620,11 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna if (Objects.equals(resolved, value)) { continue; } - + if (attrs == null) { attrs = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); } - + attrs.put(name, resolved); if (log.isDebugEnabled()) { @@ -2635,18 +2635,18 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna if (log.isDebugEnabled()) { log.debug("resolveMissingFileAttributes(" + file + ")[" + name + "]" + " failed (" + e.getClass().getSimpleName() + ")" - + " to resolve missing value: " + e.getMessage()); + + " to resolve missing value: " + e.getMessage()); } } } - + if (attrs == null) { return Collections.emptyMap(); } else { return attrs; } } - + protected Object resolveMissingFileAttributeValue(Path file, String name, Object value, FileInfoExtractor<?> x, LinkOption ... options) throws IOException { if (value != null) { return value; @@ -2660,7 +2660,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna if (value != null) { // already have the value return current; } - + // skip if still no value value = x.infoOf(file, options); if (value == null) { @@ -2670,7 +2670,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna if (current == null) { current = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); } - + current.put(name, value); return current; } @@ -2809,7 +2809,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna protected void handleUserPrincipalLookupServiceException(Class<? extends Principal> principalType, String name, IOException e) throws IOException { /* According to Javadoc: - * + * * "Where an implementation does not support any notion of group * or user then this method always throws UserPrincipalNotFoundException." */ http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a5bf6cab/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java index c9514f2..1e1bee9 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java @@ -110,7 +110,7 @@ public class BuiltinCiphersTest extends BaseTestSupport { continue; } - String name = Objects.toString(f.get(null)); + String name = Objects.toString(f.get(null), null); BuiltinCiphers value = BuiltinCiphers.fromFactoryName(name); assertNotNull("No match found for " + name, value); assertTrue(name + " re-specified", avail.add(value));
