// Send the authentication request
ByteArrayWriter baw = new ByteArrayWriter();
baw.writeString("");
baw.writeString("");
SshMessage msg = new SshMsgUserAuthRequest(getUsername(),
serviceToStart, getMethodName(), baw.toByteArray());
authentication.sendMessage(msg);
// Read a message
while (true) {
msg = authentication.readMessage(SshMsgUserAuthInfoRequest.SSH_MSG_USERAUTH_INFO_REQUEST);
if (msg instanceof SshMsgUserAuthInfoRequest) {
SshMsgUserAuthInfoRequest request = (SshMsgUserAuthInfoRequest) msg;
KBIPrompt[] prompts = request.getPrompts();
handler.showPrompts(request.getName(),
request.getInstruction(), prompts);
// Now send the response message
msg = new SshMsgUserAuthInfoResponse(prompts);
authentication.sendMessage(msg);
} else {
throw new AuthenticationProtocolException(
"Unexpected authentication message " +
msg.getMessageName());
}
}
}