http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionImpl.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionImpl.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionImpl.java index 11ca880..b524923 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionImpl.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionImpl.java @@ -26,8 +26,8 @@ import java.util.Map; import java.util.Objects; import org.apache.sshd.common.FactoryManager; -import org.apache.sshd.common.FactoryManagerUtils; import org.apache.sshd.common.NamedResource; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.ServiceFactory; import org.apache.sshd.common.SshConstants; import org.apache.sshd.common.SshException; @@ -58,8 +58,8 @@ public class ServerSessionImpl extends AbstractSession implements ServerSession public ServerSessionImpl(ServerFactoryManager server, IoSession ioSession) throws Exception { super(true, server, ioSession); - maxBytes = Math.max(32, getLongProperty(ServerFactoryManager.REKEY_BYTES_LIMIT, maxBytes)); - maxKeyInterval = getLongProperty(ServerFactoryManager.REKEY_TIME_LIMIT, maxKeyInterval); + maxBytes = Math.max(32, PropertyResolverUtils.getLongProperty(this, ServerFactoryManager.REKEY_BYTES_LIMIT, maxBytes)); + maxKeyInterval = PropertyResolverUtils.getLongProperty(this, ServerFactoryManager.REKEY_TIME_LIMIT, maxKeyInterval); log.info("Server session created from {}", ioSession.getRemoteAddress()); sendServerIdentification(); } @@ -101,7 +101,7 @@ public class ServerSessionImpl extends AbstractSession implements ServerSession protected void sendServerIdentification() { FactoryManager manager = getFactoryManager(); - String ident = FactoryManagerUtils.getString(manager, ServerFactoryManager.SERVER_IDENTIFICATION); + String ident = PropertyResolverUtils.getString(manager, ServerFactoryManager.SERVER_IDENTIFICATION); if (GenericUtils.isEmpty(ident)) { serverVersion = DEFAULT_SSH_VERSION_PREFIX + manager.getVersion(); } else {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java index 6c7a096..493ef4d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java @@ -23,10 +23,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.apache.sshd.common.FactoryManager; -import org.apache.sshd.common.FactoryManagerUtils; import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.NamedResource; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.Service; import org.apache.sshd.common.SshConstants; import org.apache.sshd.common.SshException; @@ -63,14 +62,14 @@ public class ServerUserAuthService extends AbstractCloseable implements Service, } this.session = (ServerSession) s; - maxAuthRequests = session.getIntProperty(ServerFactoryManager.MAX_AUTH_REQUESTS, ServerFactoryManager.DEFAULT_MAX_AUTH_REQUESTS); + maxAuthRequests = PropertyResolverUtils.getIntProperty(session, ServerFactoryManager.MAX_AUTH_REQUESTS, ServerFactoryManager.DEFAULT_MAX_AUTH_REQUESTS); ServerFactoryManager manager = getFactoryManager(); userAuthFactories = new ArrayList<>(manager.getUserAuthFactories()); // Get authentication methods authMethods = new ArrayList<>(); - String mths = FactoryManagerUtils.getString(manager, ServerFactoryManager.AUTH_METHODS); + String mths = PropertyResolverUtils.getString(session, ServerFactoryManager.AUTH_METHODS); if (GenericUtils.isEmpty(mths)) { for (NamedFactory<UserAuth> uaf : manager.getUserAuthFactories()) { authMethods.add(new ArrayList<>(Collections.singletonList(uaf.getName()))); @@ -203,8 +202,7 @@ public class ServerUserAuthService extends AbstractCloseable implements Service, } if (success) { - FactoryManager manager = getFactoryManager(); - Integer maxSessionCount = FactoryManagerUtils.getInteger(manager, ServerFactoryManager.MAX_CONCURRENT_SESSIONS); + Integer maxSessionCount = PropertyResolverUtils.getInteger(session, ServerFactoryManager.MAX_CONCURRENT_SESSIONS); if (maxSessionCount != null) { int currentSessionCount = session.getActiveSessionCountForUser(username); if (currentSessionCount >= maxSessionCount) { @@ -222,9 +220,9 @@ public class ServerUserAuthService extends AbstractCloseable implements Service, * authentication is successful. This message contains text to be * displayed to the client user before authentication is attempted. */ - String welcomeBanner = FactoryManagerUtils.getString(manager, ServerFactoryManager.WELCOME_BANNER); + String welcomeBanner = PropertyResolverUtils.getString(session, ServerFactoryManager.WELCOME_BANNER); if (GenericUtils.length(welcomeBanner) > 0) { - String lang = FactoryManagerUtils.getStringProperty(manager, + String lang = PropertyResolverUtils.getStringProperty(session, ServerFactoryManager.WELCOME_BANNER_LANGUAGE, ServerFactoryManager.DEFAULT_WELCOME_BANNER_LANGUAGE); buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_BANNER, welcomeBanner.length() + lang.length() + Long.SIZE); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/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 d47fc74..eb06156 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 @@ -66,8 +66,9 @@ import java.util.concurrent.Future; import org.apache.sshd.common.Factory; import org.apache.sshd.common.FactoryManager; -import org.apache.sshd.common.FactoryManagerUtils; import org.apache.sshd.common.NamedFactory; +import org.apache.sshd.common.PropertyResolver; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.config.VersionProperties; import org.apache.sshd.common.digest.BuiltinDigests; import org.apache.sshd.common.digest.Digest; @@ -96,81 +97,6 @@ import org.apache.sshd.server.ExitCallback; import org.apache.sshd.server.SessionAware; import org.apache.sshd.server.session.ServerSession; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.ACE4_APPEND_DATA; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.ACE4_READ_ATTRIBUTES; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.ACE4_READ_DATA; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.ACE4_WRITE_ATTRIBUTES; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.ACE4_WRITE_DATA; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.EXT_NEWLINE; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.EXT_SUPPORTED; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.EXT_SUPPORTED2; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.EXT_VENDOR_ID; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.EXT_VERSIONS; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SFTP_V3; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SFTP_V4; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SFTP_V5; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SFTP_V6; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FILEXFER_ATTR_ACCESSTIME; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FILEXFER_ATTR_ALL; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FILEXFER_ATTR_BITS; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FILEXFER_ATTR_CREATETIME; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FILEXFER_ATTR_MODIFYTIME; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FILEXFER_ATTR_OWNERGROUP; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FILEXFER_ATTR_PERMISSIONS; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FILEXFER_ATTR_SIZE; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_ACCESS_DISPOSITION; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_APPEND; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_APPEND_DATA; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_APPEND_DATA_ATOMIC; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_CREAT; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_CREATE_NEW; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_CREATE_TRUNCATE; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_EXCL; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_OPEN_EXISTING; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_OPEN_OR_CREATE; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_READ; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_TRUNC; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_TRUNCATE_EXISTING; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXF_WRITE; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_ATTRS; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_BLOCK; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_CLOSE; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_DATA; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_EXTENDED; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_EXTENDED_REPLY; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_FSETSTAT; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_FSTAT; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_HANDLE; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_INIT; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_LINK; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_LSTAT; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_MKDIR; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_NAME; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_OPEN; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_OPENDIR; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_READ; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_READDIR; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_READLINK; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_REALPATH; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_REALPATH_STAT_ALWAYS; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_REALPATH_STAT_IF; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_REMOVE; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_RENAME; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_RENAME_ATOMIC; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_RENAME_OVERWRITE; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_RMDIR; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_SETSTAT; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_STAT; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_STATUS; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_SYMLINK; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_UNBLOCK; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_VERSION; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_WRITE; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FX_FAILURE; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FX_OK; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FX_OP_UNSUPPORTED; - /** * SFTP subsystem * @@ -211,8 +137,8 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna */ public static final String SFTP_VERSION = "sftp-version"; - public static final int LOWER_SFTP_IMPL = SFTP_V3; // Working implementation from v3 - public static final int HIGHER_SFTP_IMPL = SFTP_V6; // .. up to + public static final int LOWER_SFTP_IMPL = SftpConstants.SFTP_V3; // Working implementation from v3 + public static final int HIGHER_SFTP_IMPL = SftpConstants.SFTP_V6; // .. up to public static final String ALL_SFTP_IMPL; /** @@ -376,11 +302,11 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna Factory<? extends Random> factory = manager.getRandomFactory(); this.randomizer = factory.create(); - this.fileHandleSize = FactoryManagerUtils.getIntProperty(manager, FILE_HANDLE_SIZE, DEFAULT_FILE_HANDLE_SIZE); + this.fileHandleSize = PropertyResolverUtils.getIntProperty(session, FILE_HANDLE_SIZE, DEFAULT_FILE_HANDLE_SIZE); ValidateUtils.checkTrue(this.fileHandleSize >= MIN_FILE_HANDLE_SIZE, "File handle size too small: %d", this.fileHandleSize); ValidateUtils.checkTrue(this.fileHandleSize <= MAX_FILE_HANDLE_SIZE, "File handle size too big: %d", this.fileHandleSize); - this.maxFileHandleRounds = FactoryManagerUtils.getIntProperty(manager, MAX_FILE_HANDLE_RAND_ROUNDS, DEFAULT_FILE_HANDLE_ROUNDS); + this.maxFileHandleRounds = PropertyResolverUtils.getIntProperty(session, MAX_FILE_HANDLE_RAND_ROUNDS, DEFAULT_FILE_HANDLE_ROUNDS); ValidateUtils.checkTrue(this.maxFileHandleRounds >= MIN_FILE_HANDLE_ROUNDS, "File handle rounds too small: %d", this.maxFileHandleRounds); ValidateUtils.checkTrue(this.maxFileHandleRounds <= MAX_FILE_HANDLE_ROUNDS, "File handle rounds too big: %d", this.maxFileHandleRounds); @@ -485,81 +411,81 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } switch (type) { - case SSH_FXP_INIT: + case SftpConstants.SSH_FXP_INIT: doInit(buffer, id); break; - case SSH_FXP_OPEN: + case SftpConstants.SSH_FXP_OPEN: doOpen(buffer, id); break; - case SSH_FXP_CLOSE: + case SftpConstants.SSH_FXP_CLOSE: doClose(buffer, id); break; - case SSH_FXP_READ: + case SftpConstants.SSH_FXP_READ: doRead(buffer, id); break; - case SSH_FXP_WRITE: + case SftpConstants.SSH_FXP_WRITE: doWrite(buffer, id); break; - case SSH_FXP_LSTAT: + case SftpConstants.SSH_FXP_LSTAT: doLStat(buffer, id); break; - case SSH_FXP_FSTAT: + case SftpConstants.SSH_FXP_FSTAT: doFStat(buffer, id); break; - case SSH_FXP_SETSTAT: + case SftpConstants.SSH_FXP_SETSTAT: doSetStat(buffer, id); break; - case SSH_FXP_FSETSTAT: + case SftpConstants.SSH_FXP_FSETSTAT: doFSetStat(buffer, id); break; - case SSH_FXP_OPENDIR: + case SftpConstants.SSH_FXP_OPENDIR: doOpenDir(buffer, id); break; - case SSH_FXP_READDIR: + case SftpConstants.SSH_FXP_READDIR: doReadDir(buffer, id); break; - case SSH_FXP_REMOVE: + case SftpConstants.SSH_FXP_REMOVE: doRemove(buffer, id); break; - case SSH_FXP_MKDIR: + case SftpConstants.SSH_FXP_MKDIR: doMakeDirectory(buffer, id); break; - case SSH_FXP_RMDIR: + case SftpConstants.SSH_FXP_RMDIR: doRemoveDirectory(buffer, id); break; - case SSH_FXP_REALPATH: + case SftpConstants.SSH_FXP_REALPATH: doRealPath(buffer, id); break; - case SSH_FXP_STAT: + case SftpConstants.SSH_FXP_STAT: doStat(buffer, id); break; - case SSH_FXP_RENAME: + case SftpConstants.SSH_FXP_RENAME: doRename(buffer, id); break; - case SSH_FXP_READLINK: + case SftpConstants.SSH_FXP_READLINK: doReadLink(buffer, id); break; - case SSH_FXP_SYMLINK: + case SftpConstants.SSH_FXP_SYMLINK: doSymLink(buffer, id); break; - case SSH_FXP_LINK: + case SftpConstants.SSH_FXP_LINK: doLink(buffer, id); break; - case SSH_FXP_BLOCK: + case SftpConstants.SSH_FXP_BLOCK: doBlock(buffer, id); break; - case SSH_FXP_UNBLOCK: + case SftpConstants.SSH_FXP_UNBLOCK: doUnblock(buffer, id); break; - case SSH_FXP_EXTENDED: + case SftpConstants.SSH_FXP_EXTENDED: doExtended(buffer, id); break; default: log.warn("Unknown command type received: {}", Integer.valueOf(type)); - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OP_UNSUPPORTED, "Command " + type + " is unsupported or not implemented"); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OP_UNSUPPORTED, "Command " + type + " is unsupported or not implemented"); } - if (type != SSH_FXP_INIT) { + if (type != SftpConstants.SSH_FXP_INIT) { requestsCount++; } } @@ -604,7 +530,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna break; default: log.info("Received unsupported SSH_FXP_EXTENDED({})", extension); - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OP_UNSUPPORTED, "Command SSH_FXP_EXTENDED(" + extension + ") is unsupported or not implemented"); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OP_UNSUPPORTED, "Command SSH_FXP_EXTENDED(" + extension + ") is unsupported or not implemented"); break; } } @@ -620,7 +546,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } buffer.clear(); - buffer.putByte((byte) SSH_FXP_EXTENDED_REPLY); + buffer.putByte((byte) SftpConstants.SSH_FXP_EXTENDED_REPLY); buffer.putInt(id); SpaceAvailableExtensionInfo.encode(buffer, info); send(buffer); @@ -651,7 +577,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doTextSeek(int id, String handle, long line) throws IOException { @@ -674,7 +600,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doOpenSSHFsync(int id, String handle) throws IOException { @@ -697,7 +623,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna int blockSize = buffer.getInt(); try { buffer.clear(); - buffer.putByte((byte) SSH_FXP_EXTENDED_REPLY); + buffer.putByte((byte) SftpConstants.SSH_FXP_EXTENDED_REPLY); buffer.putInt(id); buffer.putString(SftpConstants.EXT_CHECK_FILE); doCheckFileHash(id, targetType, target, Arrays.asList(algos), startOffset, length, blockSize, buffer); @@ -725,7 +651,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna * the server MUST return STATUS_PERMISSION_DENIED. */ int access = fileHandle.getAccessMask(); - if ((access & ACE4_READ_DATA) == 0) { + if ((access & SftpConstants.ACE4_READ_DATA) == 0) { throw new AccessDeniedException("File not opened for read: " + path); } } else { @@ -870,7 +796,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } buffer.clear(); - buffer.putByte((byte) SSH_FXP_EXTENDED_REPLY); + buffer.putByte((byte) SftpConstants.SSH_FXP_EXTENDED_REPLY); buffer.putInt(id); buffer.putString(targetType); buffer.putBytes(hashValue); @@ -897,7 +823,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna * was opened */ int access = fileHandle.getAccessMask(); - if ((access & ACE4_READ_DATA) == 0) { + if ((access & SftpConstants.ACE4_READ_DATA) == 0) { throw new AccessDeniedException("File not opened for read: " + path); } } else { @@ -1028,7 +954,9 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna * channel. */ if (requestsCount > 0L) { - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_FAILURE, "Version selection not the 1st request for proposal = " + proposed); + sendStatus(BufferUtils.clear(buffer), id, + SftpConstants.SSH_FX_FAILURE, + "Version selection not the 1st request for proposal = " + proposed); session.close(true); return; } @@ -1043,9 +971,9 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } if (result) { version = Integer.parseInt(proposed); - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } else { - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_FAILURE, "Unsupported version " + proposed); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_FAILURE, "Unsupported version " + proposed); session.close(true); } } @@ -1074,7 +1002,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } int value = digit - '0'; - String all = checkVersionCompatibility(buffer, id, value, SSH_FX_FAILURE); + String all = checkVersionCompatibility(buffer, id, value, SftpConstants.SSH_FX_FAILURE); if (GenericUtils.isEmpty(all)) { // validation failed return null; } else { @@ -1102,7 +1030,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna int hig = HIGHER_SFTP_IMPL; String available = ALL_SFTP_IMPL; // check if user wants to use a specific version - Integer sftpVersion = FactoryManagerUtils.getInteger(session, SFTP_VERSION); + Integer sftpVersion = PropertyResolverUtils.getInteger(session, SFTP_VERSION); if (sftpVersion != null) { int forcedValue = sftpVersion; if ((forcedValue < LOWER_SFTP_IMPL) || (forcedValue > HIGHER_SFTP_IMPL)) { @@ -1139,7 +1067,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doBlock(int id, String handle, long offset, long length, int mask) throws IOException { @@ -1165,7 +1093,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, found ? SSH_FX_OK : SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK, ""); + sendStatus(BufferUtils.clear(buffer), id, found ? SftpConstants.SSH_FX_OK : SftpConstants.SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK, ""); } protected boolean doUnblock(int id, String handle, long offset, long length) throws IOException { @@ -1196,7 +1124,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doLink(int id, String targetPath, String linkPath, boolean symLink) throws IOException { @@ -1216,7 +1144,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doSymLink(int id, String targetPath, String linkPath) throws IOException { @@ -1267,7 +1195,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna String oldPath = buffer.getString(); String newPath = buffer.getString(); int flags = 0; - if (version >= SFTP_V5) { + if (version >= SftpConstants.SFTP_V5) { flags = buffer.getInt(); } try { @@ -1277,7 +1205,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doRename(int id, String oldPath, String newPath, int flags) throws IOException { @@ -1289,10 +1217,10 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna Collection<CopyOption> opts = Collections.emptyList(); if (flags != 0) { opts = new ArrayList<>(); - if ((flags & SSH_FXP_RENAME_ATOMIC) == SSH_FXP_RENAME_ATOMIC) { + if ((flags & SftpConstants.SSH_FXP_RENAME_ATOMIC) == SftpConstants.SSH_FXP_RENAME_ATOMIC) { opts.add(StandardCopyOption.ATOMIC_MOVE); } - if ((flags & SSH_FXP_RENAME_OVERWRITE) == SSH_FXP_RENAME_OVERWRITE) { + if ((flags & SftpConstants.SSH_FXP_RENAME_OVERWRITE) == SftpConstants.SSH_FXP_RENAME_OVERWRITE) { opts.add(StandardCopyOption.REPLACE_EXISTING); } } @@ -1320,7 +1248,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } @SuppressWarnings("resource") @@ -1338,7 +1266,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna FileHandle srcHandle = validateHandle(readHandle, rh, FileHandle.class); Path srcPath = srcHandle.getFile(); int srcAccess = srcHandle.getAccessMask(); - if ((srcAccess & ACE4_READ_DATA) != ACE4_READ_DATA) { + if ((srcAccess & SftpConstants.ACE4_READ_DATA) != SftpConstants.ACE4_READ_DATA) { throw new AccessDeniedException("File not opened for read: " + srcPath); } @@ -1359,7 +1287,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna FileHandle dstHandle = inPlaceCopy ? srcHandle : validateHandle(writeHandle, wh, FileHandle.class); int dstAccess = dstHandle.getAccessMask(); - if ((dstAccess & ACE4_WRITE_DATA) != ACE4_WRITE_DATA) { + if ((dstAccess & SftpConstants.ACE4_WRITE_DATA) != SftpConstants.ACE4_WRITE_DATA) { throw new AccessDeniedException("File not opened for write: " + srcHandle); } @@ -1409,7 +1337,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doCopyFile(int id, String srcFile, String dstFile, boolean overwriteDestination) throws IOException { @@ -1432,8 +1360,8 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna protected void doStat(Buffer buffer, int id) throws IOException { String path = buffer.getString(); - int flags = SSH_FILEXFER_ATTR_ALL; - if (version >= SFTP_V4) { + int flags = SftpConstants.SSH_FILEXFER_ATTR_ALL; + if (version >= SftpConstants.SFTP_V4) { flags = buffer.getInt(); } @@ -1468,7 +1396,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna Pair<Path, Boolean> result; try { LinkOption[] options = IoUtils.getLinkOptions(false); - if (version < SFTP_V6) { + if (version < SftpConstants.SFTP_V6) { /* * See http://www.openssh.com/txt/draft-ietf-secsh-filexfer-02.txt: * @@ -1494,9 +1422,9 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna Path p = result.getFirst(); Boolean status = result.getSecond(); - if (control == SSH_FXP_REALPATH_STAT_IF) { + if (control == SftpConstants.SSH_FXP_REALPATH_STAT_IF) { if (status == null) { - attrs = handleUnknownStatusFileAttributes(p, SSH_FILEXFER_ATTR_ALL, options); + attrs = handleUnknownStatusFileAttributes(p, SftpConstants.SSH_FILEXFER_ATTR_ALL, options); } else if (status) { try { attrs = getAttributes(p, IoUtils.getLinkOptions(false)); @@ -1511,9 +1439,9 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna log.debug("Dummy attributes for non-existing file: " + p); } } - } else if (control == SSH_FXP_REALPATH_STAT_ALWAYS) { + } else if (control == SftpConstants.SSH_FXP_REALPATH_STAT_ALWAYS) { if (status == null) { - attrs = handleUnknownStatusFileAttributes(p, SSH_FILEXFER_ATTR_ALL, options); + attrs = handleUnknownStatusFileAttributes(p, SftpConstants.SSH_FILEXFER_ATTR_ALL, options); } else if (status) { attrs = getAttributes(p, options); } else { @@ -1576,7 +1504,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doRemoveDirectory(int id, String path, LinkOption... options) throws IOException { @@ -1599,7 +1527,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doMakeDirectory(int id, String path, Map<String, ?> attrs, LinkOption... options) throws IOException { @@ -1634,7 +1562,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doRemove(int id, String path, LinkOption... options) throws IOException { @@ -1689,12 +1617,12 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna // large size or have a timeout to occur. reply = BufferUtils.clear(buffer); - reply.putByte((byte) SSH_FXP_NAME); + reply.putByte((byte) SftpConstants.SSH_FXP_NAME); reply.putInt(id); int lenPos = reply.wpos(); reply.putInt(0); - int count = doReadDir(id, dh, reply, FactoryManagerUtils.getIntProperty(session, MAX_PACKET_LENGTH_PROP, DEFAULT_MAX_PACKET_LENGTH)); + int count = doReadDir(id, dh, reply, PropertyResolverUtils.getIntProperty(session, MAX_PACKET_LENGTH_PROP, DEFAULT_MAX_PACKET_LENGTH)); BufferUtils.updateLengthPlaceholder(reply, lenPos, count); if (log.isDebugEnabled()) { log.debug("doReadDir({})[{}] - sent {} entries", handle, h, count); @@ -1764,7 +1692,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doFSetStat(int id, String handle, Map<String, ?> attrs) throws IOException { @@ -1786,7 +1714,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doSetStat(int id, String path, Map<String, ?> attrs) throws IOException { @@ -1797,8 +1725,8 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna protected void doFStat(Buffer buffer, int id) throws IOException { String handle = buffer.getString(); - int flags = SSH_FILEXFER_ATTR_ALL; - if (version >= SFTP_V4) { + int flags = SftpConstants.SSH_FILEXFER_ATTR_ALL; + if (version >= SftpConstants.SFTP_V4) { flags = buffer.getInt(); } @@ -1824,8 +1752,8 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna protected void doLStat(Buffer buffer, int id) throws IOException { String path = buffer.getString(); - int flags = SSH_FILEXFER_ATTR_ALL; - if (version >= SFTP_V4) { + int flags = SftpConstants.SSH_FILEXFER_ATTR_ALL; + if (version >= SftpConstants.SFTP_V4) { flags = buffer.getInt(); } @@ -1860,7 +1788,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, ""); } protected void doWrite(int id, String handle, long offset, int length, byte[] data, int doff, int remaining) throws IOException { @@ -1890,7 +1818,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna String handle = buffer.getString(); long offset = buffer.getLong(); int requestedLength = buffer.getInt(); - int maxAllowed = FactoryManagerUtils.getIntProperty(session, MAX_PACKET_LENGTH_PROP, DEFAULT_MAX_PACKET_LENGTH); + int maxAllowed = PropertyResolverUtils.getIntProperty(session, MAX_PACKET_LENGTH_PROP, DEFAULT_MAX_PACKET_LENGTH); int readLen = Math.min(requestedLength, maxAllowed); if (log.isTraceEnabled()) { @@ -1904,7 +1832,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna buffer.clear(); buffer.ensureCapacity(readLen + Long.SIZE /* the header */, Int2IntFunction.IDENTITY); - buffer.putByte((byte) SSH_FXP_DATA); + buffer.putByte((byte) SftpConstants.SSH_FXP_DATA); buffer.putInt(id); int lenPos = buffer.wpos(); buffer.putInt(0); @@ -1945,7 +1873,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna return; } - sendStatus(BufferUtils.clear(buffer), id, SSH_FX_OK, "", ""); + sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_OK, "", ""); } protected void doClose(int id, String handle) throws IOException { @@ -1960,50 +1888,50 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna * Be consistent with FileChannel#open - if no mode specified then READ is assumed */ int access = 0; - if (version >= SFTP_V5) { + if (version >= SftpConstants.SFTP_V5) { access = buffer.getInt(); if (access == 0) { - access = ACE4_READ_DATA | ACE4_READ_ATTRIBUTES; + access = SftpConstants.ACE4_READ_DATA | SftpConstants.ACE4_READ_ATTRIBUTES; } } int pflags = buffer.getInt(); if (pflags == 0) { - pflags = SSH_FXF_READ; + pflags = SftpConstants.SSH_FXF_READ; } - if (version < SFTP_V5) { + if (version < SftpConstants.SFTP_V5) { int flags = pflags; pflags = 0; - switch (flags & (SSH_FXF_READ | SSH_FXF_WRITE)) { - case SSH_FXF_READ: - access |= ACE4_READ_DATA | ACE4_READ_ATTRIBUTES; + switch (flags & (SftpConstants.SSH_FXF_READ | SftpConstants.SSH_FXF_WRITE)) { + case SftpConstants.SSH_FXF_READ: + access |= SftpConstants.ACE4_READ_DATA | SftpConstants.ACE4_READ_ATTRIBUTES; break; - case SSH_FXF_WRITE: - access |= ACE4_WRITE_DATA | ACE4_WRITE_ATTRIBUTES; + case SftpConstants.SSH_FXF_WRITE: + access |= SftpConstants.ACE4_WRITE_DATA | SftpConstants.ACE4_WRITE_ATTRIBUTES; break; default: - access |= ACE4_READ_DATA | ACE4_READ_ATTRIBUTES; - access |= ACE4_WRITE_DATA | ACE4_WRITE_ATTRIBUTES; + access |= SftpConstants.ACE4_READ_DATA | SftpConstants.ACE4_READ_ATTRIBUTES; + access |= SftpConstants.ACE4_WRITE_DATA | SftpConstants.ACE4_WRITE_ATTRIBUTES; break; } - if ((flags & SSH_FXF_APPEND) != 0) { - access |= ACE4_APPEND_DATA; - pflags |= SSH_FXF_APPEND_DATA | SSH_FXF_APPEND_DATA_ATOMIC; + if ((flags & SftpConstants.SSH_FXF_APPEND) != 0) { + access |= SftpConstants.ACE4_APPEND_DATA; + pflags |= SftpConstants.SSH_FXF_APPEND_DATA | SftpConstants.SSH_FXF_APPEND_DATA_ATOMIC; } - if ((flags & SSH_FXF_CREAT) != 0) { - if ((flags & SSH_FXF_EXCL) != 0) { - pflags |= SSH_FXF_CREATE_NEW; - } else if ((flags & SSH_FXF_TRUNC) != 0) { - pflags |= SSH_FXF_CREATE_TRUNCATE; + if ((flags & SftpConstants.SSH_FXF_CREAT) != 0) { + if ((flags & SftpConstants.SSH_FXF_EXCL) != 0) { + pflags |= SftpConstants.SSH_FXF_CREATE_NEW; + } else if ((flags & SftpConstants.SSH_FXF_TRUNC) != 0) { + pflags |= SftpConstants.SSH_FXF_CREATE_TRUNCATE; } else { - pflags |= SSH_FXF_OPEN_OR_CREATE; + pflags |= SftpConstants.SSH_FXF_OPEN_OR_CREATE; } } else { - if ((flags & SSH_FXF_TRUNC) != 0) { - pflags |= SSH_FXF_TRUNCATE_EXISTING; + if ((flags & SftpConstants.SSH_FXF_TRUNC) != 0) { + pflags |= SftpConstants.SSH_FXF_TRUNCATE_EXISTING; } else { - pflags |= SSH_FXF_OPEN_EXISTING; + pflags |= SftpConstants.SSH_FXF_OPEN_EXISTING; } } } @@ -2035,7 +1963,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna path, Integer.toHexString(access), Integer.toHexString(pflags), attrs); } int curHandleCount = handles.size(); - int maxHandleCount = FactoryManagerUtils.getIntProperty(session, MAX_OPEN_HANDLES_PER_SESSION, DEFAULT_MAX_OPEN_HANDLES); + int maxHandleCount = PropertyResolverUtils.getIntProperty(session, MAX_OPEN_HANDLES_PER_SESSION, DEFAULT_MAX_OPEN_HANDLES); if (curHandleCount > maxHandleCount) { throw new IllegalStateException("Too many open handles: current=" + curHandleCount + ", max.=" + maxHandleCount); } @@ -2073,7 +2001,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna log.debug("Received SSH_FXP_INIT (version={})", Integer.valueOf(id)); } - String all = checkVersionCompatibility(buffer, id, id, SSH_FX_OP_UNSUPPORTED); + String all = checkVersionCompatibility(buffer, id, id, SftpConstants.SSH_FX_OP_UNSUPPORTED); if (GenericUtils.isEmpty(all)) { // i.e. validation failed return; } @@ -2086,7 +2014,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna buffer.clear(); - buffer.putByte((byte) SSH_FXP_VERSION); + buffer.putByte((byte) SftpConstants.SSH_FXP_VERSION); buffer.putInt(version); appendExtensions(buffer, all); @@ -2126,7 +2054,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } protected List<OpenSSHExtension> resolveOpenSSHExtensions() { - String value = FactoryManagerUtils.getString(session, OPENSSH_EXTENSIONS_PROP); + String value = PropertyResolverUtils.getString(session, OPENSSH_EXTENSIONS_PROP); if (value == null) { // No override return DEFAULT_OPEN_SSH_EXTENSIONS; } @@ -2155,7 +2083,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } protected Collection<String> getSupportedClientExtensions() { - String value = FactoryManagerUtils.getString(session, CLIENT_EXTENSIONS_PROP); + String value = PropertyResolverUtils.getString(session, CLIENT_EXTENSIONS_PROP); if (value == null) { return DEFAULT_SUPPORTED_CLIENT_EXTENSIONS; } @@ -2178,7 +2106,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna * @see SftpConstants#EXT_VERSIONS */ protected void appendVersionsExtension(Buffer buffer, String value) { - buffer.putString(EXT_VERSIONS); + buffer.putString(SftpConstants.EXT_VERSIONS); buffer.putString(value); } @@ -2192,7 +2120,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna * @see SftpConstants#EXT_NEWLINE */ protected void appendNewlineExtension(Buffer buffer, String value) { - buffer.putString(EXT_NEWLINE); + buffer.putString(SftpConstants.EXT_NEWLINE); buffer.putString(value); } @@ -2207,14 +2135,15 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna * @see <A HREF="http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt">DRAFT 09 - section 4.4</A> */ protected void appendVendorIdExtension(Buffer buffer, Map<String, ?> versionProperties) { - buffer.putString(EXT_VENDOR_ID); + buffer.putString(SftpConstants.EXT_VENDOR_ID); + PropertyResolver resolver = PropertyResolverUtils.toPropertyResolver(Collections.unmodifiableMap(versionProperties)); // placeholder for length int lenPos = buffer.wpos(); buffer.putInt(0); - buffer.putString(FactoryManagerUtils.getStringProperty(versionProperties, "groupId", getClass().getPackage().getName())); // vendor-name - buffer.putString(FactoryManagerUtils.getStringProperty(versionProperties, "artifactId", getClass().getSimpleName())); // product-name - buffer.putString(FactoryManagerUtils.getStringProperty(versionProperties, "version", FactoryManager.DEFAULT_VERSION)); // product-version + buffer.putString(PropertyResolverUtils.getStringProperty(resolver, "groupId", getClass().getPackage().getName())); // vendor-name + buffer.putString(PropertyResolverUtils.getStringProperty(resolver, "artifactId", getClass().getSimpleName())); // product-name + buffer.putString(PropertyResolverUtils.getStringProperty(resolver, "version", FactoryManager.DEFAULT_VERSION)); // product-version buffer.putLong(0L); // product-build-number BufferUtils.updateLengthPlaceholder(buffer, lenPos); } @@ -2229,20 +2158,20 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna * - may be {@code null}/empty */ protected void appendSupportedExtension(Buffer buffer, Collection<String> extras) { - buffer.putString(EXT_SUPPORTED); + buffer.putString(SftpConstants.EXT_SUPPORTED); int lenPos = buffer.wpos(); buffer.putInt(0); // length placeholder // supported-attribute-mask - buffer.putInt(SSH_FILEXFER_ATTR_SIZE | SSH_FILEXFER_ATTR_PERMISSIONS - | SSH_FILEXFER_ATTR_ACCESSTIME | SSH_FILEXFER_ATTR_CREATETIME - | SSH_FILEXFER_ATTR_MODIFYTIME | SSH_FILEXFER_ATTR_OWNERGROUP - | SSH_FILEXFER_ATTR_BITS); + buffer.putInt(SftpConstants.SSH_FILEXFER_ATTR_SIZE | SftpConstants.SSH_FILEXFER_ATTR_PERMISSIONS + | SftpConstants.SSH_FILEXFER_ATTR_ACCESSTIME | SftpConstants.SSH_FILEXFER_ATTR_CREATETIME + | SftpConstants.SSH_FILEXFER_ATTR_MODIFYTIME | SftpConstants.SSH_FILEXFER_ATTR_OWNERGROUP + | SftpConstants.SSH_FILEXFER_ATTR_BITS); // TODO: supported-attribute-bits buffer.putInt(0); // supported-open-flags - buffer.putInt(SSH_FXF_READ | SSH_FXF_WRITE | SSH_FXF_APPEND - | SSH_FXF_CREAT | SSH_FXF_TRUNC | SSH_FXF_EXCL); + buffer.putInt(SftpConstants.SSH_FXF_READ | SftpConstants.SSH_FXF_WRITE | SftpConstants.SSH_FXF_APPEND + | SftpConstants.SSH_FXF_CREAT | SftpConstants.SSH_FXF_TRUNC | SftpConstants.SSH_FXF_EXCL); // TODO: supported-access-mask buffer.putInt(0); // max-read-size @@ -2265,19 +2194,19 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna * @see <A HREF="https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#page-10">DRAFT 13 section 5.4</A> */ protected void appendSupported2Extension(Buffer buffer, Collection<String> extras) { - buffer.putString(EXT_SUPPORTED2); + buffer.putString(SftpConstants.EXT_SUPPORTED2); int lenPos = buffer.wpos(); buffer.putInt(0); // length placeholder // supported-attribute-mask - buffer.putInt(SSH_FILEXFER_ATTR_SIZE | SSH_FILEXFER_ATTR_PERMISSIONS - | SSH_FILEXFER_ATTR_ACCESSTIME | SSH_FILEXFER_ATTR_CREATETIME - | SSH_FILEXFER_ATTR_MODIFYTIME | SSH_FILEXFER_ATTR_OWNERGROUP - | SSH_FILEXFER_ATTR_BITS); + buffer.putInt(SftpConstants.SSH_FILEXFER_ATTR_SIZE | SftpConstants.SSH_FILEXFER_ATTR_PERMISSIONS + | SftpConstants.SSH_FILEXFER_ATTR_ACCESSTIME | SftpConstants.SSH_FILEXFER_ATTR_CREATETIME + | SftpConstants.SSH_FILEXFER_ATTR_MODIFYTIME | SftpConstants.SSH_FILEXFER_ATTR_OWNERGROUP + | SftpConstants.SSH_FILEXFER_ATTR_BITS); // TODO: supported-attribute-bits buffer.putInt(0); // supported-open-flags - buffer.putInt(SSH_FXF_ACCESS_DISPOSITION | SSH_FXF_APPEND_DATA); + buffer.putInt(SftpConstants.SSH_FXF_ACCESS_DISPOSITION | SftpConstants.SSH_FXF_APPEND_DATA); // TODO: supported-access-mask buffer.putInt(0); // max-read-size @@ -2295,21 +2224,21 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } protected void sendHandle(Buffer buffer, int id, String handle) throws IOException { - buffer.putByte((byte) SSH_FXP_HANDLE); + buffer.putByte((byte) SftpConstants.SSH_FXP_HANDLE); buffer.putInt(id); buffer.putString(handle); send(buffer); } protected void sendAttrs(Buffer buffer, int id, Map<String, ?> attributes) throws IOException { - buffer.putByte((byte) SSH_FXP_ATTRS); + buffer.putByte((byte) SftpConstants.SSH_FXP_ATTRS); buffer.putInt(id); writeAttrs(buffer, attributes); send(buffer); } protected void sendPath(Buffer buffer, int id, Path f, Map<String, ?> attrs) throws IOException { - buffer.putByte((byte) SSH_FXP_NAME); + buffer.putByte((byte) SftpConstants.SSH_FXP_NAME); buffer.putInt(id); buffer.putInt(1); // one reply @@ -2323,11 +2252,11 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } buffer.putString(normalizedPath); - if (version == SFTP_V3) { + if (version == SftpConstants.SFTP_V3) { f = resolveFile(normalizedPath); buffer.putString(getLongName(f, attrs)); buffer.putInt(0); // no flags - } else if (version >= SFTP_V4) { + } else if (version >= SftpConstants.SFTP_V4) { writeAttrs(buffer, attrs); } else { throw new IllegalStateException("sendPath(" + f + ") unsupported version: " + version); @@ -2338,12 +2267,12 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna protected void sendLink(Buffer buffer, int id, String link) throws IOException { //in case we are running on Windows String unixPath = link.replace(File.separatorChar, '/'); - buffer.putByte((byte) SSH_FXP_NAME); + buffer.putByte((byte) SftpConstants.SSH_FXP_NAME); buffer.putInt(id); buffer.putInt(1); // one response buffer.putString(unixPath); - if (version == SFTP_V3) { + if (version == SftpConstants.SFTP_V3) { buffer.putString(unixPath); } @@ -2397,10 +2326,10 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna * @throws IOException If failed to generate the entry data */ protected void writeDirEntry(int id, DirectoryHandle dir, Buffer buffer, int index, Path f, String shortName, LinkOption... options) throws IOException { - Map<String, ?> attrs = resolveFileAttributes(f, SSH_FILEXFER_ATTR_ALL, options); + Map<String, ?> attrs = resolveFileAttributes(f, SftpConstants.SSH_FILEXFER_ATTR_ALL, options); buffer.putString(shortName); - if (version == SFTP_V3) { + if (version == SftpConstants.SFTP_V3) { String longName = getLongName(f, options); buffer.putString(longName); if (log.isTraceEnabled()) { @@ -2532,7 +2461,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna } protected Map<String, Object> getAttributes(Path file, LinkOption... options) throws IOException { - return getAttributes(file, SSH_FILEXFER_ATTR_ALL, options); + return getAttributes(file, SftpConstants.SSH_FILEXFER_ATTR_ALL, options); } protected Map<String, Object> handleUnknownStatusFileAttributes(Path file, int flags, LinkOption... options) throws IOException { @@ -2871,7 +2800,7 @@ public class SftpSubsystem extends AbstractLoggingBean implements Command, Runna log.debug("Send SSH_FXP_STATUS (substatus={}, lang={}, msg={})", substatus, lang, msg); } - buffer.putByte((byte) SSH_FXP_STATUS); + buffer.putByte((byte) SftpConstants.SSH_FXP_STATUS); buffer.putInt(id); buffer.putInt(substatus); buffer.putString(msg); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java b/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java index 855d368..3b048e7 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java @@ -29,7 +29,7 @@ import org.apache.sshd.client.future.DefaultOpenFuture; import org.apache.sshd.client.future.OpenFuture; import org.apache.sshd.common.Closeable; import org.apache.sshd.common.FactoryManager; -import org.apache.sshd.common.FactoryManagerUtils; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.SshConstants; import org.apache.sshd.common.SshException; import org.apache.sshd.common.channel.ChannelOutputStream; @@ -152,7 +152,7 @@ public class X11ForwardSupport extends AbstractInnerCloseable implements IoHandl ChannelForwardedX11 channel = new ChannelForwardedX11(session); session.setAttribute(ChannelForwardedX11.class, channel); this.service.registerChannel(channel); - channel.open().verify(FactoryManagerUtils.getLongProperty(this.service.getSession(), CHANNEL_OPEN_TIMEOUT_PROP, DEFAULT_CHANNEL_OPEN_TIMEOUT)); + channel.open().verify(PropertyResolverUtils.getLongProperty(channel, CHANNEL_OPEN_TIMEOUT_PROP, DEFAULT_CHANNEL_OPEN_TIMEOUT)); } @Override @@ -168,7 +168,7 @@ public class X11ForwardSupport extends AbstractInnerCloseable implements IoHandl ChannelForwardedX11 channel = (ChannelForwardedX11) session.getAttribute(ChannelForwardedX11.class); Buffer buffer = new ByteArrayBuffer(); buffer.putBuffer(message); - + OutputStream outputStream = channel.getInvertedIn(); outputStream.write(buffer.array(), buffer.rpos(), buffer.available()); outputStream.flush(); @@ -195,9 +195,12 @@ public class X11ForwardSupport extends AbstractInnerCloseable implements IoHandl throw new SshException("Session has been closed"); } openFuture = new DefaultOpenFuture(lock); + + Session session = getSession(); if (log.isDebugEnabled()) { - log.debug("Send SSH_MSG_CHANNEL_OPEN on channel {}", Integer.valueOf(id)); + log.debug("Send SSH_MSG_CHANNEL_OPEN on {} channel {}", session, Integer.valueOf(id)); } + Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN); buffer.putString(type); buffer.putInt(id); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java b/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java index 642c198..d885e26 100644 --- a/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java @@ -29,7 +29,7 @@ import org.apache.sshd.client.SshClient; import org.apache.sshd.client.channel.ClientChannel; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.FactoryManager; -import org.apache.sshd.common.FactoryManagerUtils; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.server.Command; import org.apache.sshd.server.SshServer; import org.apache.sshd.util.test.BaseTestSupport; @@ -59,7 +59,7 @@ public class KeepAliveTest extends BaseTestSupport { @Before public void setUp() throws Exception { sshd = setupTestServer(); - FactoryManagerUtils.updateProperty(sshd, FactoryManager.IDLE_TIMEOUT, TIMEOUT); + PropertyResolverUtils.updateProperty(sshd, FactoryManager.IDLE_TIMEOUT, TIMEOUT); sshd.setShellFactory(new TestEchoShellFactory()); sshd.start(); port = sshd.getPort(); @@ -96,7 +96,7 @@ public class KeepAliveTest extends BaseTestSupport { @Test public void testClientWithHeartBeat() throws Exception { SshClient client = setupTestClient(); - FactoryManagerUtils.updateProperty(client, ClientFactoryManager.HEARTBEAT_INTERVAL, HEARTBEAT); + PropertyResolverUtils.updateProperty(client, ClientFactoryManager.HEARTBEAT_INTERVAL, HEARTBEAT); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java index ccb5705..d6e38ec 100644 --- a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java @@ -39,7 +39,7 @@ import org.apache.sshd.client.SshClient; import org.apache.sshd.client.channel.ChannelShell; import org.apache.sshd.client.channel.ClientChannel; import org.apache.sshd.client.session.ClientSession; -import org.apache.sshd.common.FactoryManagerUtils; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.cipher.BuiltinCiphers; import org.apache.sshd.common.future.KeyExchangeFuture; @@ -84,10 +84,10 @@ public class KeyReExchangeTest extends BaseTestSupport { protected void setUp(long bytesLimit, long timeLimit) throws Exception { sshd = setupTestServer(); if (bytesLimit > 0L) { - FactoryManagerUtils.updateProperty(sshd, ServerFactoryManager.REKEY_BYTES_LIMIT, bytesLimit); + PropertyResolverUtils.updateProperty(sshd, ServerFactoryManager.REKEY_BYTES_LIMIT, bytesLimit); } if (timeLimit > 0L) { - FactoryManagerUtils.updateProperty(sshd, ServerFactoryManager.REKEY_TIME_LIMIT, timeLimit); + PropertyResolverUtils.updateProperty(sshd, ServerFactoryManager.REKEY_TIME_LIMIT, timeLimit); } sshd.start(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/test/java/org/apache/sshd/LoadTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java index fce8bcb..45c8c4b 100644 --- a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.EnumSet; import java.util.List; -import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -35,7 +34,7 @@ import org.apache.sshd.client.SshClient; import org.apache.sshd.client.channel.ClientChannel; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.FactoryManager; -import org.apache.sshd.common.FactoryManagerUtils; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.cipher.BuiltinCiphers; import org.apache.sshd.common.cipher.Cipher; @@ -117,9 +116,8 @@ public class LoadTest extends BaseTestSupport { protected void runClient(String msg) throws Exception { try (SshClient client = setupTestClient()) { - Map<String, Object> props = client.getProperties(); - FactoryManagerUtils.updateProperty(props, FactoryManager.MAX_PACKET_SIZE, 1024 * 16); - FactoryManagerUtils.updateProperty(props, FactoryManager.WINDOW_SIZE, 1024 * 8); + PropertyResolverUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 1024 * 16); + PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024 * 8); client.setKeyExchangeFactories(Arrays.asList( ClientBuilder.DH2KEX.transform(BuiltinDHFactories.dhg1))); client.setCipherFactories(Arrays.<NamedFactory<Cipher>>asList(BuiltinCiphers.blowfishcbc)); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java b/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java index 736223d..6380390 100644 --- a/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java @@ -50,7 +50,7 @@ import org.apache.sshd.client.SshClient; import org.apache.sshd.client.channel.ChannelDirectTcpip; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.FactoryManager; -import org.apache.sshd.common.FactoryManagerUtils; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.SshdSocketAddress; import org.apache.sshd.common.forward.TcpipForwarder; import org.apache.sshd.common.forward.TcpipForwarderFactory; @@ -94,8 +94,8 @@ public class PortForwardingTest extends BaseTestSupport { @Before public void setUp() throws Exception { sshd = setupTestServer(); - FactoryManagerUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048); - FactoryManagerUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, 256); + PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048); + PropertyResolverUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, 256); sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); sshd.start(); @@ -590,8 +590,8 @@ public class PortForwardingTest extends BaseTestSupport { protected ClientSession createNativeSession() throws Exception { client = setupTestClient(); - FactoryManagerUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048); - FactoryManagerUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256); + PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048); + PropertyResolverUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256); client.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); client.start(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java b/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java index 66f3ce4..31befd4 100644 --- a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java @@ -35,7 +35,7 @@ import org.apache.mina.transport.socket.nio.NioSocketAcceptor; import org.apache.sshd.client.SshClient; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.FactoryManager; -import org.apache.sshd.common.FactoryManagerUtils; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.SshdSocketAddress; import org.apache.sshd.server.SshServer; import org.apache.sshd.server.forward.AcceptAllForwardingFilter; @@ -60,8 +60,8 @@ public class ProxyTest extends BaseTestSupport { @Before public void setUp() throws Exception { sshd = setupTestServer(); - FactoryManagerUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048); - FactoryManagerUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, "256"); + PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048); + PropertyResolverUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, "256"); sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); sshd.start(); sshPort = sshd.getPort(); @@ -140,8 +140,8 @@ public class ProxyTest extends BaseTestSupport { protected ClientSession createNativeSession() throws Exception { client = setupTestClient(); - FactoryManagerUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048); - FactoryManagerUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256); + PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 2048); + PropertyResolverUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 256); client.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE); client.start(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java b/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java index 3db63b8..7e65911 100644 --- a/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java @@ -28,7 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.sshd.client.SshClient; import org.apache.sshd.client.future.AuthFuture; import org.apache.sshd.client.session.ClientSession; -import org.apache.sshd.common.FactoryManagerUtils; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.config.keys.KeyUtils; import org.apache.sshd.common.keyprovider.KeyPairProvider; import org.apache.sshd.server.ServerFactoryManager; @@ -68,7 +68,7 @@ public class SinglePublicKeyAuthTest extends BaseTestSupport { @Before public void setUp() throws Exception { sshd = setupTestServer(); - FactoryManagerUtils.updateProperty(sshd, ServerFactoryManager.AUTH_METHODS, UserAuthPublicKeyFactory.NAME); + PropertyResolverUtils.updateProperty(sshd, ServerFactoryManager.AUTH_METHODS, UserAuthPublicKeyFactory.NAME); sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() { @SuppressWarnings("synthetic-access") @Override http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java b/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java index f4f3db9..12843e7 100644 --- a/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java @@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.sshd.client.SshClient; import org.apache.sshd.client.auth.UserInteraction; import org.apache.sshd.client.session.ClientSession; -import org.apache.sshd.common.FactoryManagerUtils; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.server.ServerFactoryManager; import org.apache.sshd.server.SshServer; import org.apache.sshd.util.test.BaseTestSupport; @@ -49,7 +49,7 @@ public class WelcomeBannerTest extends BaseTestSupport { @Before public void setUp() throws Exception { sshd = setupTestServer(); - FactoryManagerUtils.updateProperty(sshd, ServerFactoryManager.WELCOME_BANNER, WELCOME); + PropertyResolverUtils.updateProperty(sshd, ServerFactoryManager.WELCOME_BANNER, WELCOME); sshd.start(); port = sshd.getPort(); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java index 97030c9..a6a2cbb 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java @@ -64,9 +64,9 @@ import org.apache.sshd.client.subsystem.SubsystemClient; import org.apache.sshd.client.subsystem.sftp.SftpClient; import org.apache.sshd.common.Factory; import org.apache.sshd.common.FactoryManager; -import org.apache.sshd.common.FactoryManagerUtils; import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.NamedResource; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.RuntimeSshException; import org.apache.sshd.common.Service; import org.apache.sshd.common.SshConstants; @@ -228,6 +228,84 @@ public class ClientTest extends BaseTestSupport { } @Test + public void testPropertyResolutionHierarchy() throws Exception { + final String SESSION_PROP_NAME = getCurrentTestName() + "-session"; + final AtomicReference<Object> sessionConfigValueHolder = new AtomicReference<>(null); + client.addSessionListener(new SessionListener() { + @Override + public void sessionEvent(Session session, Event event) { + updateSessionConfigProperty(session, event); + } + + @Override + public void sessionCreated(Session session) { + updateSessionConfigProperty(session, "sessionCreated"); + } + + @Override + public void sessionClosed(Session session) { + updateSessionConfigProperty(session, "sessionClosed"); + } + + private void updateSessionConfigProperty(Session session, Object value) { + PropertyResolverUtils.updateProperty(session, SESSION_PROP_NAME, value); + sessionConfigValueHolder.set(value); + } + }); + + final String CHANNEL_PROP_NAME = getCurrentTestName() + "-channel"; + final AtomicReference<Object> channelConfigValueHolder = new AtomicReference<>(null); + client.addChannelListener(new ChannelListener() { + @Override + public void channelOpenSuccess(Channel channel) { + updateChannelConfigProperty(channel, "channelOpenSuccess"); + } + + @Override + public void channelOpenFailure(Channel channel, Throwable reason) { + updateChannelConfigProperty(channel, "channelOpenFailure"); + } + + @Override + public void channelInitialized(Channel channel) { + updateChannelConfigProperty(channel, "channelInitialized"); + } + + @Override + public void channelClosed(Channel channel) { + updateChannelConfigProperty(channel, "channelClosed"); + } + + private void updateChannelConfigProperty(Channel channel, Object value) { + PropertyResolverUtils.updateProperty(channel, CHANNEL_PROP_NAME, value); + channelConfigValueHolder.set(value); + } + }); + client.start(); + + try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { + assertSame("Session established", sessionConfigValueHolder.get(), PropertyResolverUtils.getObject(session, SESSION_PROP_NAME)); + session.addPasswordIdentity(getCurrentTestName()); + session.auth().verify(5L, TimeUnit.SECONDS); + assertSame("Session authenticated", sessionConfigValueHolder.get(), PropertyResolverUtils.getObject(session, SESSION_PROP_NAME)); + + try (ChannelExec channel = session.createExecChannel(getCurrentTestName()); + OutputStream stdout = new NoCloseOutputStream(System.out); + OutputStream stderr = new NoCloseOutputStream(System.err)) { + assertSame("Channel created", channelConfigValueHolder.get(), PropertyResolverUtils.getObject(channel, CHANNEL_PROP_NAME)); + assertNull("Direct channel created session prop", PropertyResolverUtils.getObject(channel.getProperties(), SESSION_PROP_NAME)); + assertSame("Indirect channel created session prop", sessionConfigValueHolder.get(), PropertyResolverUtils.getObject(channel, SESSION_PROP_NAME)); + + channel.setOut(stdout); + channel.setErr(stderr); + channel.open().verify(9L, TimeUnit.SECONDS); + } + } finally { + client.stop(); + } + } + + @Test public void testClientStillActiveIfListenerExceptions() throws Exception { final Map<String, Integer> eventsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); final Collection<String> failuresSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); @@ -389,10 +467,10 @@ public class ClientTest extends BaseTestSupport { @Test public void testAsyncClient() throws Exception { - FactoryManagerUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024); + PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024); sshd.setShellFactory(new AsyncEchoShellFactory()); - FactoryManagerUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024); + PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024); client.start(); try (ClientSession session = createTestClientSession(); @@ -1083,7 +1161,7 @@ public class ClientTest extends BaseTestSupport { }); final int MAX_PROMPTS = 3; - FactoryManagerUtils.updateProperty(client, ClientFactoryManager.PASSWORD_PROMPTS, MAX_PROMPTS); + PropertyResolverUtils.updateProperty(client, ClientFactoryManager.PASSWORD_PROMPTS, MAX_PROMPTS); client.start(); @@ -1105,7 +1183,7 @@ public class ClientTest extends BaseTestSupport { public void testDefaultKeyboardInteractiveInSessionUserInteractive() throws Exception { final AtomicInteger count = new AtomicInteger(); final int MAX_PROMPTS = 3; - FactoryManagerUtils.updateProperty(client, ClientFactoryManager.PASSWORD_PROMPTS, MAX_PROMPTS); + PropertyResolverUtils.updateProperty(client, ClientFactoryManager.PASSWORD_PROMPTS, MAX_PROMPTS); client.setUserAuthFactories(Collections.<NamedFactory<UserAuth>>singletonList(UserAuthKeyboardInteractiveFactory.INSTANCE)); client.start(); @@ -1147,7 +1225,7 @@ public class ClientTest extends BaseTestSupport { public void testKeyboardInteractiveInSessionUserInteractiveFailure() throws Exception { final AtomicInteger count = new AtomicInteger(); final int MAX_PROMPTS = 3; - FactoryManagerUtils.updateProperty(client, ClientFactoryManager.PASSWORD_PROMPTS, MAX_PROMPTS); + PropertyResolverUtils.updateProperty(client, ClientFactoryManager.PASSWORD_PROMPTS, MAX_PROMPTS); client.setUserAuthFactories(Collections.<NamedFactory<UserAuth>>singletonList(UserAuthKeyboardInteractiveFactory.INSTANCE)); client.start(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java index 769797b..7680b46 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java @@ -36,7 +36,7 @@ import org.apache.sshd.client.ClientFactoryManager; import org.apache.sshd.client.SshClient; import org.apache.sshd.client.config.keys.ClientIdentityLoader; import org.apache.sshd.client.session.ClientSession; -import org.apache.sshd.common.FactoryManagerUtils; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.SshdSocketAddress; import org.apache.sshd.common.config.keys.FilePasswordProvider; import org.apache.sshd.common.config.keys.KeyUtils; @@ -142,7 +142,7 @@ public class HostConfigEntryResolverTest extends BaseTestSupport { throw new FileNotFoundException("Unknown location: " + location); } }); - FactoryManagerUtils.updateProperty(client, ClientFactoryManager.IGNORE_INVALID_IDENTITIES, false); + PropertyResolverUtils.updateProperty(client, ClientFactoryManager.IGNORE_INVALID_IDENTITIES, false); final String HOST = getClass().getSimpleName(); final HostConfigEntry entry = new HostConfigEntry(HOST, TEST_LOCALHOST, port, USER); @@ -212,7 +212,7 @@ public class HostConfigEntryResolverTest extends BaseTestSupport { throw new FileNotFoundException("Unknown location: " + location); } }); - FactoryManagerUtils.updateProperty(client, ClientFactoryManager.IGNORE_INVALID_IDENTITIES, false); + PropertyResolverUtils.updateProperty(client, ClientFactoryManager.IGNORE_INVALID_IDENTITIES, false); final Collection<KeyPair> clientIdentities = Collections.singletonList(defaultIdentity); client.setKeyPairProvider(new AbstractKeyPairProvider() { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java index b130ba4..eaa18b9 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java @@ -55,7 +55,7 @@ import org.apache.sshd.client.subsystem.sftp.extensions.BuiltinSftpClientExtensi import org.apache.sshd.client.subsystem.sftp.extensions.SftpClientExtension; import org.apache.sshd.common.Factory; import org.apache.sshd.common.FactoryManager; -import org.apache.sshd.common.FactoryManagerUtils; +import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.file.FileSystemFactory; import org.apache.sshd.common.random.Random; import org.apache.sshd.common.session.Session; @@ -196,7 +196,7 @@ public class SftpTest extends AbstractSftpClientTestSupport { byte[] actual = new byte[expected.length]; int maxAllowed = actual.length / 4; // allow less than actual - FactoryManagerUtils.updateProperty(sshd, SftpSubsystem.MAX_PACKET_LENGTH_PROP, maxAllowed); + PropertyResolverUtils.updateProperty(sshd, SftpSubsystem.MAX_PACKET_LENGTH_PROP, maxAllowed); try(CloseableHandle handle = sftp.open(file, OpenMode.Read)) { int readLen = sftp.read(handle, 0L, actual); assertEquals("Mismatched read len", maxAllowed, readLen); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a9d975b6/sshd-core/src/test/java/org/apache/sshd/common/FactoryManagerUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/FactoryManagerUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/FactoryManagerUtilsTest.java deleted file mode 100644 index 05ccdaf..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/FactoryManagerUtilsTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sshd.common; - -import java.util.Map; -import java.util.TreeMap; - -import org.apache.sshd.common.session.Session; -import org.apache.sshd.util.test.BaseTestSupport; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; -import org.mockito.Mockito; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class FactoryManagerUtilsTest extends BaseTestSupport { - public FactoryManagerUtilsTest() { - super(); - } - - @Test - public void testLongProperty() { - final long expected = System.currentTimeMillis(); - final String name = getCurrentTestName(); - - Session session = createMockSession(); - assertEquals("Mismatched empty props value", expected, FactoryManagerUtils.getLongProperty(session, name, expected)); - - FactoryManagerUtils.updateProperty(session, name, expected); - testLongProperty(session, name, expected); - - FactoryManagerUtils.updateProperty(session, name, Long.toString(expected)); - testLongProperty(session, name, expected); - } - - private void testLongProperty(Session session, String name, long expected) { - FactoryManager manager = session.getFactoryManager(); - Map<String, ?> props = manager.getProperties(); - Object value = props.get(name); - Class<?> type = value.getClass(); - String storage = type.getSimpleName(); - - { - Long actual = FactoryManagerUtils.getLong(session, name); - assertNotNull("No actual Long value found for storage as " + storage, actual); - assertEquals("Mismatched values on Long retrieval for storage as " + storage, expected, actual.longValue()); - } - - { - String actual = FactoryManagerUtils.getString(session, name); - assertNotNull("No actual String value found for storage as " + storage, actual); - assertEquals("Mismatched values on String retrieval for storage as " + storage, Long.toString(expected), actual.toString()); - } - } - - @Test - public void testIntegerProperty() { - final int expected = 3777347; - final String name = getCurrentTestName(); - - Session session = createMockSession(); - assertEquals("Mismatched empty props value", expected, FactoryManagerUtils.getIntProperty(session, name, expected)); - - FactoryManagerUtils.updateProperty(session, name, expected); - testIntegerProperty(session, name, expected); - - FactoryManagerUtils.updateProperty(session, name, Integer.toString(expected)); - testIntegerProperty(session, name, expected); - - // store as Long but retrieve as Integer - FactoryManagerUtils.updateProperty(session, name, Long.valueOf(expected)); - testIntegerProperty(session, name, expected); - } - - private void testIntegerProperty(Session session, String name, int expected) { - FactoryManager manager = session.getFactoryManager(); - Map<String, ?> props = manager.getProperties(); - Object value = props.get(name); - Class<?> type = value.getClass(); - String storage = type.getSimpleName(); - - { - Integer actual = FactoryManagerUtils.getInteger(session, name); - assertNotNull("No actual Long value found for storage as " + storage, actual); - assertEquals("Mismatched values on Long retrieval for storage as " + storage, expected, actual.intValue()); - } - - { - String actual = FactoryManagerUtils.getString(session, name); - assertNotNull("No actual String value found for storage as " + storage, actual); - assertEquals("Mismatched values on String retrieval for storage as " + storage, Long.toString(expected), actual.toString()); - } - } - - @Test - public void testBooleanProperty() { - for (final boolean expected : new boolean[]{false, true}) { - final String name = getCurrentTestName(); - - Session session = createMockSession(); - assertEquals("Mismatched empty props value", expected, FactoryManagerUtils.getBooleanProperty(session, name, expected)); - - FactoryManagerUtils.updateProperty(session, name, expected); - testBooleanProperty(session, name, expected); - - FactoryManagerUtils.updateProperty(session, name, Boolean.toString(expected)); - testBooleanProperty(session, name, expected); - } - } - - private void testBooleanProperty(Session session, String name, boolean expected) { - FactoryManager manager = session.getFactoryManager(); - Map<String, ?> props = manager.getProperties(); - Object value = props.get(name); - Class<?> type = value.getClass(); - String storage = type.getSimpleName(); - - { - Boolean actual = FactoryManagerUtils.getBoolean(session, name); - assertNotNull("No actual Long value found for storage as " + storage, actual); - assertEquals("Mismatched values on Long retrieval for storage as " + storage, expected, actual.booleanValue()); - } - - { - String actual = FactoryManagerUtils.getString(session, name); - assertNotNull("No actual String value found for storage as " + storage, actual); - assertEquals("Mismatched values on String retrieval for storage as " + storage, Boolean.toString(expected), actual.toString()); - } - } - - private Session createMockSession() { - Map<String, Object> props = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER); - FactoryManager manager = Mockito.mock(FactoryManager.class); - Mockito.when(manager.getProperties()).thenReturn(props); - - Session session = Mockito.mock(Session.class); - Mockito.when(session.getUsername()).thenReturn(getCurrentTestName()); - Mockito.when(session.getFactoryManager()).thenReturn(manager); - return session; - } -}
