-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
authenticators for NettySshTtyBootstrap.java
- Loading branch information
Showing
1 changed file
with
15 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -48,6 +49,7 @@ public class NettySshTtyBootstrap { | |
private SshServer server; | ||
private KeyPairProvider keyPairProvider; | ||
private PasswordAuthenticator passwordAuthenticator; | ||
private PublickeyAuthenticator publicKeyAuthenticator; | ||
|
||
public NettySshTtyBootstrap() { | ||
this.host = "localhost"; | ||
|
@@ -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)); | ||
|
@@ -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(); | ||
|