You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2017/04/12 19:19:02 UTC

[2/3] mina-sshd git commit: [SSHD-740] Add default methods on PropertyResolver to actually do the property resolution

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bb25d6/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 46365b6..c33261e 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
@@ -85,7 +85,7 @@ public class ServerUserAuthService extends AbstractCloseable implements Service,
         Object phase = PropertyResolverUtils.getObject(s, ServerAuthenticationManager.WELCOME_BANNER_PHASE);
         phase = PropertyResolverUtils.toEnum(WelcomeBannerPhase.class, phase, true, WelcomeBannerPhase.VALUES);
         welcomePhase = (phase == null) ? ServerAuthenticationManager.DEFAULT_BANNER_PHASE : (WelcomeBannerPhase) phase;
-        maxAuthRequests = PropertyResolverUtils.getIntProperty(s, ServerAuthenticationManager.MAX_AUTH_REQUESTS, ServerAuthenticationManager.DEFAULT_MAX_AUTH_REQUESTS);
+        maxAuthRequests = s.getIntProperty(ServerAuthenticationManager.MAX_AUTH_REQUESTS, ServerAuthenticationManager.DEFAULT_MAX_AUTH_REQUESTS);
 
         List<NamedFactory<UserAuth>> factories = ValidateUtils.checkNotNullAndNotEmpty(
                 serverSession.getUserAuthFactories(), "No user auth factories for %s", s);
@@ -93,7 +93,7 @@ public class ServerUserAuthService extends AbstractCloseable implements Service,
         // Get authentication methods
         authMethods = new ArrayList<>();
 
