本文整理汇总了Java中org.apache.sshd.common.keyprovider.AbstractKeyPairProvider类的典型用法代码示例。如果您正苦于以下问题:Java AbstractKeyPairProvider类的具体用法?Java AbstractKeyPairProvider怎么用?Java AbstractKeyPairProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractKeyPairProvider类属于org.apache.sshd.common.keyprovider包,在下文中一共展示了AbstractKeyPairProvider类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: KeyCapture
import org.apache.sshd.common.keyprovider.AbstractKeyPairProvider; //导入依赖的package包/类
public KeyCapture() {
sshd.setPort(9422);
sshd.setPublickeyAuthenticator((username, key, session) -> {
final String expectedKey;
final String fingerprint = fingerprint(key);
synchronized (KeyCapture.this) {
final String newUser = issuedTokens.get(username);
if (null != newUser) {
userDatabase.put(newUser, fingerprint);
session.setAttribute(JUST_ADDED, true);
session.setAttribute(ACCOUNT_NAME, username);
return true;
}
expectedKey = userDatabase.get(username);
}
logger.info("{} trying to authenticate with {}, db contains {}", username, fingerprint, expectedKey);
if (null == expectedKey || !expectedKey.equals(fingerprint)) {
return false;
}
session.setAttribute(ACCOUNT_NAME, username);
session.setAttribute(JUST_ADDED, false);
return true;
});
sshd.setKeyPairProvider(new AbstractKeyPairProvider() {
@Override
public Iterable<KeyPair> loadKeys() {
return Collections.singleton(serverKeyPair);
}
});
sshd.setShellFactory(CommandWrapper.wrap((in, out, err, session) -> {
try (final PrintStream ps = new PrintStream(out)) {
final String whom = session.getAttribute(ACCOUNT_NAME);
if (session.getAttribute(JUST_ADDED)) {
ps.println("Added successfully! You can now log-in normally.\r");
synchronized (KeyCapture.this) {
issuedTokens.remove(whom);
}
return 0;
}
ps.println("Hi! You've successfully authenticated as " + whom + "\r");
ps.println("Bye!\r");
}
return 0;
}));
}