diff options
author | James Moger <james.moger@gitblit.com> | 2014-10-31 08:50:19 -0600 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-10-31 08:50:19 -0600 |
commit | db313d68712cab2b74b4487f93e194bc8d5ed633 (patch) | |
tree | 4706678c339b49459a8f7fc698f4648465d56bf5 | |
parent | 8a036644cc97e9efcd11839e5f2e5f1cc5822e24 (diff) | |
parent | 67ba8f57e15ddf8d8dece57a276e37a4b3ef7f01 (diff) | |
download | gitblit-db313d68712cab2b74b4487f93e194bc8d5ed633.tar.gz gitblit-db313d68712cab2b74b4487f93e194bc8d5ed633.zip |
Merged #215 "Allow finer-grained determination of available transport preferences"
-rw-r--r-- | src/main/java/com/gitblit/manager/IServicesManager.java | 19 | ||||
-rw-r--r-- | src/main/java/com/gitblit/manager/ServicesManager.java | 26 | ||||
-rw-r--r-- | src/main/java/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; @@ -45,6 +46,15 @@ public interface IServicesManager extends IManager { /** * 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. * * @return true if Gitblit is serving 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 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);
}
|