From 0805ff838562e3b19d31083d80762abcd0ebd106 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Mon, 15 Jun 2015 12:58:10 -0400 Subject: [PATCH] Merged #259 "Allow custom host & port specification for advertised SSH urls" --- src/main/java/com/gitblit/transport/ssh/SshDaemon.java | 26 +++++++++++++++++--------- 1 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java index 0ff5c28..68a2e90 100644 --- a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java +++ b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java @@ -35,8 +35,8 @@ import org.apache.sshd.common.io.nio2.Nio2ServiceFactoryFactory; import org.apache.sshd.common.keyprovider.FileKeyPairProvider; import org.apache.sshd.common.util.SecurityUtils; -import org.apache.sshd.server.auth.CachingPublicKeyAuthenticator; import org.apache.sshd.server.UserAuth; +import org.apache.sshd.server.auth.CachingPublicKeyAuthenticator; import org.apache.sshd.server.auth.UserAuthKeyboardInteractive; import org.apache.sshd.server.auth.UserAuthPassword; import org.apache.sshd.server.auth.UserAuthPublicKey; @@ -130,7 +130,7 @@ } else { addr = new InetSocketAddress(bindInterface, port); } - + //Will do GSS ? GSSAuthenticator gssAuthenticator = null; if(settings.getBoolean(Keys.git.sshWithKrb5, false)) { @@ -144,9 +144,9 @@ ""); if(! servicePrincipalName.isEmpty()) { gssAuthenticator.setServicePrincipalName(servicePrincipalName); - } + } } - + //Sort the authenticators for sshd List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<>(); String sshAuthenticatorsOrderString = settings.getString(Keys.git.sshAuthenticatorsOrder, @@ -156,7 +156,7 @@ switch (authenticatorName) { case "gssapi-with-mic": if(gssAuthenticator != null) { - userAuthFactories.add(new UserAuthGSS.Factory()); + userAuthFactories.add(new UserAuthGSS.Factory()); } break; case "publickey": @@ -172,7 +172,7 @@ log.error("Unknown ssh authenticator: '{}'", authenticatorName); } } - + // Create the SSH server sshd = SshServer.setUpDefaultServer(); sshd.setPort(addr.getPort()); @@ -200,14 +200,22 @@ } public String formatUrl(String gituser, String servername, String repository) { - if (sshd.getPort() == DEFAULT_PORT) { + IStoredSettings settings = gitblit.getSettings(); + + int port = sshd.getPort(); + int displayPort = settings.getInteger(Keys.git.sshAdvertisedPort, port); + String displayServername = settings.getString(Keys.git.sshAdvertisedHost, ""); + if(displayServername.isEmpty()) { + displayServername = servername; + } + if (displayPort == DEFAULT_PORT) { // standard port - return MessageFormat.format("ssh://{0}@{1}/{2}", gituser, servername, + return MessageFormat.format("ssh://{0}@{1}/{2}", gituser, displayServername, repository); } else { // non-standard port return MessageFormat.format("ssh://{0}@{1}:{2,number,0}/{3}", - gituser, servername, sshd.getPort(), repository); + gituser, displayServername, displayPort, repository); } } -- Gitblit v1.9.1