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 2015/07/17 18:18:44 UTC
[24/25] mina-sshd git commit: [SSHD-542] Checkstyle validation
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwarding.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwarding.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwarding.java
index 9d80455..1d52f6c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwarding.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwarding.java
@@ -70,28 +70,28 @@ public class ChannelAgentForwarding extends AbstractServerChannel {
if (result != Status.APR_SUCCESS) {
throwException(result);
}
-
+
ExecutorService service = getExecutorService();
forwardService = (service == null) ? ThreadUtils.newSingleThreadExecutor("ChannelAgentForwarding[" + authSocket + "]") : service;
shutdownForwarder = (service == forwardService) ? isShutdownOnExit() : true;
forwarder = forwardService.submit(new Runnable() {
- @SuppressWarnings("synthetic-access")
- @Override
- public void run() {
- try {
- byte[] buf = new byte[1024];
- while (true) {
- int len = Socket.recv(handle, buf, 0, buf.length);
- if (len > 0) {
- out.write(buf, 0, len);
- out.flush();
- }
+ @SuppressWarnings("synthetic-access")
+ @Override
+ public void run() {
+ try {
+ byte[] buf = new byte[1024];
+ while (true) {
+ int len = Socket.recv(handle, buf, 0, buf.length);
+ if (len > 0) {
+ out.write(buf, 0, len);
+ out.flush();
}
- } catch (IOException e) {
- close(true);
}
+ } catch (IOException e) {
+ close(true);
}
- });
+ }
+ });
f.setOpened();
} catch (Exception e) {
@@ -110,7 +110,7 @@ public class ChannelAgentForwarding extends AbstractServerChannel {
// We also need to close the socket.
Socket.close(handle);
-
+
try {
if ((forwarder != null) && (!forwarder.isDone())) {
forwarder.cancel(true);
@@ -118,9 +118,9 @@ public class ChannelAgentForwarding extends AbstractServerChannel {
} finally {
forwarder = null;
}
-
+
try {
- if ((forwardService != null) && shutdownForwarder) {
+ if ((forwardService != null) && shutdownForwarder) {
Collection<?> runners = forwardService.shutdownNow();
if (log.isDebugEnabled()) {
log.debug("Shut down runners count=" + GenericUtils.size(runners));
@@ -164,6 +164,7 @@ public class ChannelAgentForwarding extends AbstractServerChannel {
/**
* transform an APR error number in a more fancy exception
+ *
* @param code APR error code
* @throws java.io.IOException the produced exception for the given APR error number
*/
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwardingFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwardingFactory.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwardingFactory.java
index 4b21ac3..9690ccf 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwardingFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/ChannelAgentForwardingFactory.java
@@ -29,7 +29,7 @@ import org.apache.sshd.common.util.threads.ExecutorServiceCarrier;
*/
public class ChannelAgentForwardingFactory implements ChannelFactory, ExecutorServiceCarrier {
public static final ChannelAgentForwardingFactory INSTANCE = new ChannelAgentForwardingFactory();
-
+
public ChannelAgentForwardingFactory() {
super();
}
@@ -51,7 +51,7 @@ public class ChannelAgentForwardingFactory implements ChannelFactory, ExecutorSe
@Override
public Channel create() {
- ChannelAgentForwarding channel = new ChannelAgentForwarding();
+ ChannelAgentForwarding channel = new ChannelAgentForwarding();
channel.setExecutorService(getExecutorService());
channel.setShutdownOnExit(isShutdownOnExit());
return channel;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
index 625423a..ae22ce7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
@@ -40,17 +40,17 @@ public class UnixAgentFactory implements SshAgentFactory, ExecutorServiceConfigu
private ExecutorService executor;
private boolean shutdownExecutor;
private final NamedFactory<Channel> factory = new ChannelAgentForwardingFactory() {
- @Override
- public ExecutorService getExecutorService() {
- return UnixAgentFactory.this.getExecutorService();
- }
-
- @Override
- public boolean isShutdownOnExit() {
- return UnixAgentFactory.this.isShutdownOnExit();
- }
-
- };
+ @Override
+ public ExecutorService getExecutorService() {
+ return UnixAgentFactory.this.getExecutorService();
+ }
+
+ @Override
+ public boolean isShutdownOnExit() {
+ return UnixAgentFactory.this.isShutdownOnExit();
+ }
+
+ };
public UnixAgentFactory() {
super();
@@ -100,7 +100,7 @@ public class UnixAgentFactory implements SshAgentFactory, ExecutorServiceConfigu
public SshAgentServer createServer(ConnectionService service) throws IOException {
Session session = ValidateUtils.checkNotNull(service.getSession(), "No session");
ValidateUtils.checkTrue(session instanceof ServerSession,
- "The session used to create an agent server proxy must be a server session");
+ "The session used to create an agent server proxy must be a server session");
return new AgentServerProxy(service, getExecutorService(), isShutdownOnExit());
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/ClientBuilder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/ClientBuilder.java b/sshd-core/src/main/java/org/apache/sshd/client/ClientBuilder.java
index 435ec11..8da5ac7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/ClientBuilder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/ClientBuilder.java
@@ -29,7 +29,6 @@ import org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier;
import org.apache.sshd.common.BaseBuilder;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.channel.Channel;
-import org.apache.sshd.common.kex.BuiltinDHFactories;
import org.apache.sshd.common.kex.DHFactory;
import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.util.Transformer;
@@ -39,19 +38,25 @@ import org.apache.sshd.server.forward.ForwardedTcpipFactory;
* SshClient builder
*/
public class ClientBuilder extends BaseBuilder<SshClient, ClientBuilder> {
- public static final Transformer<DHFactory,NamedFactory<KeyExchange>> DH2KEX =
- new Transformer<DHFactory, NamedFactory<KeyExchange>>() {
- @Override
- public NamedFactory<KeyExchange> transform(DHFactory factory) {
- if (factory == null) {
- return null;
- } else if (factory.isGroupExchange()) {
- return DHGEXClient.newFactory(factory);
- } else {
- return DHGClient.newFactory(factory);
- }
+ public static final Transformer<DHFactory, NamedFactory<KeyExchange>> DH2KEX =
+ new Transformer<DHFactory, NamedFactory<KeyExchange>>() {
+ @Override
+ public NamedFactory<KeyExchange> transform(DHFactory factory) {
+ if (factory == null) {
+ return null;
+ } else if (factory.isGroupExchange()) {
+ return DHGEXClient.newFactory(factory);
+ } else {
+ return DHGClient.newFactory(factory);
}
- };
+ }
+ };
+
+ public static final List<NamedFactory<Channel>> DEFAULT_CHANNEL_FACTORIES =
+ Collections.unmodifiableList(Arrays.<NamedFactory<Channel>>asList(ForwardedTcpipFactory.INSTANCE));
+
+ public static final ServerKeyVerifier DEFAULT_SERVER_KEY_VERIFIER = AcceptAllServerKeyVerifier.INSTANCE;
+
protected ServerKeyVerifier serverKeyVerifier;
public ClientBuilder() {
@@ -63,10 +68,6 @@ public class ClientBuilder extends BaseBuilder<SshClient, ClientBuilder> {
return me();
}
- public static final List<NamedFactory<Channel>> DEFAULT_CHANNEL_FACTORIES =
- Collections.unmodifiableList(Arrays.<NamedFactory<Channel>>asList(ForwardedTcpipFactory.INSTANCE));
- public static final ServerKeyVerifier DEFAULT_SERVER_KEY_VERIFIER = AcceptAllServerKeyVerifier.INSTANCE;
-
@Override
protected ClientBuilder fillWithDefaultValues() {
super.fillWithDefaultValues();
@@ -99,15 +100,15 @@ public class ClientBuilder extends BaseBuilder<SshClient, ClientBuilder> {
/**
* @param ignoreUnsupported If {@code true} then all the default
- * key exchanges are included, regardless of whether they are currently
- * supported by the JCE. Otherwise, only the supported ones out of the
- * list are included
+ * key exchanges are included, regardless of whether they are currently
+ * supported by the JCE. Otherwise, only the supported ones out of the
+ * list are included
* @return A {@link List} of the default {@link NamedFactory}
* instances of the {@link KeyExchange}s according to the preference
* order defined by {@link #DEFAULT_KEX_PREFERENCE}.
* <B>Note:</B> the list may be filtered to exclude unsupported JCE
* key exchanges according to the <tt>ignoreUnsupported</tt> parameter
- * @see BuiltinDHFactories#isSupported()
+ * @see org.apache.sshd.common.kex.BuiltinDHFactories#isSupported()
*/
public static List<NamedFactory<KeyExchange>> setUpDefaultKeyExchanges(boolean ignoreUnsupported) {
return NamedFactory.Utils.setUpTransformedFactories(ignoreUnsupported, DEFAULT_KEX_PREFERENCE, DH2KEX);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java b/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java
index cf105d2..a38daed 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/ClientFactoryManager.java
@@ -37,19 +37,19 @@ public interface ClientFactoryManager extends FactoryManager {
* Key used to set the heartbeat interval in milliseconds (0 to disable = default)
*/
String HEARTBEAT_INTERVAL = "hearbeat-interval";
- /**
- * Default value for {@link #HEARTBEAT_INTERVAL} if none configured
- */
- long DEFAULT_HEARTBEAT_INTERVAL = 0L;
+ /**
+ * Default value for {@link #HEARTBEAT_INTERVAL} if none configured
+ */
+ long DEFAULT_HEARTBEAT_INTERVAL = 0L;
/**
* Key used to check the heartbeat request that should be sent to the server
*/
String HEARTBEAT_REQUEST = "heartbeat-request";
- /**
- * Default value for {@link ClientFactoryManager#HEARTBEAT_REQUEST} is none configured
- */
- String DEFAULT_KEEP_ALIVE_HEARTBEAT_STRING = "keepalive@sshd.apache.org";
+ /**
+ * Default value for {@link ClientFactoryManager#HEARTBEAT_REQUEST} is none configured
+ */
+ String DEFAULT_KEEP_ALIVE_HEARTBEAT_STRING = "keepalive@sshd.apache.org";
/**
* Ordered comma separated list of authentications methods.
@@ -64,10 +64,10 @@ public interface ClientFactoryManager extends FactoryManager {
* The argument to this keyword must be an integer.
*/
String PASSWORD_PROMPTS = "password-prompts";
- /**
- * Default value for {@link #PASSWORD_PROMPTS} if none configured
- */
- int DEFAULT_PASSWORD_PROMPTS = 3;
+ /**
+ * Default value for {@link #PASSWORD_PROMPTS} if none configured
+ */
+ int DEFAULT_PASSWORD_PROMPTS = 3;
/**
* Retrieve the server key verifier to be used to check the key when connecting
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/ServerKeyVerifier.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/ServerKeyVerifier.java b/sshd-core/src/main/java/org/apache/sshd/client/ServerKeyVerifier.java
index 3465553..ec2e9d6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/ServerKeyVerifier.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/ServerKeyVerifier.java
@@ -35,8 +35,8 @@ public interface ServerKeyVerifier {
* Verify that the server key provided is really the one of the host.
*
* @param sshClientSession the current session
- * @param remoteAddress the host
- * @param serverKey the presented key
+ * @param remoteAddress the host
+ * @param serverKey the presented key
* @return <code>true</code> if the key is accepted for the host
*/
boolean verifyServerKey(ClientSession sshClientSession, SocketAddress remoteAddress, PublicKey serverKey);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/SessionFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SessionFactory.java b/sshd-core/src/main/java/org/apache/sshd/client/SessionFactory.java
index 619894f..114f0e9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/SessionFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SessionFactory.java
@@ -27,9 +27,8 @@ import org.apache.sshd.common.session.AbstractSessionFactory;
* A factory of client sessions.
* This class can be used as a way to customize the creation of client sessions.
*
- * @see org.apache.sshd.client.SshClient#setSessionFactory(SessionFactory)
- *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ * @see org.apache.sshd.client.SshClient#setSessionFactory(SessionFactory)
*/
public class SessionFactory extends AbstractSessionFactory {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/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 1023668..94ad2d7 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
@@ -77,17 +77,17 @@ import org.apache.sshd.common.util.io.NoCloseOutputStream;
/**
* Entry point for the client side of the SSH protocol.
- *
+ * <p/>
* The default configured client can be created using
* the {@link #setUpDefaultClient()}. The next step is to
* start the client using the {@link #start()} method.
- *
+ * <p/>
* Sessions can then be created using on of the
* {@link #connect(String, String, int)} or {@link #connect(String, java.net.SocketAddress)}
* methods.
- *
+ * <p/>
* The client can be stopped at anytime using the {@link #stop()} method.
- *
+ * <p/>
* Following is an example of using the SshClient:
* <pre>
* SshClient client = SshClient.setUpDefaultClient();
@@ -120,6 +120,18 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
}
};
+ public static final List<NamedFactory<UserAuth>> DEFAULT_USER_AUTH_FACTORIES =
+ Collections.unmodifiableList(Arrays.<NamedFactory<UserAuth>>asList(
+ UserAuthPublicKeyFactory.INSTANCE,
+ UserAuthKeyboardInteractiveFactory.INSTANCE,
+ UserAuthPasswordFactory.INSTANCE
+ ));
+ public static final List<ServiceFactory> DEFAULT_SERVICE_FACTORIES =
+ Collections.unmodifiableList(Arrays.asList(
+ ClientUserAuthServiceFactory.INSTANCE,
+ ClientConnectionServiceFactory.INSTANCE
+ ));
+
protected IoConnector connector;
protected SessionFactory sessionFactory;
protected UserInteraction userInteraction;
@@ -166,22 +178,10 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
this.userAuthFactories = userAuthFactories;
}
- public static final List<NamedFactory<UserAuth>> DEFAULT_USER_AUTH_FACTORIES =
- Collections.unmodifiableList(Arrays.<NamedFactory<UserAuth>>asList(
- UserAuthPublicKeyFactory.INSTANCE,
- UserAuthKeyboardInteractiveFactory.INSTANCE,
- UserAuthPasswordFactory.INSTANCE
- ));
- public static final List<ServiceFactory> DEFAULT_SERVICE_FACTORIES =
- Collections.unmodifiableList(Arrays.asList(
- ClientUserAuthServiceFactory.INSTANCE,
- ClientConnectionServiceFactory.INSTANCE
- ));
-
@Override
protected void checkConfig() {
super.checkConfig();
-
+
ValidateUtils.checkNotNull(getTcpipForwarderFactory(), "TcpipForwarderFactory not set");
ValidateUtils.checkNotNull(getServerKeyVerifier(), "ServerKeyVerifier not set");
@@ -322,8 +322,8 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
// NOTE: ClientSession#getFactoryManager is the SshClient
public static ClientSession setupClientSession(
- String portOption, final BufferedReader stdin, final PrintStream stdout, final PrintStream stderr, String ... args)
- throws Exception {
+ String portOption, final BufferedReader stdin, final PrintStream stdout, final PrintStream stderr, String... args)
+ throws Exception {
int port = -1;
String host = null;
@@ -340,14 +340,15 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
error = true;
break;
}
-
+
if (port > 0) {
stderr.println(argName + " option value re-specified: " + port);
error = true;
break;
}
-
- if ((port=Integer.parseInt(args[++i])) <= 0) {
+
+ port = Integer.parseInt(args[++i]);
+ if (port <= 0) {
stderr.println("Bad option value for " + argName + ": " + port);
error = true;
break;
@@ -358,7 +359,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
error = true;
break;
}
-
+
File f = new File(args[++i]);
identities.add(f);
} else if ("-o".equals(argName)) {
@@ -381,7 +382,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
error = true;
break;
}
-
+
if (login != null) {
stderr.println(argName + " option value re-specified: " + port);
error = true;
@@ -400,7 +401,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
}
}
}
-
+
if ((!error) && GenericUtils.isEmpty(host)) {
stderr.println("Hostname not specified");
error = true;
@@ -409,11 +410,11 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
if (login == null) {
login = System.getProperty("user.name");
}
-
+
if (port <= 0) {
port = SshConfigFileReader.DEFAULT_PORT;
}
-
+
if (error) {
return null;
}
@@ -443,42 +444,42 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
}
}
- Map<String,Object> props = client.getProperties();
+ Map<String, Object> props = client.getProperties();
props.putAll(options);
-
+
client.start();
client.setUserInteraction(new UserInteraction() {
- @Override
- public void welcome(String banner) {
- stdout.println(banner);
- }
-
- @Override
- public String[] interactive(String destination, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
- int numPropmts = GenericUtils.length(prompt);
- String[] answers = new String[numPropmts];
- try {
- for (int i = 0; i < numPropmts; i++) {
- stdout.print(prompt[i] + " ");
- answers[i] = stdin.readLine();
- }
- } catch (IOException e) {
- // ignored
+ @Override
+ public void welcome(String banner) {
+ stdout.println(banner);
+ }
+
+ @Override
+ public String[] interactive(String destination, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
+ int numPropmts = GenericUtils.length(prompt);
+ String[] answers = new String[numPropmts];
+ try {
+ for (int i = 0; i < numPropmts; i++) {
+ stdout.print(prompt[i] + " ");
+ answers[i] = stdin.readLine();
}
- return answers;
+ } catch (IOException e) {
+ // ignored
}
- });
-
+ return answers;
+ }
+ });
+
// TODO use a configurable wait time
ClientSession session = client.connect(login, host, port).await().getSession();
try {
session.auth().verify(); // TODO use a configurable wait time
return session;
- } catch(Exception e) {
+ } catch (Exception e) {
session.close(true);
throw e;
}
- } catch(Exception e) {
+ } catch (Exception e) {
client.close();
throw e;
}
@@ -494,18 +495,15 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
String throwable = "";
if (record.getThrown() != null) {
StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- pw.println();
- record.getThrown().printStackTrace(pw);
- pw.close();
+ try (PrintWriter pw = new PrintWriter(sw)) {
+ pw.println();
+ record.getThrown().printStackTrace(pw);
+ }
throwable = sw.toString();
}
return String.format("%1$tY-%1$tm-%1$td: %2$-7.7s: %3$-32.32s: %4$s%5$s%n",
- new Date(record.getMillis()),
- record.getLevel().getName(),
- record.getLoggerName(),
- message,
- throwable);
+ new Date(record.getMillis()), record.getLevel().getName(),
+ record.getLoggerName(), message, throwable);
}
});
Logger root = Logger.getLogger("");
@@ -514,7 +512,8 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
}
root.addHandler(fh);
- PrintStream stdout=System.out, stderr=System.err;
+ PrintStream stdout = System.out;
+ PrintStream stderr = System.err;
boolean agentForward = false;
List<String> command = null;
int logLevel = 0;
@@ -535,8 +534,9 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
error = true;
break;
}
-
- if ((socksPort=Integer.parseInt(args[++i])) <= 0) {
+
+ socksPort = Integer.parseInt(args[++i]);
+ if (socksPort <= 0) {
stderr.println("Bad option value for " + argName + ": " + socksPort);
error = true;
break;
@@ -573,10 +573,11 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
root.setLevel(Level.FINEST);
}
- ClientSession session=null;
- try(BufferedReader stdin = new BufferedReader(new InputStreamReader(new NoCloseInputStream(System.in)))) {
+ ClientSession session = null;
+ try (BufferedReader stdin = new BufferedReader(new InputStreamReader(new NoCloseInputStream(System.in)))) {
if (!error) {
- if ((session=setupClientSession("-p", stdin, stdout, stderr, args)) == null) {
+ session = setupClientSession("-p", stdin, stdout, stderr, args);
+ if (session == null) {
error = true;
}
}
@@ -587,7 +588,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
return;
}
- try(SshClient client = (SshClient) session.getFactoryManager()) {
+ try (SshClient client = (SshClient) session.getFactoryManager()) {
/*
String authSock = System.getenv(SshAgent.SSH_AUTHSOCKET_ENV_NAME);
if (authSock == null && provider != null) {
@@ -602,7 +603,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
props.put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, authSock);
}
*/
-
+
try {
if (socksPort >= 0) {
session.startDynamicPortForwarding(new SshdSocketAddress("localhost", socksPort));
@@ -621,7 +622,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
w.close();
channel = session.createChannel(ClientChannel.CHANNEL_EXEC, w.toString());
}
-
+
try {
channel.setOut(new NoCloseOutputStream(System.out));
channel.setErr(new NoCloseOutputStream(System.err));
@@ -636,9 +637,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
client.stop();
}
} finally {
- if (session != null) {
- session.close();
- }
+ session.close();
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/SshKeyScan.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SshKeyScan.java b/sshd-core/src/main/java/org/apache/sshd/client/SshKeyScan.java
index 385ad47..e78d657 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/SshKeyScan.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SshKeyScan.java
@@ -79,14 +79,15 @@ import org.apache.sshd.common.util.logging.LoggingUtils;
/**
* A naive implementation of <A HREF="https://www.freebsd.org/cgi/man.cgi?query=ssh-keyscan&sektion=1">ssh-keyscan(1)</A>
+ *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class SshKeyScan extends AbstractSimplifiedLog
- implements Channel, Callable<Void>, ServerKeyVerifier, SessionListener {
+ implements Channel, Callable<Void>, ServerKeyVerifier, SessionListener {
/**
* Default key types if not overridden from the command line
*/
- public static final List<String> DEFAULT_KEY_TYPES =
+ public static final List<String> DEFAULT_KEY_TYPES =
Collections.unmodifiableList(Arrays.asList(BuiltinIdentities.Constants.RSA, BuiltinIdentities.Constants.ECDSA));
public static final long DEFAULT_TIMEOUT = TimeUnit.SECONDS.toMillis(5L);
public static final Level DEFAULT_LEVEL = Level.INFO;
@@ -98,7 +99,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
private List<String> keyTypes;
private InputStream input;
private Level level;
- private final Map<String,String> currentHostFingerprints = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ private final Map<String, String> currentHostFingerprints = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
public SshKeyScan() {
super();
@@ -107,7 +108,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
public int getPort() {
return port;
}
-
+
public void setPort(int port) {
this.port = port;
}
@@ -123,7 +124,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
public List<String> getKeyTypes() {
return keyTypes;
}
-
+
public void setKeyTypes(List<String> keyTypes) {
this.keyTypes = keyTypes;
}
@@ -151,14 +152,14 @@ public class SshKeyScan extends AbstractSimplifiedLog
if ((t != null) || Level.SEVERE.equals(level) || Level.WARNING.equals(level)) {
ps = System.err;
}
-
+
ps.append('\t').println(message);
if (t != null) {
ps.append("\t\t").append(t.getClass().getSimpleName()).append(": ").println(t.getMessage());
}
}
}
-
+
@Override
public boolean isEnabled(Level level) {
return LoggingUtils.isLoggable(level, getLogLevel());
@@ -169,14 +170,14 @@ public class SshKeyScan extends AbstractSimplifiedLog
ValidateUtils.checkTrue(isOpen(), "Scanner is closed");
Collection<String> typeNames = getKeyTypes();
- Map<String,List<KeyPair>> pairsMap = createKeyPairs(typeNames);
+ Map<String, List<KeyPair>> pairsMap = createKeyPairs(typeNames);
/*
* We will need to switch signature factories for each specific
* key type in order to force the server to send ONLY that specific
* key, so pre-create the factories map according to the selected
* key types
*/
- Map<String,List<NamedFactory<Signature>>> sigFactories = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, List<NamedFactory<Signature>>> sigFactories = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
for (String kt : new TreeSet<>(pairsMap.keySet())) {
List<NamedFactory<Signature>> factories = resolveSignatureFactories(kt);
if (GenericUtils.isEmpty(factories)) {
@@ -232,11 +233,11 @@ public class SshKeyScan extends AbstractSimplifiedLog
} finally {
try {
close();
- } catch(IOException e) {
+ } catch (IOException e) {
err = GenericUtils.accumulateException(err, e);
}
}
-
+
if (err != null) {
throw err;
}
@@ -244,8 +245,10 @@ public class SshKeyScan extends AbstractSimplifiedLog
return null;
}
- protected void resolveServerKeys(SshClient client, String host, Map<String,List<KeyPair>> pairsMap, Map<String,List<NamedFactory<Signature>>> sigFactories) throws IOException {
- for (Map.Entry<String,List<KeyPair>> pe : pairsMap.entrySet()) {
+ protected void resolveServerKeys(SshClient client, String host,
+ Map<String, List<KeyPair>> pairsMap,
+ Map<String, List<NamedFactory<Signature>>> sigFactories) throws IOException {
+ for (Map.Entry<String, List<KeyPair>> pe : pairsMap.entrySet()) {
String kt = pe.getKey();
if (!isOpen()) {
throw new InterruptedIOException("Closed while attempting to retrieve key type=" + kt + " from " + host);
@@ -258,14 +261,14 @@ public class SshKeyScan extends AbstractSimplifiedLog
* specific one for the key in order to extract only the
* specific host key type
*/
- List<NamedFactory<Signature>> forced = sigFactories.get(kt);
+ List<NamedFactory<Signature>> forced = sigFactories.get(kt);
client.setSignatureFactories(forced);
resolveServerKeys(client, host, kt, pe.getValue());
- } catch(Exception e) {
+ } catch (Exception e) {
if (isEnabled(Level.FINE)) {
log(Level.FINE, "Failed to resolve key=" + kt + " for " + host);
}
-
+
if (e instanceof ConnectException) {
return; // makes no sense to try again with another key type...
}
@@ -274,7 +277,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
}
}
}
-
+
protected void resolveServerKeys(SshClient client, String host, String kt, List<KeyPair> ids) throws Exception {
int connectPort = getPort();
if (isEnabled(Level.FINE)) {
@@ -285,11 +288,11 @@ public class SshKeyScan extends AbstractSimplifiedLog
long waitTime = getTimeout();
if (!future.await(waitTime)) {
throw new ConnectException("Failed to connect to " + host + ":" + connectPort
- + " within " + waitTime + " msec."
- + " to retrieve key type=" + kt);
+ + " within " + waitTime + " msec."
+ + " to retrieve key type=" + kt);
}
- try(ClientSession session = future.getSession()) {
+ try (ClientSession session = future.getSession()) {
IoSession ioSession = session.getIoSession();
SocketAddress remoteAddress = ioSession.getRemoteAddress();
String remoteLocation = toString(remoteAddress);
@@ -311,7 +314,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
// shouldn't really succeed, but do it since key exchange occurs only on auth attempt
session.auth().verify(waitTime);
log(Level.WARNING, "Unexpected authentication success using key type=" + kt + " with " + remoteLocation);
- } catch(Exception e) {
+ } catch (Exception e) {
if (isEnabled(Level.FINER)) {
log(Level.FINER, "Failed to authenticate using key type=" + kt + " with " + remoteLocation);
}
@@ -380,7 +383,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
currentHostFingerprints.put(keyType, extra);
}
}
- } catch(Exception e) {
+ } catch (Exception e) {
log(Level.SEVERE, "Failed to output the public key " + extra + " from " + remoteLocation, e);
}
@@ -422,7 +425,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
}
NamedFactory<Signature> f =
- ValidateUtils.checkNotNull(BuiltinSignatures.fromString(n), "Unknown curve signature: %s", n);
+ ValidateUtils.checkNotNull(BuiltinSignatures.fromString(n), "Unknown curve signature: %s", n);
factories.add(f);
}
@@ -432,12 +435,12 @@ public class SshKeyScan extends AbstractSimplifiedLog
}
}
- protected Map<String,List<KeyPair>> createKeyPairs(Collection<String> typeNames) throws GeneralSecurityException {
+ protected Map<String, List<KeyPair>> createKeyPairs(Collection<String> typeNames) throws GeneralSecurityException {
if (GenericUtils.isEmpty(typeNames)) {
return Collections.emptyMap();
}
- Map<String,List<KeyPair>> pairsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, List<KeyPair>> pairsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
for (String kt : typeNames) {
if (pairsMap.containsKey(kt)) {
log(Level.WARNING, "Key type " + kt + " re-specified");
@@ -449,10 +452,10 @@ public class SshKeyScan extends AbstractSimplifiedLog
log(Level.WARNING, "No key-pairs generated for key type " + kt);
continue;
}
-
+
pairsMap.put(kt, kps);
}
-
+
return pairsMap;
}
@@ -479,7 +482,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
kps.add(KeyUtils.generateKeyPair(curve.getKeyType(), curve.getKeySize()));
}
-
+
return kps;
} else {
throw new InvalidKeySpecException("Unknown key type: " + keyType);
@@ -501,7 +504,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
if (input != null) {
try {
input.close();
- } catch(IOException e) {
+ } catch (IOException e) {
err = GenericUtils.accumulateException(err, e);
} finally {
input = null;
@@ -511,7 +514,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
if (client != null) {
try {
client.close();
- } catch(IOException e) {
+ } catch (IOException e) {
err = GenericUtils.accumulateException(err, e);
} finally {
try {
@@ -529,9 +532,9 @@ public class SshKeyScan extends AbstractSimplifiedLog
//////////////////////////////////////////////////////////////////////////
// returns a List of the hosts to be contacted
- public static List<String> parseCommandLineArguments(SshKeyScan scanner, String ... args) throws IOException {
+ public static List<String> parseCommandLineArguments(SshKeyScan scanner, String... args) throws IOException {
int numArgs = GenericUtils.length(args);
- for (int index=0; index < numArgs; index++) {
+ for (int index = 0; index < numArgs; index++) {
String optName = args[index];
if ("-f".equals(optName)) {
index++;
@@ -548,7 +551,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
index++;
ValidateUtils.checkTrue(index < numArgs, "Missing %s option argument", optName);
ValidateUtils.checkTrue(GenericUtils.isEmpty(scanner.getKeyTypes()), "%s option re-specified", optName);
-
+
String typeList = args[index];
String[] types = GenericUtils.split(typeList, ',');
ValidateUtils.checkTrue(GenericUtils.length(types) > 0, "No types specified for %s", optName);
@@ -557,7 +560,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
index++;
ValidateUtils.checkTrue(index < numArgs, "Missing %s option argument", optName);
ValidateUtils.checkTrue(scanner.getPort() <= 0, "%s option re-specified", optName);
-
+
String portValue = args[index];
int port = Integer.parseInt(portValue);
ValidateUtils.checkTrue((port > 0) && (port <= 0xFFFF), "Bad port: %s", portValue);
@@ -566,7 +569,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
index++;
ValidateUtils.checkTrue(index < numArgs, "Missing %s option argument", optName);
ValidateUtils.checkTrue(scanner.getTimeout() <= 0, "%s option re-specified", optName);
-
+
String timeoutValue = args[index];
long timeout = Long.parseLong(timeoutValue);
ValidateUtils.checkTrue(timeout > 0L, "Bad timeout: %s", timeoutValue);
@@ -575,22 +578,22 @@ public class SshKeyScan extends AbstractSimplifiedLog
ValidateUtils.checkTrue(scanner.getLogLevel() == null, "%s option re-specified", optName);
scanner.setLogLevel(Level.FINEST);
} else { // stop at first non-option - assume the rest are host names/addresses
- ValidateUtils.checkTrue((optName.charAt(0) != '-'), "Unknown option: %s", optName);
-
+ ValidateUtils.checkTrue(optName.charAt(0) != '-', "Unknown option: %s", optName);
+
int remaining = numArgs - index;
if (remaining == 1) {
return Collections.singletonList(optName);
}
-
+
List<String> hosts = new ArrayList<>(remaining);
- for ( ; index < numArgs; index++) {
+ for (; index < numArgs; index++) {
hosts.add(args[index]);
}
-
+
return hosts;
}
}
-
+
return Collections.emptyList();
}
@@ -601,21 +604,21 @@ public class SshKeyScan extends AbstractSimplifiedLog
ValidateUtils.checkNotNull(scanner.getInputStream(), "No hosts or file specified");
} else {
ValidateUtils.checkTrue(scanner.getInputStream() == null, "Both hosts and file specified");
-
+
// convert the hosts from the arguments into a "file" - one host per line
- try(ByteArrayOutputStream baos = new ByteArrayOutputStream(hosts.size() * 32)) {
- try(Writer w = new OutputStreamWriter(baos, StandardCharsets.UTF_8)) {
- String EOL = System.getProperty("line.separator");
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream(hosts.size() * 32)) {
+ try (Writer w = new OutputStreamWriter(baos, StandardCharsets.UTF_8)) {
+ String eol = System.getProperty("line.separator");
for (String h : hosts) {
- w.append(h).append(EOL);
+ w.append(h).append(eol);
}
}
-
+
byte[] data = baos.toByteArray();
scanner.setInputStream(new ByteArrayInputStream(data));
}
}
-
+
return scanner;
}
@@ -624,11 +627,11 @@ public class SshKeyScan extends AbstractSimplifiedLog
if (scanner.getPort() <= 0) {
scanner.setPort(SshConfigFileReader.DEFAULT_PORT);
}
-
+
if (scanner.getTimeout() <= 0L) {
scanner.setTimeout(DEFAULT_TIMEOUT);
}
-
+
if (GenericUtils.isEmpty(scanner.getKeyTypes())) {
scanner.setKeyTypes(DEFAULT_KEY_TYPES);
}
@@ -643,7 +646,7 @@ public class SshKeyScan extends AbstractSimplifiedLog
/* -------------------------------------------------------------------- */
public static void main(String[] args) throws Exception {
- try(SshKeyScan scanner = new SshKeyScan()) {
+ try (SshKeyScan scanner = new SshKeyScan()) {
Collection<String> hosts = parseCommandLineArguments(scanner, args);
initializeScanner(scanner, hosts);
scanner.call();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthFactory.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthFactory.java
index e72f409..f05abf5 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthFactory.java
@@ -16,21 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sshd.client.auth;
import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.util.Transformer;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+// CHECKSTYLE:OFF
public interface UserAuthFactory extends NamedFactory<UserAuth> {
- // required because of generics issues
- Transformer<UserAuthFactory,NamedFactory<UserAuth>> FAC2NAMED=new Transformer<UserAuthFactory,NamedFactory<UserAuth>>() {
- @Override
- public NamedFactory<UserAuth> transform(UserAuthFactory input) {
- return input;
- }
- };
+
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthKeyboardInteractive.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthKeyboardInteractive.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthKeyboardInteractive.java
index 5ee1578..49e8d47 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthKeyboardInteractive.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthKeyboardInteractive.java
@@ -18,9 +18,6 @@
*/
package org.apache.sshd.client.auth;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_USERAUTH_INFO_REQUEST;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_USERAUTH_INFO_RESPONSE;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -34,9 +31,13 @@ import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_USERAUTH_INFO_REQUEST;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_USERAUTH_INFO_RESPONSE;
+
/**
* Manages a "keyboard-interactive" exchange according to
* <A HREF="https://www.ietf.org/rfc/rfc4256.txt">RFC4256</A>
+ *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class UserAuthKeyboardInteractive extends AbstractLoggingBean implements UserAuth {
@@ -76,7 +77,7 @@ public class UserAuthKeyboardInteractive extends AbstractLoggingBean implements
} else {
return false;
}
-
+
String username = session.getUsername();
if (log.isDebugEnabled()) {
log.debug("Send SSH_MSG_USERAUTH_REQUEST for keyboard-interactive - user={}, service={}", username, service);
@@ -109,7 +110,7 @@ public class UserAuthKeyboardInteractive extends AbstractLoggingBean implements
prompt[i] = buffer.getString();
echo[i] = buffer.getBoolean();
}
-
+
if (log.isDebugEnabled()) {
log.debug("Prompt: {}", Arrays.toString(prompt));
log.debug("Echo: {}", echo);
@@ -149,19 +150,19 @@ public class UserAuthKeyboardInteractive extends AbstractLoggingBean implements
}
/**
- * @param name The interaction name - may be empty
+ * @param name The interaction name - may be empty
* @param instruction The instruction - may be empty
- * @param lang The language tag - may be empty
- * @param prompt The prompts - may be empty
- * @param echo Whether to echo the response for the prompt or not - same
- * length as the prompts
+ * @param lang The language tag - may be empty
+ * @param prompt The prompts - may be empty
+ * @param echo Whether to echo the response for the prompt or not - same
+ * length as the prompts
* @return The response for each prompt - if {@code null} then the assumption
* is that some internal error occurred and no response is sent. <B>Note:</B>
* according to <A HREF="https://www.ietf.org/rfc/rfc4256.txt">RFC4256</A>
* the number of responses should be <U>exactly</U> the same as the number
* of prompts. However, since it is the <U>server's</U> responsibility to
* enforce this we do not validate the response (other than logging it as
- * a warning...)
+ * a warning...)
*/
protected String[] getUserResponses(String name, String instruction, String lang, String[] prompt, boolean[] echo) {
int num = GenericUtils.length(prompt);
@@ -170,12 +171,12 @@ public class UserAuthKeyboardInteractive extends AbstractLoggingBean implements
}
String candidate = getCurrentPasswordCandidate();
- if (useCurrentPassword(candidate, name, instruction, lang, prompt, echo)) {
- return new String[] { candidate };
+ if (useCurrentPassword(candidate, name, instruction, lang, prompt, echo)) {
+ return new String[]{candidate};
} else {
UserInteraction ui = session.getUserInteraction();
if (ui == null) {
- ClientFactoryManager manager = session.getFactoryManager();
+ ClientFactoryManager manager = session.getFactoryManager();
ui = manager.getUserInteraction();
}
@@ -184,7 +185,7 @@ public class UserAuthKeyboardInteractive extends AbstractLoggingBean implements
return ui.interactive(dest, name, instruction, lang, prompt, echo);
}
}
-
+
return null;
}
@@ -205,7 +206,7 @@ public class UserAuthKeyboardInteractive extends AbstractLoggingBean implements
if (sepPos <= passPos) { // no prompt separator or separator before the password keyword
return false;
}
-
+
return true;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPublicKey.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPublicKey.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPublicKey.java
index 0522218..f7450f8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPublicKey.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPublicKey.java
@@ -68,7 +68,7 @@ public class UserAuthPublicKey extends AbstractLoggingBean implements UserAuth {
ids.add(new KeyPairIdentity(session.getFactoryManager(), (KeyPair) o));
}
}
-
+
FactoryManager manager = session.getFactoryManager();
SshAgentFactory factory = manager.getAgentFactory();
if (factory != null) {
@@ -109,7 +109,7 @@ public class UserAuthPublicKey extends AbstractLoggingBean implements UserAuth {
session.writePacket(buffer);
return true;
}
-
+
log.debug("No more keys to send");
return false;
}
@@ -154,15 +154,16 @@ public class UserAuthPublicKey extends AbstractLoggingBean implements UserAuth {
public void destroy() {
if (agent != null) {
try {
- agent.close();
- } catch(IOException e) {
- throw new RuntimeException("Failed (" + e.getClass().getSimpleName() + ") to close agent: " + e.getMessage(), e);
+ agent.close();
+ } catch (IOException e) {
+ throw new RuntimeException("Failed (" + e.getClass().getSimpleName() + ") to close agent: " + e.getMessage(), e);
}
}
}
interface PublicKeyIdentity {
PublicKey getPublicKey();
+
byte[] sign(byte[] data) throws Exception;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/auth/UserInteraction.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserInteraction.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserInteraction.java
index fad4694..ee3c0ad 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserInteraction.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserInteraction.java
@@ -20,6 +20,7 @@ package org.apache.sshd.client.auth;
/**
* Interface used by the ssh client to communicate with the end user.
+ *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
* @see <a href="https://www.ietf.org/rfc/rfc4256.txt">RFC 4256</A>
*/
@@ -27,17 +28,18 @@ public interface UserInteraction {
/**
* Displays the welcome banner to the user.
+ *
* @param banner The welcome banner
*/
void welcome(String banner);
/**
* @param destination The session identifier
- * @param name The interaction name (may be empty)
+ * @param name The interaction name (may be empty)
* @param instruction The instruction (may be empty)
- * @param lang The language for the data (may be empty)
- * @param prompt The prompts to be displayed (may be empty)
- * @param echo For each prompt whether to echo the user's response
+ * @param lang The language for the data (may be empty)
+ * @param prompt The prompts to be displayed (may be empty)
+ * @param echo For each prompt whether to echo the user's response
* @return The replies - <B>Note:</B> the protocol states that the number
* of replies should be <U>exactly</U> the same as the number of prompts,
* however we do not enforce it since it is defined as the <U>server's</U>
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
index a4b26c3..e9dd0da 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
@@ -46,7 +46,7 @@ import org.apache.sshd.common.util.io.IoUtils;
*/
public abstract class AbstractClientChannel extends AbstractChannel implements ClientChannel {
- protected final AtomicBoolean opened=new AtomicBoolean();
+ protected final AtomicBoolean opened = new AtomicBoolean();
protected final String type;
protected Streaming streaming;
@@ -193,7 +193,7 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
if ((cond & mask) != 0) {
if (log.isTraceEnabled()) {
log.trace("WaitFor call returning on channel {}, mask={}, cond={}",
- this, mask, cond);
+ this, mask, cond);
}
return cond;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
index da3f0ad..b3b4346 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
@@ -90,10 +90,12 @@ public class ChannelDirectTcpip extends AbstractClientChannel {
asyncIn = new ChannelAsyncOutputStream(this, SshConstants.SSH_MSG_CHANNEL_DATA);
asyncOut = new ChannelAsyncInputStream(this);
} else {
- invertedIn = out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.SSH_MSG_CHANNEL_DATA);
+ out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.SSH_MSG_CHANNEL_DATA);
+ invertedIn = out;
ChannelPipedInputStream pis = new ChannelPipedInputStream(localWindow);
pipe = new ChannelPipedOutputStream(pis);
- invertedOut = in = pis;
+ in = pis;
+ invertedOut = in;
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
index ccf6c01..7d6ab5f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
@@ -21,7 +21,6 @@ package org.apache.sshd.client.channel;
import java.io.IOException;
import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSession.java
index 102e85f..5ef3dd1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSession.java
@@ -38,6 +38,7 @@ import org.apache.sshd.common.util.threads.ThreadUtils;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class ChannelSession extends AbstractClientChannel {
+
private ExecutorService pumperService;
private Future<?> pumper;
private boolean shutdownPumper;
@@ -81,22 +82,24 @@ public class ChannelSession extends AbstractClientChannel {
if (in != null) {
// allocate a temporary executor service if none provided
ExecutorService service = getExecutorService();
- if ((pumperService = service) == null) {
+ if (service == null) {
pumperService = ThreadUtils.newSingleThreadExecutor("ClientInputStreamPump[" + this.toString() + "]");
+ } else {
+ pumperService = service;
}
-
+
// shutdown the temporary executor service if had to create it
- shutdownPumper = (pumperService == service) ? isShutdownOnExit() : true;
+ shutdownPumper = (pumperService != service) || isShutdownOnExit();
// Interrupt does not really work and the thread will only exit when
// the call to read() will return. So ensure this thread is a daemon
// to avoid blocking the whole app
pumper = pumperService.submit(new Runnable() {
- @Override
- public void run() {
- pumpInputStream();
- }
- });
+ @Override
+ public void run() {
+ pumpInputStream();
+ }
+ });
}
}
}
@@ -108,9 +111,9 @@ public class ChannelSession extends AbstractClientChannel {
if (!pumper.isDone()) {
pumper.cancel(true);
}
-
+
pumperService.shutdownNow();
- } catch(Exception e) {
+ } catch (Exception e) {
// we log it as DEBUG since it is relatively harmless
if (log.isDebugEnabled()) {
log.debug("Failed (" + e.getClass().getSimpleName() + ") to shutdown stream pumper: " + e.getMessage());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
index 3e79913..583c937 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
@@ -23,7 +23,6 @@ import java.io.IOException;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.future.CloseFuture;
import org.apache.sshd.common.future.SshFutureListener;
-import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java
index 7931989..6f60229 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ClientChannel.java
@@ -41,14 +41,14 @@ public interface ClientChannel extends Channel {
String CHANNEL_SHELL = "shell";
String CHANNEL_SUBSYSTEM = "subsystem";
- int TIMEOUT = 0x0001;
- int CLOSED = 0x0002;
+ int TIMEOUT = 0x0001;
+ int CLOSED = 0x0002;
int STDOUT_DATA = 0x0004;
int STDERR_DATA = 0x0008;
- int EOF = 0x0010;
+ int EOF = 0x0010;
int EXIT_STATUS = 0x0020;
int EXIT_SIGNAL = 0x0040;
- int OPENED = 0x0080;
+ int OPENED = 0x0080;
enum Streaming {
Async,
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
index 8684bdc..5620c27 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.EnumMap;
import java.util.LinkedHashMap;
import java.util.Map;
+
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.channel.PtyMode;
import org.apache.sshd.common.channel.SttySupport;
@@ -39,33 +40,34 @@ import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
* ignored).</P>
* <P>A typical code snippet would be:</P>
* <CODE><PRE>
- * client = SshClient.setUpDefaultClient();
- * client.start();
- *
- * try(ClientSession s = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
- * s.addPasswordIdentity(getCurrentTestName());
- * s.auth().verify(5L, TimeUnit.SECONDS);
- *
- * try(ChannelExec shell = s.createExecChannel("my super duper command")) {
- * shell.setEnv("var1", "val1");
- * shell.setEnv("var2", "val2");
- * ...etc...
- * shell.setPtyType(...);
- * shell.setPtyLines(...);
- * ...etc...
- *
- * shell.open().verify(5L, TimeUnit.SECONDS);
- * shell.waitFor(ClientChannel.CLOSED, TimeUnit.SECONDS.toMillis(17L)); // can use zero for infinite wait
- *
- * Integer status = shell.getExitStatus();
- * if (status.intValue() != 0) {
- * ...error...
- * }
- * }
- * } finally {
- * client.stop();
- * }
+ * client = SshClient.setUpDefaultClient();
+ * client.start();
+ * <p/>
+ * try(ClientSession s = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ * s.addPasswordIdentity(getCurrentTestName());
+ * s.auth().verify(5L, TimeUnit.SECONDS);
+ * <p/>
+ * try(ChannelExec shell = s.createExecChannel("my super duper command")) {
+ * shell.setEnv("var1", "val1");
+ * shell.setEnv("var2", "val2");
+ * ...etc...
+ * shell.setPtyType(...);
+ * shell.setPtyLines(...);
+ * ...etc...
+ * <p/>
+ * shell.open().verify(5L, TimeUnit.SECONDS);
+ * shell.waitFor(ClientChannel.CLOSED, TimeUnit.SECONDS.toMillis(17L)); // can use zero for infinite wait
+ * <p/>
+ * Integer status = shell.getExitStatus();
+ * if (status.intValue() != 0) {
+ * ...error...
+ * }
+ * }
+ * } finally {
+ * client.stop();
+ * }
* </PRE></CODE>
+ *
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class PtyCapableChannelSession extends ChannelSession {
@@ -207,8 +209,8 @@ public class PtyCapableChannelSession extends ChannelSession {
if (usePty) {
if (log.isDebugEnabled()) {
log.debug("Send SSH_MSG_CHANNEL_REQUEST pty-req: type={}, cols={}, lines={}, height={}, width={}, modes={}",
- ptyType, ptyColumns, ptyLines,
- ptyHeight, ptyWidth, ptyModes);
+ ptyType, ptyColumns, ptyLines,
+ ptyHeight, ptyWidth, ptyModes);
}
buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST);
@@ -222,13 +224,13 @@ public class PtyCapableChannelSession extends ChannelSession {
buffer.putInt(ptyWidth);
Buffer modes = new ByteArrayBuffer(GenericUtils.size(ptyModes) * (1 + (Integer.SIZE / Byte.SIZE)) + Byte.SIZE);
- for (Map.Entry<PtyMode,? extends Number> modeEntry : ptyModes.entrySet()) {
+ for (Map.Entry<PtyMode, ? extends Number> modeEntry : ptyModes.entrySet()) {
PtyMode mode = modeEntry.getKey();
Number value = modeEntry.getValue();
modes.putByte((byte) mode.toInt());
modes.putInt(value.longValue());
}
- modes.putByte(PtyMode.TTY_OP_END);
+ modes.putByte(PtyMode.TTY_OP_END);
buffer.putBytes(modes.getCompactData());
writePacket(buffer);
}