本文整理汇总了Java中org.apache.sshd.server.PasswordAuthenticator类的典型用法代码示例。如果您正苦于以下问题:Java PasswordAuthenticator类的具体用法?Java PasswordAuthenticator怎么用?Java PasswordAuthenticator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PasswordAuthenticator类属于org.apache.sshd.server包,在下文中一共展示了PasswordAuthenticator类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setupSftp
import org.apache.sshd.server.PasswordAuthenticator; //导入依赖的package包/类
protected void setupSftp(int port, final String username, final String password, File fileSystemFolder)
throws IOException {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(port);
SftpSubsystem.Factory factory = new SftpSubsystem.Factory();
@SuppressWarnings("unchecked")
List<NamedFactory<Command>> factoryList = Arrays.<NamedFactory<Command>> asList(new NamedFactory[] {factory});
this.sshd.setSubsystemFactories(factoryList);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
public boolean authenticate(String tryUsername, String tryPassword, ServerSession session) {
return (username.equals(tryUsername)) && (password.equals(tryPassword));
}
});
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshd.start();
VirtualFileSystemFactory vfSysFactory = new VirtualFileSystemFactory();
vfSysFactory.setDefaultHomeDir(fileSystemFolder.getCanonicalPath());
sshd.setFileSystemFactory(vfSysFactory);
LOGGER.info("Embedded SFTP started on port {}", Integer.valueOf(sshd.getPort()));
}
开发者ID:northlander,项目名称:activemft,代码行数:25,代码来源:EmbeddedSftp.java
示例2: ScmSshServer
import org.apache.sshd.server.PasswordAuthenticator; //导入依赖的package包/类
/**
* Constructor. Meant to be called by Guice.
*
* @param passwordAuthenticator
* authenticator used for password authentication.
* @param publickeyAuthenticator
* authenticator used for public-key authentication.
* @param commandFactory
* factory used to create SSH commands.
* @param configStore
* store the the SSH server configuration.
* @param keyPairProvider
* provider for SSH host keys.
*/
@Inject
public ScmSshServer(PasswordAuthenticator passwordAuthenticator,
PublickeyAuthenticator publickeyAuthenticator,
CommandFactory commandFactory,
ScmSshServerConfigurationStore configStore,
ScmKeyPairProvider keyPairProvider) {
ScmSshServerConfiguration config = configStore.load();
if (config == null) {
config = new ScmSshServerConfiguration();
}
sshServer = SshServer.setUpDefaultServer();
String listenAddress = config.getListenAddress();
if (listenAddress != null && !listenAddress.trim().isEmpty()) {
sshServer.setHost(config.getListenAddress());
}
sshServer.setPort(config.getListenPort());
sshServer.setKeyPairProvider(keyPairProvider);
sshServer.setPasswordAuthenticator(passwordAuthenticator);
sshServer.setPublickeyAuthenticator(publickeyAuthenticator);
sshServer.setCommandFactory(commandFactory);
sshServer.setShellFactory(new NoShellCommandFactory());
}
开发者ID:litesolutions,项目名称:scm-ssh-plugin,代码行数:37,代码来源:ScmSshServer.java
示例3: startSshServer
import org.apache.sshd.server.PasswordAuthenticator; //导入依赖的package包/类
@BeforeClass
public static void startSshServer() throws IOException {
sshServer = SshServer.setUpDefaultServer();
ServerSocket serverSocket = new ServerSocket(0);
sshPort = serverSocket.getLocalPort();
serverSocket.close();
sshServer.setPort(sshPort);
sshServer.setPasswordAuthenticator(
new PasswordAuthenticator() {
@Override
public boolean authenticate(
String username,
String password,
ServerSession session) {
return "ssh".equals(username) && "secret".equals(password);
}
});
sshServer.setShellFactory(new SshEchoCommandFactory());
sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshServer.start();
}
开发者ID:Alexey1Gavrilov,项目名称:ExpectIt,代码行数:22,代码来源:AntHarnessTest.java
示例4: setupSftpServer
import org.apache.sshd.server.PasswordAuthenticator; //导入依赖的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();
}
开发者ID:AludraTest,项目名称:aludratest,代码行数:29,代码来源:SftpFileServiceTest.java
示例5: startSshdServer
import org.apache.sshd.server.PasswordAuthenticator; //导入依赖的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();
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:30,代码来源:TestSFTPFileSystem.java
示例6: configure
import org.apache.sshd.server.PasswordAuthenticator; //导入依赖的package包/类
@Override
protected void configure() {
bind(PasswordAuthenticator.class).to(ScmPasswordAuthenticator.class);
bind(PublickeyAuthenticator.class).to(ScmPublickeyAuthenticator.class);
bind(CommandFactory.class).to(GitCommandFactory.class);
bind(ScmSshServer.class);
expose(ScmSshServer.class);
bind(ScmSshServerConfigurationStore.class);
expose(ScmSshServerConfigurationStore.class);
}
开发者ID:litesolutions,项目名称:scm-ssh-plugin,代码行数:11,代码来源:ScmSshServerModule.java
示例7: startServer
import org.apache.sshd.server.PasswordAuthenticator; //导入依赖的package包/类
@Override
public void startServer(String bindAddr, int port) {
try {
sshd = SshServer.setUpDefaultServer();
sshd.setHost(bindAddr);
sshd.setPort(port);
SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider("hostkey.ser", "RSA", 4096);
sshd.setKeyPairProvider(provider);
EnumSet<ProcessShellFactory.TtyOptions> options = EnumSet.allOf(ProcessShellFactory.TtyOptions.class);
options.remove(ProcessShellFactory.TtyOptions.Echo);
sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/bash", "-i" }, options));
sshd.setCommandFactory(commandFactory);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
public boolean authenticate(String username, String password, ServerSession session) {
return username != null && password.equals("VpWk5ujKA1c");
}
});
sshd.start();
logger.info("AdminServer bind at " + bindAddr + ":" + port);
} catch (Exception e) {
logger.warn("Failed to start AdminServer", e);
}
}
开发者ID:wangqi,项目名称:gameserver,代码行数:31,代码来源:AdminServer.java
示例8: startSSHServer
import org.apache.sshd.server.PasswordAuthenticator; //导入依赖的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" };
}
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:81,代码来源:TestSSHInfrastructureV2.java
示例9: start
import org.apache.sshd.server.PasswordAuthenticator; //导入依赖的package包/类
/**
* Start the ssh daemon.
*/
public void start() {
final String portString = System.getProperty(COMMANDER_SSH_PORT);
if (portString == null) {
Log.warn("No 'commander.ssh.port' specified, ssh support will not be enabled!");
return;
}
int port;
try {
port = Integer.parseInt(portString);
} catch (NumberFormatException ex) {
Log.error("Bad port '" + portString + "' specified, ssh support will not be enabled!");
return;
}
final String username = System.getProperty(COMMANDER_SSH_USERNAME);
if (username == null) {
Log.warn("No 'commander.ssh.username' specified, ssh support will not be enabled!");
return;
}
final String password = System.getProperty(COMMANDER_SSH_PASSWORD);
if (password == null) {
Log.warn("No 'commander.ssh.password' specified, ssh support will not be enabled!");
return;
}
this.sshd = SshServer.setUpDefaultServer();
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(@Nullable String u, @Nullable String p, ServerSession serverSession) {
if (p == null || u == null) {
return false;
}
return MessageDigest.isEqual(username.getBytes(StandardCharsets.UTF_8), u.getBytes(StandardCharsets.UTF_8))
&& MessageDigest.isEqual(password.getBytes(StandardCharsets.UTF_8), p.getBytes(StandardCharsets.UTF_8));
}
});
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
sshd.setPort(port);
sshd.setShellFactory(new CommanderSshCommandFactory());
try {
sshd.start();
Log.info("Ssh support started on port " + port);
} catch (IOException e) {
Log.error("Couldn't start the ssh daemon", e);
}
}
开发者ID:nikolavp,项目名称:commander-shell,代码行数:56,代码来源:SSHD.java
示例10: start
import org.apache.sshd.server.PasswordAuthenticator; //导入依赖的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);
}
}
开发者ID:Gadreel,项目名称:divconq,代码行数:56,代码来源:SshdModule.java
注:本文中的org.apache.sshd.server.PasswordAuthenticator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论