import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
\r
+import com.gitblit.models.*;\r
import org.eclipse.jgit.lib.Repository;\r
\r
import com.gitblit.Constants;\r
import com.gitblit.IStoredSettings;\r
import com.gitblit.Keys;\r
import com.gitblit.manager.IGitblit;\r
-import com.gitblit.models.RefModel;\r
-import com.gitblit.models.RegistrantAccessPermission;\r
-import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.ServerSettings;\r
-import com.gitblit.models.TeamModel;\r
-import com.gitblit.models.UserModel;\r
import com.gitblit.utils.DeepCopier;\r
import com.gitblit.utils.HttpUtils;\r
import com.gitblit.utils.JGitUtils;\r
* Handles remote procedure calls.\r
*\r
* @author James Moger\r
- *\r
*/\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 = 7;\r
\r
- public static final int PROTOCOL_VERSION = 7;\r
+ private IStoredSettings settings;\r
\r
- private IStoredSettings settings;\r
+ private IGitblit gitblit;\r
\r
- private IGitblit gitblit;\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
- @Override\r
- protected void inject(ObjectGraph dagger) {\r
- this.settings = dagger.get(IStoredSettings.class);\r
- this.gitblit = dagger.get(IGitblit.class);\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
- /**\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
+ UserModel user = (UserModel) request.getUserPrincipal();\r
\r
- UserModel user = (UserModel) request.getUserPrincipal();\r
+ boolean allowManagement = user != null && user.canAdmin()\r
+ && settings.getBoolean(Keys.web.enableRpcManagement, false);\r
\r
- boolean allowManagement = user != null && user.canAdmin()\r
- && settings.getBoolean(Keys.web.enableRpcManagement, false);\r
+ boolean allowAdmin = user != null && user.canAdmin()\r
+ && settings.getBoolean(Keys.web.enableRpcAdministration, false);\r
\r
- boolean allowAdmin = user != null && user.canAdmin()\r
- && settings.getBoolean(Keys.web.enableRpcAdministration, false);\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
- 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
+ // 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
+ UserRepositoryCompositeModel userRepositoryCompositeModel = deserialize(request, response,\r
+ UserRepositoryCompositeModel.class);\r
+ RepositoryModel repoModel = userRepositoryCompositeModel.getRepositoryModel();\r
+ UserModel userModel = userRepositoryCompositeModel.getUserModel();\r
+ try {\r
+ if (repoModel != null && userModel != null) {\r
+ gitblit.fork(repoModel, userModel);\r
+ } else {\r
+ System.out.println("Non existing user model or repo model");\r
+ response.setStatus(failureCode);\r
+ }\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.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
+ } catch (GitBlitException e) {\r
+ response.setStatus(failureCode);\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
\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,\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
\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