Skip to content

Commit

Permalink
Always show prompt after initially sending password.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Nov 21, 2017
1 parent a849111 commit d16fc9d
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import net.schmizz.sshj.userauth.method.AuthKeyboardInteractive;
import net.schmizz.sshj.userauth.method.ChallengeResponseProvider;
Expand All @@ -59,6 +60,10 @@ public Boolean authenticate(final Host bookmark, final HostPasswordStore keychai
}
try {
session.getClient().auth(bookmark.getCredentials().getUsername(), new AuthKeyboardInteractive(new ChallengeResponseProvider() {
/**
* Password sent flag
*/
private final AtomicBoolean password = new AtomicBoolean();
private String name = StringUtils.EMPTY;
private String instruction = StringUtils.EMPTY;

Expand All @@ -79,14 +84,15 @@ public void init(final Resource resource, final String name, final String instru

@Override
public char[] getResponse(final String prompt, final boolean echo) {
// For each prompt, the corresponding echo field indicates whether the user input should be echoed as characters are typed
if(log.isDebugEnabled()) {
log.debug(String.format("Reply to challenge name %s with instruction %s", name, instruction));
}
if(echo) {
// For each prompt, the corresponding echo field indicates whether the user input should be echoed as characters are typed
return EMPTY_RESPONSE;
}
if(PasswordResponseProvider.DEFAULT_PROMPT_PATTERN.matcher(prompt).matches()) {
if(!password.get() && PasswordResponseProvider.DEFAULT_PROMPT_PATTERN.matcher(prompt).matches()) {
password.set(true);
return bookmark.getCredentials().getPassword().toCharArray();
}
else {
Expand Down

0 comments on commit d16fc9d

Please sign in to comment.