From fea7c52e9584ff117be8529b431b40590deef0ca Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 10 Apr 2014 18:58:08 -0400
Subject: [PATCH] Renamed SshContext->SshCommandContext for clarity of purpose
---
src/main/java/com/gitblit/transport/ssh/SshDaemon.java | 41 +++++++++++++++++++++++++++++++++--------
1 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java
index de57f5f..81d7878 100644
--- a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java
+++ b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java
@@ -24,6 +24,9 @@
import javax.inject.Singleton;
import org.apache.sshd.SshServer;
+import org.apache.sshd.common.io.IoServiceFactoryFactory;
+import org.apache.sshd.common.io.mina.MinaServiceFactoryFactory;
+import org.apache.sshd.common.io.nio2.Nio2ServiceFactoryFactory;
import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider;
import org.eclipse.jgit.internal.JGitText;
import org.slf4j.Logger;
@@ -38,6 +41,8 @@
import com.gitblit.transport.ssh.commands.CreateRepository;
import com.gitblit.transport.ssh.commands.DispatchCommand;
import com.gitblit.transport.ssh.commands.Receive;
+import com.gitblit.transport.ssh.commands.ReviewCommand;
+import com.gitblit.transport.ssh.commands.SetAccountCommand;
import com.gitblit.transport.ssh.commands.Upload;
import com.gitblit.transport.ssh.commands.VersionCommand;
import com.gitblit.utils.IdGenerator;
@@ -59,6 +64,10 @@
private final Logger log = LoggerFactory.getLogger(SshDaemon.class);
+ public static enum SshSessionBackend {
+ MINA, NIO2
+ }
+
/**
* 22: IANA assigned port number for ssh. Note that this is a distinct
* concept from gitblit's default conf for ssh port -- this "default" is
@@ -90,6 +99,14 @@
"localhost");
IKeyManager keyManager = getKeyManager();
+
+ String sshBackendStr = settings.getString(Keys.git.sshBackend,
+ SshSessionBackend.NIO2.name());
+ SshSessionBackend backend = SshSessionBackend.valueOf(sshBackendStr);
+ System.setProperty(IoServiceFactoryFactory.class.getName(),
+ backend == SshSessionBackend.MINA
+ ? MinaServiceFactoryFactory.class.getName()
+ : Nio2ServiceFactoryFactory.class.getName());
InetSocketAddress addr;
if (StringUtils.isEmpty(bindInterface)) {
@@ -98,20 +115,24 @@
addr = new InetSocketAddress(bindInterface, port);
}
+ SshKeyAuthenticator publickeyAuthenticator = new SshKeyAuthenticator(
+ keyManager, gitblit);
sshd = SshServer.setUpDefaultServer();
sshd.setPort(addr.getPort());
sshd.setHost(addr.getHostName());
sshd.setKeyPairProvider(new PEMGeneratorHostKeyProvider(new File(
gitblit.getBaseFolder(), HOST_KEY_STORE).getPath()));
- sshd.setPublickeyAuthenticator(new SshKeyAuthenticator(keyManager, gitblit));
+ sshd.setPublickeyAuthenticator(publickeyAuthenticator);
sshd.setPasswordAuthenticator(new SshPasswordAuthenticator(gitblit));
- sshd.setSessionFactory(new SshSessionFactory(idGenerator));
+ sshd.setSessionFactory(new SshSessionFactory());
sshd.setFileSystemFactory(new DisabledFilesystemFactory());
- sshd.setForwardingFilter(new NonForwardingFilter());
+ sshd.setTcpipForwardingFilter(new NonForwardingFilter());
DispatchCommand gitblitCmd = new DispatchCommand();
gitblitCmd.registerCommand(CreateRepository.class);
gitblitCmd.registerCommand(VersionCommand.class);
+ gitblitCmd.registerCommand(SetAccountCommand.class);
+ gitblitCmd.registerCommand(ReviewCommand.class);
DispatchCommand gitCmd = new DispatchCommand();
gitCmd.registerCommand(Upload.class);
@@ -121,9 +142,10 @@
root.registerDispatcher("gitblit", gitblitCmd);
root.registerDispatcher("git", gitCmd);
- root.setRepositoryResolver(new RepositoryResolver<SshSession>(gitblit));
- root.setUploadPackFactory(new GitblitUploadPackFactory<SshSession>(gitblit));
- root.setReceivePackFactory(new GitblitReceivePackFactory<SshSession>(gitblit));
+ root.setRepositoryResolver(new RepositoryResolver<SshDaemonClient>(gitblit));
+ root.setUploadPackFactory(new GitblitUploadPackFactory<SshDaemonClient>(gitblit));
+ root.setReceivePackFactory(new GitblitReceivePackFactory<SshDaemonClient>(gitblit));
+ root.setAuthenticator(publickeyAuthenticator);
SshCommandFactory commandFactory = new SshCommandFactory(
new WorkQueue(idGenerator),
@@ -162,9 +184,12 @@
sshd.start();
run.set(true);
+ String sshBackendStr = gitblit.getSettings().getString(Keys.git.sshBackend,
+ SshSessionBackend.NIO2.name());
+
log.info(MessageFormat.format(
- "SSH Daemon is listening on {0}:{1,number,0}",
- sshd.getHost(), sshd.getPort()));
+ "SSH Daemon ({0}) is listening on {1}:{2,number,0}",
+ sshBackendStr, sshd.getHost(), sshd.getPort()));
}
/** @return true if this daemon is receiving connections. */
--
Gitblit v1.9.1