-        String mths = PropertyResolverUtils.getString(s, ServerAuthenticationManager.AUTH_METHODS);
+        String mths = s.getString(ServerAuthenticationManager.AUTH_METHODS);
         if (GenericUtils.isEmpty(mths)) {
             for (NamedFactory<UserAuth> uaf : factories) {
                 authMethods.add(new ArrayList<>(Collections.singletonList(uaf.getName())));
@@ -272,7 +272,7 @@ public class ServerUserAuthService extends AbstractCloseable implements Service,
         }
 
         if (success) {
-            Integer maxSessionCount = PropertyResolverUtils.getInteger(session, ServerFactoryManager.MAX_CONCURRENT_SESSIONS);
+            Integer maxSessionCount = session.getInteger(ServerFactoryManager.MAX_CONCURRENT_SESSIONS);
             if (maxSessionCount != null) {
                 int currentSessionCount = session.getActiveSessionCountForUser(username);
                 if (currentSessionCount >= maxSessionCount) {
@@ -396,7 +396,7 @@ public class ServerUserAuthService extends AbstractCloseable implements Service,
     }
 
     protected String resolveWelcomeBanner(ServerSession session) throws IOException {
-        Object bannerValue = PropertyResolverUtils.getObject(session, ServerAuthenticationManager.WELCOME_BANNER);
+        Object bannerValue = session.getObject(ServerAuthenticationManager.WELCOME_BANNER);
         if (bannerValue == null) {
             return null;
         }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bb25d6/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java b/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java
index 0bf2e27..bb24619 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java
@@ -25,7 +25,6 @@ import java.util.Objects;
 import java.util.concurrent.Executor;
 import java.util.concurrent.ExecutorService;
 
-import org.apache.sshd.common.PropertyResolverUtils;
 import org.apache.sshd.common.RuntimeSshException;
 import org.apache.sshd.common.util.GenericUtils;
 import org.apache.sshd.common.util.ValidateUtils;
@@ -139,7 +138,7 @@ public class InvertedShellWrapper extends AbstractLoggingBean implements Command
 
     @Override
     public void setSession(ServerSession session) {
-        pumpSleepTime = PropertyResolverUtils.getLongProperty(session, PUMP_SLEEP_TIME, DEFAULT_PUMP_SLEEP_TIME);
+        pumpSleepTime = session.getLongProperty(PUMP_SLEEP_TIME, DEFAULT_PUMP_SLEEP_TIME);
         ValidateUtils.checkTrue(pumpSleepTime > 0L, "Invalid " + PUMP_SLEEP_TIME + ": %d", pumpSleepTime);
         shell.setSession(session);
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bb25d6/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 a9da122..8406252 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
@@ -370,11 +370,11 @@ public class SftpSubsystem
         Factory<? extends Random> factory = manager.getRandomFactory();
         this.randomizer = factory.create();
 
-        this.fileHandleSize = PropertyResolverUtils.getIntProperty(session, FILE_HANDLE_SIZE, DEFAULT_FILE_HANDLE_SIZE);
+        this.fileHandleSize = session.getIntProperty(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 = PropertyResolverUtils.getIntProperty(session, MAX_FILE_HANDLE_RAND_ROUNDS, DEFAULT_FILE_HANDLE_ROUNDS);
+        this.maxFileHandleRounds = session.getIntProperty(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);
 
@@ -1155,7 +1155,7 @@ public class SftpSubsystem
         String available = ALL_SFTP_IMPL;
         // check if user wants to use a specific version
         ServerSession session = getServerSession();
-        Integer sftpVersion = PropertyResolverUtils.getInteger(session, SFTP_VERSION);
+        Integer sftpVersion = session.getInteger(SFTP_VERSION);
         if (sftpVersion != null) {
             int forcedValue = sftpVersion;
             if ((forcedValue < LOWER_SFTP_IMPL) || (forcedValue > HIGHER_SFTP_IMPL)) {
@@ -1871,8 +1871,7 @@ public class SftpSubsystem
                 reply.putInt(0);
 
                 ServerSession session = getServerSession();
-                int maxDataSize =
-                    PropertyResolverUtils.getIntProperty(session, MAX_READDIR_DATA_SIZE_PROP, DEFAULT_MAX_READDIR_DATA_SIZE);
+                int maxDataSize = session.getIntProperty(MAX_READDIR_DATA_SIZE_PROP, DEFAULT_MAX_READDIR_DATA_SIZE);
                 int count = doReadDir(id, handle, dh, reply, maxDataSize, IoUtils.getLinkOptions(false));
                 BufferUtils.updateLengthPlaceholder(reply, lenPos, count);
                 if ((!dh.isSendDot()) && (!dh.isSendDotDot()) && (!dh.hasNext())) {
@@ -2096,7 +2095,7 @@ public class SftpSubsystem
         String handle = buffer.getString();
         long offset = buffer.getLong();
         int requestedLength = buffer.getInt();
-        int maxAllowed = PropertyResolverUtils.getIntProperty(getServerSession(), MAX_READDATA_PACKET_LENGTH_PROP, DEFAULT_MAX_READDATA_PACKET_LENGTH);
+        int maxAllowed = getServerSession().getIntProperty(MAX_READDATA_PACKET_LENGTH_PROP, DEFAULT_MAX_READDATA_PACKET_LENGTH);
         int readLen = Math.min(requestedLength, maxAllowed);
         if (log.isTraceEnabled()) {
             log.trace("doRead({})[id={}]({})[offset={}] - req={}, max={}, effective={}",
@@ -2257,7 +2256,7 @@ public class SftpSubsystem
                       getServerSession(), id, path, Integer.toHexString(access), Integer.toHexString(pflags), attrs);
         }
         int curHandleCount = handles.size();
-        int maxHandleCount = PropertyResolverUtils.getIntProperty(getServerSession(), MAX_OPEN_HANDLES_PER_SESSION, DEFAULT_MAX_OPEN_HANDLES);
+        int maxHandleCount = getServerSession().getIntProperty(MAX_OPEN_HANDLES_PER_SESSION, DEFAULT_MAX_OPEN_HANDLES);
         if (curHandleCount > maxHandleCount) {
             throw new IllegalStateException("Too many open handles: current=" + curHandleCount + ", max.=" + maxHandleCount);
         }
@@ -2371,7 +2370,7 @@ public class SftpSubsystem
     }
 
     protected Collection<Integer> resolveAclSupportedCapabilities(ServerSession session) {
-        String override = PropertyResolverUtils.getString(session, ACL_SUPPORTED_MASK_PROP);
+        String override = session.getString(ACL_SUPPORTED_MASK_PROP);
         if (override == null) {
             return DEFAULT_ACL_SUPPORTED_MASK;
         }
@@ -2411,7 +2410,7 @@ public class SftpSubsystem
     }
 
     protected List<OpenSSHExtension> resolveOpenSSHExtensions(ServerSession session) {
-        String value = PropertyResolverUtils.getString(session, OPENSSH_EXTENSIONS_PROP);
+        String value = session.getString(OPENSSH_EXTENSIONS_PROP);
         if (value == null) {    // No override
             return DEFAULT_OPEN_SSH_EXTENSIONS;
         }
@@ -2445,7 +2444,7 @@ public class SftpSubsystem
 
     protected Map<String, OptionalFeature> getSupportedClientExtensions() {
         ServerSession session = getServerSession();
-        String value = PropertyResolverUtils.getString(session, CLIENT_EXTENSIONS_PROP);
+        String value = session.getString(CLIENT_EXTENSIONS_PROP);
         if (value == null) {
             return DEFAULT_SUPPORTED_CLIENT_EXTENSIONS;
         }
@@ -2517,7 +2516,7 @@ public class SftpSubsystem
     }
 
     protected String resolveNewlineValue(ServerSession session) {
-        String value = PropertyResolverUtils.getString(session, NEWLINE_VALUE);
+        String value = session.getString(NEWLINE_VALUE);
         if (value == null) {
             return IoUtils.EOL;
         } else {
@@ -2555,9 +2554,9 @@ public class SftpSubsystem
         // placeholder for length
         int lenPos = buffer.wpos();
         buffer.putInt(0);
-        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.putString(resolver.getStringProperty("groupId", getClass().getPackage().getName()));   // vendor-name
+        buffer.putString(resolver.getStringProperty("artifactId", getClass().getSimpleName()));       // product-name
+        buffer.putString(resolver.getStringProperty("version", FactoryManager.DEFAULT_VERSION));      // product-version
         buffer.putLong(0L); // product-build-number
         BufferUtils.updateLengthPlaceholder(buffer, lenPos);
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bb25d6/sshd-core/src/main/java/org/apache/sshd/server/x11/DefaultX11ForwardSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/x11/DefaultX11ForwardSupport.java b/sshd-core/src/main/java/org/apache/sshd/server/x11/DefaultX11ForwardSupport.java
index 5758837..ac64e20 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/x11/DefaultX11ForwardSupport.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/x11/DefaultX11ForwardSupport.java
@@ -29,7 +29,6 @@ import java.util.Objects;
 
 import org.apache.sshd.common.Closeable;
 import org.apache.sshd.common.FactoryManager;
-import org.apache.sshd.common.PropertyResolverUtils;
 import org.apache.sshd.common.io.IoAcceptor;
 import org.apache.sshd.common.io.IoServiceFactory;
 import org.apache.sshd.common.io.IoSession;
@@ -92,10 +91,10 @@ public class DefaultX11ForwardSupport extends AbstractInnerCloseable implements
             acceptor = factory.createAcceptor(this);
         }
 
-        int minDisplayNumber = PropertyResolverUtils.getIntProperty(session, X11_DISPLAY_OFFSET, DEFAULT_X11_DISPLAY_OFFSET);
-        int maxDisplayNumber = PropertyResolverUtils.getIntProperty(session, X11_MAX_DISPLAYS, DEFAULT_X11_MAX_DISPLAYS);
-        int basePort = PropertyResolverUtils.getIntProperty(session, X11_BASE_PORT, DEFAULT_X11_BASE_PORT);
-        String bindHost = PropertyResolverUtils.getStringProperty(session, X11_BIND_HOST, DEFAULT_X11_BIND_HOST);
+        int minDisplayNumber = session.getIntProperty(X11_DISPLAY_OFFSET, DEFAULT_X11_DISPLAY_OFFSET);
+        int maxDisplayNumber = session.getIntProperty(X11_MAX_DISPLAYS, DEFAULT_X11_MAX_DISPLAYS);
+        int basePort = session.getIntProperty(X11_BASE_PORT, DEFAULT_X11_BASE_PORT);
+        String bindHost = session.getStringProperty(X11_BIND_HOST, DEFAULT_X11_BIND_HOST);
         InetSocketAddress addr = null;
 
         // try until bind successful or max is reached
@@ -180,7 +179,7 @@ public class DefaultX11ForwardSupport extends AbstractInnerCloseable implements
             log.debug("sessionCreated({}) channel{}", session, channel);
         }
         this.service.registerChannel(channel);
-        channel.open().verify(PropertyResolverUtils.getLongProperty(channel, CHANNEL_OPEN_TIMEOUT_PROP, DEFAULT_CHANNEL_OPEN_TIMEOUT));
+        channel.open().verify(channel.getLongProperty(CHANNEL_OPEN_TIMEOUT_PROP, DEFAULT_CHANNEL_OPEN_TIMEOUT));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bb25d6/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
index 5590bea..b32e89b 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
@@ -59,7 +59,6 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.sshd.client.SshClient;
 import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.common.PropertyResolverUtils;
 import org.apache.sshd.common.file.FileSystemFactory;
 import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
 import org.apache.sshd.common.session.Session;
@@ -149,7 +148,7 @@ public class SftpFileSystemTest extends BaseTestSupport {
                         return;
                     }
 
-                    Object actual = PropertyResolverUtils.getObject(session, key);
+                    Object actual = session.getObject(key);
                     assertEquals("Mismatched value for param '" + key + "'", expected, actual);
                 });
             }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bb25d6/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java
index ed6bdb4..cfd982e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowInitTest.java
@@ -25,6 +25,7 @@ import java.util.List;
 
 import org.apache.sshd.client.future.OpenFuture;
 import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.PropertyResolver;
 import org.apache.sshd.common.util.buffer.Buffer;
 import org.apache.sshd.common.util.buffer.BufferUtils;
 import org.apache.sshd.util.test.BaseTestSupport;
@@ -100,7 +101,7 @@ public class WindowInitTest extends BaseTestSupport {
     @Test(expected = IllegalArgumentException.class)
     public void testInitializationFailure() throws IOException {
         try (Window w = new Window(MOCK_CHANNEL, null, true, true)) {
-            w.init(initialSize, packetSize, Collections.<String, Object>emptyMap());
+            w.init(initialSize, packetSize, PropertyResolver.EMPTY);
             fail("Unexpected success for initialiSize=" + initialSize + ", packetSize=" + packetSize);
         }
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bb25d6/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java
index 83436ca..6d4b088 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.sshd.client.future.OpenFuture;
 import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.PropertyResolver;
 import org.apache.sshd.common.util.buffer.Buffer;
 import org.apache.sshd.util.test.BaseTestSupport;
 import org.junit.After;
@@ -87,7 +88,7 @@ public class WindowTimeoutTest extends BaseTestSupport {
     @Test
     public void testWindowWaitForSpaceTimeout() throws Exception {
         try (Window window = channel.getLocalWindow()) {
-            window.init(FactoryManager.DEFAULT_WINDOW_SIZE, FactoryManager.DEFAULT_MAX_PACKET_SIZE, null);
+            window.init(FactoryManager.DEFAULT_WINDOW_SIZE, FactoryManager.DEFAULT_MAX_PACKET_SIZE, PropertyResolver.EMPTY);
             window.consume(window.getSize());
             assertEquals("Window not empty", 0, window.getSize());
 
@@ -116,7 +117,7 @@ public class WindowTimeoutTest extends BaseTestSupport {
     @Test
     public void testWindowWaitAndConsumeTimeout() throws Exception {
         try (Window window = channel.getLocalWindow()) {
-            window.init(FactoryManager.DEFAULT_WINDOW_SIZE, FactoryManager.DEFAULT_MAX_PACKET_SIZE, null);
+            window.init(FactoryManager.DEFAULT_WINDOW_SIZE, FactoryManager.DEFAULT_MAX_PACKET_SIZE, PropertyResolver.EMPTY);
 
             long waitStart = System.nanoTime();
             try {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d6bb25d6/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSession.java
----------------------------------------------------------------------
diff --git a/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSession.java b/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSession.java
index 2422fbf..d8a65b5 100644
--- a/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSession.java
+++ b/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSession.java
@@ -87,7 +87,7 @@ public class GitSshdSession extends AbstractLoggingBean implements RemoteSession
         client.start();
 
         session = client.connect(user, host, port)
-                        .verify(PropertyResolverUtils.getLongProperty(client, CONNECT_TIMEOUT_PROP, DEFAULT_CONNECT_TIMEOUT))
+                        .verify(client.getLongProperty(CONNECT_TIMEOUT_PROP, DEFAULT_CONNECT_TIMEOUT))
                         .getSession();
         if (log.isDebugEnabled()) {
             log.debug("Connected to {}:{}", host, port);
@@ -98,7 +98,7 @@ public class GitSshdSession extends AbstractLoggingBean implements RemoteSession
         if (pass2 != null) {
             session.addPasswordIdentity(new String(pass2));
         }
-        session.auth().verify(PropertyResolverUtils.getLongProperty(session, AUTH_TIMEOUT_PROP, DEFAULT_AUTH_TIMEOUT));
+        session.auth().verify(session.getLongProperty(AUTH_TIMEOUT_PROP, DEFAULT_AUTH_TIMEOUT));
         if (log.isDebugEnabled()) {
             log.debug("Authenticated: {}", session);
         }
@@ -111,7 +111,7 @@ public class GitSshdSession extends AbstractLoggingBean implements RemoteSession
         }
 
         ChannelExec channel = session.createExecChannel(commandName);
-        channel.open().verify(PropertyResolverUtils.getLongProperty(channel, CHANNEL_OPEN_TIMEOUT_PROPT, DEFAULT_CHANNEL_OPEN_TIMEOUT));
+        channel.open().verify(channel.getLongProperty(CHANNEL_OPEN_TIMEOUT_PROPT, DEFAULT_CHANNEL_OPEN_TIMEOUT));
         return new GitSshdSessionProcess(channel, commandName, timeout);
     }