Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose authentication method in the Session to clients. #625

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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