http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 b040853..5da403c 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 @@ -284,7 +284,7 @@ public abstract class Buffer implements Readable { } public PublicKey getPublicKey() throws SshException { - return getPublicKey(BufferPublicKeyParser.Utils.DEFAULT); + return getPublicKey(BufferPublicKeyParser.DEFAULT); } /** @@ -306,7 +306,7 @@ public abstract class Buffer implements Readable { } public PublicKey getRawPublicKey() throws SshException { - return getRawPublicKey(BufferPublicKeyParser.Utils.DEFAULT); + return getRawPublicKey(BufferPublicKeyParser.DEFAULT); } /**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java index ab62c0e..3f8ee1e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/BufferUtils.java @@ -48,12 +48,7 @@ public final class BufferUtils { public static final Level DEFAULT_HEXDUMP_LEVEL = Level.FINEST; public static final Int2IntFunction DEFAULT_BUFFER_GROWTH_FACTOR = - new Int2IntFunction() { - @Override - public int apply(int value) { - return getNextPowerOf2(value); - } - }; + BufferUtils::getNextPowerOf2; /** * Private Constructor http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/BufferPublicKeyParser.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/BufferPublicKeyParser.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/BufferPublicKeyParser.java index bcd3173..6d05868 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/BufferPublicKeyParser.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/keys/BufferPublicKeyParser.java @@ -35,6 +35,7 @@ import org.apache.sshd.common.util.buffer.Buffer; * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public interface BufferPublicKeyParser<PUB extends PublicKey> { + BufferPublicKeyParser<PublicKey> EMPTY = new BufferPublicKeyParser<PublicKey>() { @Override public boolean isKeyTypeSupported(String keyType) { @@ -52,6 +53,12 @@ public interface BufferPublicKeyParser<PUB extends PublicKey> { } }; + BufferPublicKeyParser<PublicKey> DEFAULT = aggregate( + Arrays.asList( + RSABufferPublicKeyParser.INSTANCE, + DSSBufferPublicKeyParser.INSTANCE, + ECBufferPublicKeyParser.INSTANCE)); + /** * @param keyType The key type - e.g., "ssh-rsa", "ssh-dss" * @return {@code true} if this key type is supported by the parser @@ -71,51 +78,53 @@ public interface BufferPublicKeyParser<PUB extends PublicKey> { * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ // CHECKSTYLE:OFF + @Deprecated final class Utils { // CHECKSTYLE:ON - public static final BufferPublicKeyParser<PublicKey> DEFAULT = aggregate( - Arrays.asList( - RSABufferPublicKeyParser.INSTANCE, - DSSBufferPublicKeyParser.INSTANCE, - ECBufferPublicKeyParser.INSTANCE)); + + public static final BufferPublicKeyParser<PublicKey> DEFAULT = BufferPublicKeyParser.DEFAULT; private Utils() { throw new UnsupportedOperationException("No instance"); } public static BufferPublicKeyParser<PublicKey> aggregate(final Collection<? extends BufferPublicKeyParser<? extends PublicKey>> parsers) { - if (GenericUtils.isEmpty(parsers)) { - return EMPTY; - } + return BufferPublicKeyParser.aggregate(parsers); + } + } - return new BufferPublicKeyParser<PublicKey>() { - @Override - public boolean isKeyTypeSupported(String keyType) { - for (BufferPublicKeyParser<? extends PublicKey> p : parsers) { - if (p.isKeyTypeSupported(keyType)) { - return true; - } - } + static BufferPublicKeyParser<PublicKey> aggregate(final Collection<? extends BufferPublicKeyParser<? extends PublicKey>> parsers) { + if (GenericUtils.isEmpty(parsers)) { + return EMPTY; + } - return false; + return new BufferPublicKeyParser<PublicKey>() { + @Override + public boolean isKeyTypeSupported(String keyType) { + for (BufferPublicKeyParser<? extends PublicKey> p : parsers) { + if (p.isKeyTypeSupported(keyType)) { + return true; + } } - @Override - public PublicKey getRawPublicKey(String keyType, Buffer buffer) throws GeneralSecurityException { - for (BufferPublicKeyParser<? extends PublicKey> p : parsers) { - if (p.isKeyTypeSupported(keyType)) { - return p.getRawPublicKey(keyType, buffer); - } - } + return false; + } - throw new NoSuchAlgorithmException("No aggregate matcher for " + keyType); + @Override + public PublicKey getRawPublicKey(String keyType, Buffer buffer) throws GeneralSecurityException { + for (BufferPublicKeyParser<? extends PublicKey> p : parsers) { + if (p.isKeyTypeSupported(keyType)) { + return p.getRawPublicKey(keyType, buffer); + } } - @Override - public String toString() { - return String.valueOf(parsers); - } - }; - } + throw new NoSuchAlgorithmException("No aggregate matcher for " + keyType); + } + + @Override + public String toString() { + return String.valueOf(parsers); + } + }; } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractCloseable.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractCloseable.java b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractCloseable.java index c3780cb..1c5d78f 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractCloseable.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractCloseable.java @@ -95,15 +95,11 @@ public abstract class AbstractCloseable extends IoBaseCloseable { preClose(); SshFuture<CloseFuture> grace = doCloseGracefully(); if (grace != null) { - grace.addListener(new SshFutureListener<CloseFuture>() { - @Override - @SuppressWarnings("synthetic-access") - public void operationComplete(CloseFuture future) { - if (state.compareAndSet(State.Graceful, State.Immediate)) { - doCloseImmediately(); - if (log.isDebugEnabled()) { - log.debug("close({}][Graceful] - operationComplete() closed", AbstractCloseable.this); - } + grace.addListener(future -> { + if (state.compareAndSet(State.Graceful, State.Immediate)) { + doCloseImmediately(); + if (log.isDebugEnabled()) { + log.debug("close({}][Graceful] - operationComplete() closed", AbstractCloseable.this); } } }); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractInnerCloseable.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractInnerCloseable.java b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractInnerCloseable.java index d3a7087..949d04d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractInnerCloseable.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/AbstractInnerCloseable.java @@ -20,7 +20,6 @@ package org.apache.sshd.common.util.closeable; import org.apache.sshd.common.Closeable; import org.apache.sshd.common.future.CloseFuture; -import org.apache.sshd.common.future.SshFutureListener; /** * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> @@ -44,12 +43,6 @@ public abstract class AbstractInnerCloseable extends AbstractCloseable { @Override protected void doCloseImmediately() { - getInnerCloseable().close(true).addListener(new SshFutureListener<CloseFuture>() { - @Override - @SuppressWarnings("synthetic-access") - public void operationComplete(CloseFuture future) { - AbstractInnerCloseable.super.doCloseImmediately(); - } - }); + getInnerCloseable().close(true).addListener(future -> AbstractInnerCloseable.super.doCloseImmediately()); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/CloseableUtils.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/CloseableUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/CloseableUtils.java index 4d5d885..2309c7d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/CloseableUtils.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/CloseableUtils.java @@ -19,31 +19,30 @@ package org.apache.sshd.common.util.closeable; import java.io.IOException; -import java.net.SocketTimeoutException; -import java.util.concurrent.TimeUnit; import org.apache.sshd.common.Closeable; import org.apache.sshd.common.PropertyResolver; -import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.future.CloseFuture; /** * Utility class to help with {@link Closeable}s. * + * @deprecated Use Closeable static methods instead * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ +@Deprecated public final class CloseableUtils { /** * Timeout (milliseconds) for waiting on a {@link CloseFuture} to successfully * complete its action. * @see #DEFAULT_CLOSE_WAIT_TIMEOUT */ - public static final String CLOSE_WAIT_TIMEOUT = "sshd-close-wait-time"; + public static final String CLOSE_WAIT_TIMEOUT = Closeable.CLOSE_WAIT_TIMEOUT; /** * Default value for {@link #CLOSE_WAIT_TIMEOUT} if none specified */ - public static final long DEFAULT_CLOSE_WAIT_TIMEOUT = TimeUnit.SECONDS.toMillis(15L); + public static final long DEFAULT_CLOSE_WAIT_TIMEOUT = Closeable.DEFAULT_CLOSE_WAIT_TIMEOUT; /** * Private Constructor @@ -53,22 +52,10 @@ public final class CloseableUtils { } public static long getMaxCloseWaitTime(PropertyResolver resolver) { - return (resolver == null) ? DEFAULT_CLOSE_WAIT_TIMEOUT : PropertyResolverUtils.getLongProperty(resolver, CLOSE_WAIT_TIMEOUT, DEFAULT_CLOSE_WAIT_TIMEOUT); + return Closeable.getMaxCloseWaitTime(resolver); } - // TODO once JDK 8+ becomes the minimum for this project, make it a static method in the Closeable interface public static void close(Closeable closeable) throws IOException { - if (closeable == null) { - return; - } - - if ((!closeable.isClosed()) && (!closeable.isClosing())) { - CloseFuture future = closeable.close(true); - long maxWait = (closeable instanceof PropertyResolver) ? getMaxCloseWaitTime((PropertyResolver) closeable) : DEFAULT_CLOSE_WAIT_TIMEOUT; - boolean successful = future.await(maxWait); - if (!successful) { - throw new SocketTimeoutException("Failed to receive closure confirmation within " + maxWait + " millis"); - } - } + Closeable.close(closeable); } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/FuturesCloseable.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/FuturesCloseable.java b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/FuturesCloseable.java index 3b6188f..2a24ffc 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/FuturesCloseable.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/FuturesCloseable.java @@ -50,17 +50,13 @@ public class FuturesCloseable<T extends SshFuture> extends SimpleCloseable { future.setClosed(); } else { final AtomicInteger count = new AtomicInteger(1); - SshFutureListener<T> listener = new SshFutureListener<T>() { - @SuppressWarnings("synthetic-access") - @Override - public void operationComplete(T f) { - int pendingCount = count.decrementAndGet(); - if (log.isTraceEnabled()) { - log.trace("doClose(" + immediately + ") complete pending: " + pendingCount); - } - if (pendingCount == 0) { - future.setClosed(); - } + SshFutureListener<T> listener = f -> { + int pendingCount = count.decrementAndGet(); + if (log.isTraceEnabled()) { + log.trace("doClose(" + immediately + ") complete pending: " + pendingCount); + } + if (pendingCount == 0) { + future.setClosed(); } }; for (SshFuture<T> f : futures) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/IoBaseCloseable.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/IoBaseCloseable.java b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/IoBaseCloseable.java index d4af9d1..e8ef22b 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/IoBaseCloseable.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/IoBaseCloseable.java @@ -18,8 +18,6 @@ */ package org.apache.sshd.common.util.closeable; -import java.io.IOException; - import org.apache.sshd.common.Closeable; import org.apache.sshd.common.util.logging.AbstractLoggingBean; @@ -35,15 +33,4 @@ public abstract class IoBaseCloseable extends AbstractLoggingBean implements Clo super(discriminator); } - // TODO once JDK 8+ becomes the minimum for this project, make it a default method instead of this class - @Override - public boolean isOpen() { - return !(isClosed() || isClosing()); - } - - // TODO once JDK 8+ becomes the minimum for this project, make it a default method instead of this class - @Override - public void close() throws IOException { - CloseableUtils.close(this); - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/ParallelCloseable.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/ParallelCloseable.java b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/ParallelCloseable.java index a009ed8..029c9a0 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/ParallelCloseable.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/closeable/ParallelCloseable.java @@ -43,17 +43,13 @@ public class ParallelCloseable extends SimpleCloseable { @Override protected void doClose(final boolean immediately) { final AtomicInteger count = new AtomicInteger(1); - SshFutureListener<CloseFuture> listener = new SshFutureListener<CloseFuture>() { - @SuppressWarnings("synthetic-access") - @Override - public void operationComplete(CloseFuture f) { - int pendingCount = count.decrementAndGet(); - if (log.isTraceEnabled()) { - log.trace("doClose(" + immediately + ") completed pending: " + pendingCount); - } - if (pendingCount == 0) { - future.setClosed(); - } + SshFutureListener<CloseFuture> listener = f -> { + int pendingCount = count.decrementAndGet(); + if (log.isTraceEnabled()) { + log.trace("doClose(" + immediately + ") completed pending: " + pendingCount); + } + if (pendingCount == 0) { + future.setClosed(); } }; for (Closeable c : closeables) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/io/CloseableEmptyInputStream.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/io/CloseableEmptyInputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/util/io/CloseableEmptyInputStream.java index a11ec96..c9eca70 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/io/CloseableEmptyInputStream.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/io/CloseableEmptyInputStream.java @@ -89,6 +89,7 @@ public class CloseableEmptyInputStream extends EmptyInputStream implements Chann @Override public void close() throws IOException { if (open.getAndSet(false)) { + //noinspection UnnecessaryReturnStatement return; // debug breakpoint } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/io/FileInfoExtractor.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/io/FileInfoExtractor.java b/sshd-core/src/main/java/org/apache/sshd/common/util/io/FileInfoExtractor.java index 4693dd6..a25a686 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/io/FileInfoExtractor.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/io/FileInfoExtractor.java @@ -33,55 +33,19 @@ import java.util.Set; */ public interface FileInfoExtractor<T> { - FileInfoExtractor<Boolean> EXISTS = new FileInfoExtractor<Boolean>() { - @Override - public Boolean infoOf(Path file, LinkOption... options) throws IOException { - return Files.exists(file, options); - } - }; + FileInfoExtractor<Boolean> EXISTS = Files::exists; - FileInfoExtractor<Boolean> ISDIR = new FileInfoExtractor<Boolean>() { - @Override - public Boolean infoOf(Path file, LinkOption... options) throws IOException { - return Files.isDirectory(file, options); - } - }; + FileInfoExtractor<Boolean> ISDIR = Files::isDirectory; - FileInfoExtractor<Boolean> ISREG = new FileInfoExtractor<Boolean>() { - @Override - public Boolean infoOf(Path file, LinkOption... options) throws IOException { - return Files.isRegularFile(file, options); - } - }; + FileInfoExtractor<Boolean> ISREG = Files::isRegularFile; - FileInfoExtractor<Boolean> ISSYMLINK = new FileInfoExtractor<Boolean>() { - @Override - public Boolean infoOf(Path file, LinkOption... options) throws IOException { - return Files.isSymbolicLink(file); - } - }; + FileInfoExtractor<Boolean> ISSYMLINK = (file, options) -> Files.isSymbolicLink(file); - FileInfoExtractor<Long> SIZE = new FileInfoExtractor<Long>() { - @Override - public Long infoOf(Path file, LinkOption... options) throws IOException { - return Files.size(file); - } - }; + FileInfoExtractor<Long> SIZE = (file, options) -> Files.size(file); - FileInfoExtractor<Set<PosixFilePermission>> PERMISSIONS = new FileInfoExtractor<Set<PosixFilePermission>>() { - @Override - public Set<PosixFilePermission> infoOf(Path file, LinkOption... options) throws IOException { - return IoUtils.getPermissions(file, options); - } - }; + FileInfoExtractor<Set<PosixFilePermission>> PERMISSIONS = IoUtils::getPermissions; - FileInfoExtractor<FileTime> LASTMODIFIED = new FileInfoExtractor<FileTime>() { - @Override - public FileTime infoOf(Path file, LinkOption... options) throws IOException { - return Files.getLastModifiedTime(file, options); - } - - }; + FileInfoExtractor<FileTime> LASTMODIFIED = Files::getLastModifiedTime; T infoOf(Path file, LinkOption ... options) throws IOException; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/io/IoUtils.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/io/IoUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/io/IoUtils.java index c267c85..e8b7dd8 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/io/IoUtils.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/io/IoUtils.java @@ -122,6 +122,7 @@ public final class IoUtils { * suppressed exceptions to the first one * @see Throwable#getSuppressed() */ + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public static IOException closeQuietly(Closeable... closeables) { IOException err = null; for (Closeable c : closeables) { @@ -130,7 +131,7 @@ public final class IoUtils { c.close(); } } catch (IOException e) { - GenericUtils.accumulateException(err, e); + err = GenericUtils.accumulateException(err, e); } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/io/LimitInputStream.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/io/LimitInputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/util/io/LimitInputStream.java index 0226a4a..bbf956a 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/io/LimitInputStream.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/io/LimitInputStream.java @@ -106,6 +106,7 @@ public class LimitInputStream extends FilterInputStream implements Channel { public void close() throws IOException { // do not close the original input stream since it serves for ACK(s) if (open.getAndSet(false)) { + //noinspection UnnecessaryReturnStatement return; // debug breakpoint } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/io/NullInputStream.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/io/NullInputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/util/io/NullInputStream.java index ad7e2ed..5ac7f3e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/io/NullInputStream.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/io/NullInputStream.java @@ -82,6 +82,7 @@ public class NullInputStream extends InputStream implements Channel { @Override public void close() throws IOException { if (open.getAndSet(false)) { + //noinspection UnnecessaryReturnStatement return; // debug breakpoint } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/io/NullOutputStream.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/io/NullOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/util/io/NullOutputStream.java index 64d59b6..5e3b719 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/io/NullOutputStream.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/io/NullOutputStream.java @@ -64,6 +64,7 @@ public class NullOutputStream extends OutputStream implements Channel { @Override public void close() throws IOException { if (open.getAndSet(false)) { + //noinspection UnnecessaryReturnStatement return; // debug breakpoint } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java index 5757fb2..45bcf1b 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java @@ -58,12 +58,9 @@ public final class LoggingUtils { * @see #generateMnemonicMap(Class, Predicate) */ public static Map<Integer, String> generateMnemonicMap(Class<?> clazz, final String commonPrefix) { - return generateMnemonicMap(clazz, new Predicate<Field>() { - @Override - public boolean test(Field f) { - String name = f.getName(); - return name.startsWith(commonPrefix); - } + return generateMnemonicMap(clazz, f -> { + String name = f.getName(); + return name.startsWith(commonPrefix); }); } @@ -92,9 +89,11 @@ public final class LoggingUtils { Number value = (Number) f.get(null); String prev = result.put(NumberUtils.toInteger(value), name); if (prev != null) { + //noinspection UnnecessaryContinue continue; // debug breakpoint } } catch (Exception e) { + //noinspection UnnecessaryContinue continue; // debug breakpoint } } @@ -114,12 +113,9 @@ public final class LoggingUtils { * @see #getAmbiguousMenmonics(Class, Predicate) */ public static Map<String, Integer> getAmbiguousMenmonics(Class<?> clazz, String commonPrefix) { - return getAmbiguousMenmonics(clazz, new Predicate<Field>() { - @Override - public boolean test(Field f) { - String name = f.getName(); - return name.startsWith(commonPrefix); - } + return getAmbiguousMenmonics(clazz, f -> { + String name = f.getName(); + return name.startsWith(commonPrefix); }); } @@ -180,21 +176,18 @@ public final class LoggingUtils { * @return A {@link Collection} of all the fields that have satisfied all conditions */ public static Collection<Field> getMnemonicFields(Class<?> clazz, Predicate<? super Field> acceptor) { - return ReflectionUtils.getMatchingFields(clazz, new Predicate<Field>() { - @Override - public boolean test(Field f) { - int mods = f.getModifiers(); - if ((!Modifier.isPublic(mods)) || (!Modifier.isStatic(mods)) || (!Modifier.isFinal(mods))) { - return false; - } - - Class<?> type = f.getType(); - if (!NumberUtils.isNumericClass(type)) { - return false; - } + return ReflectionUtils.getMatchingFields(clazz, f -> { + int mods = f.getModifiers(); + if ((!Modifier.isPublic(mods)) || (!Modifier.isStatic(mods)) || (!Modifier.isFinal(mods))) { + return false; + } - return acceptor.test(f); + Class<?> type = f.getType(); + if (!NumberUtils.isNumericClass(type)) { + return false; } + + return acceptor.test(f); }); } @@ -263,9 +256,10 @@ public final class LoggingUtils { } // NOTE: assume that level enabled has been checked !!! + @SuppressWarnings("StatementWithEmptyBody") public static void logMessage(Logger logger, Level level, Object message, Throwable t) { if ((logger == null) || (level == null) || Level.OFF.equals(level)) { - return; + // ignore } else if (Level.SEVERE.equals(level)) { logger.error(Objects.toString(message), t); } else if (Level.WARNING.equals(level)) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/logging/SimplifiedLog.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/logging/SimplifiedLog.java b/sshd-core/src/main/java/org/apache/sshd/common/util/logging/SimplifiedLog.java index 068d7e1..966f71c 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/logging/SimplifiedLog.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/logging/SimplifiedLog.java @@ -36,7 +36,6 @@ public interface SimplifiedLog { @Override public void log(Level level, Object message, Throwable t) { - return; } @Override http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 e56c290..08b277b 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 @@ -79,14 +79,11 @@ public class SshdSocketAddress extends SocketAddress { * Compares {@link InetAddress}-es according to their {@link InetAddress#getHostAddress()} * value case <U>insensitive</U> */ - public static final Comparator<InetAddress> BY_HOST_ADDRESS = new Comparator<InetAddress>() { - @Override - public int compare(InetAddress a1, InetAddress a2) { - String n1 = GenericUtils.trimToEmpty(toAddressString(a1)); - String n2 = GenericUtils.trimToEmpty(toAddressString(a2)); - return String.CASE_INSENSITIVE_ORDER.compare(n1, n2); - } - }; + public static final Comparator<InetAddress> BY_HOST_ADDRESS = (a1, a2) -> { + String n1 = GenericUtils.trimToEmpty(toAddressString(a1)); + String n2 = GenericUtils.trimToEmpty(toAddressString(a2)); + return String.CASE_INSENSITIVE_ORDER.compare(n1, n2); + }; private static final long serialVersionUID = 6461645947151952729L; @@ -336,7 +333,7 @@ public class SshdSocketAddress extends SocketAddress { } } - public static final boolean isIPv4Address(String addr) { + public static boolean isIPv4Address(String addr) { if (GenericUtils.isEmpty(addr)) { return false; } @@ -367,7 +364,7 @@ public class SshdSocketAddress extends SocketAddress { * @see #PRIVATE_CLASS_C_PREFIX * @see <A HREF="http://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces">Wiki page</A> */ - public static final boolean isPrivateIPv4Address(String addr) { + public static boolean isPrivateIPv4Address(String addr) { if (GenericUtils.isEmpty(addr)) { return false; } @@ -400,7 +397,7 @@ public class SshdSocketAddress extends SocketAddress { * @return {@code true} if the address is in the 100.64.0.0/10 range * @see <A HREF="http://tools.ietf.org/html/rfc6598">RFC6598</A> */ - public static final boolean isCarrierGradeNatIPv4Address(String addr) { + public static boolean isCarrierGradeNatIPv4Address(String addr) { if (GenericUtils.isEmpty(addr)) { return false; } @@ -433,7 +430,7 @@ public class SshdSocketAddress extends SocketAddress { * @param c The {@link CharSequence} to be validate * @return {@code true} if valid IPv4 address component */ - public static final boolean isValidIPv4AddressComponent(CharSequence c) { + public static boolean isValidIPv4AddressComponent(CharSequence c) { if (GenericUtils.isEmpty(c) || (c.length() > 3)) { return false; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java index 4f61d46..de16f41 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java @@ -177,13 +177,8 @@ public final class ThreadUtils { Thread t; try { // see SSHD-668 - t = AccessController.doPrivileged(new PrivilegedExceptionAction<Thread>() { - @SuppressWarnings("synthetic-access") - @Override - public Thread run() { - return new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0); - } - }); + t = AccessController.doPrivileged((PrivilegedExceptionAction<Thread>) () -> + new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0)); } catch (PrivilegedActionException e) { Exception err = e.getException(); if (err instanceof RuntimeException) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/ServerAuthenticationManager.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/ServerAuthenticationManager.java b/sshd-core/src/main/java/org/apache/sshd/server/ServerAuthenticationManager.java index 06b970e..d954d81 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/ServerAuthenticationManager.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/ServerAuthenticationManager.java @@ -143,6 +143,14 @@ public interface ServerAuthenticationManager { */ String AUTH_METHODS = "auth-methods"; + UserAuthPublicKeyFactory DEFAULT_USER_AUTH_PUBLIC_KEY_FACTORY = UserAuthPublicKeyFactory.INSTANCE; + + UserAuthGSSFactory DEFAULT_USER_AUTH_GSS_FACTORY = UserAuthGSSFactory.INSTANCE; + + UserAuthPasswordFactory DEFAULT_USER_AUTH_PASSWORD_FACTORY = UserAuthPasswordFactory.INSTANCE; + + UserAuthKeyboardInteractiveFactory DEFAULT_USER_AUTH_KB_INTERACTIVE_FACTORY = UserAuthKeyboardInteractiveFactory.INSTANCE; + /** * Retrieve the list of named factories for <code>UserAuth</code> objects. * @@ -150,10 +158,10 @@ public interface ServerAuthenticationManager { */ List<NamedFactory<UserAuth>> getUserAuthFactories(); default String getUserAuthFactoriesNameList() { - return NamedResource.Utils.getNames(getUserAuthFactories()); + return NamedResource.getNames(getUserAuthFactories()); } default List<String> getUserAuthFactoriesNames() { - return NamedResource.Utils.getNameList(getUserAuthFactories()); + return NamedResource.getNameList(getUserAuthFactories()); } void setUserAuthFactories(List<NamedFactory<UserAuth>> userAuthFactories); @@ -228,78 +236,89 @@ public interface ServerAuthenticationManager { void setHostBasedAuthenticator(HostBasedAuthenticator hostBasedAuthenticator); // CHECKSTYLE:OFF + @Deprecated final class Utils { // CHECKSTYLE:ON + public static final UserAuthPublicKeyFactory DEFAULT_USER_AUTH_PUBLIC_KEY_FACTORY = - UserAuthPublicKeyFactory.INSTANCE; + ServerAuthenticationManager.DEFAULT_USER_AUTH_PUBLIC_KEY_FACTORY; public static final UserAuthGSSFactory DEFAULT_USER_AUTH_GSS_FACTORY = - UserAuthGSSFactory.INSTANCE; + ServerAuthenticationManager.DEFAULT_USER_AUTH_GSS_FACTORY; public static final UserAuthPasswordFactory DEFAULT_USER_AUTH_PASSWORD_FACTORY = - UserAuthPasswordFactory.INSTANCE; + ServerAuthenticationManager.DEFAULT_USER_AUTH_PASSWORD_FACTORY; public static final UserAuthKeyboardInteractiveFactory DEFAULT_USER_AUTH_KB_INTERACTIVE_FACTORY = - UserAuthKeyboardInteractiveFactory.INSTANCE; + ServerAuthenticationManager.DEFAULT_USER_AUTH_KB_INTERACTIVE_FACTORY; private Utils() { throw new UnsupportedOperationException("No instance allowed"); } - /** - * If user authentication factories already set, then simply returns them. Otherwise, - * builds the factories list from the individual authenticators available for - * the manager - password public key, keyboard-interactive, GSS, etc... - * - * @param manager The {@link ServerAuthenticationManager} - ignored if {@code null} - * @return The resolved {@link List} of {@link NamedFactory} for the {@link UserAuth}s - * @see #resolveUserAuthFactories(ServerAuthenticationManager, List) - */ public static List<NamedFactory<UserAuth>> resolveUserAuthFactories(ServerAuthenticationManager manager) { - if (manager == null) { - return Collections.emptyList(); - } else { - return resolveUserAuthFactories(manager, manager.getUserAuthFactories()); - } + return ServerAuthenticationManager.resolveUserAuthFactories(manager); } - /** - * If user authentication factories already set, then simply returns them. Otherwise, - * builds the factories list from the individual authenticators available for - * the manager - password public key, keyboard-interactive, GSS, etc... - * - * @param manager The {@link ServerAuthenticationManager} - ignored if {@code null} - * @param userFactories The currently available {@link UserAuth} factories - if not - * {@code null}/empty then they are used as-is. - * @return The resolved {@link List} of {@link NamedFactory} for the {@link UserAuth}s - */ public static List<NamedFactory<UserAuth>> resolveUserAuthFactories( ServerAuthenticationManager manager, List<NamedFactory<UserAuth>> userFactories) { - if (GenericUtils.size(userFactories) > 0) { - return userFactories; // use whatever the user decided - } - - if (manager == null) { - return Collections.emptyList(); - } - - List<NamedFactory<UserAuth>> factories = new ArrayList<>(); - if (manager.getPasswordAuthenticator() != null) { - factories.add(DEFAULT_USER_AUTH_PASSWORD_FACTORY); - factories.add(DEFAULT_USER_AUTH_KB_INTERACTIVE_FACTORY); - } else if (manager.getKeyboardInteractiveAuthenticator() != null) { - factories.add(DEFAULT_USER_AUTH_KB_INTERACTIVE_FACTORY); - } - - if (manager.getPublickeyAuthenticator() != null) { - factories.add(DEFAULT_USER_AUTH_PUBLIC_KEY_FACTORY); - } - - if (manager.getGSSAuthenticator() != null) { - factories.add(DEFAULT_USER_AUTH_GSS_FACTORY); - } - - return factories; + return ServerAuthenticationManager.resolveUserAuthFactories(manager, userFactories); + } + } + + /** + * If user authentication factories already set, then simply returns them. Otherwise, + * builds the factories list from the individual authenticators available for + * the manager - password public key, keyboard-interactive, GSS, etc... + * + * @param manager The {@link ServerAuthenticationManager} - ignored if {@code null} + * @return The resolved {@link List} of {@link NamedFactory} for the {@link UserAuth}s + * @see #resolveUserAuthFactories(ServerAuthenticationManager, List) + */ + static List<NamedFactory<UserAuth>> resolveUserAuthFactories(ServerAuthenticationManager manager) { + if (manager == null) { + return Collections.emptyList(); + } else { + return resolveUserAuthFactories(manager, manager.getUserAuthFactories()); + } + } + + /** + * If user authentication factories already set, then simply returns them. Otherwise, + * builds the factories list from the individual authenticators available for + * the manager - password public key, keyboard-interactive, GSS, etc... + * + * @param manager The {@link ServerAuthenticationManager} - ignored if {@code null} + * @param userFactories The currently available {@link UserAuth} factories - if not + * {@code null}/empty then they are used as-is. + * @return The resolved {@link List} of {@link NamedFactory} for the {@link UserAuth}s + */ + static List<NamedFactory<UserAuth>> resolveUserAuthFactories( + ServerAuthenticationManager manager, List<NamedFactory<UserAuth>> userFactories) { + if (GenericUtils.size(userFactories) > 0) { + return userFactories; // use whatever the user decided } + + if (manager == null) { + return Collections.emptyList(); + } + + List<NamedFactory<UserAuth>> factories = new ArrayList<>(); + if (manager.getPasswordAuthenticator() != null) { + factories.add(DEFAULT_USER_AUTH_PASSWORD_FACTORY); + factories.add(DEFAULT_USER_AUTH_KB_INTERACTIVE_FACTORY); + } else if (manager.getKeyboardInteractiveAuthenticator() != null) { + factories.add(DEFAULT_USER_AUTH_KB_INTERACTIVE_FACTORY); + } + + if (manager.getPublickeyAuthenticator() != null) { + factories.add(DEFAULT_USER_AUTH_PUBLIC_KEY_FACTORY); + } + + if (manager.getGSSAuthenticator() != null) { + factories.add(DEFAULT_USER_AUTH_GSS_FACTORY); + } + + return factories; } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/ServerBuilder.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/ServerBuilder.java b/sshd-core/src/main/java/org/apache/sshd/server/ServerBuilder.java index 08b3f2e..b8d6a32 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/ServerBuilder.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/ServerBuilder.java @@ -52,19 +52,12 @@ import org.apache.sshd.server.kex.DHGServer; */ public class ServerBuilder extends BaseBuilder<SshServer, ServerBuilder> { - public static final Transformer<DHFactory, NamedFactory<KeyExchange>> DH2KEX = - new Transformer<DHFactory, NamedFactory<KeyExchange>>() { - @Override - public NamedFactory<KeyExchange> transform(DHFactory factory) { - if (factory == null) { - return null; - } else if (factory.isGroupExchange()) { - return DHGEXServer.newFactory(factory); - } else { - return DHGServer.newFactory(factory); - } - } - }; + public static final Transformer<DHFactory, NamedFactory<KeyExchange>> DH2KEX = factory -> + factory == null + ? null + : factory.isGroupExchange() + ? DHGEXServer.newFactory(factory) + : DHGServer.newFactory(factory); public static final List<NamedFactory<Channel>> DEFAULT_CHANNEL_FACTORIES = Collections.unmodifiableList(Arrays.<NamedFactory<Channel>>asList( @@ -84,8 +77,8 @@ public class ServerBuilder extends BaseBuilder<SshServer, ServerBuilder> { public static final PublickeyAuthenticator DEFAULT_PUBLIC_KEY_AUTHENTICATOR = DefaultAuthorizedKeysAuthenticator.INSTANCE; public static final KeyboardInteractiveAuthenticator DEFAULT_INTERACTIVE_AUTHENTICATOR = DefaultKeyboardInteractiveAuthenticator.INSTANCE; public static final List<CompressionFactory> DEFAULT_COMPRESSION_FACTORIES = - Collections.unmodifiableList(Arrays.<CompressionFactory>asList( - BuiltinCompressions.none, BuiltinCompressions.zlib, BuiltinCompressions.delayedZlib)); + Collections.unmodifiableList(Arrays.<CompressionFactory>asList( + BuiltinCompressions.none, BuiltinCompressions.zlib, BuiltinCompressions.delayedZlib)); protected PublickeyAuthenticator pubkeyAuthenticator; protected KeyboardInteractiveAuthenticator interactiveAuthenticator; @@ -109,7 +102,7 @@ public class ServerBuilder extends BaseBuilder<SshServer, ServerBuilder> { super.fillWithDefaultValues(); if (compressionFactories == null) { - compressionFactories = NamedFactory.Utils.setUpBuiltinFactories(false, DEFAULT_COMPRESSION_FACTORIES); + compressionFactories = NamedFactory.setUpBuiltinFactories(false, DEFAULT_COMPRESSION_FACTORIES); } if (keyExchangeFactories == null) { @@ -160,7 +153,7 @@ public class ServerBuilder extends BaseBuilder<SshServer, ServerBuilder> { * @see org.apache.sshd.common.kex.BuiltinDHFactories#isSupported() */ public static List<NamedFactory<KeyExchange>> setUpDefaultKeyExchanges(boolean ignoreUnsupported) { - return NamedFactory.Utils.setUpTransformedFactories(ignoreUnsupported, DEFAULT_KEX_PREFERENCE, DH2KEX); + return NamedFactory.setUpTransformedFactories(ignoreUnsupported, DEFAULT_KEX_PREFERENCE, DH2KEX); } public static ServerBuilder builder() { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/Signal.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/Signal.java b/sshd-core/src/main/java/org/apache/sshd/server/Signal.java index ad4917e..bbbddb6 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/Signal.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/Signal.java @@ -19,11 +19,11 @@ package org.apache.sshd.server; import java.util.Collections; +import java.util.Comparator; import java.util.EnumSet; -import java.util.HashMap; import java.util.Map; import java.util.Set; -import java.util.TreeMap; +import java.util.function.Function; import org.apache.sshd.common.util.GenericUtils; @@ -75,15 +75,8 @@ public enum Signal { * @see #SIGNALS */ public static final Map<String, Signal> NAME_LOOKUP_TABLE = - Collections.unmodifiableMap(new TreeMap<String, Signal>(String.CASE_INSENSITIVE_ORDER) { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - for (Signal s : SIGNALS) { - put(s.name(), s); - } - } - }); + Collections.unmodifiableMap( + GenericUtils.toSortedMap(SIGNALS, Signal::name, Function.identity(), String.CASE_INSENSITIVE_ORDER)); /** * An un-modifiable {@link Map} of the numeric values of all available {@link Signal}s @@ -91,15 +84,8 @@ public enum Signal { * @see #getNumeric() */ public static final Map<Integer, Signal> NUMERIC_LOOKUP_TABLE = - Collections.unmodifiableMap(new HashMap<Integer, Signal>(SIGNALS.size()) { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - for (Signal s : SIGNALS) { - put(s.getNumeric(), s); - } - } - }); + Collections.unmodifiableMap( + GenericUtils.toSortedMap(SIGNALS, Signal::getNumeric, Function.identity(), Comparator.naturalOrder())); private final int numeric; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java b/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java index a9c836a..b55fd59 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java @@ -72,7 +72,6 @@ import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; import org.apache.sshd.server.scp.ScpCommandFactory; import org.apache.sshd.server.session.ServerConnectionServiceFactory; import org.apache.sshd.server.session.ServerProxyAcceptor; -import org.apache.sshd.server.session.ServerSession; import org.apache.sshd.server.session.ServerUserAuthServiceFactory; import org.apache.sshd.server.session.SessionFactory; import org.apache.sshd.server.shell.InteractiveProcessShellFactory; @@ -108,12 +107,7 @@ import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory; */ public class SshServer extends AbstractFactoryManager implements ServerFactoryManager, Closeable { - public static final Factory<SshServer> DEFAULT_SSH_SERVER_FACTORY = new Factory<SshServer>() { - @Override - public SshServer create() { - return new SshServer(); - } - }; + public static final Factory<SshServer> DEFAULT_SSH_SERVER_FACTORY = SshServer::new; public static final List<ServiceFactory> DEFAULT_SERVICE_FACTORIES = Collections.unmodifiableList(Arrays.asList( @@ -279,7 +273,7 @@ public class SshServer extends AbstractFactoryManager implements ServerFactoryMa ValidateUtils.checkTrue(getPort() >= 0 /* zero means not set yet */, "Bad port number: %d", Integer.valueOf(getPort())); - List<NamedFactory<UserAuth>> authFactories = ServerAuthenticationManager.Utils.resolveUserAuthFactories(this); + List<NamedFactory<UserAuth>> authFactories = ServerAuthenticationManager.resolveUserAuthFactories(this); setUserAuthFactories(ValidateUtils.checkNotNullAndNotEmpty(authFactories, "UserAuthFactories not set")); ValidateUtils.checkNotNullAndNotEmpty(getChannelFactories(), "ChannelFactories not set"); @@ -358,26 +352,16 @@ public class SshServer extends AbstractFactoryManager implements ServerFactoryMa @Override protected Closeable getInnerCloseable() { return builder() - .run(new Runnable() { - @SuppressWarnings("synthetic-access") - @Override - public void run() { - removeSessionTimeout(sessionFactory); - } - }) + .run(() -> removeSessionTimeout(sessionFactory)) .sequential(acceptor, ioServiceFactory) - .run(new Runnable() { - @SuppressWarnings("synthetic-access") - @Override - public void run() { - acceptor = null; - ioServiceFactory = null; - if (shutdownExecutor && (executor != null) && (!executor.isShutdown())) { - try { - executor.shutdownNow(); - } finally { - executor = null; - } + .run(() -> { + acceptor = null; + ioServiceFactory = null; + if (shutdownExecutor && (executor != null) && (!executor.isShutdown())) { + try { + executor.shutdownNow(); + } finally { + executor = null; } } }) @@ -587,20 +571,12 @@ public class SshServer extends AbstractFactoryManager implements ServerFactoryMa sshd.setPort(port); sshd.setShellFactory(InteractiveProcessShellFactory.INSTANCE); - sshd.setPasswordAuthenticator(new PasswordAuthenticator() { - @Override - public boolean authenticate(String username, String password, ServerSession session) { - return (GenericUtils.length(username) > 0) && username.equals(password); - } - }); + sshd.setPasswordAuthenticator((username, password, session) -> Objects.equals(username, password)); sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE); sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); - sshd.setCommandFactory(new ScpCommandFactory.Builder().withDelegate(new CommandFactory() { - @Override - public Command createCommand(String command) { - return new ProcessShellFactory(GenericUtils.split(command, ' ')).create(); - } - }).build()); + sshd.setCommandFactory(new ScpCommandFactory.Builder().withDelegate( + command -> new ProcessShellFactory(GenericUtils.split(command, ' ')).create() + ).build()); sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); sshd.start(); @@ -621,7 +597,7 @@ public class SshServer extends AbstractFactoryManager implements ServerFactoryMa } Object banner; - if (GenericUtils.length(bannerOption) > 0) { + if (GenericUtils.isNotEmpty(bannerOption)) { if ("none".equals(bannerOption)) { return null; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/auth/BuiltinUserAuthFactories.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/BuiltinUserAuthFactories.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/BuiltinUserAuthFactories.java index 4e69543..a77512d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/BuiltinUserAuthFactories.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/BuiltinUserAuthFactories.java @@ -74,7 +74,7 @@ public enum BuiltinUserAuthFactories implements NamedFactory<UserAuthFactory> { * @return The matching factory instance - {@code null} if no match found */ public static UserAuthFactory fromFactoryName(String name) { - Factory<UserAuthFactory> factory = NamedResource.Utils.findByName(name, String.CASE_INSENSITIVE_ORDER, VALUES); + Factory<UserAuthFactory> factory = NamedResource.findByName(name, String.CASE_INSENSITIVE_ORDER, VALUES); if (factory == null) { return null; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java index 129ac0a..2e36ab6 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java @@ -22,6 +22,7 @@ import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.HashMap; import java.util.Map; + import javax.security.auth.Subject; import javax.security.auth.login.AppConfigurationEntry; import javax.security.auth.login.Configuration; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/GSSAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/GSSAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/GSSAuthenticator.java index b11f18d..7a97ab6 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/GSSAuthenticator.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/GSSAuthenticator.java @@ -20,6 +20,7 @@ package org.apache.sshd.server.auth.gss; import java.net.InetAddress; import java.net.UnknownHostException; + import javax.security.auth.login.LoginException; import org.apache.sshd.server.session.ServerSession; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java index 2f501c3..c48ebb6 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/hostbased/UserAuthHostBased.java @@ -144,7 +144,7 @@ public class UserAuthHostBased extends AbstractUserAuth implements SignatureFact "No signature factories for session=%s", session); Signature verifier = ValidateUtils.checkNotNull( - NamedFactory.Utils.create(factories, keyType), + NamedFactory.create(factories, keyType), "No verifier located for algorithm=%s", keyType); verifier.initVerifier(clientKey); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java index 45af83f..5f4d49b 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java @@ -38,7 +38,7 @@ import org.apache.sshd.server.session.ServerSession; public class CachingPublicKeyAuthenticator extends AbstractLoggingBean implements PublickeyAuthenticator, SessionListener { protected final PublickeyAuthenticator authenticator; - protected final Map<ServerSession, Map<PublicKey, Boolean>> cache = new ConcurrentHashMap<>(); + protected final Map<Session, Map<PublicKey, Boolean>> cache = new ConcurrentHashMap<>(); public CachingPublicKeyAuthenticator(PublickeyAuthenticator authenticator) { this.authenticator = ValidateUtils.checkNotNull(authenticator, "No delegate authenticator"); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/UserAuthPublicKey.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/UserAuthPublicKey.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/UserAuthPublicKey.java index e52f176..aa65835 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/UserAuthPublicKey.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/UserAuthPublicKey.java @@ -88,11 +88,11 @@ public class UserAuthPublicKey extends AbstractUserAuth implements SignatureFact session); if (log.isDebugEnabled()) { log.debug("doAuth({}@{}) verify key type={}, factories={}, fingerprint={}", - username, session, alg, NamedResource.Utils.getNames(factories), KeyUtils.getFingerPrint(key)); + username, session, alg, NamedResource.getNames(factories), KeyUtils.getFingerPrint(key)); } Signature verifier = ValidateUtils.checkNotNull( - NamedFactory.Utils.create(factories, alg), + NamedFactory.create(factories, alg), "No verifier located for algorithm=%s", alg); verifier.initVerifier(key); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java index 22383e7..2c097c6 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java @@ -20,7 +20,6 @@ package org.apache.sshd.server.channel; import java.io.IOException; import java.io.OutputStream; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -68,7 +67,6 @@ import org.apache.sshd.server.ChannelSessionAware; import org.apache.sshd.server.Command; import org.apache.sshd.server.CommandFactory; import org.apache.sshd.server.Environment; -import org.apache.sshd.server.ExitCallback; import org.apache.sshd.server.ServerFactoryManager; import org.apache.sshd.server.SessionAware; import org.apache.sshd.server.Signal; @@ -84,8 +82,7 @@ import org.apache.sshd.server.x11.X11ForwardSupport; */ public class ChannelSession extends AbstractServerChannel { public static final List<ChannelRequestHandler> DEFAULT_HANDLERS = - Collections.unmodifiableList( - Arrays.<ChannelRequestHandler>asList(PuttyRequestHandler.INSTANCE)); + Collections.<ChannelRequestHandler>singletonList(PuttyRequestHandler.INSTANCE); protected String type; protected ChannelAsyncOutputStream asyncOut; @@ -179,12 +176,7 @@ public class ChannelSession extends AbstractServerChannel { FactoryManager manager = ValidateUtils.checkNotNull(s.getFactoryManager(), "No factory manager"); ScheduledExecutorService scheduler = ValidateUtils.checkNotNull(manager.getScheduledExecutorService(), "No scheduling service"); scheduler.schedule(task, timeout, TimeUnit.MILLISECONDS); - commandExitFuture.addListener(new SshFutureListener<CloseFuture>() { - @Override - public void operationComplete(CloseFuture future) { - task.cancel(); - } - }); + commandExitFuture.addListener(future -> task.cancel()); } return commandExitFuture; } @@ -559,7 +551,7 @@ public class ChannelSession extends AbstractServerChannel { } try { - commandInstance = NamedFactory.Utils.create(factories, subsystem); + commandInstance = NamedFactory.create(factories, subsystem); } catch (RuntimeException | Error e) { log.warn("handleSubsystem({}) Failed ({}) to create command for subsystem={}: {}", this, e.getClass().getSimpleName(), subsystem, e.getMessage()); @@ -680,19 +672,15 @@ public class ChannelSession extends AbstractServerChannel { tempBuffer = null; doWriteData(buffer.array(), buffer.rpos(), buffer.available()); } - command.setExitCallback(new ExitCallback() { - @Override - @SuppressWarnings("synthetic-access") - public void onExit(int exitValue, String exitMessage) { - try { - closeShell(exitValue); - if (log.isDebugEnabled()) { - log.debug("onExit({}) code={} message='{}' shell closed", ChannelSession.this, exitValue, exitMessage); - } - } catch (IOException e) { - log.warn("onExit({}) code={} message='{}' {} closing shell: {}", - ChannelSession.this, exitValue, exitMessage, e.getClass().getSimpleName(), e.getMessage()); + command.setExitCallback((exitValue, exitMessage) -> { + try { + closeShell(exitValue); + if (log.isDebugEnabled()) { + log.debug("onExit({}) code={} message='{}' shell closed", ChannelSession.this, exitValue, exitMessage); } + } catch (IOException e) { + log.warn("onExit({}) code={} message='{}' {} closing shell: {}", + ChannelSession.this, exitValue, exitMessage, e.getClass().getSimpleName(), e.getMessage()); } }); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java index 050a0ab..c2884b9 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java @@ -111,7 +111,7 @@ public class AuthorizedKeysAuthenticator extends ModifiableFileWatcher implement } protected boolean isValidUsername(String username, ServerSession session) { - return !GenericUtils.isEmpty(username); + return GenericUtils.isNotEmpty(username); } protected PublickeyAuthenticator resolvePublickeyAuthenticator(String username, ServerSession session) http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/config/keys/ServerIdentity.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/ServerIdentity.java b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/ServerIdentity.java index 3a9f0f2..f31db14 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/ServerIdentity.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/ServerIdentity.java @@ -57,12 +57,7 @@ public final class ServerIdentity { public static final String HOST_KEY_CONFIG_PROP = "HostKey"; public static final Transformer<String, String> ID_GENERATOR = - new Transformer<String, String>() { - @Override - public String transform(String input) { - return getIdentityFileName(input); - } - }; + ServerIdentity::getIdentityFileName; private ServerIdentity() { throw new UnsupportedOperationException("No instance"); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardingFilter.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardingFilter.java b/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardingFilter.java index 23e2f14..09bacab 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardingFilter.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardingFilter.java @@ -133,7 +133,7 @@ public interface ForwardingFilter { * or {@code null} if no match found */ public static Type fromName(String name) { - return NamedResource.Utils.findByName(name, String.CASE_INSENSITIVE_ORDER, VALUES); + return NamedResource.findByName(name, String.CASE_INSENSITIVE_ORDER, VALUES); } /** http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java index e655113..00dc37b 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java @@ -36,12 +36,10 @@ import org.apache.sshd.common.channel.ChannelOutputStream; import org.apache.sshd.common.channel.OpenChannelException; import org.apache.sshd.common.channel.Window; import org.apache.sshd.common.future.CloseFuture; -import org.apache.sshd.common.future.SshFutureListener; import org.apache.sshd.common.io.IoConnectFuture; import org.apache.sshd.common.io.IoConnector; import org.apache.sshd.common.io.IoHandler; import org.apache.sshd.common.io.IoSession; -import org.apache.sshd.common.io.IoWriteFuture; import org.apache.sshd.common.session.Session; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.Readable; @@ -188,12 +186,7 @@ public class TcpipServerChannel extends AbstractServerChannel { connector = manager.getIoServiceFactory().createConnector(handler); IoConnectFuture future = connector.connect(address.toInetSocketAddress()); - future.addListener(new SshFutureListener<IoConnectFuture>() { - @Override - public void operationComplete(IoConnectFuture future) { - handleChannelConnectResult(f, future); - } - }); + future.addListener(future1 -> handleChannelConnectResult(f, future1)); return f; } @@ -315,18 +308,14 @@ public class TcpipServerChannel extends AbstractServerChannel { : service; // shutdown the temporary executor service if had to create it final boolean shutdown = executors != service || isShutdownOnExit(); - executors.submit(new Runnable() { - @SuppressWarnings("synthetic-access") - @Override - public void run() { - try { - connector.close(true); - } finally { - if ((executors != null) && (!executors.isShutdown()) && shutdown) { - Collection<Runnable> runners = executors.shutdownNow(); - if (log.isDebugEnabled()) { - log.debug("destroy({}) - shutdown executor service - runners count={}", TcpipServerChannel.this, runners.size()); - } + executors.submit(() -> { + try { + connector.close(true); + } finally { + if (shutdown && !executors.isShutdown()) { + Collection<Runnable> runners = executors.shutdownNow(); + if (log.isDebugEnabled()) { + log.debug("destroy({}) - shutdown executor service - runners count={}", TcpipServerChannel.this, runners.size()); } } } @@ -335,27 +324,18 @@ public class TcpipServerChannel extends AbstractServerChannel { @Override public CloseFuture close(boolean immediately) { - return super.close(immediately).addListener(new SshFutureListener<CloseFuture>() { - @SuppressWarnings("synthetic-access") - @Override - public void operationComplete(CloseFuture sshFuture) { - closeImmediately0(); - } - }); + return super.close(immediately).addListener(sshFuture -> closeImmediately0()); } @Override protected void doWriteData(byte[] data, int off, final int len) throws IOException { // Make sure we copy the data as the incoming buffer may be reused final Buffer buf = ByteArrayBuffer.getCompactClone(data, off, len); - ioSession.write(buf).addListener(new SshFutureListener<IoWriteFuture>() { - @Override - public void operationComplete(IoWriteFuture future) { - if (future.isWritten()) { - handleWriteDataSuccess(SshConstants.SSH_MSG_CHANNEL_DATA, buf.array(), 0, len); - } else { - handleWriteDataFailure(SshConstants.SSH_MSG_CHANNEL_DATA, buf.array(), 0, len, future.getException()); - } + ioSession.write(buf).addListener(future -> { + if (future.isWritten()) { + handleWriteDataSuccess(SshConstants.SSH_MSG_CHANNEL_DATA, buf.array(), 0, len); + } else { + handleWriteDataFailure(SshConstants.SSH_MSG_CHANNEL_DATA, buf.array(), 0, len, future.getException()); } }); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java index 457ded9..354d678 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java @@ -38,7 +38,7 @@ public class CancelTcpipForwardHandler extends AbstractConnectionServiceRequestH /** * Default growth factor function used to resize response buffers */ - public static final Int2IntFunction RESPONSE_BUFFER_GROWTH_FACTOR = Int2IntFunction.Utils.add(Byte.SIZE); + public static final Int2IntFunction RESPONSE_BUFFER_GROWTH_FACTOR = Int2IntFunction.add(Byte.SIZE); public static final CancelTcpipForwardHandler INSTANCE = new CancelTcpipForwardHandler(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/global/OpenSshHostKeysHandler.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/OpenSshHostKeysHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/OpenSshHostKeysHandler.java index e84f82c..ce54b2d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/global/OpenSshHostKeysHandler.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/global/OpenSshHostKeysHandler.java @@ -92,7 +92,7 @@ public class OpenSshHostKeysHandler extends AbstractOpenSshHostKeysHandler imple session); if (log.isDebugEnabled()) { log.debug("handleHostKeys({})[want-reply={}] received {} keys - factories={}", - session, wantReply, GenericUtils.size(keys), NamedResource.Utils.getNames(factories)); + session, wantReply, GenericUtils.size(keys), NamedResource.getNames(factories)); } // generate the required signatures @@ -104,7 +104,7 @@ public class OpenSshHostKeysHandler extends AbstractOpenSshHostKeysHandler imple for (PublicKey k : keys) { String keyType = KeyUtils.getKeyType(k); Signature verifier = ValidateUtils.checkNotNull( - NamedFactory.Utils.create(factories, keyType), + NamedFactory.create(factories, keyType), "No signer could be located for key type=%s", keyType); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java index a8dd753..8b3368e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java @@ -39,7 +39,7 @@ public class TcpipForwardHandler extends AbstractConnectionServiceRequestHandler /** * Default growth factor function used to resize response buffers */ - public static final Int2IntFunction RESPONSE_BUFFER_GROWTH_FACTOR = Int2IntFunction.Utils.add(Byte.SIZE); + public static final Int2IntFunction RESPONSE_BUFFER_GROWTH_FACTOR = Int2IntFunction.add(Byte.SIZE); public static final TcpipForwardHandler INSTANCE = new TcpipForwardHandler(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticator.java index 300b545..30d0d89 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticator.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticator.java @@ -18,10 +18,8 @@ */ package org.apache.sshd.server.jaas; -import java.io.IOException; import javax.security.auth.Subject; import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.NameCallback; import javax.security.auth.callback.PasswordCallback; import javax.security.auth.callback.UnsupportedCallbackException; @@ -64,17 +62,14 @@ public class JaasPasswordAuthenticator extends AbstractLoggingBean implements Pa public boolean authenticate(final String username, final String password) { try { Subject subject = new Subject(); - LoginContext loginContext = new LoginContext(domain, subject, new CallbackHandler() { - @Override - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { - for (Callback callback : callbacks) { - if (callback instanceof NameCallback) { - ((NameCallback) callback).setName(username); - } else if (callback instanceof PasswordCallback) { - ((PasswordCallback) callback).setPassword(password.toCharArray()); - } else { - throw new UnsupportedCallbackException(callback); - } + LoginContext loginContext = new LoginContext(domain, subject, callbacks -> { + for (Callback callback : callbacks) { + if (callback instanceof NameCallback) { + ((NameCallback) callback).setName(username); + } else if (callback instanceof PasswordCallback) { + ((PasswordCallback) callback).setPassword(password.toCharArray()); + } else { + throw new UnsupportedCallbackException(callback); } } }); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java index e867f29..1cf3676 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java @@ -104,7 +104,7 @@ public class DHGEXServer extends AbstractDHServerKeyExchange { public boolean next(int cmd, Buffer buffer) throws Exception { ServerSession session = getServerSession(); if (log.isDebugEnabled()) { - log.debug("next({})[{}] process command={}", this, session, KeyExchange.Utils.getGroupKexOpcodeName(cmd)); + log.debug("next({})[{}] process command={}", this, session, KeyExchange.getGroupKexOpcodeName(cmd)); } if (cmd == SshConstants.SSH_MSG_KEX_DH_GEX_REQUEST_OLD && expected == SshConstants.SSH_MSG_KEX_DH_GEX_REQUEST) { @@ -162,8 +162,8 @@ public class DHGEXServer extends AbstractDHServerKeyExchange { if (cmd != expected) { throw new SshException(SshConstants.SSH2_DISCONNECT_KEY_EXCHANGE_FAILED, - "Protocol error: expected packet " + KeyExchange.Utils.getGroupKexOpcodeName(expected) - + ", got " + KeyExchange.Utils.getGroupKexOpcodeName(cmd)); + "Protocol error: expected packet " + KeyExchange.getGroupKexOpcodeName(expected) + + ", got " + KeyExchange.getGroupKexOpcodeName(cmd)); } if (cmd == SshConstants.SSH_MSG_KEX_DH_GEX_INIT) { @@ -176,7 +176,7 @@ public class DHGEXServer extends AbstractDHServerKeyExchange { KeyPair kp = ValidateUtils.checkNotNull(session.getHostKey(), "No server key pair available"); String algo = session.getNegotiatedKexParameter(KexProposalOption.SERVERKEYS); Signature sig = ValidateUtils.checkNotNull( - NamedFactory.Utils.create(session.getSignatureFactories(), algo), + NamedFactory.create(session.getSignatureFactories(), algo), "Unknown negotiated server keys: %s", algo); sig.initSigner(kp.getPrivate()); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java index 81bbae6..3110c29 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java @@ -87,12 +87,12 @@ public class DHGServer extends AbstractDHServerKeyExchange { public boolean next(int cmd, Buffer buffer) throws Exception { ServerSession session = getServerSession(); if (log.isDebugEnabled()) { - log.debug("next({})[{}] process command={}", this, session, KeyExchange.Utils.getSimpleKexOpcodeName(cmd)); + log.debug("next({})[{}] process command={}", this, session, KeyExchange.getSimpleKexOpcodeName(cmd)); } if (cmd != SshConstants.SSH_MSG_KEXDH_INIT) { throw new SshException(SshConstants.SSH2_DISCONNECT_KEY_EXCHANGE_FAILED, - "Protocol error: expected packet SSH_MSG_KEXDH_INIT, got " + KeyExchange.Utils.getSimpleKexOpcodeName(cmd)); + "Protocol error: expected packet SSH_MSG_KEXDH_INIT, got " + KeyExchange.getSimpleKexOpcodeName(cmd)); } e = buffer.getMPIntAsBytes(); @@ -102,7 +102,7 @@ public class DHGServer extends AbstractDHServerKeyExchange { KeyPair kp = ValidateUtils.checkNotNull(session.getHostKey(), "No server key pair available"); String algo = session.getNegotiatedKexParameter(KexProposalOption.SERVERKEYS); Signature sig = ValidateUtils.checkNotNull( - NamedFactory.Utils.create(session.getSignatureFactories(), algo), + NamedFactory.create(session.getSignatureFactories(), algo), "Unknown negotiated server keys: %s", algo); sig.initSigner(kp.getPrivate()); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java b/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java index 5026e1b..44869d3 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/session/AbstractServerSession.java @@ -36,7 +36,6 @@ import org.apache.sshd.common.ServiceFactory; import org.apache.sshd.common.SshConstants; import org.apache.sshd.common.SshException; import org.apache.sshd.common.auth.AbstractUserAuthServiceFactory; -import org.apache.sshd.common.future.SshFutureListener; import org.apache.sshd.common.io.IoService; import org.apache.sshd.common.io.IoSession; import org.apache.sshd.common.io.IoWriteFuture; @@ -205,7 +204,7 @@ public abstract class AbstractServerSession extends AbstractSession implements S @Override public void startService(String name) throws Exception { FactoryManager factoryManager = getFactoryManager(); - currentService = ServiceFactory.Utils.create( + currentService = ServiceFactory.create( factoryManager.getServiceFactories(), ValidateUtils.checkNotNullAndNotEmpty(name, "No service name"), this); @@ -246,7 +245,7 @@ public abstract class AbstractServerSession extends AbstractSession implements S ValidateUtils.checkTrue(proposedManager == getFactoryManager(), "Mismatched signatures proposed factory manager"); KeyPairProvider kpp = getKeyPairProvider(); - Collection<String> supported = NamedResource.Utils.getNameList(getSignatureFactories()); + Collection<String> supported = NamedResource.getNameList(getSignatureFactories()); Iterable<String> provided; try { provided = (kpp == null) ? null : kpp.getKeyTypes(); @@ -363,12 +362,7 @@ public abstract class AbstractServerSession extends AbstractSession implements S if (GenericUtils.length(errorMessage) > 0) { ioSession.write(new ByteArrayBuffer((errorMessage + "\n").getBytes(StandardCharsets.UTF_8))) - .addListener(new SshFutureListener<IoWriteFuture>() { - @Override - public void operationComplete(IoWriteFuture future) { - close(true); - } - }); + .addListener(future -> close(true)); throw new SshException(errorMessage); }
