Added skeleton mechanism to update server settings via rpc.
# SINCE 0.7.0 \r
web.enableRpcServlet = true\r
\r
-# Allows remote clients to administer the Gitblit instance, if the authenticated\r
-# account has administrator permissions. Requires *web.enableRpcServlet=true*.\r
+# Allows remote clients to manage repositories and users of the Gitblit instance,\r
+# if the authenticated account has administrator permissions.\r
+# Requires *web.enableRpcServlet=true*.\r
+#\r
+# SINCE 0.7.0 \r
+web.enableRpcManagement = false\r
+\r
+# Allows remote clients to control the server settings of the Gitblit instance,\r
+# if the authenticated account has administrator permissions.\r
+# Requires *web.enableRpcServlet=true* and *web.enableRpcManagement*.\r
#\r
# SINCE 0.7.0 \r
web.enableRpcAdministration = false\r
LIST_REPOSITORIES, CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,\r
LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, LIST_REPOSITORY_MEMBERS,\r
SET_REPOSITORY_MEMBERS, LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS,\r
- LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS, LIST_SETTINGS,\r
+ LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS, LIST_SETTINGS, EDIT_SETTINGS,\r
LIST_STATUS;\r
\r
public static RpcRequest fromName(String name) {\r
import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
+import java.util.Collection;\r
import java.util.Collections;\r
import java.util.HashMap;\r
import java.util.List;\r
import com.gitblit.models.Metric;\r
import com.gitblit.models.ObjectCache;\r
import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.models.ServerSettings;\r
import com.gitblit.models.ServerStatus;\r
import com.gitblit.models.SettingModel;\r
-import com.gitblit.models.ServerSettings;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.ByteFormat;\r
import com.gitblit.utils.FederationUtils;\r
return self().settings.getBoolean(Keys.web.debugMode, false);\r
}\r
\r
+ /**\r
+ * Updates the list of server settings.\r
+ * \r
+ * @param settings\r
+ * @return true if the update succeeded\r
+ */\r
+ public boolean updateSettings(Collection<SettingModel> settings) {\r
+ // TODO update the settings\r
+ return false;\r
+ }\r
+\r
public ServerStatus getStatus() {\r
// update heap memory status\r
serverStatus.heapAllocated = Runtime.getRuntime().totalMemory();\r
throws GitBlitException {\r
if (!username.equalsIgnoreCase(user.username)) {\r
if (userService.getUserModel(user.username) != null) {\r
- throw new GitBlitException(\r
- MessageFormat\r
- .format("Failed to rename ''{0}'' because ''{1}'' already exists.",\r
- username, user.username));\r
+ throw new GitBlitException(MessageFormat.format(\r
+ "Failed to rename ''{0}'' because ''{1}'' already exists.", username,\r
+ user.username));\r
}\r
}\r
if (!userService.updateUserModel(username, user)) {\r
repository.name += org.eclipse.jgit.lib.Constants.DOT_GIT_EXT;\r
}\r
if (new File(repositoriesFolder, repository.name).exists()) {\r
- throw new GitBlitException(\r
- MessageFormat\r
- .format("Failed to rename ''{0}'' because ''{1}'' already exists.",\r
- repositoryName, repository.name));\r
+ throw new GitBlitException(MessageFormat.format(\r
+ "Failed to rename ''{0}'' because ''{1}'' already exists.",\r
+ repositoryName, repository.name));\r
}\r
closeRepository(repositoryName);\r
File folder = new File(repositoriesFolder, repositoryName);\r
String fullUrl = getFullUrl(httpRequest);\r
RpcRequest requestType = RpcRequest.fromName(httpRequest.getParameter("req"));\r
if (requestType == null) {\r
- httpResponse.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); \r
+ httpResponse.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);\r
return;\r
}\r
\r
\r
boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, false);\r
boolean authenticateAdmin = GitBlit.getBoolean(Keys.web.authenticateAdminPages, true);\r
- \r
- // Wrap the HttpServletRequest with the RpcServletnRequest which\r
+\r
+ // Wrap the HttpServletRequest with the RpcServletRequest which\r
// overrides the servlet container user principal methods.\r
AuthenticatedRequest authenticatedRequest = new AuthenticatedRequest(httpRequest);\r
UserModel user = getUser(httpRequest);\r
if (user != null) {\r
authenticatedRequest.setUser(user);\r
}\r
- \r
- // conditionally reject rpc administration requests\r
- if (adminRequest && !GitBlit.getBoolean(Keys.web.enableRpcAdministration, false)) {\r
- logger.warn(Keys.web.enableRpcAdministration + " must be set TRUE for administrative rpc requests.");\r
+\r
+ // conditionally reject rpc management/administration requests\r
+ if (adminRequest && !GitBlit.getBoolean(Keys.web.enableRpcManagement, false)) {\r
+ logger.warn(Keys.web.enableRpcManagement\r
+ + " must be set TRUE for management/administrative rpc requests.");\r
httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);\r
return;\r
}\r
- \r
+\r
// BASIC authentication challenge and response processing\r
if ((adminRequest && authenticateAdmin) || (!adminRequest && authenticateView)) {\r
if (user == null) {\r
\r
import com.gitblit.Constants.RpcRequest;\r
import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.models.SettingModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.HttpUtils;\r
import com.gitblit.utils.RpcUtils;\r
}\r
} else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {\r
// return the server's settings\r
- result = GitBlit.self().getSettingsModel();\r
+ if (GitBlit.getBoolean(Keys.web.enableRpcAdministration, false)) {\r
+ result = GitBlit.self().getSettingsModel();\r
+ } else {\r
+ response.sendError(notAllowedCode);\r
+ }\r
+ } else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) {\r
+ // update settings on the server\r
+ if (GitBlit.getBoolean(Keys.web.enableRpcAdministration, false)) {\r
+ Collection<SettingModel> settings = deserialize(request, response,\r
+ RpcUtils.SETTINGS_TYPE);\r
+ GitBlit.self().updateSettings(settings);\r
+ } else {\r
+ response.sendError(notAllowedCode);\r
+ }\r
} else if (RpcRequest.LIST_STATUS.equals(reqType)) {\r
// return the server's status information\r
result = GitBlit.self().getStatus();\r
public final String account;\r
\r
private final char[] password;\r
+ \r
+ private volatile boolean allowManagement;\r
\r
- private volatile boolean isAdmin;\r
+ private volatile boolean allowAdministration;\r
\r
private volatile ServerSettings settings;\r
\r
public void login() throws IOException {\r
refreshRepositories();\r
\r
+ try {\r
+ refreshUsers();\r
+ allowManagement = true;\r
+ } catch (UnauthorizedException e) {\r
+ } catch (ForbiddenException e) {\r
+ } catch (IOException e) {\r
+ System.err.println(e.getMessage());\r
+ }\r
+\r
try {\r
settings = RpcUtils.getSettings(url, account, password);\r
status = RpcUtils.getStatus(url, account, password);\r
- refreshUsers();\r
- isAdmin = true;\r
+ allowAdministration = true;\r
} catch (UnauthorizedException e) {\r
} catch (ForbiddenException e) {\r
} catch (IOException e) {\r
System.err.println(e.getMessage());\r
}\r
+\r
}\r
\r
- public boolean allowAdmin() {\r
- return isAdmin;\r
+ public boolean allowManagement() {\r
+ return allowManagement;\r
+ }\r
+ \r
+ public boolean allowAdministration() {\r
+ return allowAdministration;\r
}\r
\r
public boolean isOwner(RepositoryModel model) {\r
repositoriesTable = Utils.newTable(repositoriesModel);\r
repositoriesTable.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
repositoriesTable.setRowSorter(defaultRepositoriesSorter);\r
- repositoriesTable.getRowSorter().toggleSortOrder(RepositoriesTableModel.Columns.Name.ordinal());\r
+ repositoriesTable.getRowSorter().toggleSortOrder(\r
+ RepositoriesTableModel.Columns.Name.ordinal());\r
\r
setRepositoryRenderer(RepositoriesTableModel.Columns.Name, nameRenderer, -1);\r
setRepositoryRenderer(RepositoriesTableModel.Columns.Indicators, typeRenderer, 100);\r
RepositoryModel model = ((RepositoriesTableModel) repositoriesTable.getModel()).list\r
.get(modelRow);\r
editRepository.setEnabled(singleSelection\r
- && (gitblit.allowAdmin() || gitblit.isOwner(model)));\r
+ && (gitblit.allowManagement() || gitblit.isOwner(model)));\r
} else {\r
editRepository.setEnabled(false);\r
}\r
\r
repositoriesTable.addMouseListener(new MouseAdapter() {\r
public void mouseClicked(MouseEvent e) {\r
- if (e.getClickCount() == 2 && gitblit.allowAdmin()) {\r
+ if (e.getClickCount() == 2 && gitblit.allowManagement()) {\r
editRepository(getSelectedRepositories().get(0));\r
}\r
}\r
return repositoriesPanel;\r
}\r
\r
- private void setRepositoryRenderer(RepositoriesTableModel.Columns col, TableCellRenderer renderer,\r
- int maxWidth) {\r
+ private void setRepositoryRenderer(RepositoriesTableModel.Columns col,\r
+ TableCellRenderer renderer, int maxWidth) {\r
String name = repositoriesTable.getColumnName(col.ordinal());\r
repositoriesTable.getColumn(name).setCellRenderer(renderer);\r
if (maxWidth > 0) {\r
updateRepositoriesTable();\r
Utils.packColumns(repositoriesTable, 2);\r
\r
- if (gitblit.allowAdmin()) {\r
+ if (gitblit.allowManagement()) {\r
updateUsersTable();\r
- updateSettingsTable();\r
} else {\r
// user does not have administrator privileges\r
// hide admin repository buttons\r
delRepository.setVisible(false);\r
\r
while (tabs.getTabCount() > 1) {\r
- // remove admin tabs\r
+ // remove all management/administration tabs\r
tabs.removeTabAt(1);\r
}\r
}\r
+\r
+ if (gitblit.allowAdministration()) {\r
+ updateSettingsTable();\r
+ } else {\r
+ // remove the settings tab\r
+ String settingsTitle = Translation.get("gb.settings");\r
+ for (int i= 0; i < tabs.getTabCount(); i++) {\r
+ if (tabs.getTitleAt(i).equals(settingsTitle)) {\r
+ tabs.removeTabAt(i);\r
+ break;\r
+ } \r
+ }\r
+ }\r
}\r
\r
private void updateRepositoriesTable() {\r
return false;\r
}\r
};\r
- TableRowSorter<SettingsTableModel> sorter = new TableRowSorter<SettingsTableModel>(settingsModel);\r
+ TableRowSorter<SettingsTableModel> sorter = new TableRowSorter<SettingsTableModel>(\r
+ settingsModel);\r
sorter.setRowFilter(containsFilter);\r
settingsTable.setRowSorter(sorter);\r
}\r
import com.gitblit.models.FederationProposal;\r
import com.gitblit.models.FederationSet;\r
import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.ServerStatus;\r
import com.gitblit.models.ServerSettings;\r
+import com.gitblit.models.ServerStatus;\r
+import com.gitblit.models.SettingModel;\r
import com.gitblit.models.UserModel;\r
import com.google.gson.reflect.TypeToken;\r
\r
public static final Type NAMES_TYPE = new TypeToken<Collection<String>>() {\r
}.getType();\r
\r
+ public static final Type SETTINGS_TYPE = new TypeToken<Collection<SettingModel>>() {\r
+ }.getType();\r
+\r
private static final Type REPOSITORIES_TYPE = new TypeToken<Map<String, RepositoryModel>>() {\r
}.getType();\r
\r
public static ServerSettings getSettings(String serverUrl, String account, char[] password)\r
throws IOException {\r
String url = asLink(serverUrl, RpcRequest.LIST_SETTINGS);\r
- ServerSettings settings = JsonUtils.retrieveJson(url, ServerSettings.class, account, password);\r
+ ServerSettings settings = JsonUtils.retrieveJson(url, ServerSettings.class, account,\r
+ password);\r
return settings;\r
}\r
\r
+ /**\r
+ * Update the settings on the Gitblit server.\r
+ * \r
+ * @param settings\r
+ * the settings to update\r
+ * @param serverUrl\r
+ * @param account\r
+ * @param password\r
+ * @return true if the action succeeded\r
+ * @throws IOException\r
+ */\r
+ public static boolean updateSettings(Map<String, String> settings, String serverUrl,\r
+ String account, char[] password) throws IOException {\r
+ return doAction(RpcRequest.EDIT_SETTINGS, null, settings, serverUrl, account, password);\r
+\r
+ }\r
+\r
/**\r
* Retrieves the server status object.\r
* \r