Repository: mina-sshd Updated Branches: refs/heads/master 9ea83de5e -> 4651d235b
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4651d235/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java index 262bd05..08213ee 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java @@ -772,6 +772,7 @@ public abstract class AbstractSftpSubsystemHelper Digest digest = factory.create(); digest.init(); + boolean traceEnabled = log.isTraceEnabled(); if (blockSize == 0) { while (effectiveLength > 0L) { int remainLen = Math.min(digestBuf.length, (int) effectiveLength); @@ -791,7 +792,7 @@ public abstract class AbstractSftpSubsystemHelper } byte[] hashValue = digest.digest(); - if (log.isTraceEnabled()) { + if (traceEnabled) { log.trace("doCheckFileHash({})[{}] offset={}, length={} - algo={}, hash={}", getServerSession(), file, startOffset, length, digest.getAlgorithm(), BufferUtils.toHex(':', hashValue)); @@ -815,7 +816,7 @@ public abstract class AbstractSftpSubsystemHelper digest.update(digestBuf, 0, readLen); byte[] hashValue = digest.digest(); // NOTE: this also resets the hash for the next read - if (log.isTraceEnabled()) { + if (traceEnabled) { log.trace("doCheckFileHash({})({})[{}] offset={}, length={} - algo={}, hash={}", getServerSession(), file, count, startOffset, length, digest.getAlgorithm(), BufferUtils.toHex(':', hashValue)); @@ -876,6 +877,7 @@ public abstract class AbstractSftpSubsystemHelper boolean hashMatches = false; byte[] hashValue = null; SftpFileSystemAccessor accessor = getFileSystemAccessor(); + boolean traceEnabled = log.isTraceEnabled(); try (SeekableByteChannel channel = accessor.openFile(getServerSession(), this, path, null, EnumSet.of(StandardOpenOption.READ))) { channel.position(startOffset); @@ -915,7 +917,7 @@ public abstract class AbstractSftpSubsystemHelper hashValue = null; // start again } } else { - if (log.isTraceEnabled()) { + if (traceEnabled) { log.trace("doMD5Hash({})({}) offset={}, length={} - quick-hash mismatched expected={}, actual={}", getServerSession(), path, startOffset, length, BufferUtils.toHex(':', quickCheckHash), @@ -949,7 +951,7 @@ public abstract class AbstractSftpSubsystemHelper } } - if (log.isTraceEnabled()) { + if (traceEnabled) { log.trace("doMD5Hash({})({}) offset={}, length={} - matches={}, quick={} hash={}", getServerSession(), path, startOffset, length, hashMatches, BufferUtils.toHex(':', quickCheckHash), @@ -1171,7 +1173,8 @@ public abstract class AbstractSftpSubsystemHelper protected void doRealPath(Buffer buffer, int id) throws IOException { String path = buffer.getString(); - if (log.isDebugEnabled()) { + boolean debugEnabled = log.isDebugEnabled(); + if (debugEnabled) { log.debug("doRealPath({})[id={}] SSH_FXP_REALPATH (path={})", getServerSession(), id, path); } path = GenericUtils.trimToEmpty(path); @@ -1206,9 +1209,9 @@ public abstract class AbstractSftpSubsystemHelper int control = SftpConstants.SSH_FXP_REALPATH_NO_CHECK; if (buffer.available() > 0) { control = buffer.getUByte(); - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("doRealPath({}) - control=0x{} for path={}", - getServerSession(), Integer.toHexString(control), path); + getServerSession(), Integer.toHexString(control), path); } } @@ -1233,7 +1236,7 @@ public abstract class AbstractSftpSubsystemHelper try { attrs = getAttributes(p, options); } catch (IOException e) { - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("doRealPath({}) - failed ({}) to retrieve attributes of {}: {}", getServerSession(), e.getClass().getSimpleName(), p, e.getMessage()); } @@ -1242,7 +1245,7 @@ public abstract class AbstractSftpSubsystemHelper } } } else { - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("doRealPath({}) - dummy attributes for non-existing file: {}", getServerSession(), p); } } @@ -1260,7 +1263,7 @@ public abstract class AbstractSftpSubsystemHelper break; default: log.warn("doRealPath({}) unknown control value 0x{} for path={}", - getServerSession(), Integer.toHexString(control), p); + getServerSession(), Integer.toHexString(control), p); } } } catch (IOException | RuntimeException e) { @@ -1465,9 +1468,10 @@ public abstract class AbstractSftpSubsystemHelper List<String> extras = (numExtensions <= 0) ? Collections.emptyList() : new ArrayList<>(numExtensions); if (numExtensions > 0) { ServerSession session = getServerSession(); + boolean debugEnabled = log.isDebugEnabled(); extensions.forEach((name, f) -> { if (!f.isSupported()) { - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("appendExtensions({}) skip unsupported extension={}", session, name); } return; @@ -2053,6 +2057,7 @@ public abstract class AbstractSftpSubsystemHelper */ protected NavigableMap<String, Object> resolveMissingFileAttributes( Path file, int flags, Map<String, Object> current, LinkOption... options) throws IOException { + boolean debugEnabled = log.isDebugEnabled(); NavigableMap<String, Object> attrs = null; // Cannot use forEach because the attrs variable is not effectively final for (Map.Entry<String, FileInfoExtractor<?>> re : SftpFileSystemAccessor.FILEATTRS_RESOLVERS.entrySet()) { @@ -2071,12 +2076,12 @@ public abstract class AbstractSftpSubsystemHelper attrs.put(name, resolved); - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("resolveMissingFileAttributes({})[{}[{}]] replace {} with {}", getServerSession(), file, name, value, resolved); } } catch (IOException e) { - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("resolveMissingFileAttributes({})[{}[{}]] failed ({}) to resolve missing value: {}", getServerSession(), file, name, e.getClass().getSimpleName(), e.getMessage()); } @@ -2243,8 +2248,9 @@ public abstract class AbstractSftpSubsystemHelper } protected void handleSetFileAttributeFailure(Path file, String view, String attribute, Object value, Collection<String> unsupported, Exception e) throws IOException { + boolean debugEnabled = log.isDebugEnabled(); if (e instanceof UnsupportedOperationException) { - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("handleSetFileAttributeFailure({})[{}] {}:{}={} unsupported: {}", getServerSession(), file, view, attribute, value, e.getMessage()); } @@ -2252,7 +2258,7 @@ public abstract class AbstractSftpSubsystemHelper } else { log.warn("handleSetFileAttributeFailure({})[{}] {}:{}={} - failed ({}) to set: {}", getServerSession(), file, view, attribute, value, e.getClass().getSimpleName(), e.getMessage()); - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("handleSetFileAttributeFailure(" + getServerSession() + ")" + "[" + file + "] " + view + ":" + attribute + "=" + value + " failure details", e); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4651d235/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java index 640ce9a..5cfbf01 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java @@ -281,16 +281,16 @@ public class SftpSubsystem } } } finally { + boolean debugEnabled = log.isDebugEnabled(); handles.forEach((id, handle) -> { try { handle.close(); - if (log.isDebugEnabled()) { - log.debug("run({}) closed pending handle {} [{}]", - getServerSession(), id, handle); + if (debugEnabled) { + log.debug("run({}) closed pending handle {} [{}]", getServerSession(), id, handle); } } catch (IOException ioe) { log.error("run({}) failed ({}) to close handle={}[{}]: {}", - getServerSession(), ioe.getClass().getSimpleName(), id, handle, ioe.getMessage()); + getServerSession(), ioe.getClass().getSimpleName(), id, handle, ioe.getMessage()); } }); @@ -746,7 +746,8 @@ public class SftpSubsystem protected void doReadDir(Buffer buffer, int id) throws IOException { String handle = buffer.getString(); Handle h = handles.get(handle); - if (log.isDebugEnabled()) { + boolean debugEnabled = log.isDebugEnabled(); + if (debugEnabled) { log.debug("doReadDir({})[id={}] SSH_FXP_READDIR (handle={}[{}])", getServerSession(), id, handle, h); } @@ -797,7 +798,7 @@ public class SftpSubsystem Boolean indicator = SftpHelper.indicateEndOfNamesList(reply, getVersion(), session, dh.isDone()); - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("doReadDir({})({})[{}] - seding {} entries - eol={}", session, handle, h, count, indicator); } } else { @@ -1015,7 +1016,8 @@ public class SftpSubsystem } ServerSession session = getServerSession(); - if (log.isDebugEnabled()) { + boolean debugEnabled = log.isDebugEnabled(); + if (debugEnabled) { log.debug("destroy({}) - mark as closed", session); } @@ -1024,8 +1026,8 @@ public class SftpSubsystem listener.destroying(session); } catch (Exception e) { log.warn("destroy({}) Failed ({}) to announce destruction event: {}", - session, e.getClass().getSimpleName(), e.getMessage()); - if (log.isDebugEnabled()) { + session, e.getClass().getSimpleName(), e.getMessage()); + if (debugEnabled) { log.debug("destroy(" + session + ") destruction announcement failure details", e); } } @@ -1034,7 +1036,7 @@ public class SftpSubsystem if ((pendingFuture != null) && (!pendingFuture.isDone())) { boolean result = pendingFuture.cancel(true); // TODO consider waiting some reasonable (?) amount of time for cancellation - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("destroy(" + session + ") - cancel pending future=" + result); } } @@ -1044,7 +1046,7 @@ public class SftpSubsystem ExecutorService executors = getExecutorService(); if ((executors != null) && (!executors.isShutdown()) && isShutdownOnExit()) { Collection<Runnable> runners = executors.shutdownNow(); - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("destroy(" + session + ") - shutdown executor service - runners count=" + runners.size()); } } @@ -1053,11 +1055,11 @@ public class SftpSubsystem try { fileSystem.close(); } catch (UnsupportedOperationException e) { - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("destroy(" + session + ") closing the file system is not supported"); } } catch (IOException e) { - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("destroy(" + session + ")" + " failed (" + e.getClass().getSimpleName() + ")" + " to close file system: " + e.getMessage(), e); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4651d235/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java index 3c5efa6..f02f619 100644 --- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java +++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java @@ -46,8 +46,12 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth { public Result next(Buffer buffer) throws IOException { ClientSession session = getClientSession(); String service = getService(); + boolean debugEnabled = log.isDebugEnabled(); if (buffer == null) { - log.debug("Send SSH_MSG_USERAUTH_REQUEST for password"); + if (debugEnabled) { + log.debug("Send SSH_MSG_USERAUTH_REQUEST for password"); + } + buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST); buffer.putString(session.getUsername()); buffer.putString(service); @@ -63,7 +67,7 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth { String name = buffer.getString(); String instruction = buffer.getString(); String language_tag = buffer.getString(); - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("next({}) Received SSH_MSG_USERAUTH_INFO_REQUEST - name={}, instruction={}, lang={}", session, name, instruction, language_tag); } @@ -74,7 +78,7 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth { prompt[i] = buffer.getString(); echo[i] = buffer.getBoolean(); } - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("Promt: {}", Arrays.toString(prompt)); log.debug("Echo: {}", echo); } @@ -103,19 +107,21 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth { return Result.Continued; } case SshConstants.SSH_MSG_USERAUTH_SUCCESS: - log.debug("Received SSH_MSG_USERAUTH_SUCCESS"); + if (debugEnabled) { + log.debug("Received SSH_MSG_USERAUTH_SUCCESS"); + } return Result.Success; case SshConstants.SSH_MSG_USERAUTH_FAILURE: { String methods = buffer.getString(); boolean partial = buffer.getBoolean(); - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("Received SSH_MSG_USERAUTH_FAILURE - partial={}, methods={}", partial, methods); } return Result.Failure; } default: - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("Received unknown packet {}", cmd); } return Result.Continued; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4651d235/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java index cb66827..ef919ad 100644 --- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java +++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java @@ -43,8 +43,11 @@ public class UserAuthPassword extends AbstractUserAuth { public Result next(Buffer buffer) throws IOException { ClientSession session = getClientSession(); String service = getService(); + boolean debugEnabled = log.isDebugEnabled(); if (buffer == null) { - log.debug("Send SSH_MSG_USERAUTH_REQUEST for password"); + if (debugEnabled) { + log.debug("Send SSH_MSG_USERAUTH_REQUEST for password"); + } buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST); buffer.putString(session.getUsername()); buffer.putString(service); @@ -56,18 +59,20 @@ public class UserAuthPassword extends AbstractUserAuth { } else { int cmd = buffer.getUByte(); if (cmd == SshConstants.SSH_MSG_USERAUTH_SUCCESS) { - log.debug("Received SSH_MSG_USERAUTH_SUCCESS"); + if (debugEnabled) { + log.debug("Received SSH_MSG_USERAUTH_SUCCESS"); + } return Result.Success; } if (cmd == SshConstants.SSH_MSG_USERAUTH_FAILURE) { String methods = buffer.getString(); boolean partial = buffer.getBoolean(); - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("Received SSH_MSG_USERAUTH_FAILURE - partial={}, methods={}", partial, methods); } return Result.Failure; } else { - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("Received unknown packet {}", cmd & 0xFF); } // TODO: check packets @@ -75,6 +80,5 @@ public class UserAuthPassword extends AbstractUserAuth { } } } - } // CHECKSTYLE:ON http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4651d235/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java index 7fd811b..d207e84 100644 --- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java +++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java @@ -49,9 +49,12 @@ public class UserAuthPublicKey extends AbstractUserAuth { public Result next(Buffer buffer) throws IOException { ClientSession session = getClientSession(); String service = getService(); + boolean debugEnabled = log.isDebugEnabled(); if (buffer == null) { try { - log.debug("Send SSH_MSG_USERAUTH_REQUEST for publickey"); + if (debugEnabled) { + log.debug("Send SSH_MSG_USERAUTH_REQUEST for publickey"); + } buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST); buffer.putString(session.getUsername()); buffer.putString(service); @@ -94,7 +97,7 @@ public class UserAuthPublicKey extends AbstractUserAuth { } else { int cmd = buffer.getUByte(); if (cmd == SshConstants.SSH_MSG_USERAUTH_SUCCESS) { - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("Received SSH_MSG_USERAUTH_SUCCESS"); } return Result.Success; @@ -102,12 +105,12 @@ public class UserAuthPublicKey extends AbstractUserAuth { if (cmd == SshConstants.SSH_MSG_USERAUTH_FAILURE) { String methods = buffer.getString(); boolean partial = buffer.getBoolean(); - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("Received SSH_MSG_USERAUTH_FAILURE - partial={}, methods={}", partial, methods); } return Result.Failure; } else { - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("Received unknown packet {}", cmd); } // TODO: check packets http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4651d235/sshd-ldap/src/main/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-ldap/src/main/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticator.java b/sshd-ldap/src/main/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticator.java index c976ced..5e97db6 100644 --- a/sshd-ldap/src/main/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticator.java +++ b/sshd-ldap/src/main/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticator.java @@ -117,19 +117,21 @@ public class LdapPublickeyAuthenticator extends LdapAuthenticator implements Pub * @return {@code true} whether to accept the presented public key */ protected boolean authenticate(String username, PublicKey expected, ServerSession session, Map<String, ?> attrs, Collection<? extends PublicKey> keys) { + boolean debugEnabled = log.isDebugEnabled(); if (GenericUtils.isEmpty(keys)) { - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("authenticate({}@{}) no registered keys", username, session); } return false; } - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("authenticate({}@{}) check {} registered keys", username, session, keys.size()); } + boolean traceEnabled = log.isTraceEnabled(); for (PublicKey actual : keys) { - if (log.isTraceEnabled()) { + if (traceEnabled) { log.trace("authenticate({}@{}) expected={}-{}, actual={}-{}", username, session, KeyUtils.getKeyType(expected), KeyUtils.getFingerPrint(expected), @@ -141,7 +143,7 @@ public class LdapPublickeyAuthenticator extends LdapAuthenticator implements Pub } } - if (log.isDebugEnabled()) { + if (debugEnabled) { log.debug("authenticate({}@{}) no matching keys", username, session); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4651d235/sshd-mina/pom.xml ---------------------------------------------------------------------- diff --git a/sshd-mina/pom.xml b/sshd-mina/pom.xml index 815a934..c4699cd 100644 --- a/sshd-mina/pom.xml +++ b/sshd-mina/pom.xml @@ -129,12 +129,13 @@ <org.apache.sshd.common.io.IoServiceFactory>org.apache.sshd.common.io.mina.MinaServiceFactory</org.apache.sshd.common.io.IoServiceFactory> </systemProperties> <excludes> - <!-- These tests use NIO explicitly --> + <!-- These tests use NIO explicitly --> <exclude>**/*LoadTest.java</exclude> <exclude>**/ProxyTest.java</exclude> - <!-- TODO need some more research as to why this fails on MINA but not on NIO2 --> + <!-- TODO need some more research as to why this fails on MINA but not on NIO2 --> <exclude>**/ApacheServer*Test.java</exclude> </excludes> + <!-- No need to re-run core tests that do not involve session creation --> <excludedGroups>org.apache.sshd.util.test.NoIoTestCase</excludedGroups> </configuration> </plugin> @@ -147,5 +148,4 @@ </plugin> </plugins> </build> - </project> http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4651d235/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaConnector.java ---------------------------------------------------------------------- diff --git a/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaConnector.java b/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaConnector.java index e7da612..77bb90a 100644 --- a/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaConnector.java +++ b/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaConnector.java @@ -63,7 +63,7 @@ public class MinaConnector extends MinaService implements org.apache.sshd.common } if (log.isDebugEnabled()) { - log.debug("Created IoConnector"); + log.debug("Created IoConnector: {}", connector); } return connector; }