You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2018/05/28 10:58:05 UTC
mina-sshd git commit: [SSHD-824] Do not use anonymous inner classes
to initialize collections
Repository: mina-sshd
Updated Branches:
refs/heads/master a4f4e2811 -> 3c6bfab46
[SSHD-824] Do not use anonymous inner classes to initialize collections
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/3c6bfab4
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/3c6bfab4
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/3c6bfab4
Branch: refs/heads/master
Commit: 3c6bfab46d08e87b195d5d7f72cb940eeedda495
Parents: a4f4e28
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 28 12:42:06 2018 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 28 12:42:06 2018 +0200
----------------------------------------------------------------------
.../config/keys/loader/putty/PuttyKeyUtils.java | 58 ++++++---------
.../sshd/agent/unix/UnixAgentFactory.java | 37 ++++------
.../loader/PrivateKeyEncryptionContext.java | 21 ++----
.../apache/sshd/common/io/nio2/Nio2Service.java | 26 +++----
.../sshd/common/util/net/SshdSocketAddress.java | 32 ++------
.../sshd/common/channel/WindowInitTest.java | 28 +++----
...AuthorizedKeyEntryLoginOptionsParseTest.java | 78 +++++++++-----------
.../pem/PKCS8PEMResourceKeyPairParserTest.java | 25 ++-----
.../sshd/common/io/nio2/Nio2ServiceTest.java | 22 ++----
.../util/net/SshdSocketIpv6AddressTest.java | 21 ++----
...SecurityProviderRegistrarCipherNameTest.java | 27 +++----
.../util/security/eddsa/Ed25519VectorsTest.java | 25 +++----
.../sshd/common/subsystem/sftp/SftpHelper.java | 78 ++++++++++----------
13 files changed, 188 insertions(+), 290 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-contrib/src/main/java/org/apache/sshd/common/config/keys/loader/putty/PuttyKeyUtils.java
----------------------------------------------------------------------
diff --git a/sshd-contrib/src/main/java/org/apache/sshd/common/config/keys/loader/putty/PuttyKeyUtils.java b/sshd-contrib/src/main/java/org/apache/sshd/common/config/keys/loader/putty/PuttyKeyUtils.java
index ee2851b..e750ace 100644
--- a/sshd-contrib/src/main/java/org/apache/sshd/common/config/keys/loader/putty/PuttyKeyUtils.java
+++ b/sshd-contrib/src/main/java/org/apache/sshd/common/config/keys/loader/putty/PuttyKeyUtils.java
@@ -33,43 +33,33 @@ import org.apache.sshd.common.util.security.SecurityUtils;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public final class PuttyKeyUtils {
- public static final List<PuttyKeyPairResourceParser<?, ?>> DEFAULT_PARSERS =
- Collections.unmodifiableList(new ArrayList<PuttyKeyPairResourceParser<?, ?>>() {
- // Not serializing it
- private static final long serialVersionUID = 1L;
+ public static final List<PuttyKeyPairResourceParser<?, ?>> DEFAULT_PARSERS;
- {
- add(RSAPuttyKeyDecoder.INSTANCE);
- add(DSSPuttyKeyDecoder.INSTANCE);
+ public static final NavigableMap<String, PuttyKeyPairResourceParser<?, ?>> BY_KEY_TYPE;
- if (SecurityUtils.isECCSupported()) {
- add(ECDSAPuttyKeyDecoder.INSTANCE);
- }
+ public static final KeyPairResourceParser DEFAULT_INSTANCE;
- if (SecurityUtils.isEDDSACurveSupported()) {
- add(EdDSAPuttyKeyDecoder.INSTANCE);
- }
- }
- });
-
- public static final NavigableMap<String, PuttyKeyPairResourceParser<?, ?>> BY_KEY_TYPE =
- Collections.unmodifiableNavigableMap(
- new TreeMap<String, PuttyKeyPairResourceParser<?, ?>>(String.CASE_INSENSITIVE_ORDER) {
- // Not serializing it
- private static final long serialVersionUID = 1L;
-
- {
- for (PuttyKeyPairResourceParser<?, ?> p : DEFAULT_PARSERS) {
- Collection<String> supported = p.getSupportedTypeNames();
- for (String k : supported) {
- put(k, p);
- }
- }
- }
- });
-
- public static final KeyPairResourceParser DEFAULT_INSTANCE =
- KeyPairResourceParser.aggregate(DEFAULT_PARSERS);
+ static {
+ List<PuttyKeyPairResourceParser<?, ?>> parsers = new ArrayList<>();
+ parsers.add(RSAPuttyKeyDecoder.INSTANCE);
+ parsers.add(DSSPuttyKeyDecoder.INSTANCE);
+ if (SecurityUtils.isECCSupported()) {
+ parsers.add(ECDSAPuttyKeyDecoder.INSTANCE);
+ }
+ if (SecurityUtils.isEDDSACurveSupported()) {
+ parsers.add(EdDSAPuttyKeyDecoder.INSTANCE);
+ }
+ NavigableMap<String, PuttyKeyPairResourceParser<?, ?>> map = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ for (PuttyKeyPairResourceParser<?, ?> p : parsers) {
+ Collection<String> supported = p.getSupportedTypeNames();
+ for (String k : supported) {
+ map.put(k, p);
+ }
+ }
+ DEFAULT_PARSERS = Collections.unmodifiableList(parsers);
+ BY_KEY_TYPE = Collections.unmodifiableNavigableMap(map);
+ DEFAULT_INSTANCE = KeyPairResourceParser.aggregate(parsers);
+ }
private PuttyKeyUtils() {
throw new UnsupportedOperationException("No instance");
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
index c701dbe..128214b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
@@ -19,19 +19,18 @@
package org.apache.sshd.agent.unix;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
+import java.util.stream.Collectors;
import org.apache.sshd.agent.SshAgent;
import org.apache.sshd.agent.SshAgentFactory;
import org.apache.sshd.agent.SshAgentServer;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.NamedResource;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.session.ConnectionService;
@@ -84,27 +83,19 @@ public class UnixAgentFactory implements SshAgentFactory, ExecutorServiceConfigu
@Override
public List<NamedFactory<Channel>> getChannelForwardingFactories(FactoryManager manager) {
final ExecutorServiceConfigurer configurer = this;
- return Collections.unmodifiableList(new ArrayList<NamedFactory<Channel>>(DEFAULT_FORWARDING_CHANNELS.size()) {
- // Not serializing it
- private static final long serialVersionUID = 1L;
-
- {
- for (NamedResource r : DEFAULT_FORWARDING_CHANNELS) {
- String channelType = r.getName();
- add(new ChannelAgentForwardingFactory(channelType) {
- @Override
- public ExecutorService getExecutorService() {
- return configurer.getExecutorService();
- }
-
- @Override
- public boolean isShutdownOnExit() {
- return configurer.isShutdownOnExit();
- }
- });
- }
- }
- });
+ return Collections.unmodifiableList(DEFAULT_FORWARDING_CHANNELS.stream()
+ .map(cf -> new ChannelAgentForwardingFactory(cf.getName()) {
+ @Override
+ public ExecutorService getExecutorService() {
+ return configurer.getExecutorService();
+ }
+
+ @Override
+ public boolean isShutdownOnExit() {
+ return configurer.isShutdownOnExit();
+ }
+ })
+ .collect(Collectors.toList()));
}
@Override
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/PrivateKeyEncryptionContext.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/PrivateKeyEncryptionContext.java b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/PrivateKeyEncryptionContext.java
index f4f4cda..5e03cdb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/PrivateKeyEncryptionContext.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/keys/loader/PrivateKeyEncryptionContext.java
@@ -23,10 +23,12 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.NavigableMap;
+import java.util.Map;
import java.util.NavigableSet;
import java.util.Objects;
-import java.util.TreeMap;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
@@ -37,18 +39,9 @@ import org.apache.sshd.common.util.ValidateUtils;
public class PrivateKeyEncryptionContext implements Cloneable {
public static final String DEFAULT_CIPHER_MODE = "CBC";
- private static final NavigableMap<String, PrivateKeyObfuscator> OBFUSCATORS =
- new TreeMap<String, PrivateKeyObfuscator>(String.CASE_INSENSITIVE_ORDER) {
- private static final long serialVersionUID = 1L; // no serialization expected
-
- {
- for (PrivateKeyObfuscator o : new PrivateKeyObfuscator[]{
- AESPrivateKeyObfuscator.INSTANCE, DESPrivateKeyObfuscator.INSTANCE
- }) {
- put(o.getCipherName(), o);
- }
- }
- };
+ private static final Map<String, PrivateKeyObfuscator> OBFUSCATORS =
+ Stream.of(AESPrivateKeyObfuscator.INSTANCE, DESPrivateKeyObfuscator.INSTANCE)
+ .collect(Collectors.toMap(AbstractPrivateKeyObfuscator::getCipherName, Function.identity()));
private String cipherName;
private String cipherType;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
index acf5761..d0983ff 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
@@ -48,20 +48,18 @@ import org.apache.sshd.common.util.closeable.AbstractInnerCloseable;
*/
public abstract class Nio2Service extends AbstractInnerCloseable implements IoService, FactoryManagerHolder {
// Note: order may be important so that's why we use a LinkedHashMap
- public static final Map<String, SimpleImmutableEntry<SocketOption<?>, Object>> CONFIGURABLE_OPTIONS =
- Collections.unmodifiableMap(new LinkedHashMap<String, SimpleImmutableEntry<SocketOption<?>, Object>>() {
- // Not serializing it
- private static final long serialVersionUID = 1L;
-
- {
- put(FactoryManager.SOCKET_KEEPALIVE, new SimpleImmutableEntry<>(StandardSocketOptions.SO_KEEPALIVE, null));
- put(FactoryManager.SOCKET_LINGER, new SimpleImmutableEntry<>(StandardSocketOptions.SO_LINGER, null));
- put(FactoryManager.SOCKET_RCVBUF, new SimpleImmutableEntry<>(StandardSocketOptions.SO_RCVBUF, null));
- put(FactoryManager.SOCKET_REUSEADDR, new SimpleImmutableEntry<>(StandardSocketOptions.SO_REUSEADDR, DEFAULT_REUSE_ADDRESS));
- put(FactoryManager.SOCKET_SNDBUF, new SimpleImmutableEntry<>(StandardSocketOptions.SO_SNDBUF, null));
- put(FactoryManager.TCP_NODELAY, new SimpleImmutableEntry<>(StandardSocketOptions.TCP_NODELAY, null));
- }
- });
+ public static final Map<String, SimpleImmutableEntry<SocketOption<?>, Object>> CONFIGURABLE_OPTIONS;
+
+ static {
+ Map<String, SimpleImmutableEntry<SocketOption<?>, Object>> map = new LinkedHashMap<>();
+ map.put(FactoryManager.SOCKET_KEEPALIVE, new SimpleImmutableEntry<>(StandardSocketOptions.SO_KEEPALIVE, null));
+ map.put(FactoryManager.SOCKET_LINGER, new SimpleImmutableEntry<>(StandardSocketOptions.SO_LINGER, null));
+ map.put(FactoryManager.SOCKET_RCVBUF, new SimpleImmutableEntry<>(StandardSocketOptions.SO_RCVBUF, null));
+ map.put(FactoryManager.SOCKET_REUSEADDR, new SimpleImmutableEntry<>(StandardSocketOptions.SO_REUSEADDR, DEFAULT_REUSE_ADDRESS));
+ map.put(FactoryManager.SOCKET_SNDBUF, new SimpleImmutableEntry<>(StandardSocketOptions.SO_SNDBUF, null));
+ map.put(FactoryManager.TCP_NODELAY, new SimpleImmutableEntry<>(StandardSocketOptions.TCP_NODELAY, null));
+ CONFIGURABLE_OPTIONS = Collections.unmodifiableMap(map);
+ }
protected final Map<Long, IoSession> sessions;
protected final AtomicBoolean disposing = new AtomicBoolean();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-core/src/main/java/org/apache/sshd/common/util/net/SshdSocketAddress.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/net/SshdSocketAddress.java b/sshd-core/src/main/java/org/apache/sshd/common/util/net/SshdSocketAddress.java
index c14b7f1..9e51bd9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/net/SshdSocketAddress.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/net/SshdSocketAddress.java
@@ -29,10 +29,10 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
+import java.util.LinkedHashSet;
import java.util.List;
-import java.util.NavigableSet;
import java.util.Objects;
-import java.util.TreeSet;
+import java.util.Set;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.NumberUtils;
@@ -62,16 +62,8 @@ public class SshdSocketAddress extends SocketAddress {
public static final String LOCALHOST_IPV4 = "127.0.0.1";
public static final String IPV4_ANYADDR = "0.0.0.0";
- public static final NavigableSet<String> WELL_KNOWN_IPV4_ADDRESSES =
- Collections.unmodifiableNavigableSet(
- new TreeSet<String>(String.CASE_INSENSITIVE_ORDER) {
- // Not serializing it
- private static final long serialVersionUID = 1L;
-
- {
- addAll(Arrays.asList(LOCALHOST_IPV4, IPV4_ANYADDR));
- }
- });
+ public static final Set<String> WELL_KNOWN_IPV4_ADDRESSES =
+ Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(LOCALHOST_IPV4, IPV4_ANYADDR)));
// 10.0.0.0 - 10.255.255.255
public static final String PRIVATE_CLASS_A_PREFIX = "10.";
@@ -96,18 +88,10 @@ public class SshdSocketAddress extends SocketAddress {
public static final String IPV6_LONG_LOCALHOST = "0:0:0:0:0:0:0:1";
public static final String IPV6_SHORT_LOCALHOST = "::1";
- public static final NavigableSet<String> WELL_KNOWN_IPV6_ADDRESSES =
- Collections.unmodifiableNavigableSet(
- new TreeSet<String>(String.CASE_INSENSITIVE_ORDER) {
- // Not serializing it
- private static final long serialVersionUID = 1L;
-
- {
- addAll(Arrays.asList(
- IPV6_LONG_LOCALHOST, IPV6_SHORT_LOCALHOST,
- IPV6_LONG_ANY_ADDRESS, IPV6_SHORT_ANY_ADDRESS));
- }
- });
+ public static final Set<String> WELL_KNOWN_IPV6_ADDRESSES =
+ Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(
+ IPV6_LONG_LOCALHOST, IPV6_SHORT_LOCALHOST,
+ IPV6_LONG_ANY_ADDRESS, IPV6_SHORT_ANY_ADDRESS)));
/**
* A dummy placeholder that can be used instead of {@code null}s
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java
index 2a8ccd6..90e9811 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java
@@ -20,7 +20,6 @@ package org.apache.sshd.common.channel;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import org.apache.sshd.client.future.OpenFuture;
@@ -85,30 +84,21 @@ public class WindowInitTest extends BaseTestSupport {
@Parameters(name = "initial-size={0}, packet-size={1}")
public static List<Object[]> parameters() {
- return Collections.unmodifiableList(new ArrayList<Object[]>() {
- // Not serializing it
- private static final long serialVersionUID = 1L;
-
- {
- addTestCase(Byte.MIN_VALUE, FactoryManager.DEFAULT_MAX_PACKET_SIZE);
- addTestCase(BufferUtils.MAX_UINT32_VALUE + 1L, FactoryManager.DEFAULT_MAX_PACKET_SIZE);
- addTestCase(FactoryManager.DEFAULT_WINDOW_SIZE, 0L);
- addTestCase(FactoryManager.DEFAULT_WINDOW_SIZE, Byte.MIN_VALUE);
- addTestCase(FactoryManager.DEFAULT_WINDOW_SIZE, BufferUtils.MAX_UINT32_VALUE + 1L);
- addTestCase(FactoryManager.DEFAULT_WINDOW_SIZE, FactoryManager.DEFAULT_LIMIT_PACKET_SIZE + 1L);
- }
-
- private void addTestCase(long initialSize, long packetSize) {
- add(new Object[]{initialSize, packetSize});
- }
- });
+ List<Object[]> params = new ArrayList<>();
+ params.add(new Object[] {Byte.MIN_VALUE, FactoryManager.DEFAULT_MAX_PACKET_SIZE });
+ params.add(new Object[] {BufferUtils.MAX_UINT32_VALUE + 1L, FactoryManager.DEFAULT_MAX_PACKET_SIZE });
+ params.add(new Object[] {FactoryManager.DEFAULT_WINDOW_SIZE, 0L });
+ params.add(new Object[] {FactoryManager.DEFAULT_WINDOW_SIZE, Byte.MIN_VALUE });
+ params.add(new Object[] {FactoryManager.DEFAULT_WINDOW_SIZE, BufferUtils.MAX_UINT32_VALUE + 1L });
+ params.add(new Object[] {FactoryManager.DEFAULT_WINDOW_SIZE, FactoryManager.DEFAULT_LIMIT_PACKET_SIZE + 1L });
+ return params;
}
@Test(expected = IllegalArgumentException.class)
public void testInitializationFailure() throws IOException {
try (Window w = new Window(MOCK_CHANNEL, null, true, true)) {
w.init(initialSize, packetSize, PropertyResolver.EMPTY);
- fail("Unexpected success for initialiSize=" + initialSize + ", packetSize=" + packetSize);
+ fail("Unexpected success for initialSize=" + initialSize + ", packetSize=" + packetSize);
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryLoginOptionsParseTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryLoginOptionsParseTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryLoginOptionsParseTest.java
index 7f3be56..5588622 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryLoginOptionsParseTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryLoginOptionsParseTest.java
@@ -19,7 +19,6 @@
package org.apache.sshd.common.config.keys;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -56,55 +55,48 @@ public class AuthorizedKeyEntryLoginOptionsParseTest extends BaseTestSupport {
@Parameters(name = "{0}")
public static List<Object[]> parameters() {
- return Collections.unmodifiableList(new ArrayList<Object[]>() {
- // not serializing it
- private static final long serialVersionUID = 1L;
+ List<Object[]> params = new ArrayList<>();
+ addData(params, "ssh-rsa AAAAB2...19Q==", "john@example.net", "from=\"*.sales.example.net,!pc.sales.example.net\"");
+ addData(params, "ssh-dss AAAAC3...51R==", "example.net", "command=\"dump /home\"", "no-pty", "no-port-forwarding");
+ addData(params, "ssh-dss AAAAB5...21S==", "", "permitopen=\"192.0.2.1:80\"", "permitopen=\"192.0.2.2:25\"");
+ addData(params, "ssh-rsa AAAA...==", "jane@example.net", "tunnel=\"0\"", "command=\"sh /etc/netstart tun0\"");
+ addData(params, "ssh-rsa AAAA1C8...32Tv==", "user@example.net", "!restrict", "command=\"uptime\"");
+ addData(params, "ssh-rsa AAAA1f8...IrrC5==", "user@example.net", "restrict", "!pty", "command=\"nethack\"");
+ return params;
+ }
- private final StringBuilder sb = new StringBuilder(Byte.MAX_VALUE);
+ private static void addData(List<Object[]> params, String keyData, String comment, String... comps) {
+ StringBuilder sb = new StringBuilder();
- {
- addData("ssh-rsa AAAAB2...19Q==", "john@example.net", "from=\"*.sales.example.net,!pc.sales.example.net\"");
- addData("ssh-dss AAAAC3...51R==", "example.net", "command=\"dump /home\"", "no-pty", "no-port-forwarding");
- addData("ssh-dss AAAAB5...21S==", "", "permitopen=\"192.0.2.1:80\"", "permitopen=\"192.0.2.2:25\"");
- addData("ssh-rsa AAAA...==", "jane@example.net", "tunnel=\"0\"", "command=\"sh /etc/netstart tun0\"");
- addData("ssh-rsa AAAA1C8...32Tv==", "user@example.net", "!restrict", "command=\"uptime\"");
- addData("ssh-rsa AAAA1f8...IrrC5==", "user@example.net", "restrict", "!pty", "command=\"nethack\"");
+ Map<String, String> optionsMap = new HashMap<>();
+ for (String c : comps) {
+ if (sb.length() > 0) {
+ sb.append(',');
}
-
- private void addData(String keyData, String comment, String... comps) {
- sb.setLength(0);
-
- Map<String, String> optionsMap = new HashMap<>();
- for (String c : comps) {
- if (sb.length() > 0) {
- sb.append(',');
- }
- sb.append(c);
-
- int pos = c.indexOf('=');
- if (pos > 0) {
- String name = c.substring(0, pos);
- String value = GenericUtils.stripQuotes(c.substring(pos + 1)).toString();
- String prev = optionsMap.put(name, value);
- if (prev != null) {
- optionsMap.put(name, prev + "," + value);
- }
- } else {
- optionsMap.put(c, Boolean.toString(c.charAt(0) != AuthorizedKeyEntry.BOOLEAN_OPTION_NEGATION_INDICATOR));
- }
+ sb.append(c);
+
+ int pos = c.indexOf('=');
+ if (pos > 0) {
+ String name = c.substring(0, pos);
+ String value = GenericUtils.stripQuotes(c.substring(pos + 1)).toString();
+ String prev = optionsMap.put(name, value);
+ if (prev != null) {
+ optionsMap.put(name, prev + "," + value);
}
+ } else {
+ optionsMap.put(c, Boolean.toString(c.charAt(0) != AuthorizedKeyEntry.BOOLEAN_OPTION_NEGATION_INDICATOR));
+ }
+ }
- int pos = sb.length();
+ int pos = sb.length();
- sb.append(' ').append(keyData);
- if (GenericUtils.isNotEmpty(comment)) {
- sb.append(' ').append(comment);
- }
+ sb.append(' ').append(keyData);
+ if (GenericUtils.isNotEmpty(comment)) {
+ sb.append(' ').append(comment);
+ }
- String value = sb.toString();
- add(new Object[] {value, value.substring(0, pos), value.substring(pos + 1), optionsMap});
- }
- });
+ String value = sb.toString();
+ params.add(new Object[] {value, value.substring(0, pos), value.substring(pos + 1), optionsMap});
}
@Test
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/pem/PKCS8PEMResourceKeyPairParserTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/pem/PKCS8PEMResourceKeyPairParserTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/pem/PKCS8PEMResourceKeyPairParserTest.java
index 7e1aba7..69e6b66 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/pem/PKCS8PEMResourceKeyPairParserTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/loader/pem/PKCS8PEMResourceKeyPairParserTest.java
@@ -27,7 +27,6 @@ import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import org.apache.commons.ssl.PEMItem;
@@ -66,22 +65,14 @@ public class PKCS8PEMResourceKeyPairParserTest extends BaseTestSupport {
@Parameters(name = "{0} / {1}")
public static List<Object[]> parameters() {
- return Collections.unmodifiableList(new ArrayList<Object[]>() {
- // Not serializing it
- private static final long serialVersionUID = 1L;
-
- {
- addTestCases(KeyUtils.RSA_ALGORITHM, RSA_SIZES);
- addTestCases(KeyUtils.DSS_ALGORITHM, DSS_SIZES);
- // TODO add test cases for ECDSA
- }
-
- private void addTestCases(String algorithm, Collection<Integer> keySizes) {
- for (Integer ks : keySizes) {
- add(new Object[]{algorithm, ks});
- }
- }
- });
+ List<Object[]> params = new ArrayList<>();
+ for (Integer ks : RSA_SIZES) {
+ params.add(new Object[]{KeyUtils.RSA_ALGORITHM, ks});
+ }
+ for (Integer ks : DSS_SIZES) {
+ params.add(new Object[]{KeyUtils.DSS_ALGORITHM, ks});
+ }
+ return params;
}
@Test // see SSHD-760
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-core/src/test/java/org/apache/sshd/common/io/nio2/Nio2ServiceTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/io/nio2/Nio2ServiceTest.java b/sshd-core/src/test/java/org/apache/sshd/common/io/nio2/Nio2ServiceTest.java
index a2a6436..0ab8ff4 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/io/nio2/Nio2ServiceTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/io/nio2/Nio2ServiceTest.java
@@ -25,7 +25,6 @@ import java.net.SocketOption;
import java.nio.channels.AsynchronousSocketChannel;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -57,20 +56,13 @@ public class Nio2ServiceTest extends BaseTestSupport {
@Test // see SSHD-554, SSHD-722
public void testSetSocketOptions() throws Exception {
try (SshServer sshd = setupTestServer()) {
- Map<String, Object> expectedOptions =
- Collections.unmodifiableMap(new LinkedHashMap<String, Object>() {
- // Not serializing it
- private static final long serialVersionUID = 1L;
-
- {
- put(FactoryManager.SOCKET_KEEPALIVE, true);
- put(FactoryManager.SOCKET_LINGER, 5);
- put(FactoryManager.SOCKET_RCVBUF, 1024);
- put(FactoryManager.SOCKET_REUSEADDR, true);
- put(FactoryManager.SOCKET_SNDBUF, 1024);
- put(FactoryManager.TCP_NODELAY, true);
- }
- });
+ Map<String, Object> expectedOptions = new LinkedHashMap<String, Object>();
+ expectedOptions.put(FactoryManager.SOCKET_KEEPALIVE, true);
+ expectedOptions.put(FactoryManager.SOCKET_LINGER, 5);
+ expectedOptions.put(FactoryManager.SOCKET_RCVBUF, 1024);
+ expectedOptions.put(FactoryManager.SOCKET_REUSEADDR, true);
+ expectedOptions.put(FactoryManager.SOCKET_SNDBUF, 1024);
+ expectedOptions.put(FactoryManager.TCP_NODELAY, true);
for (Map.Entry<String, ?> oe : expectedOptions.entrySet()) {
PropertyResolverUtils.updateProperty(sshd, oe.getKey(), oe.getValue());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-core/src/test/java/org/apache/sshd/common/util/net/SshdSocketIpv6AddressTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/net/SshdSocketIpv6AddressTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/net/SshdSocketIpv6AddressTest.java
index bab005f..cc69df5 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/net/SshdSocketIpv6AddressTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/net/SshdSocketIpv6AddressTest.java
@@ -18,10 +18,11 @@
*/
package org.apache.sshd.common.util.net;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.sshd.util.test.BaseTestSupport;
import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory;
@@ -66,20 +67,10 @@ public class SshdSocketIpv6AddressTest extends BaseTestSupport {
@Parameters(name = "{0}")
public static List<Object[]> parameters() {
- return new ArrayList<Object[]>() {
- // Not serializing it
- private static final long serialVersionUID = 1L;
-
- {
- for (String address : SshdSocketAddress.WELL_KNOWN_IPV6_ADDRESSES) {
- add(new Object[] {address, Boolean.TRUE});
- }
-
- for (String address : VALID_ADDRESSES) {
- add(new Object[] {address, Boolean.TRUE});
- }
- }
- };
+ return Stream
+ .concat(SshdSocketAddress.WELL_KNOWN_IPV6_ADDRESSES.stream(), VALID_ADDRESSES.stream())
+ .map(address -> new Object[] {address, Boolean.TRUE})
+ .collect(Collectors.toList());
}
@Test
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarCipherNameTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarCipherNameTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarCipherNameTest.java
index db50770..c0c89eb 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarCipherNameTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/security/SecurityProviderRegistrarCipherNameTest.java
@@ -19,7 +19,6 @@
package org.apache.sshd.common.util.security;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import javax.crypto.Cipher;
@@ -54,23 +53,17 @@ public class SecurityProviderRegistrarCipherNameTest extends BaseTestSupport {
@Parameters(name = "{0}")
public static List<Object[]> parameters() {
- return Collections.unmodifiableList(
- new ArrayList<Object[]>(BuiltinCiphers.VALUES.size()) {
- // Not serializing it
- private static final long serialVersionUID = 1L;
+ List<Object[]> params = new ArrayList<>();
+ for (CipherInformation cipherInfo : BuiltinCiphers.VALUES) {
+ String algorithm = cipherInfo.getAlgorithm();
+ String xform = cipherInfo.getTransformation();
+ if (!xform.startsWith(algorithm)) {
+ continue;
+ }
- {
- for (CipherInformation cipherInfo : BuiltinCiphers.VALUES) {
- String algorithm = cipherInfo.getAlgorithm();
- String xform = cipherInfo.getTransformation();
- if (!xform.startsWith(algorithm)) {
- continue;
- }
-
- add(new Object[]{cipherInfo});
- }
- }
- });
+ params.add(new Object[]{cipherInfo});
+ }
+ return params;
}
@Test
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/Ed25519VectorsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/Ed25519VectorsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/Ed25519VectorsTest.java
index 8354c21..00a64b9 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/Ed25519VectorsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/security/eddsa/Ed25519VectorsTest.java
@@ -24,6 +24,7 @@ import java.security.GeneralSecurityException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import net.i2p.crypto.eddsa.EdDSAPrivateKey;
@@ -76,12 +77,8 @@ public class Ed25519VectorsTest extends BaseTestSupport {
@Parameters(name = "{0}")
@SuppressWarnings("checkstyle:anoninnerlength")
public static List<Object[]> parameters() {
- return new ArrayList<Object[]>() {
- // Not serializing it
- private static final long serialVersionUID = 1L;
-
- {
- add(new Object[]{
+ return new ArrayList<>(Arrays.asList(
+ new Object[]{
"TEST1 - empty message",
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60",
"d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a",
@@ -90,8 +87,8 @@ public class Ed25519VectorsTest extends BaseTestSupport {
+ "84877f1eb8e5d974d873e06522490155"
+ "5fb8821590a33bacc61e39701cf9b46b"
+ "d25bf5f0595bbe24655141438e7a100b"
- });
- add(new Object[]{
+ },
+ new Object[]{
"TEST2 - one byte",
"4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb",
"3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c",
@@ -100,8 +97,8 @@ public class Ed25519VectorsTest extends BaseTestSupport {
+ "a2b27b5416503f8fb3762223ebdb69da"
+ "085ac1e43e15996e458f3613d0f11d8c"
+ "387b2eaeb4302aeeb00d291612bb0c00"
- });
- add(new Object[]{
+ },
+ new Object[]{
"TEST3 - 2 bytes",
"c5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7",
"fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025",
@@ -110,8 +107,8 @@ public class Ed25519VectorsTest extends BaseTestSupport {
+ "0ce548a284743a445e3680d7db5ac3ac"
+ "18ff9b538d16f290ae67f760984dc659"
+ "4a7c15e9716ed28dc027beceea1ec40a"
- });
- add(new Object[]{
+ },
+ new Object[]{
"TEST1024 - large message",
"f5e5767cf153319517630f226876b86c8160cc583bc013744c6bf255f5cc0ee5",
"278117fc144c72340f67d0f2316e8386ceffbf2b2428c9c51fef7c597f1d426e",
@@ -183,9 +180,7 @@ public class Ed25519VectorsTest extends BaseTestSupport {
+ "87df5e4843b2cbdb67cbf6e460fec350"
+ "aa5371b1508f9f4528ecea23c436d94b"
+ "5e8fcd4f681e30a6ac00a9704a188a03"
- });
- }
- };
+ }));
}
@BeforeClass
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3c6bfab4/sshd-sftp/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpHelper.java
----------------------------------------------------------------------
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpHelper.java b/sshd-sftp/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpHelper.java
index 90cdfad..d0d87e7 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpHelper.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpHelper.java
@@ -80,46 +80,44 @@ public final class SftpHelper {
*/
public static final boolean DEFAULT_APPEND_END_OF_LIST_INDICATOR = true;
- public static final NavigableMap<Integer, String> DEFAULT_SUBSTATUS_MESSAGE =
- Collections.unmodifiableNavigableMap(new TreeMap<Integer, String>(Comparator.naturalOrder()) {
- // Not serializing it
- private static final long serialVersionUID = 1L;
-
- {
- put(SftpConstants.SSH_FX_OK, "Success");
- put(SftpConstants.SSH_FX_EOF, "End of file");
- put(SftpConstants.SSH_FX_NO_SUCH_FILE, "No such file or directory");
- put(SftpConstants.SSH_FX_PERMISSION_DENIED, "Permission denied");
- put(SftpConstants.SSH_FX_FAILURE, "General failure");
- put(SftpConstants.SSH_FX_BAD_MESSAGE, "Bad message data");
- put(SftpConstants.SSH_FX_NO_CONNECTION, "No connection to server");
- put(SftpConstants.SSH_FX_CONNECTION_LOST, "Connection lost");
- put(SftpConstants.SSH_FX_OP_UNSUPPORTED, "Unsupported operation requested");
- put(SftpConstants.SSH_FX_INVALID_HANDLE, "Invalid handle value");
- put(SftpConstants.SSH_FX_NO_SUCH_PATH, "No such path");
- put(SftpConstants.SSH_FX_FILE_ALREADY_EXISTS, "File/Directory already exists");
- put(SftpConstants.SSH_FX_WRITE_PROTECT, "File/Directory is write-protected");
- put(SftpConstants.SSH_FX_NO_MEDIA, "No such meadia");
- put(SftpConstants.SSH_FX_NO_SPACE_ON_FILESYSTEM, "No space left on device");
- put(SftpConstants.SSH_FX_QUOTA_EXCEEDED, "Quota exceeded");
- put(SftpConstants.SSH_FX_UNKNOWN_PRINCIPAL, "Unknown user/group");
- put(SftpConstants.SSH_FX_LOCK_CONFLICT, "Lock conflict");
- put(SftpConstants.SSH_FX_DIR_NOT_EMPTY, "Directory not empty");
- put(SftpConstants.SSH_FX_NOT_A_DIRECTORY, "Accessed location is not a directory");
- put(SftpConstants.SSH_FX_INVALID_FILENAME, "Invalid filename");
- put(SftpConstants.SSH_FX_LINK_LOOP, "Link loop");
- put(SftpConstants.SSH_FX_CANNOT_DELETE, "Cannot remove");
- put(SftpConstants.SSH_FX_INVALID_PARAMETER, "Invalid parameter");
- put(SftpConstants.SSH_FX_FILE_IS_A_DIRECTORY, "Accessed location is a directory");
- put(SftpConstants.SSH_FX_BYTE_RANGE_LOCK_CONFLICT, "Range lock conflict");
- put(SftpConstants.SSH_FX_BYTE_RANGE_LOCK_REFUSED, "Range lock refused");
- put(SftpConstants.SSH_FX_DELETE_PENDING, "Delete pending");
- put(SftpConstants.SSH_FX_FILE_CORRUPT, "Corrupted file/directory");
- put(SftpConstants.SSH_FX_OWNER_INVALID, "Invalid file/directory owner");
- put(SftpConstants.SSH_FX_GROUP_INVALID, "Invalid file/directory group");
- put(SftpConstants.SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK, "No matching byte range lock");
- }
- });
+ public static final Map<Integer, String> DEFAULT_SUBSTATUS_MESSAGE;
+
+ static {
+ Map<Integer, String> map = new TreeMap<>(Comparator.naturalOrder());
+ map.put(SftpConstants.SSH_FX_OK, "Success");
+ map.put(SftpConstants.SSH_FX_EOF, "End of file");
+ map.put(SftpConstants.SSH_FX_NO_SUCH_FILE, "No such file or directory");
+ map.put(SftpConstants.SSH_FX_PERMISSION_DENIED, "Permission denied");
+ map.put(SftpConstants.SSH_FX_FAILURE, "General failure");
+ map.put(SftpConstants.SSH_FX_BAD_MESSAGE, "Bad message data");
+ map.put(SftpConstants.SSH_FX_NO_CONNECTION, "No connection to server");
+ map.put(SftpConstants.SSH_FX_CONNECTION_LOST, "Connection lost");
+ map.put(SftpConstants.SSH_FX_OP_UNSUPPORTED, "Unsupported operation requested");
+ map.put(SftpConstants.SSH_FX_INVALID_HANDLE, "Invalid handle value");
+ map.put(SftpConstants.SSH_FX_NO_SUCH_PATH, "No such path");
+ map.put(SftpConstants.SSH_FX_FILE_ALREADY_EXISTS, "File/Directory already exists");
+ map.put(SftpConstants.SSH_FX_WRITE_PROTECT, "File/Directory is write-protected");
+ map.put(SftpConstants.SSH_FX_NO_MEDIA, "No such meadia");
+ map.put(SftpConstants.SSH_FX_NO_SPACE_ON_FILESYSTEM, "No space left on device");
+ map.put(SftpConstants.SSH_FX_QUOTA_EXCEEDED, "Quota exceeded");
+ map.put(SftpConstants.SSH_FX_UNKNOWN_PRINCIPAL, "Unknown user/group");
+ map.put(SftpConstants.SSH_FX_LOCK_CONFLICT, "Lock conflict");
+ map.put(SftpConstants.SSH_FX_DIR_NOT_EMPTY, "Directory not empty");
+ map.put(SftpConstants.SSH_FX_NOT_A_DIRECTORY, "Accessed location is not a directory");
+ map.put(SftpConstants.SSH_FX_INVALID_FILENAME, "Invalid filename");
+ map.put(SftpConstants.SSH_FX_LINK_LOOP, "Link loop");
+ map.put(SftpConstants.SSH_FX_CANNOT_DELETE, "Cannot remove");
+ map.put(SftpConstants.SSH_FX_INVALID_PARAMETER, "Invalid parameter");
+ map.put(SftpConstants.SSH_FX_FILE_IS_A_DIRECTORY, "Accessed location is a directory");
+ map.put(SftpConstants.SSH_FX_BYTE_RANGE_LOCK_CONFLICT, "Range lock conflict");
+ map.put(SftpConstants.SSH_FX_BYTE_RANGE_LOCK_REFUSED, "Range lock refused");
+ map.put(SftpConstants.SSH_FX_DELETE_PENDING, "Delete pending");
+ map.put(SftpConstants.SSH_FX_FILE_CORRUPT, "Corrupted file/directory");
+ map.put(SftpConstants.SSH_FX_OWNER_INVALID, "Invalid file/directory owner");
+ map.put(SftpConstants.SSH_FX_GROUP_INVALID, "Invalid file/directory group");
+ map.put(SftpConstants.SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK, "No matching byte range lock");
+ DEFAULT_SUBSTATUS_MESSAGE = Collections.unmodifiableMap(map);
+ }
private SftpHelper() {
throw new UnsupportedOperationException("No instance allowed");