]> source.dussan.org Git - gitblit.git/commitdiff
Allow finer-grained determination of available transport preferences 15/215/1
authorJames Moger <james.moger@gitblit.com>
Fri, 31 Oct 2014 14:36:52 +0000 (10:36 -0400)
committerJames Moger <james.moger@gitblit.com>
Fri, 31 Oct 2014 14:36:52 +0000 (10:36 -0400)
src/main/java/com/gitblit/manager/IServicesManager.java
src/main/java/com/gitblit/manager/ServicesManager.java
src/main/java/com/gitblit/wicket/pages/UserPage.java

index 5bb135ddce35811425cc76661498903c8d8c783d..b3a973b3987d5266b05af28d7da41c6b6cf9c9e5 100644 (file)
@@ -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<RepositoryUrl> 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
index 7185854512d19829a2d7f90ee624df2976c3545d..69e5e408ba58be2afc263b8bba53a94fa38cd1c0 100644 (file)
@@ -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;
index e21431d99882a8215b7feac6174c4a74a771ff5d..6e7e7a7634b783532cbf2af2728a6b485634c1bc 100644 (file)
@@ -252,9 +252,11 @@ public class UserPage extends RootPage {
                        availableTransports.add(Transport.SSH);\r
                }\r
                if (app().services().isServingHTTP()) {\r
-                       availableTransports.add(Transport.HTTPS);\r
                        availableTransports.add(Transport.HTTP);\r
                }\r
+               if (app().services().isServingHTTPS()) {\r
+                       availableTransports.add(Transport.HTTPS);\r
+               }\r
                if (app().services().isServingGIT()) {\r
                        availableTransports.add(Transport.GIT);\r
                }\r