Java Code Examples for org.apache.sshd.server.SshServer#setPasswordAuthenticator()

The following examples show how to use org.apache.sshd.server.SshServer#setPasswordAuthenticator() . 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: SshShellConfiguration.java    From ssh-shell-spring-boot with Apache License 2.0 6 votes vote down vote up
/**
 * Construct ssh server thanks to ssh shell properties
 *
 * @return ssh server
 */
@Bean
public SshServer sshServer() {
    SshServer server = SshServer.setUpDefaultServer();
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(properties.getHostKeyFile().toPath()));
    server.setHost(properties.getHost());
    server.setPasswordAuthenticator(passwordAuthenticator);
    server.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE);
    if (properties.getAuthorizedPublicKeysFile() != null) {
        if (properties.getAuthorizedPublicKeysFile().exists() && properties.getAuthorizedPublicKeysFile().canRead()) {
            server.setPublickeyAuthenticator(new SshShellPublicKeyAuthenticationProvider(properties.getAuthorizedPublicKeysFile()));
        } else {
            LOGGER.warn("Could not read authorized public keys file [{}], public key authentication is disabled.",
                    properties.getAuthorizedPublicKeysFile().getAbsolutePath());
        }
    }
    server.setPort(properties.getPort());
    server.setShellFactory(channelSession -> shellCommandFactory);
    server.setCommandFactory((channelSession, s) -> shellCommandFactory);
    return server;
}
 
Example 2
Source File: FakeSftpServerRule.java    From fake-sftp-server-rule with MIT License 6 votes vote down vote up
private SshServer startServer(
    FileSystem fileSystem
) throws IOException {
    SshServer server = SshServer.setUpDefaultServer();
    server.setPort(port);
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    server.setPasswordAuthenticator(this::authenticate);
    server.setSubsystemFactories(singletonList(new SftpSubsystemFactory()));
    /* When a channel is closed SshServer calls close() on the file system.
     * In order to use the file system for multiple channels/sessions we
     * have to use a file system wrapper whose close() does nothing.
     */
    server.setFileSystemFactory(session -> new DoNotClose(fileSystem));
    server.start();
    this.server = server;
    return server;
}
 
Example 3
Source File: Utils.java    From termd with Apache License 2.0 5 votes vote down vote up
public static SshServer setupTestServer(Class<?> anchor) {
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setKeyPairProvider(createTestHostKeyProvider(anchor));
    sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
    sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
    sshd.setShellFactory(EchoShellFactory.INSTANCE);
    sshd.setCommandFactory(UnknownCommandFactory.INSTANCE);
    return sshd;
}
 
Example 4
Source File: SshdServerConfiguration.java    From sshd-shell-spring-boot with Apache License 2.0 5 votes vote down vote up
private void configureAuthenticationPolicies(SshServer server, Shell props) {
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Paths.get(props.getHostKeyFile())));
    server.setPublickeyAuthenticator(Objects.isNull(props.getPublicKeyFile())
            ? RejectAllPublickeyAuthenticator.INSTANCE
            : new SshdAuthorizedKeysAuthenticator(Paths.get(props.getPublicKeyFile())));
    server.setPasswordAuthenticator(passwordAuthenticator(props));
}
 
Example 5
Source File: Utils.java    From termd with Apache License 2.0 5 votes vote down vote up
public static SshServer setupTestServer(Class<?> anchor) {
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setKeyPairProvider(createTestHostKeyProvider(anchor));
    sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
    sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
    sshd.setShellFactory(EchoShellFactory.INSTANCE);
    sshd.setCommandFactory(UnknownCommandFactory.INSTANCE);
    return sshd;
}