From 67ba8f57e15ddf8d8dece57a276e37a4b3ef7f01 Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 31 Oct 2014 10:36:52 -0400 Subject: [PATCH] Allow finer-grained determination of available transport preferences --- .../com/gitblit/manager/IServicesManager.java | 19 ++++++++++++++ .../com/gitblit/manager/ServicesManager.java | 26 ++++++++++++++----- .../com/gitblit/wicket/pages/UserPage.java | 4 ++- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gitblit/manager/IServicesManager.java b/src/main/java/com/gitblit/manager/IServicesManager.java index 5bb135dd..b3a973b3 100644 --- a/src/main/java/com/gitblit/manager/IServicesManager.java +++ b/src/main/java/com/gitblit/manager/IServicesManager.java @@ -19,6 +19,7 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; +import com.gitblit.Constants.Transport; import com.gitblit.models.RepositoryModel; import com.gitblit.models.RepositoryUrl; import com.gitblit.models.UserModel; @@ -43,6 +44,15 @@ public interface IServicesManager extends IManager { */ boolean isServingHTTP(); + /** + * Determine if this Gitblit instance is actively serving git repositories + * over HTTP. + * + * @return true if Gitblit is serving repositories over HTTPS + * @since 1.7.0 + */ + boolean isServingHTTPS(); + /** * Determine if this Gitblit instance is actively serving git repositories * over the GIT Daemon protocol. @@ -72,4 +82,13 @@ public interface IServicesManager extends IManager { */ List getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository); + /** + * Returns true if the transport may be used for pushing. + * + * @param byTransport + * @return true if the transport can be used for pushes. + * @since 1.7.0 + */ + boolean acceptsPush(Transport byTransport); + } \ No newline at end of file diff --git a/src/main/java/com/gitblit/manager/ServicesManager.java b/src/main/java/com/gitblit/manager/ServicesManager.java index 71858545..69e5e408 100644 --- a/src/main/java/com/gitblit/manager/ServicesManager.java +++ b/src/main/java/com/gitblit/manager/ServicesManager.java @@ -166,7 +166,7 @@ public class ServicesManager implements IServicesManager { AccessPermission permission = user.getRepositoryPermission(repository).permission; if (permission.exceeds(AccessPermission.NONE)) { Transport transport = Transport.fromString(request.getScheme()); - if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(transport)) { + if (permission.atLeast(AccessPermission.PUSH) && !acceptsPush(transport)) { // downgrade the repo permission for this transport // because it is not an acceptable PUSH transport permission = AccessPermission.CLONE; @@ -180,7 +180,7 @@ public class ServicesManager implements IServicesManager { if (!StringUtils.isEmpty(sshDaemonUrl)) { AccessPermission permission = user.getRepositoryPermission(repository).permission; if (permission.exceeds(AccessPermission.NONE)) { - if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(Transport.SSH)) { + if (permission.atLeast(AccessPermission.PUSH) && !acceptsPush(Transport.SSH)) { // downgrade the repo permission for this transport // because it is not an acceptable PUSH transport permission = AccessPermission.CLONE; @@ -195,7 +195,7 @@ public class ServicesManager implements IServicesManager { if (!StringUtils.isEmpty(gitDaemonUrl)) { AccessPermission permission = getGitDaemonAccessPermission(user, repository); if (permission.exceeds(AccessPermission.NONE)) { - if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(Transport.GIT)) { + if (permission.atLeast(AccessPermission.PUSH) && !acceptsPush(Transport.GIT)) { // downgrade the repo permission for this transport // because it is not an acceptable PUSH transport permission = AccessPermission.CLONE; @@ -272,7 +272,8 @@ public class ServicesManager implements IServicesManager { */ @Override public boolean isServingRepositories() { - return isServingHTTP() + return isServingHTTPS() + || isServingHTTP() || isServingGIT() || isServingSSH(); } @@ -282,7 +283,19 @@ public class ServicesManager implements IServicesManager { */ @Override public boolean isServingHTTP() { - return settings.getBoolean(Keys.git.enableGitServlet, true); + return settings.getBoolean(Keys.git.enableGitServlet, true) + && ((gitblit.getStatus().isGO && settings.getInteger(Keys.server.httpPort, 0) > 0) + || !gitblit.getStatus().isGO); + } + + /* (non-Javadoc) + * @see com.gitblit.manager.IServicesManager#isServingHTTPS() + */ + @Override + public boolean isServingHTTPS() { + return settings.getBoolean(Keys.git.enableGitServlet, true) + && ((gitblit.getStatus().isGO && settings.getInteger(Keys.server.httpsPort, 0) > 0) + || !gitblit.getStatus().isGO); } /* (non-Javadoc) @@ -330,7 +343,8 @@ public class ServicesManager implements IServicesManager { } } - protected boolean acceptPush(Transport byTransport) { + @Override + public boolean acceptsPush(Transport byTransport) { if (byTransport == null) { logger.info("Unknown transport, push rejected!"); return false; diff --git a/src/main/java/com/gitblit/wicket/pages/UserPage.java b/src/main/java/com/gitblit/wicket/pages/UserPage.java index e21431d9..6e7e7a76 100644 --- a/src/main/java/com/gitblit/wicket/pages/UserPage.java +++ b/src/main/java/com/gitblit/wicket/pages/UserPage.java @@ -252,9 +252,11 @@ public class UserPage extends RootPage { availableTransports.add(Transport.SSH); } if (app().services().isServingHTTP()) { - availableTransports.add(Transport.HTTPS); availableTransports.add(Transport.HTTP); } + if (app().services().isServingHTTPS()) { + availableTransports.add(Transport.HTTPS); + } if (app().services().isServingGIT()) { availableTransports.add(Transport.GIT); } -- 2.39.5