From d5623a235d54b308280d90920238bf75a2880b84 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Mon, 24 Oct 2011 16:32:57 -0400 Subject: [PATCH] Combined-md5 password storage option --- src/com/gitblit/GitBlit.java | 56 +++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 238c01f..ffef94a 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -25,12 +25,12 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -68,6 +68,7 @@ import com.gitblit.models.Metric; import com.gitblit.models.ObjectCache; import com.gitblit.models.RepositoryModel; +import com.gitblit.models.ServerSettings; import com.gitblit.models.ServerStatus; import com.gitblit.models.SettingModel; import com.gitblit.models.UserModel; @@ -123,7 +124,7 @@ private IStoredSettings settings; - private Map<String, SettingModel> settingModels; + private ServerSettings settingsModel; private ServerStatus serverStatus; @@ -244,6 +245,17 @@ */ public static boolean isDebugMode() { return self().settings.getBoolean(Keys.web.debugMode, false); + } + + /** + * Updates the list of server settings. + * + * @param settings + * @return true if the update succeeded + */ + public boolean updateSettings(Collection<SettingModel> settings) { + // TODO update the settings + return false; } public ServerStatus getStatus() { @@ -440,6 +452,13 @@ */ public void updateUserModel(String username, UserModel user, boolean isCreate) throws GitBlitException { + if (!username.equalsIgnoreCase(user.username)) { + if (userService.getUserModel(user.username) != null) { + throw new GitBlitException(MessageFormat.format( + "Failed to rename ''{0}'' because ''{1}'' already exists.", username, + user.username)); + } + } if (!userService.updateUserModel(username, user)) { throw new GitBlitException(isCreate ? "Failed to add user!" : "Failed to update user!"); } @@ -575,6 +594,7 @@ model.isFrozen = getConfig(config, "isFrozen", false); model.showReadme = getConfig(config, "showReadme", false); model.skipSizeCalculation = getConfig(config, "skipSizeCalculation", false); + model.skipSummaryMetrics = getConfig(config, "skipSummaryMetrics", false); model.federationStrategy = FederationStrategy.fromName(getConfig(config, "federationStrategy", null)); model.federationSets = new ArrayList<String>(Arrays.asList(config.getStringList( @@ -722,6 +742,15 @@ } else { // rename repository if (!repositoryName.equalsIgnoreCase(repository.name)) { + if (!repository.name.toLowerCase().endsWith( + org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) { + repository.name += org.eclipse.jgit.lib.Constants.DOT_GIT_EXT; + } + if (new File(repositoriesFolder, repository.name).exists()) { + throw new GitBlitException(MessageFormat.format( + "Failed to rename ''{0}'' because ''{1}'' already exists.", + repositoryName, repository.name)); + } closeRepository(repositoryName); File folder = new File(repositoriesFolder, repositoryName); File destFolder = new File(repositoriesFolder, repository.name); @@ -786,6 +815,7 @@ config.setBoolean("gitblit", null, "isFrozen", repository.isFrozen); config.setBoolean("gitblit", null, "showReadme", repository.showReadme); config.setBoolean("gitblit", null, "skipSizeCalculation", repository.skipSizeCalculation); + config.setBoolean("gitblit", null, "skipSummaryMetrics", repository.skipSummaryMetrics); config.setStringList("gitblit", null, "federationSets", repository.federationSets); config.setString("gitblit", null, "federationStrategy", repository.federationStrategy.name()); @@ -1275,16 +1305,12 @@ /** * Returns the descriptions/comments of the Gitblit config settings. * - * @return Map<String, SettingModel> + * @return SettingsModel */ - public Map<String, SettingModel> getSettingModels() { + public ServerSettings getSettingsModel() { // ensure that the current values are updated in the setting models - for (String key : settings.getAllKeys(null)) { - if (settingModels.containsKey(key)) { - settingModels.get(key).currentValue = settings.getString(key, ""); - } - } - return settingModels; + settingsModel.updateCurrentValues(settings); + return settingsModel; } /** @@ -1294,8 +1320,8 @@ * * @return Map<String, SettingModel> */ - private Map<String, SettingModel> loadSettingModels() { - Map<String, SettingModel> map = new TreeMap<String, SettingModel>(); + private ServerSettings loadSettingModels() { + ServerSettings settingsModel = new ServerSettings(); try { // Read bundled Gitblit properties to extract setting descriptions. // This copy is pristine and only used for populating the setting @@ -1337,7 +1363,7 @@ setting.defaultValue = kvp[1].trim(); setting.currentValue = setting.defaultValue; setting.description = description.toString().trim(); - map.put(key, setting); + settingsModel.add(setting); description.setLength(0); setting = new SettingModel(); } @@ -1349,7 +1375,7 @@ } catch (IOException e) { logger.error("Failed to load resource copy of gitblit.properties"); } - return map; + return settingsModel; } /** @@ -1409,7 +1435,7 @@ @Override public void contextInitialized(ServletContextEvent contextEvent) { servletContext = contextEvent.getServletContext(); - settingModels = loadSettingModels(); + settingsModel = loadSettingModels(); if (settings == null) { // Gitblit WAR is running in a servlet container WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext()); -- Gitblit v1.9.1