本文整理汇总了Java中org.apache.sshd.server.auth.UserAuthPassword类的典型用法代码示例。如果您正苦于以下问题:Java UserAuthPassword类的具体用法?Java UserAuthPassword怎么用?Java UserAuthPassword使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserAuthPassword类属于org.apache.sshd.server.auth包,在下文中一共展示了UserAuthPassword类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupSftpServer
import org.apache.sshd.server.auth.UserAuthPassword; //导入依赖的package包/类
public void setupSftpServer() throws IOException {
sshd = SshServer.setUpDefaultServer();
sshd.setHost("127.0.0.1");
sshd.setPort(4922);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("target/hostkey.ser"));
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
return "ftpuser".equals(username) && "topsecret".equals(password);
}
});
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setCommandFactory(new ScpCommandFactory());
List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
// prepare directory for test files
VirtualFileSystemFactory fileSystemFactory = new VirtualFileSystemFactory(ROOT.getAbsolutePath());
sshd.setFileSystemFactory(fileSystemFactory);
sshd.start();
}
示例2: start
import org.apache.sshd.server.auth.UserAuthPassword; //导入依赖的package包/类
public void start() {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(configuration.port());
sshd.setKeyPairProvider(keyPairProvider);
setupUserHomeDirectories();
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setPasswordAuthenticator(new SftpUserBackedPasswordAuthenticator(loginToUserDictionary()));
userAuthFactories.add(new UserAuthPublicKey.Factory());
sshd.setPublickeyAuthenticator(new SftpUserBackedPublicKeyAuthenticator(loginToUserDictionary()));
sshd.setUserAuthFactories(userAuthFactories);
sshd.setCommandFactory(new ScpCommandFactory());
List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
try {
sshd.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: startSshdServer
import org.apache.sshd.server.auth.UserAuthPassword; //导入依赖的package包/类
private static void startSshdServer() throws IOException {
sshd = SshServer.setUpDefaultServer();
// ask OS to assign a port
sshd.setPort(0);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
List<NamedFactory<UserAuth>> userAuthFactories =
new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password,
ServerSession session) {
if (username.equals("user") && password.equals("password")) {
return true;
}
return false;
}
});
sshd.setSubsystemFactories(
Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.start();
port = sshd.getPort();
}
示例4: startSSHServer
import org.apache.sshd.server.auth.UserAuthPassword; //导入依赖的package包/类
@BeforeClass
public static void startSSHServer() throws Exception {
// Disable bouncy castle to avoid versions conflict
System.setProperty("org.apache.sshd.registerBouncyCastle", "false");
sshd = SshServer.setUpDefaultServer();
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<>(1);
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
return username != null && username.equals(password);
}
});
sshd.setCommandFactory(new ScpCommandFactory(new CommandFactory() {
@Override
public Command createCommand(String command) {
String[] splitCommand;
if (OsUtils.isUNIX()) {
splitCommand = SSHInfrastructureHelper.splitCommand(command);
} else if (OsUtils.isWin32()) {
splitCommand = SSHInfrastructureHelper.splitCommandWithoutRemovingQuotes(command);
} else {
throw new IllegalStateException("Operating system is not recognized");
}
StringBuilder rebuiltCommand = new StringBuilder();
for (String commandPiece : splitCommand) {
rebuiltCommand.append(commandPiece).append(" ");
}
rebuiltCommand.trimToSize();
EnumSet<ProcessShellFactory.TtyOptions> ttyOptions;
if (OsUtils.isUNIX()) {
ttyOptions = EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr);
} else {
ttyOptions = EnumSet.of(ProcessShellFactory.TtyOptions.Echo,
ProcessShellFactory.TtyOptions.ICrNl,
ProcessShellFactory.TtyOptions.ONlCr);
}
if (OsUtils.isUNIX()) {
return new ProcessShellFactory(new String[] { "/bin/sh", "-c", rebuiltCommand.toString() },
ttyOptions).create();
} else {
return new ProcessShellFactory(new String[] { "cmd.exe", "/C", rebuiltCommand.toString() },
ttyOptions).create();
}
}
}));
sshd.start();
port = sshd.getPort();
javaExePath = System.getProperty("java.home") + File.separator + "bin" + File.separator +
(OsUtils.isWin32() ? "java.exe" : "java");
javaExePath = "\"" + javaExePath + "\"";
infraParams = new Object[] { ("localhost " + NB_NODES + "\n").getBytes(), //hosts
60000, //timeout
0, //attempts
10, //wait between failures
port, //ssh server port
"toto", //ssh username
"toto", //ssh password
new byte[0], // optional ssh private key
new byte[0], // optional ssh options file
javaExePath, //java path on the remote machines
PAResourceManagerProperties.RM_HOME.getValueAsString(), //Scheduling path on remote machines
OperatingSystem.getOperatingSystem(), "" }; // extra java options
policyParameters = new Object[] { AccessType.ALL.toString(), AccessType.ALL.toString(), "20000" };
}
示例5: start
import org.apache.sshd.server.auth.UserAuthPassword; //导入依赖的package包/类
@Override
public void start() {
this.sshd = SshServer.setUpDefaultServer();
this.sshd.setPort(8022);
this.sshd.setHost("192.168.0.13");
this.sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(
"/Work/Keys/testsshdkeys"));
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
// userAuthFactories.add(new UserAuthPublicKey.Factory());
userAuthFactories.add(new UserAuthPassword.Factory());
this.sshd.setUserAuthFactories(userAuthFactories);
/*
* this.sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
*
* @Override public boolean authenticate(String user, PublicKey key,
* ServerSession session) { //session. return "jack".equals(user); } });
*/
this.sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String user, String password,
ServerSession sess) {
boolean auth = "jack".equals(user);
if (auth) {
ApiSession apisess = SshdModule.this.apimap.get(sess);
if (apisess == null) {
apisess = ApiSession.createLocalSession("root");
SshdModule.this.apimap.put(sess, apisess);
System.out.println("Adding ssh session: " + sess.getId());
} else
System.out.println("Reusing ssh session: " + sess.getId());
}
return auth;
}
});
// this.sshd.setCommandFactory(new ScpCommandFactory(new CommonCommandFactory()));
this.sshd.setCommandFactory(new ScpCommandFactory());
List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
this.sshd.setSubsystemFactories(namedFactoryList);
this.sshd.setFileSystemFactory(new FileSystemFactoryImpl(this));
try {
this.sshd.start();
} catch (Exception x) {
Logger.error("Error starting sshd module: " + x);
}
}