]> source.dussan.org Git - gitblit.git/commitdiff
Improve Sparkleshare integration, but leave disabled for now
authorJames Moger <james.moger@gitblit.com>
Fri, 21 Mar 2014 15:29:11 +0000 (11:29 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 10 Apr 2014 22:58:09 +0000 (18:58 -0400)
src/main/distrib/data/clientapps.json
src/main/java/com/gitblit/servlet/SparkleShareInviteServlet.java
src/main/java/com/gitblit/wicket/panels/RepositoryUrlPanel.java

index 31e53efdc8ca60e930fab31d9489c8dca03ef742..a19cbcc8c63fe90b67454a0f11be5c964e00cc7a 100644 (file)
@@ -82,7 +82,7 @@
                "title": "SparkleShare\u2122",\r
                "description": "an open source collaboration and sharing tool",\r
                "legal": "released under the GPLv3 open source license",\r
-               "cloneUrl": "sparkleshare://addProject/${baseUrl}/sparkleshare/${repoUrl}.xml",\r
+               "cloneUrl": "sparkleshare://addProject/${baseUrl}/sparkleshare/${username}@${repository}.xml",\r
                "productUrl": "http://sparkleshare.org",\r
                "transports": [ "ssh" ],\r
                "platforms": [ "windows", "macintosh", "linux" ],\r
index d7f00c672de5d2959dc8155b50deff9d8c716a82..150dd68a14cbe0695cd10304c04521f8ee2e01b4 100644 (file)
 package com.gitblit.servlet;\r
 \r
 import java.io.IOException;\r
+import java.net.URL;\r
 import java.text.MessageFormat;\r
 \r
 import javax.servlet.ServletException;\r
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
 \r
-import com.gitblit.Constants;\r
 import com.gitblit.IStoredSettings;\r
 import com.gitblit.Keys;\r
 import com.gitblit.dagger.DaggerServlet;\r
@@ -77,6 +77,12 @@ public class SparkleShareInviteServlet extends DaggerServlet {
                        javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
                        java.io.IOException {\r
 \r
+               int sshPort = settings.getInteger(Keys.git.sshPort, 0);\r
+               if (sshPort == 0) {\r
+                       response.setStatus(HttpServletResponse.SC_FORBIDDEN);\r
+                       response.getWriter().append("SSH is not active on this server!");\r
+                       return;\r
+               }\r
                // extract repo name from request\r
                String repoUrl = request.getPathInfo().substring(1);\r
 \r
@@ -85,25 +91,32 @@ public class SparkleShareInviteServlet extends DaggerServlet {
                        repoUrl = repoUrl.substring(0, repoUrl.length() - 4);\r
                }\r
 \r
-               String servletPath =  Constants.R_PATH;\r
-\r
-               int schemeIndex = repoUrl.indexOf("://") + 3;\r
-               String host = repoUrl.substring(0, repoUrl.indexOf('/', schemeIndex));\r
-               String path = repoUrl.substring(repoUrl.indexOf(servletPath) + servletPath.length());\r
                String username = null;\r
+               String path;\r
                int fetchIndex = repoUrl.indexOf('@');\r
                if (fetchIndex > -1) {\r
-                       username = repoUrl.substring(schemeIndex, fetchIndex);\r
+                       username = repoUrl.substring(0, fetchIndex);\r
+                       path = repoUrl.substring(fetchIndex + 1);\r
+               } else {\r
+                       path = repoUrl;\r
+               }\r
+\r
+               String host = request.getServerName();\r
+               String url = settings.getString(Keys.web.canonicalUrl, "https://localhost:8443");\r
+               if (!StringUtils.isEmpty(url) && url.indexOf("localhost") == -1) {\r
+                       host = new URL(url).getHost();\r
                }\r
+\r
                UserModel user;\r
                if (StringUtils.isEmpty(username)) {\r
                        user = authenticationManager.authenticate(request);\r
                } else {\r
                        user = userManager.getUserModel(username);\r
                }\r
-               if (user == null) {\r
-                       user = UserModel.ANONYMOUS;\r
-                       username = "";\r
+               if (user == null || user.disabled) {\r
+                       response.setStatus(HttpServletResponse.SC_FORBIDDEN);\r
+                       response.getWriter().append("Access is not permitted!");\r
+                       return;\r
                }\r
 \r
                // ensure that the requested repository exists\r
@@ -114,14 +127,20 @@ public class SparkleShareInviteServlet extends DaggerServlet {
                        return;\r
                }\r
 \r
+               if (!user.canRewindRef(model)) {\r
+                       response.setStatus(HttpServletResponse.SC_FORBIDDEN);\r
+                       response.getWriter().append(MessageFormat.format("{0} does not have RW+ permissions to \"{1}\"!", user.username, model.name));\r
+               }\r
+\r
                StringBuilder sb = new StringBuilder();\r
                sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");\r
                sb.append("<sparkleshare><invite>\n");\r
-               sb.append(MessageFormat.format("<address>{0}</address>\n", host));\r
-               sb.append(MessageFormat.format("<remote_path>{0}{1}</remote_path>\n", servletPath, model.name));\r
-               if (settings.getInteger(Keys.fanout.port, 0) > 0) {\r
+               sb.append(MessageFormat.format("<address>ssh://{0}@{1}:{2,number,0}/</address>\n", user.username, host, sshPort));\r
+               sb.append(MessageFormat.format("<remote_path>/{0}</remote_path>\n", model.name));\r
+               int fanoutPort = settings.getInteger(Keys.fanout.port, 0);\r
+               if (fanoutPort > 0) {\r
                        // Gitblit is running it's own fanout service for pubsub notifications\r
-                       sb.append(MessageFormat.format("<announcements_url>tcp://{0}:{1}</announcements_url>\n", request.getServerName(), settings.getString(Keys.fanout.port, "")));\r
+                       sb.append(MessageFormat.format("<announcements_url>tcp://{0}:{1,number,0}</announcements_url>\n", request.getServerName(), fanoutPort));\r
                }\r
                sb.append("</invite></sparkleshare>\n");\r
 \r
index 0f31b31ed572140916718646988148795391a134..938226a62cdbd6f9704d8e708e431f905b2ef4ad 100644 (file)
@@ -210,7 +210,7 @@ public class RepositoryUrlPanel extends BasePanel {
                return urlPanel;\r
        }\r
 \r
-       protected Fragment createApplicationMenus(String wicketId, UserModel user, final RepositoryModel repository, final List<RepositoryUrl> repositoryUrls) {\r
+       protected Fragment createApplicationMenus(String wicketId, final UserModel user, final RepositoryModel repository, final List<RepositoryUrl> repositoryUrls) {\r
                final List<GitClientApplication> displayedApps = new ArrayList<GitClientApplication>();\r
                final String userAgent = ((WebClientInfo) GitBlitWebSession.get().getClientInfo()).getUserAgent();\r
 \r
@@ -309,13 +309,13 @@ public class RepositoryUrlPanel extends BasePanel {
 \r
                                                if (!StringUtils.isEmpty(clientApp.cloneUrl)) {\r
                                                        // custom registered url\r
-                                                       String url = substitute(clientApp.cloneUrl, repoUrl.url, baseURL);\r
+                                                       String url = substitute(clientApp.cloneUrl, repoUrl.url, baseURL, user.username, repository.name);\r
                                                        fragment.add(new LinkPanel("content", "applicationMenuItem", getString("gb.clone") + " " + repoUrl.url, url));\r
                                                        repoLinkItem.add(fragment);\r
                                                        fragment.add(new Label("copyFunction").setVisible(false));\r
                                                } else if (!StringUtils.isEmpty(clientApp.command)) {\r
                                                        // command-line\r
-                                                       String command = substitute(clientApp.command, repoUrl.url, baseURL);\r
+                                                       String command = substitute(clientApp.command, repoUrl.url, baseURL, user.username, repository.name);\r
                                                        Label content = new Label("content", command);\r
                                                        WicketUtils.setCssClass(content, "commandMenuItem");\r
                                                        fragment.add(content);\r
@@ -334,8 +334,8 @@ public class RepositoryUrlPanel extends BasePanel {
                return applicationMenus;\r
        }\r
 \r
-       protected String substitute(String pattern, String repoUrl, String baseUrl) {\r
-               return pattern.replace("${repoUrl}", repoUrl).replace("${baseUrl}", baseUrl);\r
+       protected String substitute(String pattern, String repoUrl, String baseUrl, String username, String repository) {\r
+               return pattern.replace("${repoUrl}", repoUrl).replace("${baseUrl}", baseUrl).replace("${username}", username).replace("${repository}", repository);\r
        }\r
 \r
        protected Label createPermissionBadge(String wicketId, RepositoryUrl repoUrl) {\r