Skip to content

Commit

Permalink
Expose authentication method in the Session to clients.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitrii Beliakov committed Aug 19, 2024
1 parent d064f44 commit ede630d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/jcraft/jsch/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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, ",");
Expand Down Expand Up @@ -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 + ").");
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ede630d

Please sign in to comment.