Skip to content

Commit

Permalink
authenticators for NettySshTtyBootstrap.java
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdenise committed Nov 23, 2017
1 parent c2be591 commit 32e4c0d
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;

/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
Expand All @@ -48,6 +49,7 @@ public class NettySshTtyBootstrap {
private SshServer server;
private KeyPairProvider keyPairProvider;
private PasswordAuthenticator passwordAuthenticator;
private PublickeyAuthenticator publicKeyAuthenticator;

public NettySshTtyBootstrap() {
this.host = "localhost";
Expand Down Expand Up @@ -77,6 +79,16 @@ public NettySshTtyBootstrap setPort(int port) {
return this;
}

public NettySshTtyBootstrap setPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator) {
this.passwordAuthenticator = passwordAuthenticator;
return this;
}

public NettySshTtyBootstrap setPublicKeyAuthenticator(PublickeyAuthenticator publicKeyAuthenticator) {
this.publicKeyAuthenticator = publicKeyAuthenticator;
return this;
}

public CompletableFuture<Void> start(Consumer<Connection> handler) throws Exception {
CompletableFuture<Void> fut = new CompletableFuture<>();
start(handler, Helper.startedHandler(fut));
Expand Down Expand Up @@ -107,6 +119,9 @@ public void start(Consumer<Connection> factory, Consumer<Throwable> doneHandler)
server.setHost(host);
server.setKeyPairProvider(keyPairProvider);
server.setPasswordAuthenticator(passwordAuthenticator);
if (publicKeyAuthenticator != null) {
server.setPublickeyAuthenticator(publicKeyAuthenticator);
}
server.setShellFactory(() -> new TtyCommand(charset, factory));
try {
server.start();
Expand Down

0 comments on commit 32e4c0d

Please sign in to comment.