]> source.dussan.org Git - gitblit.git/commitdiff
Return management-level settings if web.enableRpcAdministration=false
authorJames Moger <james.moger@gitblit.com>
Wed, 26 Oct 2011 21:11:12 +0000 (17:11 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 26 Oct 2011 21:11:12 +0000 (17:11 -0400)
Require web.enableRpcAdministration=true to process federation RPCs.

src/com/gitblit/RpcServlet.java

index dd99e3f4c6a6fbda24694071c8f408754d9ce119..53628a094e6cefe8aaea85060751604a21d0e370 100644 (file)
@@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletResponse;
 \r
 import com.gitblit.Constants.RpcRequest;\r
 import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.SettingModel;\r
+import com.gitblit.models.ServerSettings;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.HttpUtils;\r
 import com.gitblit.utils.RpcUtils;\r
@@ -64,6 +64,8 @@ public class RpcServlet extends JsonServlet {
                logger.info(MessageFormat.format("Rpc {0} request from {1}", reqType,\r
                                request.getRemoteAddr()));\r
 \r
+               boolean allowAdmin = GitBlit.getBoolean(Keys.web.enableRpcAdministration, false);\r
+\r
                UserModel user = (UserModel) request.getUserPrincipal();\r
 \r
                Object result = null;\r
@@ -158,24 +160,28 @@ public class RpcServlet extends JsonServlet {
                        }\r
                } else if (RpcRequest.LIST_FEDERATION_REGISTRATIONS.equals(reqType)) {\r
                        // return the list of federation registrations\r
-                       result = GitBlit.self().getFederationRegistrations();\r
+                       if (allowAdmin) {\r
+                               result = GitBlit.self().getFederationRegistrations();\r
+                       } else {\r
+                               response.sendError(notAllowedCode);\r
+                       }\r
                } else if (RpcRequest.LIST_FEDERATION_RESULTS.equals(reqType)) {\r
                        // return the list of federation result registrations\r
-                       if (GitBlit.canFederate()) {\r
+                       if (allowAdmin && GitBlit.canFederate()) {\r
                                result = GitBlit.self().getFederationResultRegistrations();\r
                        } else {\r
                                response.sendError(notAllowedCode);\r
                        }\r
                } else if (RpcRequest.LIST_FEDERATION_PROPOSALS.equals(reqType)) {\r
                        // return the list of federation proposals\r
-                       if (GitBlit.canFederate()) {\r
+                       if (allowAdmin && GitBlit.canFederate()) {\r
                                result = GitBlit.self().getPendingFederationProposals();\r
                        } else {\r
                                response.sendError(notAllowedCode);\r
                        }\r
                } else if (RpcRequest.LIST_FEDERATION_SETS.equals(reqType)) {\r
                        // return the list of federation sets\r
-                       if (GitBlit.canFederate()) {\r
+                       if (allowAdmin && GitBlit.canFederate()) {\r
                                String gitblitUrl = HttpUtils.getGitblitURL(request);\r
                                result = GitBlit.self().getFederationSets(gitblitUrl);\r
                        } else {\r
@@ -183,14 +189,23 @@ public class RpcServlet extends JsonServlet {
                        }\r
                } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {\r
                        // return the server's settings\r
-                       if (GitBlit.getBoolean(Keys.web.enableRpcAdministration, false)) {\r
-                               result = GitBlit.self().getSettingsModel();\r
+                       ServerSettings settings = GitBlit.self().getSettingsModel();\r
+                       if (allowAdmin) {\r
+                               // return all settings\r
+                               result = settings;\r
                        } else {\r
-                               response.sendError(notAllowedCode);\r
+                               // return management settings only\r
+                               String[] keys = { Keys.realm.minPasswordLength, Keys.realm.passwordStorage,\r
+                                               Keys.federation.sets };\r
+                               ServerSettings managementSettings = new ServerSettings();\r
+                               for (String key : keys) {\r
+                                       managementSettings.add(settings.get(key));\r
+                               }\r
+                               result = managementSettings;\r
                        }\r
                } else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) {\r
                        // update settings on the server\r
-                       if (GitBlit.getBoolean(Keys.web.enableRpcAdministration, false)) {\r
+                       if (allowAdmin) {\r
                                Map<String, String> settings = deserialize(request, response,\r
                                                RpcUtils.SETTINGS_TYPE);\r
                                GitBlit.self().updateSettings(settings);\r
@@ -199,7 +214,7 @@ public class RpcServlet extends JsonServlet {
                        }\r
                } else if (RpcRequest.LIST_STATUS.equals(reqType)) {\r
                        // return the server's status information\r
-                       if (GitBlit.getBoolean(Keys.web.enableRpcAdministration, false)) {\r
+                       if (allowAdmin) {\r
                                result = GitBlit.self().getStatus();\r
                        } else {\r
                                response.sendError(notAllowedCode);\r