]> source.dussan.org Git - gitblit.git/commitdiff
Restore tabbed formatting to make diffs to develop useful 65/65/4
authorJames Moger <james.moger@gitblit.com>
Thu, 8 May 2014 15:17:39 +0000 (11:17 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 8 May 2014 15:17:39 +0000 (11:17 -0400)
src/main/java/com/gitblit/servlet/RpcServlet.java

index b3016ad6265a4b9f02d9e3dcf68a180db34917d4..b8cdfb04794adbb3874fb03fd67fafe8b021bf89 100644 (file)
@@ -56,374 +56,376 @@ import dagger.ObjectGraph;
  */\r
 public class RpcServlet extends JsonServlet {\r
 \r
-    private static final long serialVersionUID = 1L;\r
+       private static final long serialVersionUID = 1L;\r
 \r
-    public static final int PROTOCOL_VERSION = 8;\r
+       public static final int PROTOCOL_VERSION = 8;\r
 \r
-    private IStoredSettings settings;\r
+       private IStoredSettings settings;\r
 \r
-    private IGitblit gitblit;\r
+       private IGitblit gitblit;\r
 \r
-    @Override\r
-    protected void inject(ObjectGraph dagger) {\r
-        this.settings = dagger.get(IStoredSettings.class);\r
-        this.gitblit = dagger.get(IGitblit.class);\r
-    }\r
+       @Override\r
+       protected void inject(ObjectGraph dagger) {\r
+               this.settings = dagger.get(IStoredSettings.class);\r
+               this.gitblit = dagger.get(IGitblit.class);\r
+       }\r
 \r
-    /**\r
-     * Processes an rpc request.\r
-     *\r
-     * @param request\r
-     * @param response\r
-     * @throws javax.servlet.ServletException\r
-     * @throws java.io.IOException\r
-     */\r
-    @Override\r
-    protected void processRequest(HttpServletRequest request, HttpServletResponse response)\r
-            throws ServletException, IOException {\r
-        RpcRequest reqType = RpcRequest.fromName(request.getParameter("req"));\r
-        String objectName = request.getParameter("name");\r
-        logger.info(MessageFormat.format("Rpc {0} request from {1}", reqType,\r
-                request.getRemoteAddr()));\r
+       /**\r
+        * Processes an rpc request.\r
+        *\r
+        * @param request\r
+        * @param response\r
+        * @throws javax.servlet.ServletException\r
+        * @throws java.io.IOException\r
+        */\r
+       @Override\r
+       protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException,\r
+                       IOException {\r
+               RpcRequest reqType = RpcRequest.fromName(request.getParameter("req"));\r
+               String objectName = request.getParameter("name");\r
+               logger.info(MessageFormat.format("Rpc {0} request from {1}", reqType, request.getRemoteAddr()));\r
 \r
-        UserModel user = (UserModel) request.getUserPrincipal();\r
+               UserModel user = (UserModel) request.getUserPrincipal();\r
 \r
-        boolean allowManagement = user != null && user.canAdmin()\r
-                && settings.getBoolean(Keys.web.enableRpcManagement, false);\r
+               boolean allowManagement = user != null && user.canAdmin()\r
+                               && settings.getBoolean(Keys.web.enableRpcManagement, false);\r
 \r
-        boolean allowAdmin = user != null && user.canAdmin()\r
-                && settings.getBoolean(Keys.web.enableRpcAdministration, false);\r
+               boolean allowAdmin = user != null && user.canAdmin()\r
+                               && settings.getBoolean(Keys.web.enableRpcAdministration, false);\r
 \r
-        Object result = null;\r
-        if (RpcRequest.GET_PROTOCOL.equals(reqType)) {\r
-            // Return the protocol version\r
-            result = PROTOCOL_VERSION;\r
-        } else if (RpcRequest.LIST_REPOSITORIES.equals(reqType)) {\r
-            // Determine the Gitblit clone url\r
-            String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);\r
-            if (StringUtils.isEmpty(gitblitUrl)) {\r
-                gitblitUrl = HttpUtils.getGitblitURL(request);\r
-            }\r
-            StringBuilder sb = new StringBuilder();\r
-            sb.append(gitblitUrl);\r
-            sb.append(Constants.R_PATH);\r
-            sb.append("{0}");\r
-            String cloneUrl = sb.toString();\r
+               Object result = null;\r
+               if (RpcRequest.GET_PROTOCOL.equals(reqType)) {\r
+                       // Return the protocol version\r
+                       result = PROTOCOL_VERSION;\r
+               } else if (RpcRequest.LIST_REPOSITORIES.equals(reqType)) {\r
+                       // Determine the Gitblit clone url\r
+                       String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);\r
+                       if (StringUtils.isEmpty(gitblitUrl)) {\r
+                               gitblitUrl = HttpUtils.getGitblitURL(request);\r
+                       }\r
+                       StringBuilder sb = new StringBuilder();\r
+                       sb.append(gitblitUrl);\r
+                       sb.append(Constants.R_PATH);\r
+                       sb.append("{0}");\r
+                       String cloneUrl = sb.toString();\r
 \r
-            // list repositories\r
-            List<RepositoryModel> list = gitblit.getRepositoryModels(user);\r
-            Map<String, RepositoryModel> repositories = new HashMap<String, RepositoryModel>();\r
-            for (RepositoryModel model : list) {\r
-                String url = MessageFormat.format(cloneUrl, model.name);\r
-                repositories.put(url, model);\r
-            }\r
-            result = repositories;\r
-        } else if (RpcRequest.LIST_BRANCHES.equals(reqType)) {\r
-            // list all local branches in all repositories accessible to user\r
-            Map<String, List<String>> localBranches = new HashMap<String, List<String>>();\r
-            List<RepositoryModel> models = gitblit.getRepositoryModels(user);\r
-            for (RepositoryModel model : models) {\r
-                if (!model.hasCommits) {\r
-                    // skip empty repository\r
-                    continue;\r
-                }\r
-                if (model.isCollectingGarbage) {\r
-                    // skip garbage collecting repository\r
-                    logger.warn(MessageFormat.format("Temporarily excluding {0} from RPC, busy collecting garbage", model.name));\r
-                    continue;\r
-                }\r
-                // get local branches\r
-                Repository repository = gitblit.getRepository(model.name);\r
-                List<RefModel> refs = JGitUtils.getLocalBranches(repository, false, -1);\r
-                if (model.showRemoteBranches) {\r
-                    // add remote branches if repository displays them\r
-                    refs.addAll(JGitUtils.getRemoteBranches(repository, false, -1));\r
-                }\r
-                if (refs.size() > 0) {\r
-                    List<String> branches = new ArrayList<String>();\r
-                    for (RefModel ref : refs) {\r
-                        branches.add(ref.getName());\r
-                    }\r
-                    localBranches.put(model.name, branches);\r
-                }\r
-                repository.close();\r
-            }\r
-            result = localBranches;\r
-        } else if (RpcRequest.GET_USER.equals(reqType)) {\r
-            if (StringUtils.isEmpty(objectName)) {\r
-                if (UserModel.ANONYMOUS.equals(user)) {\r
-                    response.sendError(forbiddenCode);\r
-                } else {\r
-                    // return the current user, reset credentials\r
-                    UserModel requestedUser = DeepCopier.copy(user);\r
-                    result = requestedUser;\r
-                }\r
-            } else {\r
-                if (user.canAdmin() || objectName.equals(user.username)) {\r
-                    // return the specified user\r
-                    UserModel requestedUser = gitblit.getUserModel(objectName);\r
-                    if (requestedUser == null) {\r
-                        response.setStatus(failureCode);\r
-                    } else {\r
-                        result = requestedUser;\r
-                    }\r
-                } else {\r
-                    response.sendError(forbiddenCode);\r
-                }\r
-            }\r
-        } else if (RpcRequest.LIST_USERS.equals(reqType)) {\r
-            // list users\r
-            List<String> names = gitblit.getAllUsernames();\r
-            List<UserModel> users = new ArrayList<UserModel>();\r
-            for (String name : names) {\r
-                users.add(gitblit.getUserModel(name));\r
-            }\r
-            result = users;\r
-        } else if (RpcRequest.LIST_TEAMS.equals(reqType)) {\r
-            // list teams\r
-            List<String> names = gitblit.getAllTeamNames();\r
-            List<TeamModel> teams = new ArrayList<TeamModel>();\r
-            for (String name : names) {\r
-                teams.add(gitblit.getTeamModel(name));\r
-            }\r
-            result = teams;\r
-        } else if (RpcRequest.CREATE_REPOSITORY.equals(reqType)) {\r
-            // create repository\r
-            RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
-            try {\r
-                gitblit.updateRepositoryModel(model.name, model, true);\r
-            } catch (GitBlitException e) {\r
-                response.setStatus(failureCode);\r
-            }\r
-        } else if (RpcRequest.FORK_REPOSITORY.equals(reqType)) {\r
-               // fork repository\r
-               RepositoryModel origin = gitblit.getRepositoryModel(objectName);\r
-               if (origin == null) {\r
-                       // failed to find repository, error is logged by the repository manager\r
-                       response.setStatus(failureCode);\r
-               } else {\r
-                       if (user == null || !user.canFork(origin)) {\r
-                               logger.error("User {} is not permitted to fork '{}'!",\r
-                                               user == null ? "anonymous" : user.username, objectName);\r
-                               response.setStatus(failureCode);\r
-                       } else {\r
-                               try {\r
-                                       // fork the origin\r
-                                       RepositoryModel fork = gitblit.fork(origin, user);\r
-                                       if (fork == null) {\r
-                                               logger.error("Failed to fork repository '{}'!", objectName);\r
-                                               response.setStatus(failureCode);\r
-                                       } else {\r
-                                               logger.info("User {} has forked '{}'!", user.username, objectName);\r
-                                       }\r
-                               } catch (GitBlitException e) {\r
-                                       response.setStatus(failureCode);\r
-                               }\r
-                       }\r
-               }\r
-        } else if (RpcRequest.EDIT_REPOSITORY.equals(reqType)) {\r
-            // edit repository\r
-            RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
-            // name specifies original repository name in event of rename\r
-            String repoName = objectName;\r
-            if (repoName == null) {\r
-                repoName = model.name;\r
-            }\r
-            try {\r
-                gitblit.updateRepositoryModel(repoName, model, false);\r
-            } catch (GitBlitException e) {\r
-                response.setStatus(failureCode);\r
-            }\r
-        } else if (RpcRequest.DELETE_REPOSITORY.equals(reqType)) {\r
-            // delete repository\r
-            RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
-            gitblit.deleteRepositoryModel(model);\r
-        } else if (RpcRequest.CREATE_USER.equals(reqType)) {\r
-            // create user\r
-            UserModel model = deserialize(request, response, UserModel.class);\r
-            try {\r
-                gitblit.addUser(model);\r
-            } catch (GitBlitException e) {\r
-                response.setStatus(failureCode);\r
-            }\r
-        } else if (RpcRequest.EDIT_USER.equals(reqType)) {\r
-            // edit user\r
-            UserModel model = deserialize(request, response, UserModel.class);\r
-            // name parameter specifies original user name in event of rename\r
-            String username = objectName;\r
-            if (username == null) {\r
-                username = model.username;\r
-            }\r
-            try {\r
-                gitblit.reviseUser(username, model);\r
-            } catch (GitBlitException e) {\r
-                response.setStatus(failureCode);\r
-            }\r
-        } else if (RpcRequest.DELETE_USER.equals(reqType)) {\r
-            // delete user\r
-            UserModel model = deserialize(request, response, UserModel.class);\r
-            if (!gitblit.deleteUser(model.username)) {\r
-                response.setStatus(failureCode);\r
-            }\r
-        } else if (RpcRequest.CREATE_TEAM.equals(reqType)) {\r
-            // create team\r
-            TeamModel model = deserialize(request, response, TeamModel.class);\r
-            try {\r
-                gitblit.addTeam(model);\r
-            } catch (GitBlitException e) {\r
-                response.setStatus(failureCode);\r
-            }\r
-        } else if (RpcRequest.EDIT_TEAM.equals(reqType)) {\r
-            // edit team\r
-            TeamModel model = deserialize(request, response, TeamModel.class);\r
-            // name parameter specifies original team name in event of rename\r
-            String teamname = objectName;\r
-            if (teamname == null) {\r
-                teamname = model.name;\r
-            }\r
-            try {\r
-                gitblit.reviseTeam(teamname, model);\r
-            } catch (GitBlitException e) {\r
-                response.setStatus(failureCode);\r
-            }\r
-        } else if (RpcRequest.DELETE_TEAM.equals(reqType)) {\r
-            // delete team\r
-            TeamModel model = deserialize(request, response, TeamModel.class);\r
-            if (!gitblit.deleteTeam(model.name)) {\r
-                response.setStatus(failureCode);\r
-            }\r
-        } else if (RpcRequest.LIST_REPOSITORY_MEMBERS.equals(reqType)) {\r
-            // get repository members\r
-            RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
-            result = gitblit.getRepositoryUsers(model);\r
-        } else if (RpcRequest.SET_REPOSITORY_MEMBERS.equals(reqType)) {\r
-            // rejected since 1.2.0\r
-            response.setStatus(failureCode);\r
-        } else if (RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
-            // get repository member permissions\r
-            RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
-            result = gitblit.getUserAccessPermissions(model);\r
-        } else if (RpcRequest.SET_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
-            // set the repository permissions for the specified users\r
-            RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
-            Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
-            result = gitblit.setUserAccessPermissions(model, permissions);\r
-        } else if (RpcRequest.LIST_REPOSITORY_TEAMS.equals(reqType)) {\r
-            // get repository teams\r
-            RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
-            result = gitblit.getRepositoryTeams(model);\r
-        } else if (RpcRequest.SET_REPOSITORY_TEAMS.equals(reqType)) {\r
-            // rejected since 1.2.0\r
-            response.setStatus(failureCode);\r
-        } else if (RpcRequest.LIST_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
-            // get repository team permissions\r
-            RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
-            result = gitblit.getTeamAccessPermissions(model);\r
-        } else if (RpcRequest.SET_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
-            // set the repository permissions for the specified teams\r
-            RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
-            Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
-            result = gitblit.setTeamAccessPermissions(model, permissions);\r
-        } else if (RpcRequest.LIST_FEDERATION_REGISTRATIONS.equals(reqType)) {\r
-            // return the list of federation registrations\r
-            if (allowAdmin) {\r
-                result = gitblit.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 (allowAdmin && gitblit.canFederate()) {\r
-                result = gitblit.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 (allowAdmin && gitblit.canFederate()) {\r
-                result = gitblit.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 (allowAdmin && gitblit.canFederate()) {\r
-                String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);\r
-                if (StringUtils.isEmpty(gitblitUrl)) {\r
-                    gitblitUrl = HttpUtils.getGitblitURL(request);\r
-                }\r
-                result = gitblit.getFederationSets(gitblitUrl);\r
-            } else {\r
-                response.sendError(notAllowedCode);\r
-            }\r
-        } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {\r
-            // return the server's settings\r
-            ServerSettings serverSettings = gitblit.getSettingsModel();\r
-            if (allowAdmin) {\r
-                // return all settings\r
-                result = serverSettings;\r
-            } else {\r
-                // anonymous users get a few settings to allow browser launching\r
-                List<String> keys = new ArrayList<String>();\r
-                keys.add(Keys.web.siteName);\r
-                keys.add(Keys.web.mountParameters);\r
-                keys.add(Keys.web.syndicationEntries);\r
+                       // list repositories\r
+                       List<RepositoryModel> list = gitblit.getRepositoryModels(user);\r
+                       Map<String, RepositoryModel> repositories = new HashMap<String, RepositoryModel>();\r
+                       for (RepositoryModel model : list) {\r
+                               String url = MessageFormat.format(cloneUrl, model.name);\r
+                               repositories.put(url, model);\r
+                       }\r
+                       result = repositories;\r
+               } else if (RpcRequest.LIST_BRANCHES.equals(reqType)) {\r
+                       // list all local branches in all repositories accessible to user\r
+                       Map<String, List<String>> localBranches = new HashMap<String, List<String>>();\r
+                       List<RepositoryModel> models = gitblit.getRepositoryModels(user);\r
+                       for (RepositoryModel model : models) {\r
+                               if (!model.hasCommits) {\r
+                                       // skip empty repository\r
+                                       continue;\r
+                               }\r
+                               if (model.isCollectingGarbage) {\r
+                                       // skip garbage collecting repository\r
+                                       logger.warn(MessageFormat.format("Temporarily excluding {0} from RPC, busy collecting garbage",\r
+                                                       model.name));\r
+                                       continue;\r
+                               }\r
+                               // get local branches\r
+                               Repository repository = gitblit.getRepository(model.name);\r
+                               List<RefModel> refs = JGitUtils.getLocalBranches(repository, false, -1);\r
+                               if (model.showRemoteBranches) {\r
+                                       // add remote branches if repository displays them\r
+                                       refs.addAll(JGitUtils.getRemoteBranches(repository, false, -1));\r
+                               }\r
+                               if (refs.size() > 0) {\r
+                                       List<String> branches = new ArrayList<String>();\r
+                                       for (RefModel ref : refs) {\r
+                                               branches.add(ref.getName());\r
+                                       }\r
+                                       localBranches.put(model.name, branches);\r
+                               }\r
+                               repository.close();\r
+                       }\r
+                       result = localBranches;\r
+               } else if (RpcRequest.GET_USER.equals(reqType)) {\r
+                       if (StringUtils.isEmpty(objectName)) {\r
+                               if (UserModel.ANONYMOUS.equals(user)) {\r
+                                       response.sendError(forbiddenCode);\r
+                               } else {\r
+                                       // return the current user, reset credentials\r
+                                       UserModel requestedUser = DeepCopier.copy(user);\r
+                                       result = requestedUser;\r
+                               }\r
+                       } else {\r
+                               if (user.canAdmin() || objectName.equals(user.username)) {\r
+                                       // return the specified user\r
+                                       UserModel requestedUser = gitblit.getUserModel(objectName);\r
+                                       if (requestedUser == null) {\r
+                                               response.setStatus(failureCode);\r
+                                       } else {\r
+                                               result = requestedUser;\r
+                                       }\r
+                               } else {\r
+                                       response.sendError(forbiddenCode);\r
+                               }\r
+                       }\r
+               } else if (RpcRequest.LIST_USERS.equals(reqType)) {\r
+                       // list users\r
+                       List<String> names = gitblit.getAllUsernames();\r
+                       List<UserModel> users = new ArrayList<UserModel>();\r
+                       for (String name : names) {\r
+                               users.add(gitblit.getUserModel(name));\r
+                       }\r
+                       result = users;\r
+               } else if (RpcRequest.LIST_TEAMS.equals(reqType)) {\r
+                       // list teams\r
+                       List<String> names = gitblit.getAllTeamNames();\r
+                       List<TeamModel> teams = new ArrayList<TeamModel>();\r
+                       for (String name : names) {\r
+                               teams.add(gitblit.getTeamModel(name));\r
+                       }\r
+                       result = teams;\r
+               } else if (RpcRequest.CREATE_REPOSITORY.equals(reqType)) {\r
+                       // create repository\r
+                       RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
+                       try {\r
+                               gitblit.updateRepositoryModel(model.name, model, true);\r
+                       } catch (GitBlitException e) {\r
+                               response.setStatus(failureCode);\r
+                       }\r
+               } else if (RpcRequest.FORK_REPOSITORY.equals(reqType)) {\r
+                       // fork repository\r
+                       RepositoryModel origin = gitblit.getRepositoryModel(objectName);\r
+                       if (origin == null) {\r
+                               // failed to find repository, error is logged by the repository\r
+                               // manager\r
+                               response.setStatus(failureCode);\r
+                       } else {\r
+                               if (user == null || !user.canFork(origin)) {\r
+                                       logger.error("User {} is not permitted to fork '{}'!", user == null ? "anonymous" : user.username,\r
+                                                       objectName);\r
+                                       response.setStatus(failureCode);\r
+                               } else {\r
+                                       try {\r
+                                               // fork the origin\r
+                                               RepositoryModel fork = gitblit.fork(origin, user);\r
+                                               if (fork == null) {\r
+                                                       logger.error("Failed to fork repository '{}'!", objectName);\r
+                                                       response.setStatus(failureCode);\r
+                                               } else {\r
+                                                       logger.info("User {} has forked '{}'!", user.username, objectName);\r
+                                               }\r
+                                       } catch (GitBlitException e) {\r
+                                               response.setStatus(failureCode);\r
+                                       }\r
+                               }\r
+                       }\r
+               } else if (RpcRequest.EDIT_REPOSITORY.equals(reqType)) {\r
+                       // edit repository\r
+                       RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
+                       // name specifies original repository name in event of rename\r
+                       String repoName = objectName;\r
+                       if (repoName == null) {\r
+                               repoName = model.name;\r
+                       }\r
+                       try {\r
+                               gitblit.updateRepositoryModel(repoName, model, false);\r
+                       } catch (GitBlitException e) {\r
+                               response.setStatus(failureCode);\r
+                       }\r
+               } else if (RpcRequest.DELETE_REPOSITORY.equals(reqType)) {\r
+                       // delete repository\r
+                       RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
+                       gitblit.deleteRepositoryModel(model);\r
+               } else if (RpcRequest.CREATE_USER.equals(reqType)) {\r
+                       // create user\r
+                       UserModel model = deserialize(request, response, UserModel.class);\r
+                       try {\r
+                               gitblit.addUser(model);\r
+                       } catch (GitBlitException e) {\r
+                               response.setStatus(failureCode);\r
+                       }\r
+               } else if (RpcRequest.EDIT_USER.equals(reqType)) {\r
+                       // edit user\r
+                       UserModel model = deserialize(request, response, UserModel.class);\r
+                       // name parameter specifies original user name in event of rename\r
+                       String username = objectName;\r
+                       if (username == null) {\r
+                               username = model.username;\r
+                       }\r
+                       try {\r
+                               gitblit.reviseUser(username, model);\r
+                       } catch (GitBlitException e) {\r
+                               response.setStatus(failureCode);\r
+                       }\r
+               } else if (RpcRequest.DELETE_USER.equals(reqType)) {\r
+                       // delete user\r
+                       UserModel model = deserialize(request, response, UserModel.class);\r
+                       if (!gitblit.deleteUser(model.username)) {\r
+                               response.setStatus(failureCode);\r
+                       }\r
+               } else if (RpcRequest.CREATE_TEAM.equals(reqType)) {\r
+                       // create team\r
+                       TeamModel model = deserialize(request, response, TeamModel.class);\r
+                       try {\r
+                               gitblit.addTeam(model);\r
+                       } catch (GitBlitException e) {\r
+                               response.setStatus(failureCode);\r
+                       }\r
+               } else if (RpcRequest.EDIT_TEAM.equals(reqType)) {\r
+                       // edit team\r
+                       TeamModel model = deserialize(request, response, TeamModel.class);\r
+                       // name parameter specifies original team name in event of rename\r
+                       String teamname = objectName;\r
+                       if (teamname == null) {\r
+                               teamname = model.name;\r
+                       }\r
+                       try {\r
+                               gitblit.reviseTeam(teamname, model);\r
+                       } catch (GitBlitException e) {\r
+                               response.setStatus(failureCode);\r
+                       }\r
+               } else if (RpcRequest.DELETE_TEAM.equals(reqType)) {\r
+                       // delete team\r
+                       TeamModel model = deserialize(request, response, TeamModel.class);\r
+                       if (!gitblit.deleteTeam(model.name)) {\r
+                               response.setStatus(failureCode);\r
+                       }\r
+               } else if (RpcRequest.LIST_REPOSITORY_MEMBERS.equals(reqType)) {\r
+                       // get repository members\r
+                       RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+                       result = gitblit.getRepositoryUsers(model);\r
+               } else if (RpcRequest.SET_REPOSITORY_MEMBERS.equals(reqType)) {\r
+                       // rejected since 1.2.0\r
+                       response.setStatus(failureCode);\r
+               } else if (RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
+                       // get repository member permissions\r
+                       RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+                       result = gitblit.getUserAccessPermissions(model);\r
+               } else if (RpcRequest.SET_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
+                       // set the repository permissions for the specified users\r
+                       RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+                       Collection<RegistrantAccessPermission> permissions = deserialize(request, response,\r
+                                       RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
+                       result = gitblit.setUserAccessPermissions(model, permissions);\r
+               } else if (RpcRequest.LIST_REPOSITORY_TEAMS.equals(reqType)) {\r
+                       // get repository teams\r
+                       RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+                       result = gitblit.getRepositoryTeams(model);\r
+               } else if (RpcRequest.SET_REPOSITORY_TEAMS.equals(reqType)) {\r
+                       // rejected since 1.2.0\r
+                       response.setStatus(failureCode);\r
+               } else if (RpcRequest.LIST_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
+                       // get repository team permissions\r
+                       RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+                       result = gitblit.getTeamAccessPermissions(model);\r
+               } else if (RpcRequest.SET_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
+                       // set the repository permissions for the specified teams\r
+                       RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+                       Collection<RegistrantAccessPermission> permissions = deserialize(request, response,\r
+                                       RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
+                       result = gitblit.setTeamAccessPermissions(model, permissions);\r
+               } else if (RpcRequest.LIST_FEDERATION_REGISTRATIONS.equals(reqType)) {\r
+                       // return the list of federation registrations\r
+                       if (allowAdmin) {\r
+                               result = gitblit.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 (allowAdmin && gitblit.canFederate()) {\r
+                               result = gitblit.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 (allowAdmin && gitblit.canFederate()) {\r
+                               result = gitblit.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 (allowAdmin && gitblit.canFederate()) {\r
+                               String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);\r
+                               if (StringUtils.isEmpty(gitblitUrl)) {\r
+                                       gitblitUrl = HttpUtils.getGitblitURL(request);\r
+                               }\r
+                               result = gitblit.getFederationSets(gitblitUrl);\r
+                       } else {\r
+                               response.sendError(notAllowedCode);\r
+                       }\r
+               } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {\r
+                       // return the server's settings\r
+                       ServerSettings serverSettings = gitblit.getSettingsModel();\r
+                       if (allowAdmin) {\r
+                               // return all settings\r
+                               result = serverSettings;\r
+                       } else {\r
+                               // anonymous users get a few settings to allow browser launching\r
+                               List<String> keys = new ArrayList<String>();\r
+                               keys.add(Keys.web.siteName);\r
+                               keys.add(Keys.web.mountParameters);\r
+                               keys.add(Keys.web.syndicationEntries);\r
 \r
-                if (allowManagement) {\r
-                    // keys necessary for repository and/or user management\r
-                    keys.add(Keys.realm.minPasswordLength);\r
-                    keys.add(Keys.realm.passwordStorage);\r
-                    keys.add(Keys.federation.sets);\r
-                }\r
-                // build the settings\r
-                ServerSettings managementSettings = new ServerSettings();\r
-                for (String key : keys) {\r
-                    managementSettings.add(serverSettings.get(key));\r
-                }\r
-                if (allowManagement) {\r
-                    managementSettings.pushScripts = serverSettings.pushScripts;\r
-                }\r
-                result = managementSettings;\r
-            }\r
-        } else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) {\r
-            // update settings on the server\r
-            if (allowAdmin) {\r
-                Map<String, String> map = deserialize(request, response,\r
-                        RpcUtils.SETTINGS_TYPE);\r
-                gitblit.updateSettings(map);\r
-            } else {\r
-                response.sendError(notAllowedCode);\r
-            }\r
-        } else if (RpcRequest.LIST_STATUS.equals(reqType)) {\r
-            // return the server's status information\r
-            if (allowAdmin) {\r
-                result = gitblit.getStatus();\r
-            } else {\r
-                response.sendError(notAllowedCode);\r
-            }\r
-        } else if (RpcRequest.CLEAR_REPOSITORY_CACHE.equals(reqType)) {\r
-            // clear the repository list cache\r
-            if (allowManagement) {\r
-                gitblit.resetRepositoryListCache();\r
-            } else {\r
-                response.sendError(notAllowedCode);\r
-            }\r
-        } else if (RpcRequest.REINDEX_TICKETS.equals(reqType)) {\r
-            if (allowManagement) {\r
-                if (StringUtils.isEmpty(objectName)) {\r
-                    // reindex all tickets\r
-                    gitblit.getTicketService().reindex();\r
-                } else {\r
-                    // reindex tickets in a specific repository\r
-                    RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
-                    gitblit.getTicketService().reindex(model);\r
-                }\r
-            } else {\r
-                response.sendError(notAllowedCode);\r
-            }\r
-        }\r
+                               if (allowManagement) {\r
+                                       // keys necessary for repository and/or user management\r
+                                       keys.add(Keys.realm.minPasswordLength);\r
+                                       keys.add(Keys.realm.passwordStorage);\r
+                                       keys.add(Keys.federation.sets);\r
+                               }\r
+                               // build the settings\r
+                               ServerSettings managementSettings = new ServerSettings();\r
+                               for (String key : keys) {\r
+                                       managementSettings.add(serverSettings.get(key));\r
+                               }\r
+                               if (allowManagement) {\r
+                                       managementSettings.pushScripts = serverSettings.pushScripts;\r
+                               }\r
+                               result = managementSettings;\r
+                       }\r
+               } else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) {\r
+                       // update settings on the server\r
+                       if (allowAdmin) {\r
+                               Map<String, String> map = deserialize(request, response, RpcUtils.SETTINGS_TYPE);\r
+                               gitblit.updateSettings(map);\r
+                       } else {\r
+                               response.sendError(notAllowedCode);\r
+                       }\r
+               } else if (RpcRequest.LIST_STATUS.equals(reqType)) {\r
+                       // return the server's status information\r
+                       if (allowAdmin) {\r
+                               result = gitblit.getStatus();\r
+                       } else {\r
+                               response.sendError(notAllowedCode);\r
+                       }\r
+               } else if (RpcRequest.CLEAR_REPOSITORY_CACHE.equals(reqType)) {\r
+                       // clear the repository list cache\r
+                       if (allowManagement) {\r
+                               gitblit.resetRepositoryListCache();\r
+                       } else {\r
+                               response.sendError(notAllowedCode);\r
+                       }\r
+               } else if (RpcRequest.REINDEX_TICKETS.equals(reqType)) {\r
+                       if (allowManagement) {\r
+                               if (StringUtils.isEmpty(objectName)) {\r
+                                       // reindex all tickets\r
+                                       gitblit.getTicketService().reindex();\r
+                               } else {\r
+                                       // reindex tickets in a specific repository\r
+                                       RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+                                       gitblit.getTicketService().reindex(model);\r
+                               }\r
+                       } else {\r
+                               response.sendError(notAllowedCode);\r
+                       }\r
+               }\r
 \r
-        // send the result of the request\r
-        serialize(response, result);\r
-    }\r
+               // send the result of the request\r
+               serialize(response, result);\r
+       }\r
 }\r