public class KBIAuthentication extends Object implements AuthenticationClient
keyboard-interactive authentication implementation as specified in draft-ietf-secsh-auth-kbdinteract-04.txt. Keyboard interactive provides a challenge-response type authentication which allows clients to support authentication mechanisms where the actual specification is not known.
The process works by the client first requesting the keyboard-interactive method; the server then responds with any number of prompts to which the user must provide an answer. This is acheived through the use of the KBIRequestHandler interface.
KBIAuthentication kbi = new KBIAuthentication(); kbi.setKBIRequestHandler(new KBIRequestHandler() { public void showPrompts(String name, String instruction, KBIPrompt[] prompts) { try { System.out.println(name); System.out.println(instruction); for (int i = 0; i & ltprompts.length; i++) { System.out.print(prompts[i].getPrompt()); prompts[i].setResponse(reader.readLine()); } } catch (IOException e) { e.printStackTrace(); } } }); ssh.authenticate(kbi);
Special care should be taken to check the echo flag of the KBIPrompt if set to false the user reponse entered by the user should not be echo'd back to the screen, for example in the process of entering a password.
CANCELLED, COMPLETE, FAILED, FURTHER_AUTHENTICATION_REQUIRED, PUBLIC_KEY_ACCEPTABLE
Constructor and Description |
---|
KBIAuthentication() |
KBIAuthentication(KBIRequestHandler handler) |
Modifier and Type | Method and Description |
---|---|
void |
authenticate(AuthenticationProtocol authentication,
String servicename)
Perform the authentication according to the specification.
|
String |
getMethod()
The SSH authentication method name
|
String |
getMethodName() |
String |
getUsername()
Get the username for this authentication attempt.
|
void |
setKBIRequestHandler(KBIRequestHandler handler)
Set the KBIRequestHandler for this
authentication attempt.
|
void |
setUsername(String username)
Set the username for this authentication attempt.
|
public KBIAuthentication()
public KBIAuthentication(KBIRequestHandler handler)
public String getUsername()
SshAuthentication
getUsername
in interface SshAuthentication
public void setUsername(String username)
SshAuthentication
setUsername
in interface SshAuthentication
public String getMethod()
SshAuthentication
getMethod
in interface SshAuthentication
public void setKBIRequestHandler(KBIRequestHandler handler)
handler
- public void authenticate(AuthenticationProtocol authentication, String servicename) throws SshException, AuthenticationResult
AuthenticationClient
authenticate
in interface AuthenticationClient
AuthenticationResult
SshException
public String getMethodName()
Copyright © 2024. All rights reserved.