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 2015/12/16 11:17:13 UTC
[3/5] mina-sshd git commit: Define SessionHolder + update the various
Client/Session
Define SessionHolder + update the various Client/Session
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/fa0af69a
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/fa0af69a
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/fa0af69a
Branch: refs/heads/master
Commit: fa0af69af1ce04d13c7872c8435ff41948d901dc
Parents: 4c106fe
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Wed Dec 16 12:13:05 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Wed Dec 16 12:13:05 2015 +0200
----------------------------------------------------------------------
.../auth/pubkey/AbstractKeyPairIterator.java | 61 ++++++++++++++++++++
.../auth/pubkey/SessionKeyPairIterator.java | 26 +++------
.../auth/pubkey/SshAgentPublicKeyIterator.java | 22 +------
.../auth/pubkey/UserAuthPublicKeyIterator.java | 21 +------
.../client/kex/AbstractDHClientKeyExchange.java | 12 +++-
.../org/apache/sshd/client/kex/DHGClient.java | 3 +-
.../org/apache/sshd/client/kex/DHGEXClient.java | 3 +-
.../client/session/ClientConnectionService.java | 16 +++--
.../session/ClientConnectionServiceFactory.java | 4 +-
.../sshd/client/session/ClientSessionImpl.java | 15 ++---
.../client/session/ClientUserAuthService.java | 5 +-
.../subsystem/AbstractSubsystemClient.java | 37 ++++++++++++
.../sshd/client/subsystem/SubsystemClient.java | 4 +-
.../subsystem/sftp/AbstractSftpClient.java | 4 +-
.../java/org/apache/sshd/common/Service.java | 1 -
.../org/apache/sshd/common/channel/Channel.java | 4 --
.../org/apache/sshd/common/kex/KeyExchange.java | 4 +-
.../common/kex/dh/AbstractDHKeyExchange.java | 10 +++-
.../session/AbstractConnectionService.java | 12 ++--
.../sshd/common/session/AbstractSession.java | 8 ++-
.../org/apache/sshd/common/session/Session.java | 2 +-
.../sshd/common/session/SessionHolder.java | 28 +++++++++
.../server/kex/AbstractDHServerKeyExchange.java | 8 +--
.../org/apache/sshd/server/kex/DHGEXServer.java | 4 +-
.../org/apache/sshd/server/kex/DHGServer.java | 4 +-
.../org/apache/sshd/server/scp/ScpCommand.java | 21 ++++++-
.../server/session/ServerConnectionService.java | 16 ++---
.../session/ServerConnectionServiceFactory.java | 4 +-
.../server/session/ServerSessionHolder.java | 3 +
.../sshd/deprecated/AbstractUserAuth.java | 10 +++-
.../java/org/apache/sshd/server/ServerTest.java | 41 +++++++------
.../server/command/ScpCommandFactoryTest.java | 4 +-
32 files changed, 274 insertions(+), 143 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/AbstractKeyPairIterator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/AbstractKeyPairIterator.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/AbstractKeyPairIterator.java
new file mode 100644
index 0000000..cb33de9
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/AbstractKeyPairIterator.java
@@ -0,0 +1,61 @@
+/*
+ * 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.client.auth.pubkey;
+
+import java.util.Iterator;
+
+import org.apache.sshd.client.session.ClientSession;
+import org.apache.sshd.client.session.ClientSessionHolder;
+import org.apache.sshd.common.session.SessionHolder;
+import org.apache.sshd.common.util.ValidateUtils;
+
+/**
+ * @param <I> Type of {@link PublicKeyIdentity} being iterated
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public abstract class AbstractKeyPairIterator<I extends PublicKeyIdentity>
+ implements Iterator<I>, SessionHolder<ClientSession>, ClientSessionHolder {
+
+ private final ClientSession session;
+
+ protected AbstractKeyPairIterator(ClientSession session) {
+ this.session = ValidateUtils.checkNotNull(session, "No session");
+ }
+
+ @Override
+ public final ClientSession getClientSession() {
+ return session;
+ }
+
+ @Override
+ public final ClientSession getSession() {
+ return getClientSession();
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("No removal allowed");
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "[" + getClientSession() + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SessionKeyPairIterator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SessionKeyPairIterator.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SessionKeyPairIterator.java
index 5ff50b4..09ad1e7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SessionKeyPairIterator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SessionKeyPairIterator.java
@@ -22,22 +22,24 @@ package org.apache.sshd.client.auth.pubkey;
import java.security.KeyPair;
import java.util.Iterator;
+import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.kex.KexFactoryManager;
-import org.apache.sshd.common.util.ValidateUtils;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class SessionKeyPairIterator implements Iterator<KeyPairIdentity> {
-
- private final KexFactoryManager manager;
+public class SessionKeyPairIterator extends AbstractKeyPairIterator<KeyPairIdentity> {
private final Iterator<KeyPair> keys;
- public SessionKeyPairIterator(KexFactoryManager manager, Iterator<KeyPair> keys) {
- this.manager = ValidateUtils.checkNotNull(manager, "No KEX factory manager");
+ public SessionKeyPairIterator(ClientSession session, Iterator<KeyPair> keys) {
+ super(session);
this.keys = keys; // OK if null
}
+ public KexFactoryManager getKexFactoryManager() {
+ return getClientSession();
+ }
+
@Override
public boolean hasNext() {
return (keys != null) && keys.hasNext();
@@ -45,16 +47,6 @@ public class SessionKeyPairIterator implements Iterator<KeyPairIdentity> {
@Override
public KeyPairIdentity next() {
- return new KeyPairIdentity(manager, keys.next());
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("No removal allowed");
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "[" + manager + "]";
+ return new KeyPairIdentity(getKexFactoryManager(), keys.next());
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SshAgentPublicKeyIterator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SshAgentPublicKeyIterator.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SshAgentPublicKeyIterator.java
index 8becc4b..8bb18c9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SshAgentPublicKeyIterator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/SshAgentPublicKeyIterator.java
@@ -25,7 +25,6 @@ import java.util.Iterator;
import org.apache.sshd.agent.SshAgent;
import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionHolder;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
@@ -33,23 +32,17 @@ import org.apache.sshd.common.util.ValidateUtils;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class SshAgentPublicKeyIterator implements Iterator<KeyAgentIdentity>, ClientSessionHolder {
- private final ClientSession clientSession;
+public class SshAgentPublicKeyIterator extends AbstractKeyPairIterator<KeyAgentIdentity> {
private final SshAgent agent;
private final Iterator<Pair<PublicKey, String>> keys;
public SshAgentPublicKeyIterator(ClientSession session, SshAgent agent) throws IOException {
- this.clientSession = ValidateUtils.checkNotNull(session, "No session");
+ super(session);
this.agent = ValidateUtils.checkNotNull(agent, "No agent");
keys = GenericUtils.iteratorOf(agent.getIdentities());
}
@Override
- public ClientSession getClientSession() {
- return clientSession;
- }
-
- @Override
public boolean hasNext() {
return (keys != null) && keys.hasNext();
}
@@ -59,15 +52,4 @@ public class SshAgentPublicKeyIterator implements Iterator<KeyAgentIdentity>, Cl
Pair<PublicKey, String> kp = keys.next();
return new KeyAgentIdentity(agent, kp.getFirst(), kp.getSecond());
}
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("No removal allowed");
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "[" + getClientSession() + "]";
- }
-
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
index 83ed94c..e1e9b3e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/pubkey/UserAuthPublicKeyIterator.java
@@ -30,7 +30,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.sshd.agent.SshAgent;
import org.apache.sshd.agent.SshAgentFactory;
import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionHolder;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.keyprovider.KeyIdentityProvider;
import org.apache.sshd.common.util.GenericUtils;
@@ -39,16 +38,15 @@ import org.apache.sshd.common.util.ValidateUtils;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class UserAuthPublicKeyIterator implements Iterator<PublicKeyIdentity>, ClientSessionHolder, Channel {
+public class UserAuthPublicKeyIterator extends AbstractKeyPairIterator<PublicKeyIdentity> implements Channel {
private final AtomicBoolean open = new AtomicBoolean(true);
- private final ClientSession clientSession;
private final Iterator<Iterator<? extends PublicKeyIdentity>> iterators;
private Iterator<? extends PublicKeyIdentity> current;
private SshAgent agent;
public UserAuthPublicKeyIterator(ClientSession session) throws Exception {
- clientSession = ValidateUtils.checkNotNull(session, "No session");
+ super(session);
Collection<Iterator<? extends PublicKeyIdentity>> identities = new LinkedList<>();
identities.add(new SessionKeyPairIterator(session, KeyIdentityProvider.Utils.iteratorOf(session)));
@@ -75,11 +73,6 @@ public class UserAuthPublicKeyIterator implements Iterator<PublicKeyIdentity>, C
}
@Override
- public ClientSession getClientSession() {
- return clientSession;
- }
-
- @Override
public boolean hasNext() {
if (!isOpen()) {
return false;
@@ -102,11 +95,6 @@ public class UserAuthPublicKeyIterator implements Iterator<PublicKeyIdentity>, C
}
@Override
- public void remove() {
- throw new UnsupportedOperationException("No removal allowed");
- }
-
- @Override
public boolean isOpen() {
return open.get();
}
@@ -139,9 +127,4 @@ public class UserAuthPublicKeyIterator implements Iterator<PublicKeyIdentity>, C
return null;
}
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "[" + getClientSession() + "]";
- }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java b/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java
index 9eacdfd..eef04e0 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java
@@ -22,14 +22,15 @@ package org.apache.sshd.client.kex;
import java.security.PublicKey;
import org.apache.sshd.client.session.ClientSession;
+import org.apache.sshd.client.session.ClientSessionHolder;
import org.apache.sshd.common.kex.dh.AbstractDHKeyExchange;
-import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.ValidateUtils;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public abstract class AbstractDHClientKeyExchange extends AbstractDHKeyExchange {
+public abstract class AbstractDHClientKeyExchange extends AbstractDHKeyExchange implements ClientSessionHolder {
protected PublicKey serverKey;
protected AbstractDHClientKeyExchange() {
@@ -37,7 +38,12 @@ public abstract class AbstractDHClientKeyExchange extends AbstractDHKeyExchange
}
@Override
- public void init(AbstractSession s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
+ public final ClientSession getClientSession() {
+ return (ClientSession) getSession();
+ }
+
+ @Override
+ public void init(Session s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
super.init(s, v_s, v_c, i_s, i_c);
ValidateUtils.checkTrue(s instanceof ClientSession, "Using a client side KeyExchange on a server");
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
index 1d16973..dc736f9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
@@ -26,7 +26,6 @@ import org.apache.sshd.common.kex.AbstractDH;
import org.apache.sshd.common.kex.DHFactory;
import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.kex.KeyExchangeFactory;
-import org.apache.sshd.common.session.AbstractSession;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.signature.Signature;
import org.apache.sshd.common.util.GenericUtils;
@@ -77,7 +76,7 @@ public class DHGClient extends AbstractDHClientKeyExchange {
}
@Override
- public void init(AbstractSession s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
+ public void init(Session s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
super.init(s, v_s, v_c, i_s, i_c);
dh = getDH();
hash = dh.getHash();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
index 36feac4..4f7748d 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
@@ -29,7 +29,6 @@ import org.apache.sshd.common.kex.AbstractDH;
import org.apache.sshd.common.kex.DHFactory;
import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.kex.KeyExchangeFactory;
-import org.apache.sshd.common.session.AbstractSession;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.signature.Signature;
import org.apache.sshd.common.util.GenericUtils;
@@ -87,7 +86,7 @@ public class DHGEXClient extends AbstractDHClientKeyExchange {
}
@Override
- public void init(AbstractSession s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
+ public void init(Session s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
super.init(s, v_s, v_c, i_s, i_c);
if (log.isDebugEnabled()) {
log.debug("init({}) Send SSH_MSG_KEX_DH_GEX_REQUEST", s);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
index 356efbf..85ddb97 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
@@ -28,8 +28,6 @@ import org.apache.sshd.common.PropertyResolverUtils;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.session.AbstractConnectionService;
-import org.apache.sshd.common.session.Session;
-import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
/**
@@ -37,22 +35,27 @@ import org.apache.sshd.common.util.buffer.Buffer;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class ClientConnectionService extends AbstractConnectionService {
- public ClientConnectionService(Session s) throws SshException {
+public class ClientConnectionService extends AbstractConnectionService<AbstractClientSession> implements ClientSessionHolder {
+ public ClientConnectionService(AbstractClientSession s) throws SshException {
super(s);
+ }
- ValidateUtils.checkTrue(s instanceof ClientSession, "Client side service used on server side");
+ @Override
+ public final ClientSession getClientSession() {
+ return getSession();
}
@Override
public void start() {
- if (!((ClientSession) session).isAuthenticated()) {
+ ClientSession session = getClientSession();
+ if (!session.isAuthenticated()) {
throw new IllegalStateException("Session is not authenticated");
}
startHeartBeat();
}
protected void startHeartBeat() {
+ ClientSession session = getClientSession();
long interval = PropertyResolverUtils.getLongProperty(session, ClientFactoryManager.HEARTBEAT_INTERVAL, ClientFactoryManager.DEFAULT_HEARTBEAT_INTERVAL);
if (interval > 0L) {
FactoryManager manager = session.getFactoryManager();
@@ -70,6 +73,7 @@ public class ClientConnectionService extends AbstractConnectionService {
}
protected void sendHeartBeat() {
+ ClientSession session = getClientSession();
String request = PropertyResolverUtils.getStringProperty(session, ClientFactoryManager.HEARTBEAT_REQUEST, ClientFactoryManager.DEFAULT_KEEP_ALIVE_HEARTBEAT_STRING);
try {
Buffer buf = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST, request.length() + Byte.SIZE);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionServiceFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionServiceFactory.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionServiceFactory.java
index ba331e1..2efe7b7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionServiceFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionServiceFactory.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import org.apache.sshd.common.Service;
import org.apache.sshd.common.ServiceFactory;
import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.util.ValidateUtils;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
@@ -41,6 +42,7 @@ public class ClientConnectionServiceFactory implements ServiceFactory {
@Override
public Service create(Session session) throws IOException {
- return new ClientConnectionService(session);
+ ValidateUtils.checkTrue(session instanceof AbstractClientSession, "Not a client sesssion: %s", session);
+ return new ClientConnectionService((AbstractClientSession) session);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
index 8166f2b..44c6e9c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
@@ -20,6 +20,7 @@ package org.apache.sshd.client.session;
import java.io.IOException;
import java.net.SocketAddress;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
@@ -106,16 +107,12 @@ public class ClientSessionImpl extends AbstractClientSession {
}
@Override
- protected Service[] getServices() {
- Service[] services;
+ protected List<Service> getServices() {
if (nextService != null) {
- services = new Service[]{currentService, nextService};
- } else if (currentService != null) {
- services = new Service[]{currentService};
+ return Arrays.asList(currentService, nextService);
} else {
- services = new Service[0];
+ return super.getServices();
}
- return services;
}
@Override
@@ -175,8 +172,8 @@ public class ClientSessionImpl extends AbstractClientSession {
@Override
public KeyExchangeFuture switchToNoneCipher() throws IOException {
- if (!(currentService instanceof AbstractConnectionService)
- || !((AbstractConnectionService) currentService).getChannels().isEmpty()) {
+ if (!(currentService instanceof AbstractConnectionService<?>)
+ || !GenericUtils.isEmpty(((AbstractConnectionService<?>) currentService).getChannels())) {
throw new IllegalStateException("The switch to the none cipher must be done immediately after authentication");
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java
index 23c1b4b..521da96 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthService.java
@@ -37,6 +37,7 @@ import org.apache.sshd.common.Service;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.session.SessionHolder;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
@@ -47,7 +48,9 @@ import org.apache.sshd.common.util.closeable.AbstractCloseable;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class ClientUserAuthService extends AbstractCloseable implements Service, ClientSessionHolder {
+public class ClientUserAuthService
+ extends AbstractCloseable
+ implements Service, SessionHolder<ClientSession>, ClientSessionHolder {
/**
* The AuthFuture that is being used by the current auth request. This encodes the state.
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/AbstractSubsystemClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/AbstractSubsystemClient.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/AbstractSubsystemClient.java
new file mode 100644
index 0000000..6bd32c1
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/AbstractSubsystemClient.java
@@ -0,0 +1,37 @@
+/*
+ * 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.client.subsystem;
+
+import org.apache.sshd.client.session.ClientSession;
+import org.apache.sshd.common.util.logging.AbstractLoggingBean;
+
+/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public abstract class AbstractSubsystemClient extends AbstractLoggingBean implements SubsystemClient {
+ protected AbstractSubsystemClient() {
+ super();
+ }
+
+ @Override
+ public final ClientSession getSession() {
+ return getClientSession();
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/SubsystemClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/SubsystemClient.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/SubsystemClient.java
index 5f2a7fd..dca1b38 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/SubsystemClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/SubsystemClient.java
@@ -22,13 +22,15 @@ package org.apache.sshd.client.subsystem;
import java.nio.channels.Channel;
import org.apache.sshd.client.channel.ClientChannel;
+import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.client.session.ClientSessionHolder;
import org.apache.sshd.common.NamedResource;
+import org.apache.sshd.common.session.SessionHolder;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public interface SubsystemClient extends ClientSessionHolder, NamedResource, Channel {
+public interface SubsystemClient extends SessionHolder<ClientSession>, ClientSessionHolder, NamedResource, Channel {
/**
* @return The underlying {@link ClientChannel} used
*/
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
index 6f061ac..56dcf80 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClient.java
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
+import org.apache.sshd.client.subsystem.AbstractSubsystemClient;
import org.apache.sshd.client.subsystem.sftp.extensions.BuiltinSftpClientExtensions;
import org.apache.sshd.client.subsystem.sftp.extensions.SftpClientExtension;
import org.apache.sshd.client.subsystem.sftp.extensions.SftpClientExtensionFactory;
@@ -42,13 +43,12 @@ import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
-import org.apache.sshd.common.util.logging.AbstractLoggingBean;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public abstract class AbstractSftpClient extends AbstractLoggingBean implements SftpClient, RawSftpClient {
+public abstract class AbstractSftpClient extends AbstractSubsystemClient implements SftpClient, RawSftpClient {
private final AtomicReference<Map<String, Object>> parsedExtensionsHolder = new AtomicReference<>(null);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/common/Service.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/Service.java b/sshd-core/src/main/java/org/apache/sshd/common/Service.java
index ee13a22..35bc7c0 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/Service.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/Service.java
@@ -28,7 +28,6 @@ import org.apache.sshd.common.util.buffer.Buffer;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface Service extends Closeable {
-
Session getSession();
// TODO: this is specific to clients
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
index 20436c8..d023fed 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
@@ -23,7 +23,6 @@ import java.io.IOException;
import org.apache.sshd.client.future.OpenFuture;
import org.apache.sshd.common.Closeable;
import org.apache.sshd.common.PropertyResolver;
-import org.apache.sshd.common.future.CloseFuture;
import org.apache.sshd.common.session.ConnectionService;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.buffer.Buffer;
@@ -69,9 +68,6 @@ public interface Channel extends ChannelListenerManager, PropertyResolver, Close
void handleFailure() throws IOException;
- @Override
- CloseFuture close(boolean immediately);
-
void init(ConnectionService service, Session session, int id) throws IOException;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/common/kex/KeyExchange.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/kex/KeyExchange.java b/sshd-core/src/main/java/org/apache/sshd/common/kex/KeyExchange.java
index a3364a9..bd5f7ed 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/kex/KeyExchange.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/kex/KeyExchange.java
@@ -24,7 +24,7 @@ import java.util.Map;
import org.apache.sshd.common.NamedResource;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.digest.Digest;
-import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.logging.LoggingUtils;
@@ -46,7 +46,7 @@ public interface KeyExchange extends NamedResource {
* @param i_c the client key init packet
* @throws Exception if an error occurs
*/
- void init(AbstractSession session, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception;
+ void init(Session session, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception;
/**
* Process the next packet
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/common/kex/dh/AbstractDHKeyExchange.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/kex/dh/AbstractDHKeyExchange.java b/sshd-core/src/main/java/org/apache/sshd/common/kex/dh/AbstractDHKeyExchange.java
index 666e2b7..a92a5bc 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/kex/dh/AbstractDHKeyExchange.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/kex/dh/AbstractDHKeyExchange.java
@@ -22,13 +22,15 @@ package org.apache.sshd.common.kex.dh;
import org.apache.sshd.common.digest.Digest;
import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.session.SessionHolder;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public abstract class AbstractDHKeyExchange extends AbstractLoggingBean implements KeyExchange {
+public abstract class AbstractDHKeyExchange extends AbstractLoggingBean implements KeyExchange, SessionHolder<AbstractSession> {
protected byte[] v_s;
protected byte[] v_c;
@@ -47,14 +49,16 @@ public abstract class AbstractDHKeyExchange extends AbstractLoggingBean implemen
}
@Override
- public void init(AbstractSession s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
- this.session = ValidateUtils.checkNotNull(s, "No session");
+ public void init(Session s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
+ ValidateUtils.checkTrue(s instanceof AbstractSession, "Not an abstract session: %s", s);
+ this.session = (AbstractSession) s;
this.v_s = ValidateUtils.checkNotNullAndNotEmpty(v_s, "No v_s value");
this.v_c = ValidateUtils.checkNotNullAndNotEmpty(v_c, "No v_c value");
this.i_s = ValidateUtils.checkNotNullAndNotEmpty(i_s, "No i_s value");
this.i_c = ValidateUtils.checkNotNullAndNotEmpty(i_c, "No i_c value");
}
+ @Override
public AbstractSession getSession() {
return session;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
index b00d8a8..179d67c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
@@ -53,9 +53,10 @@ import org.apache.sshd.server.x11.X11ForwardSupport;
/**
* Base implementation of ConnectionService.
*
+ * @param <S> Type of {@link AbstractSession} being used
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public abstract class AbstractConnectionService extends AbstractInnerCloseable implements ConnectionService {
+public abstract class AbstractConnectionService<S extends AbstractSession> extends AbstractInnerCloseable implements ConnectionService {
/**
* Property that can be used to configure max. allowed concurrent active channels
*
@@ -78,7 +79,7 @@ public abstract class AbstractConnectionService extends AbstractInnerCloseable i
*/
protected final AtomicInteger nextChannelId = new AtomicInteger(0);
- protected final AbstractSession session;
+ private final S session;
/**
* The tcpip forwarder
@@ -88,9 +89,8 @@ public abstract class AbstractConnectionService extends AbstractInnerCloseable i
protected final X11ForwardSupport x11Forward;
private final AtomicBoolean allowMoreSessions = new AtomicBoolean(true);
- protected AbstractConnectionService(Session session) {
- ValidateUtils.checkTrue(session instanceof AbstractSession, "Not an AbstractSession");
- this.session = (AbstractSession) session;
+ protected AbstractConnectionService(S session) {
+ this.session = session;
FactoryManager manager = session.getFactoryManager();
agentForward = new AgentForwardSupport(this);
x11Forward = new X11ForwardSupport(this);
@@ -107,7 +107,7 @@ public abstract class AbstractConnectionService extends AbstractInnerCloseable i
}
@Override
- public AbstractSession getSession() {
+ public S getSession() {
return session;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
index bfe9592..95edc26 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
@@ -22,9 +22,11 @@ import java.io.IOException;
import java.io.InterruptedIOException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.EnumMap;
import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
@@ -752,8 +754,10 @@ public abstract class AbstractSession extends AbstractKexFactoryManager implemen
super.preClose();
}
- protected Service[] getServices() {
- return currentService != null ? new Service[]{currentService} : new Service[0];
+ protected List<Service> getServices() {
+ return (currentService != null)
+ ? Collections.singletonList(currentService)
+ : Collections.<Service>emptyList();
}
@Override
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java b/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
index 142835b..1832002 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
@@ -234,7 +234,7 @@ public interface Session
* If the service is not of the specified class,
* an IllegalStateException will be thrown.
*
- * @param <T> The generic service type
+ * @param <T> The generic {@link Service} type
* @param clazz The service class
* @return The service instance
* @throws IllegalStateException If failed to find a matching service
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/common/session/SessionHolder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/SessionHolder.java b/sshd-core/src/main/java/org/apache/sshd/common/session/SessionHolder.java
new file mode 100644
index 0000000..1f7a204
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/SessionHolder.java
@@ -0,0 +1,28 @@
+/*
+ * 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.session;
+
+/**
+ * @param <S> Type of {@link Session} being held
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public interface SessionHolder<S extends Session> {
+ S getSession();
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/server/kex/AbstractDHServerKeyExchange.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/kex/AbstractDHServerKeyExchange.java b/sshd-core/src/main/java/org/apache/sshd/server/kex/AbstractDHServerKeyExchange.java
index 03ccda6..589d702 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/kex/AbstractDHServerKeyExchange.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/kex/AbstractDHServerKeyExchange.java
@@ -22,7 +22,7 @@ package org.apache.sshd.server.kex;
import java.security.PublicKey;
import org.apache.sshd.common.kex.dh.AbstractDHKeyExchange;
-import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.server.session.ServerSessionHolder;
@@ -37,12 +37,12 @@ public abstract class AbstractDHServerKeyExchange extends AbstractDHKeyExchange
}
@Override
- public ServerSession getServerSession() {
- return (ServerSession) super.getSession();
+ public final ServerSession getServerSession() {
+ return (ServerSession) getSession();
}
@Override
- public void init(AbstractSession s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
+ public void init(Session s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
super.init(s, v_s, v_c, i_s, i_c);
ValidateUtils.checkTrue(s instanceof ServerSession, "Using a server side KeyExchange on a client");
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java
index b427c08..c2e0742 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGEXServer.java
@@ -40,7 +40,7 @@ import org.apache.sshd.common.kex.KexProposalOption;
import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.kex.KeyExchangeFactory;
import org.apache.sshd.common.random.Random;
-import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.signature.Signature;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.SecurityUtils;
@@ -95,7 +95,7 @@ public class DHGEXServer extends AbstractDHServerKeyExchange {
}
@Override
- public void init(AbstractSession s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
+ public void init(Session s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
super.init(s, v_s, v_c, i_s, i_c);
expected = SshConstants.SSH_MSG_KEX_DH_GEX_REQUEST;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java
index e6a9ef2..3cdcd17 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/kex/DHGServer.java
@@ -28,7 +28,7 @@ import org.apache.sshd.common.kex.DHFactory;
import org.apache.sshd.common.kex.KexProposalOption;
import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.kex.KeyExchangeFactory;
-import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.signature.Signature;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
@@ -75,7 +75,7 @@ public class DHGServer extends AbstractDHServerKeyExchange {
}
@Override
- public void init(AbstractSession s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
+ public void init(Session s, byte[] v_s, byte[] v_c, byte[] i_s, byte[] i_c) throws Exception {
super.init(s, v_s, v_c, i_s, i_c);
dh = factory.create();
hash = dh.getHash();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommand.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommand.java b/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommand.java
index 78458a1..fc6f492 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommand.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/scp/ScpCommand.java
@@ -37,6 +37,9 @@ import org.apache.sshd.common.util.threads.ThreadUtils;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
+import org.apache.sshd.server.SessionAware;
+import org.apache.sshd.server.session.ServerSession;
+import org.apache.sshd.server.session.ServerSessionHolder;
/**
* This commands provide SCP support on both server and client side.
@@ -45,7 +48,10 @@ import org.apache.sshd.server.ExitCallback;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class ScpCommand extends AbstractLoggingBean implements Command, Runnable, FileSystemAware {
+public class ScpCommand
+ extends AbstractLoggingBean
+ implements Command, Runnable, FileSystemAware, SessionAware, ServerSessionHolder {
+
protected String name;
protected boolean optR;
protected boolean optT;
@@ -65,6 +71,7 @@ public class ScpCommand extends AbstractLoggingBean implements Command, Runnable
protected int sendBufferSize;
protected int receiveBufferSize;
protected ScpTransferEventListener listener;
+ protected ServerSession serverSession;
/**
* @param command The command to be executed
@@ -154,6 +161,16 @@ public class ScpCommand extends AbstractLoggingBean implements Command, Runnable
}
@Override
+ public ServerSession getServerSession() {
+ return serverSession;
+ }
+
+ @Override
+ public void setSession(ServerSession session) {
+ serverSession = session;
+ }
+
+ @Override
public void setInputStream(InputStream in) {
this.in = in;
}
@@ -227,7 +244,7 @@ public class ScpCommand extends AbstractLoggingBean implements Command, Runnable
public void run() {
int exitValue = ScpHelper.OK;
String exitMessage = null;
- ScpHelper helper = new ScpHelper(in, out, fileSystem, listener);
+ ScpHelper helper = new ScpHelper(getServerSession(), in, out, fileSystem, listener);
try {
if (optT) {
helper.receive(helper.resolveLocalPath(path), optR, optD, optP, receiveBufferSize);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerConnectionService.java
index a36d38b..97e96b8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerConnectionService.java
@@ -22,27 +22,27 @@ import java.io.IOException;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.session.AbstractConnectionService;
-import org.apache.sshd.common.session.Session;
-import org.apache.sshd.common.util.ValidateUtils;
/**
* Server side <code>ssh-connection</code> service.
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class ServerConnectionService extends AbstractConnectionService {
-
- protected ServerConnectionService(Session s) throws SshException {
+public class ServerConnectionService extends AbstractConnectionService<AbstractServerSession> implements ServerSessionHolder {
+ protected ServerConnectionService(AbstractServerSession s) throws SshException {
super(s);
- ValidateUtils.checkTrue(s instanceof ServerSession, "Server side service used on client side");
-
- if (!session.isAuthenticated()) {
+ if (!s.isAuthenticated()) {
throw new SshException("Session is not authenticated");
}
}
@Override
+ public final ServerSession getServerSession() {
+ return getSession();
+ }
+
+ @Override
public String initAgentForward() throws IOException {
return agentForward.initialize();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerConnectionServiceFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerConnectionServiceFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerConnectionServiceFactory.java
index fb0ede1..1607e32 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerConnectionServiceFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerConnectionServiceFactory.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import org.apache.sshd.common.Service;
import org.apache.sshd.common.ServiceFactory;
import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.util.ValidateUtils;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
@@ -41,6 +42,7 @@ public class ServerConnectionServiceFactory implements ServiceFactory {
@Override
public Service create(Session session) throws IOException {
- return new ServerConnectionService(session);
+ ValidateUtils.checkTrue(session instanceof AbstractServerSession, "Not a server session: %s", session);
+ return new ServerConnectionService((AbstractServerSession) session);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionHolder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionHolder.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionHolder.java
index cf4aca4..6b4ff38 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionHolder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSessionHolder.java
@@ -23,5 +23,8 @@ package org.apache.sshd.server.session;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface ServerSessionHolder {
+ /**
+ * @return The underlying {@link ServerSession} used
+ */
ServerSession getServerSession();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/test/java/org/apache/sshd/deprecated/AbstractUserAuth.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/AbstractUserAuth.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/AbstractUserAuth.java
index bcaac59..1b891e7 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/AbstractUserAuth.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/AbstractUserAuth.java
@@ -20,12 +20,15 @@ package org.apache.sshd.deprecated;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.client.session.ClientSessionHolder;
+import org.apache.sshd.common.session.SessionHolder;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
/**
*/
-public abstract class AbstractUserAuth extends AbstractLoggingBean implements UserAuth, ClientSessionHolder {
+public abstract class AbstractUserAuth
+ extends AbstractLoggingBean
+ implements UserAuth, SessionHolder<ClientSession>, ClientSessionHolder {
private final ClientSession session;
private final String service;
@@ -39,6 +42,11 @@ public abstract class AbstractUserAuth extends AbstractLoggingBean implements Us
return session;
}
+ @Override
+ public final ClientSession getSession() {
+ return getClientSession();
+ }
+
public String getService() {
return service;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
index e9ba550..f21e070 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
@@ -310,27 +310,30 @@ public class ServerTest extends BaseTestSupport {
assertTrue("No changes in open channels", channelListener.waitForModification(3L, TimeUnit.SECONDS));
assertTrue("No open server side channels", GenericUtils.size(channelListener.getOpenChannels()) > 0);
- try (AbstractSession serverSession = sshd.getActiveSessions().iterator().next();
- Channel channel = serverSession.getService(AbstractConnectionService.class).getChannels().iterator().next()) {
-
- final long MAX_TIMEOUT_VALUE = IDLE_TIMEOUT_VALUE + DISCONNECT_TIMEOUT_VALUE + TimeUnit.SECONDS.toMillis(3L);
- for (long totalNanoTime = 0L; channel.getRemoteWindow().getSize() > 0; ) {
- long nanoStart = System.nanoTime();
- Thread.sleep(1L);
- long nanoEnd = System.nanoTime();
- long nanoDuration = nanoEnd - nanoStart;
-
- totalNanoTime += nanoDuration;
- assertTrue("Waiting for too long on remote window size to reach zero", totalNanoTime < TimeUnit.MILLISECONDS.toNanos(MAX_TIMEOUT_VALUE));
- }
+ try (AbstractSession serverSession = sshd.getActiveSessions().iterator().next()) {
+ AbstractConnectionService<?> service = serverSession.getService(AbstractConnectionService.class);
+ Collection<? extends Channel> channels = service.getChannels();
+
+ try (Channel channel = channels.iterator().next()) {
+ final long MAX_TIMEOUT_VALUE = IDLE_TIMEOUT_VALUE + DISCONNECT_TIMEOUT_VALUE + TimeUnit.SECONDS.toMillis(3L);
+ for (long totalNanoTime = 0L; channel.getRemoteWindow().getSize() > 0; ) {
+ long nanoStart = System.nanoTime();
+ Thread.sleep(1L);
+ long nanoEnd = System.nanoTime();
+ long nanoDuration = nanoEnd - nanoStart;
+
+ totalNanoTime += nanoDuration;
+ assertTrue("Waiting for too long on remote window size to reach zero", totalNanoTime < TimeUnit.MILLISECONDS.toNanos(MAX_TIMEOUT_VALUE));
+ }
- LoggerFactory.getLogger(getClass()).info("Waiting for session idle timeouts");
+ LoggerFactory.getLogger(getClass()).info("Waiting for session idle timeouts");
- long t0 = System.currentTimeMillis();
- latch.await(1, TimeUnit.MINUTES);
- long t1 = System.currentTimeMillis(), diff = t1 - t0;
- assertTrue("Wait time too low: " + diff, diff > IDLE_TIMEOUT_VALUE);
- assertTrue("Wait time too high: " + diff, diff < MAX_TIMEOUT_VALUE);
+ long t0 = System.currentTimeMillis();
+ latch.await(1, TimeUnit.MINUTES);
+ long t1 = System.currentTimeMillis(), diff = t1 - t0;
+ assertTrue("Wait time too low: " + diff, diff > IDLE_TIMEOUT_VALUE);
+ assertTrue("Wait time too high: " + diff, diff < MAX_TIMEOUT_VALUE);
+ }
}
} finally {
client.stop();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa0af69a/sshd-core/src/test/java/org/apache/sshd/server/command/ScpCommandFactoryTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/command/ScpCommandFactoryTest.java b/sshd-core/src/test/java/org/apache/sshd/server/command/ScpCommandFactoryTest.java
index 916576b..5bcc437 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/command/ScpCommandFactoryTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/command/ScpCommandFactoryTest.java
@@ -79,12 +79,12 @@ public class ScpCommandFactoryTest extends BaseTestSupport {
* <UL>
* <LI>
* Make sure the builder returns new instances on every call to
- * {@link ScpCommandFactory.Builder#build()} method
+ * {@link org.apache.sshd.server.scp.ScpCommandFactory.Builder#build()} method
* </LI>
*
* <LI>
* Make sure values are preserved between successive invocations
- * of the {@link ScpCommandFactory.Builder#build()} method
+ * of the {@link org.apache.sshd.server.scp.ScpCommandFactory.Builder#build()} method
* </LI>
* </UL
*/