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/03/30 10:24:58 UTC

[2/3] mina-sshd git commit: [SSHD-441] Remove all deprecated code

[SSHD-441] Remove all deprecated code


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/6824d759
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/6824d759
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/6824d759

Branch: refs/heads/master
Commit: 6824d759a9f89940c7deccc710a2f6071ce93dba
Parents: aea11e3
Author: Guillaume Nodet <gn...@apache.org>
Authored: Fri Mar 27 18:33:03 2015 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon Mar 30 10:07:50 2015 +0200

----------------------------------------------------------------------
 .../java/org/apache/sshd/ClientSession.java     |  36 ---
 .../main/java/org/apache/sshd/SshClient.java    |  15 +-
 .../auth/UserAuthKeyboardInteractive.java       |   2 -
 .../sshd/client/auth/UserAuthPassword.java      |   1 -
 .../sshd/client/auth/UserAuthPublicKey.java     |   1 -
 .../auth/deprecated/AbstractUserAuth.java       |  43 ----
 .../sshd/client/auth/deprecated/UserAuth.java   |  40 ----
 .../client/auth/deprecated/UserAuthAgent.java   | 116 ----------
 .../deprecated/UserAuthKeyboardInteractive.java | 111 ----------
 .../auth/deprecated/UserAuthPassword.java       |  72 ------
 .../auth/deprecated/UserAuthPublicKey.java      | 108 ---------
 .../client/channel/AbstractClientChannel.java   |   1 -
 .../sshd/client/channel/ChannelDirectTcpip.java |  16 --
 .../sshd/client/session/ClientSessionImpl.java  |  34 +--
 .../client/session/ClientUserAuthService.java   | 197 +++++++++++++----
 .../session/ClientUserAuthServiceNew.java       | 220 -------------------
 .../session/ClientUserAuthServiceOld.java       | 189 ----------------
 .../org/apache/sshd/common/TcpipForwarder.java  |   6 -
 .../common/forward/DefaultTcpipForwarder.java   |   4 -
 .../org/apache/sshd/common/io/IoService.java    |   3 -
 .../org/apache/sshd/AuthenticationTest.java     |  69 +++++-
 .../test/java/org/apache/sshd/ServerTest.java   |  22 +-
 .../sshd/deprecated/AbstractUserAuth.java       |  43 ++++
 .../deprecated/ClientUserAuthServiceOld.java    | 199 +++++++++++++++++
 .../org/apache/sshd/deprecated/UserAuth.java    |  40 ++++
 .../apache/sshd/deprecated/UserAuthAgent.java   | 116 ++++++++++
 .../deprecated/UserAuthKeyboardInteractive.java | 111 ++++++++++
 .../sshd/deprecated/UserAuthPassword.java       |  72 ++++++
 .../sshd/deprecated/UserAuthPublicKey.java      | 106 +++++++++
 29 files changed, 919 insertions(+), 1074 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/ClientSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/ClientSession.java b/sshd-core/src/main/java/org/apache/sshd/ClientSession.java
