From 93f4729cdfc856d2a3b155bcf3e97f85b47ce760 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Sun, 04 Dec 2011 16:55:42 -0500
Subject: [PATCH] Implemented ConfigUserService. Fixed and deprecated FileUserService.
---
src/com/gitblit/GitBlit.java | 42 ++++++++++++++++++++++++++++++++++--------
1 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java
index 80550f4..60a96e6 100644
--- a/src/com/gitblit/GitBlit.java
+++ b/src/com/gitblit/GitBlit.java
@@ -1435,6 +1435,7 @@
*
* @param settings
*/
+ @SuppressWarnings("deprecation")
public void configureContext(IStoredSettings settings, boolean startFederation) {
logger.info("Reading configuration from " + settings.toString());
this.settings = settings;
@@ -1453,20 +1454,45 @@
} catch (Throwable t) {
// not a login service class or class could not be instantiated.
// try to use default file login service
- File realmFile = getFileOrFolder(Keys.realm.userService, "users.properties");
+ File realmFile = getFileOrFolder(Keys.realm.userService, "users.conf");
if (realmFile.exists()) {
// load the existing realm file
- loginService = new FileUserService(realmFile);
- } else {
- // create a new realm file and add the default admin account.
- // this is necessary for bootstrapping a dynamic environment
- // like running on a cloud service.
- try {
- realmFile.createNewFile();
+ if (realmFile.getName().toLowerCase().endsWith(".properties")) {
+ // load the v0.5.0 - v0.7.0 properties-based realm file
loginService = new FileUserService(realmFile);
+
+ // automatically create a users.conf realm file from the
+ // original users.properties file
+ File usersConfig = new File(realmFile.getParentFile(), "users.conf");
+ if (!usersConfig.exists()) {
+ logger.info(MessageFormat.format("Automatically creating {0} based on {1}",
+ usersConfig.getAbsolutePath(), realmFile.getAbsolutePath()));
+ ConfigUserService configService = new ConfigUserService(usersConfig);
+ for (String username : loginService.getAllUsernames()) {
+ UserModel userModel = loginService.getUserModel(username);
+ configService.updateUserModel(userModel);
+ }
+ }
+
+ // issue suggestion about switching to users.conf
+ logger.warn("Please consider using \"users.conf\" instead of the deprecated \"users.properties\" file");
+ } else if (realmFile.getName().toLowerCase().endsWith(".conf")) {
+ // load the config-based realm file
+ loginService = new ConfigUserService(realmFile);
+ }
+ } else {
+ // Create a new realm file and add the default admin
+ // account. This is necessary for bootstrapping a dynamic
+ // environment like running on a cloud service.
+ // As of v0.8.0 the default realm file is ConfigUserService.
+ try {
+ realmFile = getFileOrFolder(Keys.realm.userService, "users.conf");
+ realmFile.createNewFile();
+ loginService = new ConfigUserService(realmFile);
UserModel admin = new UserModel("admin");
admin.password = "admin";
admin.canAdmin = true;
+ admin.excludeFromFederation = true;
loginService.updateUserModel(admin);
} catch (IOException x) {
logger.error(
--
Gitblit v1.9.1