本文整理汇总了Java中org.apache.sshd.client.auth.keyboard.UserInteraction类的典型用法代码示例。如果您正苦于以下问题:Java UserInteraction类的具体用法?Java UserInteraction怎么用?Java UserInteraction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserInteraction类属于org.apache.sshd.client.auth.keyboard包,在下文中一共展示了UserInteraction类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.sshd.client.auth.keyboard.UserInteraction; //导入依赖的package包/类
@Override
public void process(int cmd, Buffer buffer) throws Exception {
if (this.authFuture.isSuccess()) {
throw new IllegalStateException("UserAuth message delivered to authenticated client");
} else if (this.authFuture.isDone()) {
log.debug("Ignoring random message");
// ignore for now; TODO: random packets
} else if (cmd == SshConstants.SSH_MSG_USERAUTH_BANNER) {
String welcome = buffer.getString();
String lang = buffer.getString();
log.debug("Welcome banner[{}]: {}", lang, welcome);
UserInteraction ui = session.getUserInteraction();
if ((ui != null) && ui.isInteractionAllowed(session)) {
ui.welcome(session, welcome, lang);
}
} else {
buffer.rpos(buffer.rpos() - 1);
processUserAuth(buffer);
}
}
示例2: next
import org.apache.sshd.client.auth.keyboard.UserInteraction; //导入依赖的package包/类
@Override
public Result next(Buffer buffer) throws IOException {
ClientSession session = getClientSession();
String service = getService();
if (buffer == null) {
log.debug("Send SSH_MSG_USERAUTH_REQUEST for password");
buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_REQUEST);
buffer.putString(session.getUsername());
buffer.putString(service);
buffer.putString("keyboard-interactive");
buffer.putString("");
buffer.putString("");
session.writePacket(buffer);
return Result.Continued;
} else {
int cmd = buffer.getUByte();
switch (cmd) {
case SshConstants.SSH_MSG_USERAUTH_INFO_REQUEST: {
String name = buffer.getString();
String instruction = buffer.getString();
String language_tag = buffer.getString();
if (log.isDebugEnabled()) {
log.debug("next({}) Received SSH_MSG_USERAUTH_INFO_REQUEST - name={}, instruction={}, lang={}",
session, name, instruction, language_tag);
}
int num = buffer.getInt();
String[] prompt = new String[num];
boolean[] echo = new boolean[num];
for (int i = 0; i < num; i++) {
prompt[i] = buffer.getString();
echo[i] = buffer.getBoolean();
}
log.debug("Promt: {}", Arrays.toString(prompt));
log.debug("Echo: {}", echo);
String[] rep = null;
if (num == 0) {
rep = new String[0];
} else if (num == 1 && password != null && !echo[0] && prompt[0].toLowerCase().startsWith("password:")) {
rep = new String[]{password};
} else {
UserInteraction ui = session.getUserInteraction();
if ((ui != null) && ui.isInteractionAllowed(session)) {
rep = ui.interactive(session, name, instruction, language_tag, prompt, echo);
}
}
if (rep == null) {
return Result.Failure;
}
buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_INFO_RESPONSE);
buffer.putInt(rep.length);
for (String r : rep) {
buffer.putString(r);
}
session.writePacket(buffer);
return Result.Continued;
}
case SshConstants.SSH_MSG_USERAUTH_SUCCESS:
log.debug("Received SSH_MSG_USERAUTH_SUCCESS");
return Result.Success;
case SshConstants.SSH_MSG_USERAUTH_FAILURE:
{
String methods = buffer.getString();
boolean partial = buffer.getBoolean();
if (log.isDebugEnabled()) {
log.debug("Received SSH_MSG_USERAUTH_FAILURE - partial={}, methods={}", partial, methods);
}
return Result.Failure;
}
default:
log.debug("Received unknown packet {}", Integer.valueOf(cmd));
return Result.Continued;
}
}
}
示例3: getUserInteraction
import org.apache.sshd.client.auth.keyboard.UserInteraction; //导入依赖的package包/类
@Override
public UserInteraction getUserInteraction() {
throw new RuntimeException("Not implemented");
}
示例4: setUserInteraction
import org.apache.sshd.client.auth.keyboard.UserInteraction; //导入依赖的package包/类
@Override
public void setUserInteraction(UserInteraction userInteraction) {
throw new RuntimeException("Not implemented");
}