index a84534e..e1d587c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/ClientSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/ClientSession.java
@@ -86,42 +86,6 @@ public interface ClientSession extends Session {
     AuthFuture auth() throws IOException;
 
     /**
-     * Authenticate the session with the given username using an ssh agent.
-     *
-     * @deprecated Use {@link #auth()} instead
-     * @see #auth()
-     */
-    @Deprecated
-    AuthFuture authAgent(String username) throws IOException;
-
-    /**
-     * Authenticate the session with the given username and password.
-     *
-     * @deprecated Use {@link #auth()} instead
-     * @see #auth()
-     */
-    @Deprecated
-    AuthFuture authPassword(String username, String password) throws IOException;
-
-    /**
-     * Authenticate the session with the given username and password.
-     *
-     * @deprecated Use {@link #auth()} instead
-     * @see #auth()
-     */
-    @Deprecated
-    AuthFuture authInteractive(String username, String password) throws IOException;
-
-    /**
-     * Authenticate the session with the given username and public key.
-     *
-     * @deprecated Use {@link #auth()} instead
-     * @see #auth()
-     */
-    @Deprecated
-    AuthFuture authPublicKey(String username, KeyPair key) throws IOException;
-
-    /**
      * Create a channel of the given type.
      * Same as calling <code>createChannel(type, null)</code>.
      */

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/SshClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/SshClient.java
index 1b2e6aa..25be1f4 100644
--- a/sshd-core/src/main/java/org/apache/sshd/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/SshClient.java
@@ -86,7 +86,7 @@ import org.bouncycastle.openssl.PasswordFinder;
  * start the client using the {@link #start()} method.
  *
  * Sessions can then be created using on of the
- * {@link #connect(String, int)} or {@link #connect(java.net.SocketAddress)}
+ * {@link #connect(String, String, int)} or {@link #connect(String, java.net.SocketAddress)}
  * methods.
  *
  * The client can be stopped at anytime using the {@link #stop()} method.
@@ -266,14 +266,6 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
                 .build();
     }
 
-    /**
-     * @deprecated Use {@link #connect(String, String, int)} instead
-     */
-    @Deprecated
-    public ConnectFuture connect(String host, int port) throws IOException {
-        return connect(null, host, port);
-    }
-
     public ConnectFuture connect(String username, String host, int port) throws IOException {
         assert host != null;
         assert port >= 0;
@@ -284,11 +276,6 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
         return connect(username, address);
     }
 
-    @Deprecated
-    public ConnectFuture connect(SocketAddress address) {
-        return connect(null, address);
-    }
-
     public ConnectFuture connect(final String username, SocketAddress address) {
         assert address != null;
         if (connector == null) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/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 a0e6292..cce5bf1 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
@@ -26,10 +26,8 @@ import org.apache.sshd.ClientSession;
 import org.apache.sshd.client.ClientFactoryManager;
 import org.apache.sshd.client.UserAuth;
 import org.apache.sshd.client.UserInteraction;
-import org.apache.sshd.client.session.ClientUserAuthServiceNew;
 import org.apache.sshd.common.NamedFactory;
 import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.session.AbstractSession;
 import org.apache.sshd.common.util.Buffer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPassword.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPassword.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPassword.java
index 8ecae4b..d1db9de 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPassword.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/UserAuthPassword.java
@@ -24,7 +24,6 @@ import java.util.List;
 
 import org.apache.sshd.ClientSession;
 import org.apache.sshd.client.UserAuth;
-import org.apache.sshd.client.session.ClientUserAuthServiceNew;
 import org.apache.sshd.common.NamedFactory;
 import org.apache.sshd.common.SshConstants;
 import org.apache.sshd.common.util.Buffer;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/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 6fdba21..9ff8487 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
@@ -28,7 +28,6 @@ import org.apache.sshd.ClientSession;
 import org.apache.sshd.agent.SshAgent;
 import org.apache.sshd.agent.SshAgentFactory;
 import org.apache.sshd.client.UserAuth;
-import org.apache.sshd.client.session.ClientUserAuthServiceNew;
 import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.KeyPairProvider;
 import org.apache.sshd.common.NamedFactory;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/AbstractUserAuth.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/AbstractUserAuth.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/AbstractUserAuth.java
deleted file mode 100644
index d847283..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/AbstractUserAuth.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.client.auth.deprecated;
-
-import org.apache.sshd.client.session.ClientSessionImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- */
-public abstract class AbstractUserAuth implements UserAuth {
-
-    protected final Logger log = LoggerFactory.getLogger(this.getClass());
-
-    protected final ClientSessionImpl session;
-    protected final String service;
-
-    protected AbstractUserAuth(ClientSessionImpl session, String service) {
-        this.session = session;
-        this.service = service;
-    }
-
-    public String getService() {
-        return service;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuth.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuth.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuth.java
deleted file mode 100644
index af354ee..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuth.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.client.auth.deprecated;
-
-import java.io.IOException;
-
-import org.apache.sshd.common.util.Buffer;
-
-/**
- * TODO Add javadoc
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public interface UserAuth {
-
-    enum Result {
-        Success,
-        Failure,
-        Continued
-    }
-
-    Result next(Buffer buffer) throws IOException;
-
-}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthAgent.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthAgent.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthAgent.java
deleted file mode 100644
index a02e8f9..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthAgent.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.client.auth.deprecated;
-
-import java.io.IOException;
-import java.security.PublicKey;
-import java.util.Iterator;
-
-import org.apache.sshd.agent.SshAgent;
-import org.apache.sshd.client.session.ClientSessionImpl;
-import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.KeyUtils;
-
-/**
- * Authentication delegating to an SSH agent
- */
-public class UserAuthAgent extends AbstractUserAuth {
-
-    private final SshAgent agent;
-    private final Iterator<SshAgent.Pair<PublicKey, String>> keys;
-
-    public UserAuthAgent(ClientSessionImpl session, String service) throws IOException {
-        super(session, service);
-        if (session.getFactoryManager().getAgentFactory() == null) {
-            throw new IllegalStateException("No ssh agent factory has been configured");
-        }
-        this.agent = session.getFactoryManager().getAgentFactory().createClient(session.getFactoryManager());
-        this.keys = agent.getIdentities().iterator();
-    }
-
-    protected void sendNextKey(PublicKey key) throws IOException {
-        try {
-            log.debug("Send SSH_MSG_USERAUTH_REQUEST for publickey");
-            Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST);
-            int pos1 = buffer.wpos() - 1;
-            buffer.putString(session.getUsername());
-            buffer.putString(service);
-            buffer.putString("publickey");
-            buffer.putByte((byte) 1);
-            buffer.putString(KeyUtils.getKeyType(key));
-            int pos2 = buffer.wpos();
-            buffer.putPublicKey(key);
-
-
-            Buffer bs = new Buffer();
-            bs.putString(session.getKex().getH());
-            bs.putByte(SshConstants.SSH_MSG_USERAUTH_REQUEST);
-            bs.putString(session.getUsername());
-            bs.putString(service);
-            bs.putString("publickey");
-            bs.putByte((byte) 1);
-            bs.putString(KeyUtils.getKeyType(key));
-            bs.putPublicKey(key);
-
-            Buffer bs2 = new Buffer();
-            bs2.putString(KeyUtils.getKeyType(key));
-            bs2.putBytes(agent.sign(key, bs.getCompactData()));
-            buffer.putBytes(bs2.array(), bs2.rpos(), bs2.available());
-
-            session.writePacket(buffer);
-        } catch (IOException e) {
-            throw e;
-        } catch (Exception e) {
-            throw (IOException) new IOException("Error performing public key authentication").initCause(e);
-        }
-    }
-
-    public Result next(Buffer buffer) throws IOException {
-        if (buffer == null) {
-            if (keys.hasNext()) {
-                sendNextKey(keys.next().getFirst());
-                return Result.Continued;
-            } else {
-                agent.close();
-                return Result.Failure;
-            }
-        } else {
-            byte cmd = buffer.getByte();
-            if (cmd == SshConstants.SSH_MSG_USERAUTH_SUCCESS) {
-                log.info("Received SSH_MSG_USERAUTH_SUCCESS");
-                agent.close();
-                return Result.Success;
-            } if (cmd == SshConstants.SSH_MSG_USERAUTH_FAILURE) {
-                log.info("Received SSH_MSG_USERAUTH_FAILURE");
-                if (keys.hasNext()) {
-                    sendNextKey(keys.next().getFirst());
-                    return Result.Continued;
-                } else {
-                    agent.close();
-                    return Result.Failure;
-                }
-            } else {
-                // TODO: check packets
-                log.info("Received unknown packet: {}", cmd);
-                return Result.Continued;
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthKeyboardInteractive.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthKeyboardInteractive.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthKeyboardInteractive.java
deleted file mode 100644
index d71d151..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthKeyboardInteractive.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.client.auth.deprecated;
-
-import java.io.IOException;
-
-import org.apache.sshd.client.UserInteraction;
-import org.apache.sshd.client.session.ClientSessionImpl;
-import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
-
-import static org.apache.sshd.common.SshConstants.*;
-
-/**
- * Userauth with keyboard-interactive method.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- * @author <a href="mailto:j.kapitza@schwarze-allianz.de">Jens Kapitza</a>
- */
-public class UserAuthKeyboardInteractive extends AbstractUserAuth {
-
-    private final String password;
-
-    public UserAuthKeyboardInteractive(ClientSessionImpl session, String service, String password) {
-        super(session, service);
-        this.password = password;
-    }
-
-    public Result next(Buffer buffer) throws IOException {
-        if (buffer == null) {
-            log.debug("Send SSH_MSG_USERAUTH_REQUEST for password");
-            buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST);
-            buffer.putString(session.getUsername());
-            buffer.putString(service);
-            buffer.putString("keyboard-interactive");
-            buffer.putString("");
-            buffer.putString("");
-            session.writePacket(buffer);
-            return Result.Continued;
-        } else {
-            byte cmd = buffer.getByte();
-            switch (cmd) {
-                case SSH_MSG_USERAUTH_INFO_REQUEST:
-                    log.debug("Received SSH_MSG_USERAUTH_INFO_REQUEST");
-                    String name = buffer.getString();
-                    String instruction = buffer.getString();
-                    String language_tag = buffer.getString();
-                    log.info("Received {} {} {}", new Object[]{name, instruction, language_tag});
-                    int num = buffer.getInt();
-                    String[] prompt = new String[num];
-                    boolean[] echo = new boolean[num];
-                    for (int i = 0; i < num; i++) {
-                        prompt[i] = buffer.getString();
-                        echo[i] = (buffer.getByte() != 0);
-                    }
-                    log.debug("Promt: {}", prompt);
-                    log.debug("Echo: {}", echo);
-
-                    String[] rep = null;
-                    if (num == 0) {
-                        rep = new String[0];
-                    } else if (num == 1 && password != null && !echo[0] && prompt[0].toLowerCase().startsWith("password:")) {
-                        rep = new String[] { password };
-                    } else {
-                        UserInteraction ui = session.getFactoryManager().getUserInteraction();
-                        if (ui != null) {
-                            String dest = session.getUsername() + "@" + session.getIoSession().getRemoteAddress().toString();
-                            rep = ui.interactive(dest, name, instruction, prompt, echo);
-                        }
-                    }
-                    if (rep == null) {
-                        return Result.Failure;
-                    }
-
-                    buffer = session.createBuffer(SSH_MSG_USERAUTH_INFO_RESPONSE);
-                    buffer.putInt(rep.length);
-                    for (String r : rep) {
-                        buffer.putString(r);
-                    }
-                    session.writePacket(buffer);
-                    return Result.Continued;
-                case SSH_MSG_USERAUTH_SUCCESS:
-                    log.debug("Received SSH_MSG_USERAUTH_SUCCESS");
-                    return Result.Success;
-                case SSH_MSG_USERAUTH_FAILURE:
-                    log.debug("Received SSH_MSG_USERAUTH_FAILURE");
-                    return Result.Failure;
-                default:
-                    log.debug("Received unknown packet {}", cmd);
-                    return Result.Continued;
-            }
-        }
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthPassword.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthPassword.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthPassword.java
deleted file mode 100644
index 8b43da6..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthPassword.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.client.auth.deprecated;
-
-import java.io.IOException;
-
-import org.apache.sshd.client.session.ClientSessionImpl;
-import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * TODO Add javadoc
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class UserAuthPassword extends AbstractUserAuth {
-
-    protected final Logger log = LoggerFactory.getLogger(getClass());
-
-    private final String password;
-
-    public UserAuthPassword(ClientSessionImpl session, String service, String password) {
-        super(session, service);
-        this.password = password;
-    }
-
-    public Result next(Buffer buffer) throws IOException {
-        if (buffer == null) {
-            log.debug("Send SSH_MSG_USERAUTH_REQUEST for password");
-            buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST);
-            buffer.putString(session.getUsername());
-            buffer.putString(service);
-            buffer.putString("password");
-            buffer.putByte((byte) 0);
-            buffer.putString(password);
-            session.writePacket(buffer);
-            return Result.Continued;
-        } else {
-            byte cmd = buffer.getByte();
-            if (cmd == SshConstants.SSH_MSG_USERAUTH_SUCCESS) {
-                log.debug("Received SSH_MSG_USERAUTH_SUCCESS");
-                return Result.Success;
-            } if (cmd == SshConstants.SSH_MSG_USERAUTH_FAILURE) {
-                log.debug("Received SSH_MSG_USERAUTH_FAILURE");
-                return Result.Failure;
-            } else {
-                log.debug("Received unkown packet {}", cmd);
-                // TODO: check packets
-                return Result.Continued;
-            }
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthPublicKey.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthPublicKey.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthPublicKey.java
deleted file mode 100644
index 5694847..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/client/auth/deprecated/UserAuthPublicKey.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.client.auth.deprecated;
-
-import java.io.IOException;
-import java.security.KeyPair;
-import java.security.interfaces.RSAPublicKey;
-
-import org.apache.sshd.client.session.ClientSessionImpl;
-import org.apache.sshd.common.KeyPairProvider;
-import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.Signature;
-import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.KeyUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * TODO Add javadoc
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class UserAuthPublicKey extends AbstractUserAuth {
-
-    protected final Logger log = LoggerFactory.getLogger(getClass());
-
-    private final KeyPair key;
-
-    public UserAuthPublicKey(ClientSessionImpl session, String service, KeyPair key) {
-        super(session, service);
-        this.key = key;
-    }
-
-    public Result next(Buffer buffer) throws IOException {
-        if (buffer == null) {
-            try {
-                log.debug("Send SSH_MSG_USERAUTH_REQUEST for publickey");
-                buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST);
-                int pos1 = buffer.wpos() - 1;
-                buffer.putString(session.getUsername());
-                buffer.putString(service);
-                buffer.putString("publickey");
-                buffer.putByte((byte) 1);
-                String alg = KeyUtils.getKeyType(key);
-                buffer.putString(alg);
-                int pos2 = buffer.wpos();
-                buffer.putPublicKey(key.getPublic());
-
-                Signature verif = NamedFactory.Utils.create(session.getFactoryManager().getSignatureFactories(), alg);
-                verif.init(key.getPublic(), key.getPrivate());
-
-                Buffer bs = new Buffer();
-                bs.putString(session.getKex().getH());
-                bs.putByte(SshConstants.SSH_MSG_USERAUTH_REQUEST);
-                bs.putString(session.getUsername());
-                bs.putString(service);
-                bs.putString("publickey");
-                bs.putByte((byte) 1);
-                bs.putString(alg);
-                bs.putPublicKey(key.getPublic());
-                verif.update(bs.array(), bs.rpos(), bs.available());
-
-                bs = new Buffer();
-                bs.putString(alg);
-                bs.putBytes(verif.sign());
-                buffer.putBytes(bs.array(), bs.rpos(), bs.available());
-
-                session.writePacket(buffer);
-                return Result.Continued;
-            } catch (IOException e) {
-                throw e;
-            } catch (Exception e) {
-                throw (IOException) new IOException("Error performing public key authentication").initCause(e);
-            }
-        } else {
-            byte cmd = buffer.getByte();
-            if (cmd == SshConstants.SSH_MSG_USERAUTH_SUCCESS) {
-                log.debug("Received SSH_MSG_USERAUTH_SUCCESS");
-                return Result.Success;
-            } if (cmd == SshConstants.SSH_MSG_USERAUTH_FAILURE) {
-                log.debug("Received SSH_MSG_USERAUTH_FAILURE");
-                return Result.Failure;
-            } else {
-                log.debug("Received unknown packet {}", cmd);
-                // TODO: check packets
-                return Result.Continued;
-            }
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/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 00a245e..382e8af 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
@@ -121,7 +121,6 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
         return invertedErr;
     }
 
-    @Deprecated
     public OutputStream getErr() {
         return err;
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/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 0024894..453c0ef 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
@@ -96,22 +96,6 @@ public class ChannelDirectTcpip extends AbstractClientChannel {
         }
     }
 
-    /**
-     * @deprecated Use {@link #getInvertedOut()} instead
-     */
-    @Deprecated
-    public InputStream getIn() {
-        return in;
-    }
-
-    /**
-     * @deprecated Use {@link #getInvertedIn()} instead
-     */
-    @Deprecated
-    public OutputStream getOut() {
-        return out;
-    }
-
     @Override
     protected void doWriteData(byte[] data, int off, int len) throws IOException {
         pipe.write(data, off, len);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/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 492f5f4..0e14596 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
@@ -34,11 +34,6 @@ import org.apache.sshd.client.ScpClient;
 import org.apache.sshd.client.ServerKeyVerifier;
 import org.apache.sshd.client.SftpClient;
 import org.apache.sshd.client.UserInteraction;
-import org.apache.sshd.client.auth.deprecated.UserAuth;
-import org.apache.sshd.client.auth.deprecated.UserAuthAgent;
-import org.apache.sshd.client.auth.deprecated.UserAuthKeyboardInteractive;
-import org.apache.sshd.client.auth.deprecated.UserAuthPassword;
-import org.apache.sshd.client.auth.deprecated.UserAuthPublicKey;
 import org.apache.sshd.client.channel.ChannelDirectTcpip;
 import org.apache.sshd.client.channel.ChannelExec;
 import org.apache.sshd.client.channel.ChannelShell;
@@ -76,14 +71,14 @@ public class ClientSessionImpl extends AbstractSession implements ClientSession
     /**
      * For clients to store their own metadata
      */
-    private Map<Object, Object> metadataMap = new HashMap<Object, Object>();
+    private Map<Object, Object> metadataMap = new HashMap<>();
 
     // TODO: clean service support a bit
     private boolean initialServiceRequestSent;
     private ServiceFactory currentServiceFactory;
     private Service nextService;
     private ServiceFactory nextServiceFactory;
-    private final List<Object> identities = new ArrayList<Object>();
+    private final List<Object> identities = new ArrayList<>();
     private UserInteraction userInteraction;
     private ScpTransferEventListener scpListener;
 
@@ -155,36 +150,13 @@ public class ClientSessionImpl extends AbstractSession implements ClientSession
         }
     }
 
-    public AuthFuture authAgent(String user) throws IOException {
-        return tryAuth(user, new UserAuthAgent(this, nextServiceName()));
-    }
-
-    public AuthFuture authPassword(String user, String password) throws IOException {
-        return tryAuth(user, new UserAuthPassword(this, nextServiceName(), password));
-    }
-
-    public AuthFuture authInteractive(String user, String password) throws IOException {
-        return tryAuth(user, new UserAuthKeyboardInteractive(this, nextServiceName(), password));
-    }
-
-    public AuthFuture authPublicKey(String user, KeyPair key) throws IOException {
-        return tryAuth(user, new UserAuthPublicKey(this, nextServiceName(), key));
-    }
-
-    private AuthFuture tryAuth(String user, UserAuth auth) throws IOException {
-        this.username = user;
-        synchronized (lock) {
-            return authFuture = getUserAuthService().auth(auth);
-        }
-    }
-
     private String nextServiceName() {
         synchronized (lock) {
             return nextServiceFactory.getName();
         }
     }
 
-    protected void switchToNextService() throws IOException {
+    public void switchToNextService() throws IOException {
         synchronized (lock) {
             if (nextService == null) {
                 throw new IllegalStateException("No service available");

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/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 3dfcced..cc1c655 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
@@ -19,24 +19,32 @@
 package org.apache.sshd.client.session;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
-import org.apache.sshd.client.auth.deprecated.UserAuth;
+import org.apache.sshd.client.ClientFactoryManager;
+import org.apache.sshd.client.UserAuth;
+import org.apache.sshd.client.UserInteraction;
 import org.apache.sshd.client.future.AuthFuture;
-import org.apache.sshd.common.Closeable;
+import org.apache.sshd.client.future.DefaultAuthFuture;
+import org.apache.sshd.common.FactoryManagerUtils;
+import org.apache.sshd.common.NamedFactory;
 import org.apache.sshd.common.Service;
 import org.apache.sshd.common.ServiceFactory;
 import org.apache.sshd.common.Session;
-import org.apache.sshd.common.future.DefaultCloseFuture;
+import org.apache.sshd.common.SshConstants;
+import org.apache.sshd.common.SshException;
 import org.apache.sshd.common.util.Buffer;
 import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.common.util.GenericUtils;
 
 /**
  * Client side <code>ssh-auth</code> service.
  *
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
-public class ClientUserAuthService extends CloseableUtils.AbstractInnerCloseable implements Service {
+public class ClientUserAuthService extends CloseableUtils.AbstractCloseable implements Service {
 
     public static class Factory implements ServiceFactory {
 
@@ -49,17 +57,45 @@ public class ClientUserAuthService extends CloseableUtils.AbstractInnerCloseable
         }
     }
 
+    /**
+     * The AuthFuture that is being used by the current auth request.  This encodes the state.
+     * isSuccess -> authenticated, else if isDone -> server waiting for user auth, else authenticating.
+     */
+    private final AuthFuture authFuture;
+
     protected final ClientSessionImpl session;
-    protected ClientUserAuthServiceNew delegateNew;
-    protected ClientUserAuthServiceOld delegateOld;
-    protected boolean started;
-    protected DefaultCloseFuture future = new DefaultCloseFuture(null);
+
+    private List<Object> identities;
+    private String service;
+
+    private List<NamedFactory<UserAuth>> authFactories;
+    private List<String> clientMethods;
+    private List<String> serverMethods;
+    private UserAuth userAuth;
 
     public ClientUserAuthService(Session s) {
         if (!(s instanceof ClientSessionImpl)) {
             throw new IllegalStateException("Client side service used on server side");
         }
         session = (ClientSessionImpl) s;
+        authFuture = new DefaultAuthFuture(session.getLock());
+        authFactories = session.getFactoryManager().getUserAuthFactories();
+        clientMethods = new ArrayList<>();
+
+        String prefs = FactoryManagerUtils.getString(session, ClientFactoryManager.PREFERRED_AUTHS);
+        if (!GenericUtils.isEmpty(prefs)) {
+            for (String pref : prefs.split(",")) {
+                if (NamedFactory.Utils.get(authFactories, pref) != null) {
+                    clientMethods.add(pref);
+                } else {
+                    log.debug("Skip unknown prefered authentication method: {}", pref);
+                }
+            }
+        } else {
+            for (NamedFactory<UserAuth> factory : authFactories) {
+                clientMethods.add(factory.getName());
+            }
+        }
     }
 
     public ClientSessionImpl getSession() {
@@ -67,57 +103,130 @@ public class ClientUserAuthService extends CloseableUtils.AbstractInnerCloseable
     }
 
     public void start() {
-        if (delegateNew != null) {
-            delegateNew.start();
-        } else if (delegateOld != null) {
-            delegateOld.start();
-        }
-        started = true;
     }
 
-    public void process(byte cmd, Buffer buffer) throws Exception {
-        if (delegateNew != null) {
-            delegateNew.process(cmd, buffer);
-        } else if (delegateOld != null) {
-            delegateOld.process(cmd, buffer);
-        } else {
-            throw new IllegalStateException();
-        }
+    public AuthFuture auth(List<Object> identities, String service) throws IOException {
+        log.debug("Start authentication");
+        this.identities = new ArrayList<>(identities);
+        this.service = service;
+
+        log.debug("Send SSH_MSG_USERAUTH_REQUEST for none");
+        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST);
+        buffer.putString(session.getUsername());
+        buffer.putString(service);
+        buffer.putString("none");
+        session.writePacket(buffer);
+
+        return authFuture;
     }
 
-    @Override
-    protected Closeable getInnerCloseable() {
-        if (delegateNew != null) {
-            return delegateNew;
-        } else if (delegateOld != null) {
-            return delegateOld;
+    public void process(byte cmd, Buffer buffer) throws Exception {
+        if (this.authFuture.isSuccess()) {
+            throw new IllegalStateException("UserAuth message delivered to authenticated client");
+        } else if (this.authFuture.isDone()) {
+            log.debug("Ignoring random message");
+            // ignore for now; TODO: random packets
+        } else if (cmd == SshConstants.SSH_MSG_USERAUTH_BANNER) {
+            String welcome = buffer.getString();
+            String lang = buffer.getString();
+            log.debug("Welcome banner(lang={}): {}", lang, welcome);
+            UserInteraction ui = session.getFactoryManager().getUserInteraction();
+            if (ui != null) {
+                ui.welcome(welcome);
+            }
         } else {
-            return builder().build();
+            buffer.rpos(buffer.rpos() - 1);
+            processUserAuth(buffer);
         }
     }
 
-    public AuthFuture auth(UserAuth userAuth) throws IOException {
-        if (delegateNew != null) {
-            throw new IllegalStateException();
+    private int currentMethod;
+
+    /**
+     * execute one step in user authentication.
+     * @param buffer
+     * @throws java.io.IOException
+     */
+    private void processUserAuth(Buffer buffer) throws Exception {
+        byte cmd = buffer.getByte();
+        if (cmd == SshConstants.SSH_MSG_USERAUTH_SUCCESS) {
+            log.info("Received SSH_MSG_USERAUTH_SUCCESS");
+            log.debug("Succeeded with {}", userAuth);
+            if (userAuth != null) {
+                userAuth.destroy();
+                userAuth = null;
+            }
+            session.setAuthenticated();
+            session.switchToNextService();
+            // Will wake up anyone sitting in waitFor
+            authFuture.setAuthed(true);
+            return;
         }
-        if (delegateOld == null) {
-            delegateOld = new ClientUserAuthServiceOld(session);
-            if (started) {
-                delegateOld.start();
+        if (cmd == SshConstants.SSH_MSG_USERAUTH_FAILURE) {
+            log.info("Received SSH_MSG_USERAUTH_FAILURE");
+            String mths = buffer.getString();
+            boolean partial = buffer.getBoolean();
+            if (partial || serverMethods == null) {
+                serverMethods = Arrays.asList(mths.split(","));
+                if (log.isDebugEnabled()) {
+                    StringBuilder sb = new StringBuilder("Authentications that can continue: ");
+                    for (int i = 0; i < serverMethods.size(); i++) {
+                        if (i > 0) {
+                            sb.append(", ");
+                        }
+                        sb.append(serverMethods.get(i));
+                    }
+                    log.debug(sb.toString());
+                }
+                if (userAuth != null) {
+                    userAuth.destroy();
+                    userAuth = null;
+                }
             }
+            tryNext();
+            return;
+        }
+        if (userAuth == null) {
+            throw new IllegalStateException("Received unknown packet");
+        }
+        buffer.rpos(buffer.rpos() - 1);
+        if (!userAuth.process(buffer)) {
+            tryNext();
         }
-        return delegateOld.auth(userAuth);
     }
 
-    public AuthFuture auth(List<Object> identities, String service) throws IOException {
-        if (delegateOld != null || delegateNew != null) {
-            throw new IllegalStateException();
+    private void tryNext() throws Exception {
+        // Loop until we find something to try
+        while (true) {
+            if (userAuth == null) {
+                currentMethod = 0;
+            } else if (!userAuth.process(null)) {
+                userAuth.destroy();
+                currentMethod++;
+            } else {
+                return;
+            }
+            while (currentMethod < clientMethods.size() && !serverMethods.contains(clientMethods.get(currentMethod))) {
+                currentMethod++;
+            }
+            if (currentMethod >= clientMethods.size()) {
+                // Failure
+                authFuture.setAuthed(false);
+                return;
+            }
+            String method = clientMethods.get(currentMethod);
+            userAuth = NamedFactory.Utils.create(authFactories, method);
+            assert userAuth != null;
+            userAuth.init(session, service, identities);
         }
-        delegateNew = new ClientUserAuthServiceNew(session);
-        if (started) {
-            delegateNew.start();
+    }
+
+    @Override
+    protected void preClose() {
+        super.preClose();
+        if (!authFuture.isDone()) {
+            authFuture.setException(new SshException("Session is closed"));
         }
-        return delegateNew.auth(identities, service);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthServiceNew.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthServiceNew.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthServiceNew.java
deleted file mode 100644
index 7e1f310..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthServiceNew.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.client.session;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.sshd.client.ClientFactoryManager;
-import org.apache.sshd.client.UserAuth;
-import org.apache.sshd.client.UserInteraction;
-import org.apache.sshd.client.future.AuthFuture;
-import org.apache.sshd.client.future.DefaultAuthFuture;
-import org.apache.sshd.common.FactoryManagerUtils;
-import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.Service;
-import org.apache.sshd.common.Session;
-import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.CloseableUtils;
-import org.apache.sshd.common.util.GenericUtils;
-
-/**
- * Client side <code>ssh-auth</code> service.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class ClientUserAuthServiceNew extends CloseableUtils.AbstractCloseable implements Service {
-
-    /**
-     * The AuthFuture that is being used by the current auth request.  This encodes the state.
-     * isSuccess -> authenticated, else if isDone -> server waiting for user auth, else authenticating.
-     */
-    private final AuthFuture authFuture;
-
-    protected final ClientSessionImpl session;
-
-    private List<Object> identities;
-    private String service;
-
-    private List<NamedFactory<UserAuth>> authFactories;
-    private List<String> clientMethods;
-    private List<String> serverMethods;
-    private UserAuth userAuth;
-
-    public ClientUserAuthServiceNew(Session s) {
-        if (!(s instanceof ClientSessionImpl)) {
-            throw new IllegalStateException("Client side service used on server side");
-        }
-        session = (ClientSessionImpl) s;
-        authFuture = new DefaultAuthFuture(session.getLock());
-        authFactories = session.getFactoryManager().getUserAuthFactories();
-        clientMethods = new ArrayList<String>();
-
-        String prefs = FactoryManagerUtils.getString(session, ClientFactoryManager.PREFERRED_AUTHS);
-        if (!GenericUtils.isEmpty(prefs)) {
-            for (String pref : prefs.split(",")) {
-                if (NamedFactory.Utils.get(authFactories, pref) != null) {
-                    clientMethods.add(pref);
-                } else {
-                    log.debug("Skip unknown prefered authentication method: {}", pref);
-                }
-            }
-        } else {
-            for (NamedFactory<UserAuth> factory : authFactories) {
-                clientMethods.add(factory.getName());
-            }
-        }
-    }
-
-    public ClientSessionImpl getSession() {
-        return session;
-    }
-
-    public void start() {
-    }
-
-    public AuthFuture auth(List<Object> identities, String service) throws IOException {
-        log.debug("Start authentication");
-        this.identities = new ArrayList<Object>(identities);
-        this.service = service;
-
-        log.debug("Send SSH_MSG_USERAUTH_REQUEST for none");
-        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST);
-        buffer.putString(session.getUsername());
-        buffer.putString(service);
-        buffer.putString("none");
-        session.writePacket(buffer);
-
-        return authFuture;
-    }
-
-    public void process(byte cmd, Buffer buffer) throws Exception {
-        if (this.authFuture.isSuccess()) {
-            throw new IllegalStateException("UserAuth message delivered to authenticated client");
-        } else if (this.authFuture.isDone()) {
-            log.debug("Ignoring random message");
-            // ignore for now; TODO: random packets
-        } else if (cmd == SshConstants.SSH_MSG_USERAUTH_BANNER) {
-            String welcome = buffer.getString();
-            String lang = buffer.getString();
-            log.debug("Welcome banner(lang={}): {}", lang, welcome);
-            UserInteraction ui = session.getFactoryManager().getUserInteraction();
-            if (ui != null) {
-                ui.welcome(welcome);
-            }
-        } else {
-            buffer.rpos(buffer.rpos() - 1);
-            processUserAuth(buffer);
-        }
-    }
-
-    private int currentMethod;
-
-    /**
-     * execute one step in user authentication.
-     * @param buffer
-     * @throws java.io.IOException
-     */
-    private void processUserAuth(Buffer buffer) throws Exception {
-        byte cmd = buffer.getByte();
-        if (cmd == SshConstants.SSH_MSG_USERAUTH_SUCCESS) {
-            log.info("Received SSH_MSG_USERAUTH_SUCCESS");
-            log.debug("Succeeded with {}", userAuth);
-            if (userAuth != null) {
-                userAuth.destroy();
-                userAuth = null;
-            }
-            session.setAuthenticated();
-            session.switchToNextService();
-            // Will wake up anyone sitting in waitFor
-            authFuture.setAuthed(true);
-            return;
-        }
-        if (cmd == SshConstants.SSH_MSG_USERAUTH_FAILURE) {
-            log.info("Received SSH_MSG_USERAUTH_FAILURE");
-            String mths = buffer.getString();
-            boolean partial = buffer.getBoolean();
-            if (partial || serverMethods == null) {
-                serverMethods = Arrays.asList(mths.split(","));
-                if (log.isDebugEnabled()) {
-                    StringBuilder sb = new StringBuilder("Authentications that can continue: ");
-                    for (int i = 0; i < serverMethods.size(); i++) {
-                        if (i > 0) {
-                            sb.append(", ");
-                        }
-                        sb.append(serverMethods.get(i));
-                    }
-                    log.debug(sb.toString());
-                }
-                if (userAuth != null) {
-                    userAuth.destroy();
-                    userAuth = null;
-                }
-            }
-            tryNext();
-            return;
-        }
-        if (userAuth == null) {
-            throw new IllegalStateException("Received unknown packet");
-        }
-        buffer.rpos(buffer.rpos() - 1);
-        if (!userAuth.process(buffer)) {
-            tryNext();
-        }
-    }
-
-    private void tryNext() throws Exception {
-        // Loop until we find something to try
-        while (true) {
-            if (userAuth == null) {
-                currentMethod = 0;
-            } else if (!userAuth.process(null)) {
-                userAuth.destroy();
-                currentMethod++;
-            } else {
-                return;
-            }
-            while (currentMethod < clientMethods.size() && !serverMethods.contains(clientMethods.get(currentMethod))) {
-                currentMethod++;
-            }
-            if (currentMethod >= clientMethods.size()) {
-                // Failure
-                authFuture.setAuthed(false);
-                return;
-            }
-            String method = clientMethods.get(currentMethod);
-            userAuth = NamedFactory.Utils.create(authFactories, method);
-            assert userAuth != null;
-            userAuth.init(session, service, identities);
-        }
-    }
-
-    @Override
-    protected void preClose() {
-        super.preClose();
-        if (!authFuture.isDone()) {
-            authFuture.setException(new SshException("Session is closed"));
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthServiceOld.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthServiceOld.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthServiceOld.java
deleted file mode 100644
index 73518b4..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientUserAuthServiceOld.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.client.session;
-
-import java.io.IOException;
-
-import org.apache.sshd.client.auth.deprecated.UserAuth;
-import org.apache.sshd.client.UserInteraction;
-import org.apache.sshd.client.future.AuthFuture;
-import org.apache.sshd.client.future.DefaultAuthFuture;
-import org.apache.sshd.common.Service;
-import org.apache.sshd.common.Session;
-import org.apache.sshd.common.SshConstants;
-import org.apache.sshd.common.SshException;
-import org.apache.sshd.common.future.CloseFuture;
-import org.apache.sshd.common.future.DefaultCloseFuture;
-import org.apache.sshd.common.util.Buffer;
-import org.apache.sshd.common.util.CloseableUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Client side <code>ssh-auth</code> service.
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class ClientUserAuthServiceOld extends CloseableUtils.AbstractCloseable implements Service {
-
-    /** Our logger */
-    protected final Logger log = LoggerFactory.getLogger(getClass());
-
-    /**
-     * When !authFuture.isDone() the current authentication
-     */
-    private UserAuth userAuth;
-
-    /**
-     * The AuthFuture that is being used by the current auth request.  This encodes the state.
-     * isSuccess -> authenticated, else if isDone -> server waiting for user auth, else authenticating.
-     */
-    private volatile AuthFuture authFuture;
-
-    protected final ClientSessionImpl session;
-    protected final Object lock;
-
-    public ClientUserAuthServiceOld(Session s) {
-        if (!(s instanceof ClientSessionImpl)) {
-            throw new IllegalStateException("Client side service used on server side");
-        }
-        session = (ClientSessionImpl) s;
-        lock = session.getLock();
-        // Maintain the current auth status in the authFuture.
-        authFuture = new DefaultAuthFuture(lock);
-    }
-
-    public ClientSessionImpl getSession() {
-        return session;
-    }
-
-    public void start() {
-        synchronized (lock) {
-            log.debug("accepted");
-            // kick start the authentication process by failing the pending auth.
-            this.authFuture.setAuthed(false);
-        }
-    }
-
-    public void process(byte cmd, Buffer buffer) throws Exception {
-        if (this.authFuture.isSuccess()) {
-            throw new IllegalStateException("UserAuth message delivered to authenticated client");
-        } else if (this.authFuture.isDone()) {
-            log.debug("Ignoring random message");
-            // ignore for now; TODO: random packets
-        } else if (cmd == SshConstants.SSH_MSG_USERAUTH_BANNER) {
-            String welcome = buffer.getString();
-            String lang = buffer.getString();
-            log.debug("Welcome banner: {}", welcome);
-            UserInteraction ui = session.getFactoryManager().getUserInteraction();
-            if (ui != null) {
-                ui.welcome(welcome);
-            }
-        } else {
-            buffer.rpos(buffer.rpos() - 1);
-            processUserAuth(buffer);
-        }
-    }
-
-    /**
-     * return true if/when ready for auth; false if never ready.
-     * @return server is ready and waiting for auth
-     */
-    private boolean readyForAuth(UserAuth userAuth) {
-        // isDone indicates that the last auth finished and a new one can commence.
-        while (!this.authFuture.isDone()) {
-            log.debug("waiting to send authentication");
-            try {
-                this.authFuture.await();
-            } catch (InterruptedException e) {
-                log.debug("Unexpected interrupt", e);
-                throw new RuntimeException(e);
-            }
-        }
-        if (this.authFuture.isSuccess()) {
-            log.debug("already authenticated");
-            throw new IllegalStateException("Already authenticated");
-        }
-        if (this.authFuture.getException() != null) {
-            log.debug("probably closed", this.authFuture.getException());
-            return false;
-        }
-        if (!this.authFuture.isFailure()) {
-            log.debug("unexpected state");
-            throw new IllegalStateException("Unexpected authentication state");
-        }
-        if (this.userAuth != null) {
-            log.debug("authentication already in progress");
-            throw new IllegalStateException("Authentication already in progress?");
-        }
-        // Set up the next round of authentication.  Each round gets a new lock.
-        this.userAuth = userAuth;
-        // The new future !isDone() - i.e., in progress blocking out other waits.
-        this.authFuture = new DefaultAuthFuture(lock);
-        log.debug("ready to try authentication with new lock");
-        return true;
-    }
-
-    /**
-     * execute one step in user authentication.
-     * @param buffer
-     * @throws java.io.IOException
-     */
-    private void processUserAuth(Buffer buffer) throws IOException {
-        log.debug("processing {}", userAuth);
-        switch (userAuth.next(buffer)) {
-            case Success:
-                log.debug("succeeded with {}", userAuth);
-                session.setAuthenticated();
-                session.switchToNextService();
-                // Will wake up anyone sitting in waitFor
-                authFuture.setAuthed(true);
-                break;
-            case Failure:
-                log.debug("failed with {}", userAuth);
-                this.userAuth = null;
-                // Will wake up anyone sitting in waitFor
-                this.authFuture.setAuthed(false);
-                break;
-            case Continued:
-                // Will wake up anyone sitting in waitFor
-                log.debug("continuing with {}", userAuth);
-                break;
-        }
-    }
-
-    @Override
-    protected void preClose() {
-        super.preClose();
-        if (!authFuture.isDone()) {
-            authFuture.setException(new SshException("Session is closed"));
-        }
-    }
-
-    public AuthFuture auth(UserAuth userAuth) throws IOException {
-        log.debug("Trying authentication with {}", userAuth);
-        synchronized (lock) {
-            if (readyForAuth(userAuth)) {
-                processUserAuth(null);
-            }
-            return authFuture;
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/common/TcpipForwarder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/TcpipForwarder.java b/sshd-core/src/main/java/org/apache/sshd/common/TcpipForwarder.java
index cfed8e3..bd77bf9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/TcpipForwarder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/TcpipForwarder.java
@@ -79,12 +79,6 @@ public interface TcpipForwarder extends Closeable {
      */
     void localPortForwardingCancelled(SshdSocketAddress local) throws IOException;
 
-    /**
-     * Close the forwarder
-     */
-    @Deprecated
-    void close();
-
     SshdSocketAddress startDynamicPortForwarding(SshdSocketAddress local) throws IOException;
 
     void stopDynamicPortForwarding(SshdSocketAddress local) throws IOException;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
index daede16..cb68ea4 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
@@ -175,10 +175,6 @@ public class DefaultTcpipForwarder extends CloseableUtils.AbstractInnerCloseable
         }
     }
 
-    public synchronized void close() {
-        close(true);
-    }
-
     @Override
     protected synchronized Closeable getInnerCloseable() {
         return builder().parallel(dynamicLocal.values()).close(acceptor).build();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/main/java/org/apache/sshd/common/io/IoService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/IoService.java b/sshd-core/src/main/java/org/apache/sshd/common/io/IoService.java
index 5c19a3e..be55b5f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/IoService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/IoService.java
@@ -26,9 +26,6 @@ import org.apache.sshd.common.Closeable;
  */
 public interface IoService extends Closeable {
 
-    @Deprecated
-    void dispose();
-
     /**
      * Returns the map of all sessions which are currently managed by this
      * service.  The key of map is the {@link IoSession#getId() ID} of the

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java b/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
index 8c1fb0b..95b23c6 100644
--- a/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
@@ -18,12 +18,21 @@
  */
 package org.apache.sshd;
 
+import java.io.IOException;
 import java.security.KeyPair;
+import java.util.Arrays;
 
+import org.apache.sshd.client.future.AuthFuture;
+import org.apache.sshd.client.session.ClientConnectionService;
+import org.apache.sshd.client.session.ClientSessionImpl;
 import org.apache.sshd.common.KeyPairProvider;
 import org.apache.sshd.common.io.IoSession;
 import org.apache.sshd.common.session.AbstractSession;
 import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.deprecated.ClientUserAuthServiceOld;
+import org.apache.sshd.deprecated.UserAuthKeyboardInteractive;
+import org.apache.sshd.deprecated.UserAuthPassword;
+import org.apache.sshd.deprecated.UserAuthPublicKey;
 import org.apache.sshd.server.ServerFactoryManager;
 import org.apache.sshd.server.session.ServerSession;
 import org.apache.sshd.server.session.SessionFactory;
@@ -74,25 +83,35 @@ public class AuthenticationTest extends BaseTest {
     @Test
     public void testChangeUser() throws Exception {
         SshClient client = SshClient.setUpDefaultClient();
+        client.setServiceFactories(Arrays.asList(
+                new ClientUserAuthServiceOld.Factory(),
+                new ClientConnectionService.Factory()
+        ));
         client.start();
-        ClientSession s = client.connect("localhost", port).await().getSession();
+        ClientSession s = client.connect(null, "localhost", port).await().getSession();
         s.waitFor(ClientSession.CLOSED | ClientSession.WAIT_AUTH, 0);
 
-        assertFalse(s.authPassword("user1", "the-password").await().isSuccess());
-        assertFalse(s.authPassword("user2", "the-password").await().isSuccess());
+        assertFalse(authPassword(s, "user1", "the-password").await().isSuccess());
+        assertFalse(authPassword(s, "user2", "the-password").await().isSuccess());
 
-        assertEquals(ClientSession.CLOSED, s.waitFor(ClientSession.CLOSED, 1000));
+        // Note that WAIT_AUTH flag should be false, but since the internal
+        // authentication future is not updated, it's still returned
+        assertEquals(ClientSession.CLOSED | ClientSession.WAIT_AUTH, s.waitFor(ClientSession.CLOSED, 1000));
         client.stop();
     }
 
     @Test
     public void testAuthPasswordOnly() throws Exception {
         SshClient client = SshClient.setUpDefaultClient();
+        client.setServiceFactories(Arrays.asList(
+                new ClientUserAuthServiceOld.Factory(),
+                new ClientConnectionService.Factory()
+        ));
         client.start();
-        ClientSession s = client.connect("localhost", port).await().getSession();
+        ClientSession s = client.connect(null, "localhost", port).await().getSession();
         s.waitFor(ClientSession.CLOSED | ClientSession.WAIT_AUTH, 0);
 
-        assertFalse(s.authPassword("smx", "smx").await().isSuccess());
+        assertFalse(authPassword(s, "smx", "smx").await().isSuccess());
 
         s.close(true);
         client.stop();
@@ -101,14 +120,18 @@ public class AuthenticationTest extends BaseTest {
     @Test
     public void testAuthKeyPassword() throws Exception {
         SshClient client = SshClient.setUpDefaultClient();
+        client.setServiceFactories(Arrays.asList(
+                new ClientUserAuthServiceOld.Factory(),
+                new ClientConnectionService.Factory()
+        ));
         client.start();
-        ClientSession s = client.connect("localhost", port).await().getSession();
+        ClientSession s = client.connect(null, "localhost", port).await().getSession();
         s.waitFor(ClientSession.CLOSED | ClientSession.WAIT_AUTH, 0);
 
         KeyPair pair = Utils.createTestHostKeyProvider().loadKey(KeyPairProvider.SSH_RSA);
-        assertFalse(s.authPublicKey("smx", pair).await().isSuccess());
+        assertFalse(authPublicKey(s, "smx", pair).await().isSuccess());
 
-        assertTrue(s.authPassword("smx", "smx").await().isSuccess());
+        assertTrue(authPassword(s, "smx", "smx").await().isSuccess());
 
         s.close(true);
         client.stop();
@@ -117,19 +140,41 @@ public class AuthenticationTest extends BaseTest {
     @Test
     public void testAuthKeyInteractive() throws Exception {
         SshClient client = SshClient.setUpDefaultClient();
+        client.setServiceFactories(Arrays.asList(
+                new ClientUserAuthServiceOld.Factory(),
+                new ClientConnectionService.Factory()
+        ));
         client.start();
-        ClientSession s = client.connect("localhost", port).await().getSession();
+        ClientSession s = client.connect(null, "localhost", port).await().getSession();
         s.waitFor(ClientSession.CLOSED | ClientSession.WAIT_AUTH, 0);
 
         KeyPair pair = Utils.createTestHostKeyProvider().loadKey(KeyPairProvider.SSH_RSA);
-        assertFalse(s.authPublicKey("smx", pair).await().isSuccess());
+        assertFalse(authPublicKey(s, "smx", pair).await().isSuccess());
 
-        assertTrue(s.authInteractive("smx", "smx").await().isSuccess());
+        assertTrue(authInteractive(s, "smx", "smx").await().isSuccess());
 
         s.close(true);
         client.stop();
     }
 
+    private AuthFuture authPassword(ClientSession s, String user, String pswd) throws IOException {
+        ((ClientSessionImpl) s).setUsername(user);
+        return s.getService(ClientUserAuthServiceOld.class)
+                .auth(new UserAuthPassword((ClientSessionImpl) s, "ssh-connection", pswd));
+    }
+
+    private AuthFuture authInteractive(ClientSession s, String user, String pswd) throws IOException {
+        ((ClientSessionImpl) s).setUsername(user);
+        return s.getService(ClientUserAuthServiceOld.class)
+                .auth(new UserAuthKeyboardInteractive((ClientSessionImpl) s, "ssh-connection", pswd));
+    }
+
+    private AuthFuture authPublicKey(ClientSession s, String user, KeyPair pair) throws IOException {
+        ((ClientSessionImpl) s).setUsername(user);
+        return s.getService(ClientUserAuthServiceOld.class)
+                .auth(new UserAuthPublicKey((ClientSessionImpl) s, "ssh-connection", pair));
+    }
+
     public static class TestSession extends ServerSession {
         public TestSession(ServerFactoryManager server, IoSession ioSession) throws Exception {
             super(server, ioSession);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ServerTest.java b/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
index 3c7e5bb..9e82ca6 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
@@ -40,6 +40,7 @@ import org.apache.sshd.client.SessionFactory;
 import org.apache.sshd.client.channel.ChannelExec;
 import org.apache.sshd.client.channel.ChannelShell;
 import org.apache.sshd.client.future.AuthFuture;
+import org.apache.sshd.client.session.ClientConnectionService;
 import org.apache.sshd.client.session.ClientSessionImpl;
 import org.apache.sshd.common.Channel;
 import org.apache.sshd.common.NamedFactory;
@@ -50,6 +51,7 @@ import org.apache.sshd.common.channel.WindowClosedException;
 import org.apache.sshd.common.io.IoSession;
 import org.apache.sshd.common.session.AbstractConnectionService;
 import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.deprecated.UserAuthPassword;
 import org.apache.sshd.server.Command;
 import org.apache.sshd.server.CommandFactory;
 import org.apache.sshd.server.Environment;
@@ -65,6 +67,8 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import org.apache.sshd.deprecated.ClientUserAuthServiceOld;
+
 /**
  * TODO Add javadoc
  *
@@ -106,13 +110,18 @@ public class ServerTest extends BaseTest {
         sshd.getProperties().put(SshServer.MAX_AUTH_REQUESTS, "10");
 
         client = SshClient.setUpDefaultClient();
+        client.setServiceFactories(Arrays.asList(
+                new ClientUserAuthServiceOld.Factory(),
+                new ClientConnectionService.Factory()
+        ));
         client.start();
-        ClientSession s = client.connect("localhost", port).await().getSession();
+        ClientSession s = client.connect("smx", "localhost", port).await().getSession();
         int nbTrials = 0;
         int res = 0;
         while ((res & ClientSession.CLOSED) == 0) {
             nbTrials ++;
-            s.authPassword("smx", "buggy");
+            s.getService(ClientUserAuthServiceOld.class)
+                    .auth(new UserAuthPassword((ClientSessionImpl) s, "ssh-connection", "buggy"));
             res = s.waitFor(ClientSession.CLOSED | ClientSession.WAIT_AUTH, 5000);
             if (res == ClientSession.TIMEOUT) {
                 throw new TimeoutException();
@@ -126,14 +135,19 @@ public class ServerTest extends BaseTest {
         sshd.getProperties().put(SshServer.MAX_AUTH_REQUESTS, "10");
 
         client = SshClient.setUpDefaultClient();
+        client.setServiceFactories(Arrays.asList(
+                new ClientUserAuthServiceOld.Factory(),
+                new ClientConnectionService.Factory()
+        ));
         client.start();
-        ClientSession s = client.connect("localhost", port).await().getSession();
+        ClientSession s = client.connect("smx", "localhost", port).await().getSession();
         int nbTrials = 0;
         AuthFuture authFuture;
         do {
             nbTrials++;
             assertTrue(nbTrials < 100);
-            authFuture = s.authPassword("smx", "buggy");
+            authFuture = s.getService(ClientUserAuthServiceOld.class)
+                    .auth(new UserAuthPassword((ClientSessionImpl) s, "ssh-connection", "buggy"));
             assertTrue(authFuture.await(5000));
             assertTrue(authFuture.isDone());
             assertFalse(authFuture.isSuccess());

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/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
new file mode 100644
index 0000000..0666192
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/AbstractUserAuth.java
@@ -0,0 +1,43 @@
+/*
+ * 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.deprecated;
+
+import org.apache.sshd.client.session.ClientSessionImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ */
+public abstract class AbstractUserAuth implements UserAuth {
+
+    protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+    protected final ClientSessionImpl session;
+    protected final String service;
+
+    protected AbstractUserAuth(ClientSessionImpl session, String service) {
+        this.session = session;
+        this.service = service;
+    }
+
+    public String getService() {
+        return service;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java
new file mode 100644
index 0000000..5265af0
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java
@@ -0,0 +1,199 @@
+/*
+ * 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.deprecated;
+
+import java.io.IOException;
+
+import org.apache.sshd.client.UserInteraction;
+import org.apache.sshd.client.future.AuthFuture;
+import org.apache.sshd.client.future.DefaultAuthFuture;
+import org.apache.sshd.client.session.ClientSessionImpl;
+import org.apache.sshd.common.Service;
+import org.apache.sshd.common.ServiceFactory;
+import org.apache.sshd.common.Session;
+import org.apache.sshd.common.SshConstants;
+import org.apache.sshd.common.SshException;
+import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.CloseableUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Client side <code>ssh-auth</code> service.
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public class ClientUserAuthServiceOld extends CloseableUtils.AbstractCloseable implements Service {
+
+    public static class Factory implements ServiceFactory {
+
+        public String getName() {
+            return "ssh-userauth";
+        }
+
+        public Service create(Session session) throws IOException {
+            return new ClientUserAuthServiceOld(session);
+        }
+    }
+
+    /** Our logger */
+    protected final Logger log = LoggerFactory.getLogger(getClass());
+
+    /**
+     * When !authFuture.isDone() the current authentication
+     */
+    private UserAuth userAuth;
+
+    /**
+     * The AuthFuture that is being used by the current auth request.  This encodes the state.
+     * isSuccess -> authenticated, else if isDone -> server waiting for user auth, else authenticating.
+     */
+    private volatile AuthFuture authFuture;
+
+    protected final ClientSessionImpl session;
+    protected final Object lock;
+
+    public ClientUserAuthServiceOld(Session s) {
+        if (!(s instanceof ClientSessionImpl)) {
+            throw new IllegalStateException("Client side service used on server side");
+        }
+        session = (ClientSessionImpl) s;
+        lock = session.getLock();
+        // Maintain the current auth status in the authFuture.
+        authFuture = new DefaultAuthFuture(lock);
+    }
+
+    public ClientSessionImpl getSession() {
+        return session;
+    }
+
+    public void start() {
+        synchronized (lock) {
+            log.debug("accepted");
+            // kick start the authentication process by failing the pending auth.
+            this.authFuture.setAuthed(false);
+        }
+    }
+
+    public void process(byte cmd, Buffer buffer) throws Exception {
+        if (this.authFuture.isSuccess()) {
+            throw new IllegalStateException("UserAuth message delivered to authenticated client");
+        } else if (this.authFuture.isDone()) {
+            log.debug("Ignoring random message");
+            // ignore for now; TODO: random packets
+        } else if (cmd == SshConstants.SSH_MSG_USERAUTH_BANNER) {
+            String welcome = buffer.getString();
+            String lang = buffer.getString();
+            log.debug("Welcome banner: {}", welcome);
+            UserInteraction ui = session.getFactoryManager().getUserInteraction();
+            if (ui != null) {
+                ui.welcome(welcome);
+            }
+        } else {
+            buffer.rpos(buffer.rpos() - 1);
+            processUserAuth(buffer);
+        }
+    }
+
+    /**
+     * return true if/when ready for auth; false if never ready.
+     * @return server is ready and waiting for auth
+     */
+    private boolean readyForAuth(UserAuth userAuth) {
+        // isDone indicates that the last auth finished and a new one can commence.
+        while (!this.authFuture.isDone()) {
+            log.debug("waiting to send authentication");
+            try {
+                this.authFuture.await();
+            } catch (InterruptedException e) {
+                log.debug("Unexpected interrupt", e);
+                throw new RuntimeException(e);
+            }
+        }
+        if (this.authFuture.isSuccess()) {
+            log.debug("already authenticated");
+            throw new IllegalStateException("Already authenticated");
+        }
+        if (this.authFuture.getException() != null) {
+            log.debug("probably closed", this.authFuture.getException());
+            return false;
+        }
+        if (!this.authFuture.isFailure()) {
+            log.debug("unexpected state");
+            throw new IllegalStateException("Unexpected authentication state");
+        }
+        if (this.userAuth != null) {
+            log.debug("authentication already in progress");
+            throw new IllegalStateException("Authentication already in progress?");
+        }
+        // Set up the next round of authentication.  Each round gets a new lock.
+        this.userAuth = userAuth;
+        // The new future !isDone() - i.e., in progress blocking out other waits.
+        this.authFuture = new DefaultAuthFuture(lock);
+        log.debug("ready to try authentication with new lock");
+        return true;
+    }
+
+    /**
+     * execute one step in user authentication.
+     * @param buffer
+     * @throws java.io.IOException
+     */
+    private void processUserAuth(Buffer buffer) throws IOException {
+        log.debug("processing {}", userAuth);
+        switch (userAuth.next(buffer)) {
+            case Success:
+                log.debug("succeeded with {}", userAuth);
+                session.setAuthenticated();
+                session.switchToNextService();
+                // Will wake up anyone sitting in waitFor
+                authFuture.setAuthed(true);
+                break;
+            case Failure:
+                log.debug("failed with {}", userAuth);
+                this.userAuth = null;
+                // Will wake up anyone sitting in waitFor
+                this.authFuture.setAuthed(false);
+                break;
+            case Continued:
+                // Will wake up anyone sitting in waitFor
+                log.debug("continuing with {}", userAuth);
+                break;
+        }
+    }
+
+    @Override
+    protected void preClose() {
+        super.preClose();
+        if (!authFuture.isDone()) {
+            authFuture.setException(new SshException("Session is closed"));
+        }
+    }
+
+    public AuthFuture auth(UserAuth userAuth) throws IOException {
+        log.debug("Trying authentication with {}", userAuth);
+        synchronized (lock) {
+            if (readyForAuth(userAuth)) {
+                processUserAuth(null);
+            }
+            return authFuture;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6824d759/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuth.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuth.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuth.java
new file mode 100644
index 0000000..d5aa426
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuth.java
@@ -0,0 +1,40 @@
+/*
+ * 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.deprecated;
+
+import java.io.IOException;
+
+import org.apache.sshd.common.util.Buffer;
+
+/**
+ * TODO Add javadoc
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public interface UserAuth {
+
+    enum Result {
+        Success,
+        Failure,
+        Continued
+    }
+
+    Result next(Buffer buffer) throws IOException;
+
+}