org.apache.sshd.server.PasswordAuthenticator Java Examples
The following examples show how to use
org.apache.sshd.server.PasswordAuthenticator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AntHarnessTest.java From ExpectIt with Apache License 2.0 | 6 votes |
@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(); }
Example #2
Source File: AdminServer.java From gameserver with Apache License 2.0 | 5 votes |
@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); } }