diff --git a/src/main/java/com/jcraft/jsch/Session.java b/src/main/java/com/jcraft/jsch/Session.java index 22a0c103..cfdf2438 100644 --- a/src/main/java/com/jcraft/jsch/Session.java +++ b/src/main/java/com/jcraft/jsch/Session.java @@ -161,6 +161,8 @@ public class Session { private volatile long kex_start_time = 0L; + private String auth_method = null; + int max_auth_tries = 6; int auth_failures = 0; @@ -425,6 +427,8 @@ public void connect(int connectTimeout) throws JSchException { // smethods = "publickey,password,keyboard-interactive"; smethods = cmethods; } + } else { + auth_method = "none"; } String[] smethoda = Util.split(smethods, ","); @@ -477,6 +481,9 @@ public void connect(int connectTimeout) throws JSchException { auth_cancel = false; try { auth = ua.start(this); + if (auth) { + auth_method = method; + } if (auth && getLogger().isEnabled(Logger.INFO)) { getLogger().log(Logger.INFO, "Authentication succeeded (" + method + ")."); } @@ -2946,6 +2953,15 @@ public void setDaemonThread(boolean enable) { this.daemon_thread = enable; } + /** + * Get the authentication method used + * + * @return authenticate method or null if not authenticated + */ + public String getAuthMethod() { + return auth_method; + } + private String[] checkCiphers(String ciphers) { if (ciphers == null || ciphers.length() == 0) return null;