You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/12/13 13:44:00 UTC
[3/3] mina-sshd git commit: [SSHD-875] Propagate connection
establishment context (if any provided) to
HostConfigEntryResolver#resolveEffectiveHost
[SSHD-875] Propagate connection establishment context (if any provided) to HostConfigEntryResolver#resolveEffectiveHost
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/04a435fc
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/04a435fc
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/04a435fc
Branch: refs/heads/master
Commit: 04a435fcf74dcf034a1a7caa222428ab95617057
Parents: 7f6c564
Author: Lyor Goldstein <lg...@apache.org>
Authored: Thu Dec 13 13:05:20 2018 +0200
Committer: Lyor Goldstein <lg...@apache.org>
Committed: Thu Dec 13 15:43:50 2018 +0200
----------------------------------------------------------------------
CHANGES.md | 14 +++++++++-----
.../config/hosts/ConfigFileHostEntryResolver.java | 9 ++++++---
.../sshd/client/config/hosts/HostConfigEntry.java | 2 +-
.../config/hosts/HostConfigEntryResolver.java | 17 +++++++++++++----
.../hosts/ConfigFileHostEntryResolverTest.java | 2 +-
.../java/org/apache/sshd/client/SshClient.java | 4 ++--
.../config/hosts/HostConfigEntryResolverTest.java | 18 +++++++++---------
7 files changed, 41 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/04a435fc/CHANGES.md
----------------------------------------------------------------------
diff --git a/CHANGES.md b/CHANGES.md
index 5323e32..d7ed56c 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -20,12 +20,16 @@
and is called both for `SSH_MSG_UNIMPLEMENTED` as well as for any other unexpected/unrecognized
command encountered during the session message processing loop.
-* `ClientSessionCreator` has extra `connect` methods with an `AttributeRepository`
-connection context argument
+* `AttributeRepository` optional context propagated during initial connection establishment
-* `connectionEstablished` and `abortEstablishedConnection` methods of `IoServiceEventListener`
-accept also an `AttributeRepository` connection context argument (propagated from the
-`ClientSessionCreator#connect` invocation).
+ * `ClientSessionCreator` has extra `connect` methods with an `AttributeRepository`
+ connection context argument
+
+ * The context is also propagated to `HostConfigEntryResolver#resolveEffectiveHost` method
+
+ * `connectionEstablished` and `abortEstablishedConnection` methods of `IoServiceEventListener`
+ accept also an `AttributeRepository` connection context argument (propagated from the
+ `ClientSessionCreator#connect` invocation).
* `FilePasswordProvider`
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/04a435fc/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolver.java
----------------------------------------------------------------------
diff --git a/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolver.java b/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolver.java
index e14ed9f..8895bf5 100644
--- a/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolver.java
+++ b/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolver.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
+import org.apache.sshd.common.AttributeRepository;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.common.util.io.ModifiableFileWatcher;
@@ -49,10 +50,12 @@ public class ConfigFileHostEntryResolver extends ModifiableFileWatcher implement
}
@Override
- public HostConfigEntry resolveEffectiveHost(String host, int port, String username) throws IOException {
+ public HostConfigEntry resolveEffectiveHost(
+ String host, int port, String username, AttributeRepository context)
+ throws IOException {
try {
HostConfigEntryResolver delegate = Objects.requireNonNull(resolveEffectiveResolver(host, port, username), "No delegate");
- HostConfigEntry entry = delegate.resolveEffectiveHost(host, port, username);
+ HostConfigEntry entry = delegate.resolveEffectiveHost(host, port, username, context);
if (log.isDebugEnabled()) {
log.debug("resolveEffectiveHost({}@{}:{}) => {}", username, host, port, entry);
}
@@ -61,7 +64,7 @@ public class ConfigFileHostEntryResolver extends ModifiableFileWatcher implement
} catch (Throwable e) {
if (log.isDebugEnabled()) {
log.debug("resolveEffectiveHost({}@{}:{}) failed ({}) to resolve: {}",
- username, host, port, e.getClass().getSimpleName(), e.getMessage());
+ username, host, port, e.getClass().getSimpleName(), e.getMessage());
}
if (log.isTraceEnabled()) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/04a435fc/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntry.java
----------------------------------------------------------------------
diff --git a/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntry.java b/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntry.java
index f94f775..f705585 100644
--- a/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntry.java
+++ b/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntry.java
@@ -669,7 +669,7 @@ public class HostConfigEntry extends HostPatternsHolder implements MutableUserHo
if (GenericUtils.isEmpty(entries)) {
return HostConfigEntryResolver.EMPTY;
} else {
- return (host1, port1, username1) -> {
+ return (host1, port1, username1, ctx) -> {
List<HostConfigEntry> matches = findMatchingEntries(host1, entries);
int numMatches = GenericUtils.size(matches);
if (numMatches <= 0) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/04a435fc/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolver.java
----------------------------------------------------------------------
diff --git a/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolver.java b/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolver.java
index a07cfcf..a33dd26 100644
--- a/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolver.java
+++ b/sshd-common/src/main/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolver.java
@@ -21,18 +21,23 @@ package org.apache.sshd.client.config.hosts;
import java.io.IOException;
+import org.apache.sshd.common.AttributeRepository;
+
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ * @see <A HREF="http://www.gsp.com/cgi-bin/man.cgi?topic=ssh_config">ssh_config</A>
*/
@FunctionalInterface
public interface HostConfigEntryResolver {
-
/**
- * An "empty" implementation that does not resolve any entry
+ * An "empty" implementation that does not resolve any entry - i.e.,
+ * uses the original entry as-is
*/
HostConfigEntryResolver EMPTY = new HostConfigEntryResolver() {
@Override
- public HostConfigEntry resolveEffectiveHost(String host, int port, String username) throws IOException {
+ public HostConfigEntry resolveEffectiveHost(
+ String host, int port, String username, AttributeRepository context)
+ throws IOException {
return null;
}
@@ -49,6 +54,8 @@ public interface HostConfigEntryResolver {
* @param host The requested host - never {@code null}/empty
* @param port The requested port
* @param username The requested username
+ * @param context An optional "context" provided during the connection
+ * request (to be attached to the established session if successfully connected)
* @return A {@link HostConfigEntry} for the actual target - {@code null} if use
* original parameters. <B>Note:</B> if any identity files are attached to the
* configuration then they must point to <U>existing</U> locations. This means
@@ -56,5 +63,7 @@ public interface HostConfigEntryResolver {
* to returning the value
* @throws IOException If failed to resolve the configuration
*/
- HostConfigEntry resolveEffectiveHost(String host, int port, String username) throws IOException;
+ HostConfigEntry resolveEffectiveHost(
+ String host, int port, String username, AttributeRepository context)
+ throws IOException;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/04a435fc/sshd-common/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
----------------------------------------------------------------------
diff --git a/sshd-common/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java b/sshd-common/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
index 741ba7b..1414f27 100644
--- a/sshd-common/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
+++ b/sshd-common/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
@@ -114,7 +114,7 @@ public class ConfigFileHostEntryResolverTest extends JUnitTestSupport {
for (int index = 1; index < Byte.SIZE; index++) {
HostConfigEntry actual =
- resolver.resolveEffectiveHost(query.getHostName(), query.getPort(), query.getUsername());
+ resolver.resolveEffectiveHost(query.getHostName(), query.getPort(), query.getUsername(), null);
if (entries == null) {
assertEquals(phase + "[" + index + "]: mismatched reload count", 0, reloadCount.get());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/04a435fc/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
index f01f7bf..fb5cf14 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
@@ -458,7 +458,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
String username, String host, int port, AttributeRepository context, SocketAddress localAddress)
throws IOException {
HostConfigEntryResolver resolver = getHostConfigEntryResolver();
- HostConfigEntry entry = resolver.resolveEffectiveHost(host, port, username);
+ HostConfigEntry entry = resolver.resolveEffectiveHost(host, port, username, context);
if (entry == null) {
// generate a synthetic entry
if (log.isDebugEnabled()) {
@@ -493,7 +493,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
ValidateUtils.checkTrue(port > 0, "Invalid port: %d", port);
HostConfigEntryResolver resolver = getHostConfigEntryResolver();
- HostConfigEntry entry = resolver.resolveEffectiveHost(host, port, username);
+ HostConfigEntry entry = resolver.resolveEffectiveHost(host, port, username, context);
if (entry == null) {
if (log.isDebugEnabled()) {
log.debug("connect({}@{}:{}) no overrides", username, host, port);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/04a435fc/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 2fd8584..8adac15 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
@@ -93,8 +93,8 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
@Test
public void testEffectiveHostConfigResolution() throws Exception {
- final HostConfigEntry entry = new HostConfigEntry(getCurrentTestName(), TEST_LOCALHOST, port, getCurrentTestName());
- client.setHostConfigEntryResolver((host, portValue, username) -> entry);
+ HostConfigEntry entry = new HostConfigEntry(getCurrentTestName(), TEST_LOCALHOST, port, getCurrentTestName());
+ client.setHostConfigEntryResolver((host, portValue, username, context) -> entry);
client.start();
try (ClientSession session = client.connect(
@@ -113,13 +113,13 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
public void testNegatedHostEntriesResolution() throws Exception {
HostConfigEntry positiveEntry = new HostConfigEntry(TEST_LOCALHOST, TEST_LOCALHOST, port, getCurrentTestName());
HostConfigEntry negativeEntry = new HostConfigEntry(
- Character.toString(HostPatternsHolder.NEGATION_CHAR_PATTERN) + positiveEntry.getHost(),
- positiveEntry.getHostName(),
- getMovedPortNumber(positiveEntry.getPort()),
- getClass().getPackage().getName());
+ Character.toString(HostPatternsHolder.NEGATION_CHAR_PATTERN) + positiveEntry.getHost(),
+ positiveEntry.getHostName(),
+ getMovedPortNumber(positiveEntry.getPort()),
+ getClass().getPackage().getName());
client.setHostConfigEntryResolver(
- HostConfigEntry.toHostConfigEntryResolver(
- Arrays.asList(negativeEntry, positiveEntry)));
+ HostConfigEntry.toHostConfigEntryResolver(
+ Arrays.asList(negativeEntry, positiveEntry)));
client.start();
try (ClientSession session = client.connect(
@@ -171,7 +171,7 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
String host = getClass().getSimpleName();
HostConfigEntry entry = new HostConfigEntry(host, TEST_LOCALHOST, port, user);
entry.addIdentity(clientIdentity);
- client.setHostConfigEntryResolver((host1, portValue, username) -> entry);
+ client.setHostConfigEntryResolver((host1, portValue, username, context) -> entry);
client.start();
try (ClientSession session = client.connect(