* @param subject\r
* @param message\r
*/\r
- public void notifyAdministrators(String subject, String message) {\r
+ public void sendEmailToAdministrators(String subject, String message) {\r
try {\r
Message mail = mailExecutor.createMessageForAdministrators();\r
if (mail != null) {\r
* @param message\r
* @param toAddresses\r
*/\r
- public void notifyUsers(String subject, String message, ArrayList<String> toAddresses) {\r
- this.notifyUsers(subject, message, toAddresses.toArray(new String[0]));\r
+ public void sendEmail(String subject, String message, ArrayList<String> toAddresses) {\r
+ this.sendEmail(subject, message, toAddresses.toArray(new String[0]));\r
}\r
\r
/**\r
* @param message\r
* @param toAddresses\r
*/\r
- public void notifyUsers(String subject, String message, String... toAddresses) {\r
+ public void sendEmail(String subject, String message, String... toAddresses) {\r
try {\r
Message mail = mailExecutor.createMessage(toAddresses);\r
if (mail != null) {\r
* \r
* @param settings\r
*/\r
- @SuppressWarnings("deprecation")\r
public void configureContext(IStoredSettings settings, boolean startFederation) {\r
logger.info("Reading configuration from " + settings.toString());\r
this.settings = settings;\r
loginService = (IUserService) realmClass.newInstance();\r
}\r
} catch (Throwable t) {\r
- // not a login service class or class could not be instantiated.\r
- // try to use default file login service\r
- File realmFile = getFileOrFolder(Keys.realm.userService, "users.conf");\r
- if (realmFile.exists()) {\r
- // load the existing realm file\r
- if (realmFile.getName().toLowerCase().endsWith(".properties")) {\r
- // load the v0.5.0 - v0.7.0 properties-based realm file\r
- loginService = new FileUserService(realmFile);\r
-\r
- // automatically create a users.conf realm file from the\r
- // original users.properties file\r
- File usersConfig = new File(realmFile.getParentFile(), "users.conf");\r
- if (!usersConfig.exists()) {\r
- logger.info(MessageFormat.format("Automatically creating {0} based on {1}",\r
- usersConfig.getAbsolutePath(), realmFile.getAbsolutePath()));\r
- ConfigUserService configService = new ConfigUserService(usersConfig);\r
- for (String username : loginService.getAllUsernames()) {\r
- UserModel userModel = loginService.getUserModel(username);\r
- configService.updateUserModel(userModel);\r
- }\r
- }\r
-\r
- // issue suggestion about switching to users.conf\r
- logger.warn("Please consider using \"users.conf\" instead of the deprecated \"users.properties\" file");\r
- } else if (realmFile.getName().toLowerCase().endsWith(".conf")) {\r
- // load the config-based realm file\r
- loginService = new ConfigUserService(realmFile);\r
- }\r
- } else {\r
- // Create a new realm file and add the default admin\r
- // account. This is necessary for bootstrapping a dynamic\r
- // environment like running on a cloud service.\r
- // As of v0.8.0 the default realm file is ConfigUserService.\r
- try {\r
- realmFile = getFileOrFolder(Keys.realm.userService, "users.conf");\r
- realmFile.createNewFile();\r
- loginService = new ConfigUserService(realmFile);\r
- UserModel admin = new UserModel("admin");\r
- admin.password = "admin";\r
- admin.canAdmin = true;\r
- admin.excludeFromFederation = true;\r
- loginService.updateUserModel(admin);\r
- } catch (IOException x) {\r
- logger.error(\r
- MessageFormat.format("COULD NOT CREATE REALM FILE {0}!", realmFile), x);\r
+ loginService = new UserServiceWrapper() {\r
+ @Override\r
+ public void setupService(IStoredSettings settings) {\r
}\r
- }\r
+ };\r
}\r
setUserService(loginService);\r
mailExecutor = new MailExecutor(settings);\r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.text.MessageFormat;\r
+import java.util.List;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+import com.gitblit.models.TeamModel;\r
+import com.gitblit.models.UserModel;\r
+\r
+/**\r
+ * This class wraps the default user service and is recommended as the starting\r
+ * point for custom user service implementations.\r
+ * \r
+ * This does seem a little convoluted, but the idea is to allow IUserService to\r
+ * evolve and be replaced without hampering custom implementations.\r
+ * \r
+ * The most common need for a custom IUserService is to override authentication\r
+ * and then delegate to one of Gitblit's user services. Subclassing this allows\r
+ * for authentication customization without having to keep-up-with IUSerService\r
+ * API changes.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public abstract class UserServiceWrapper implements IUserService {\r
+\r
+ protected IUserService defaultService;\r
+\r
+ private final Logger logger = LoggerFactory.getLogger(UserServiceWrapper.class);\r
+\r
+ public UserServiceWrapper() {\r
+ }\r
+\r
+ @SuppressWarnings("deprecation")\r
+ @Override\r
+ public final void setup(IStoredSettings settings) {\r
+ File realmFile = GitBlit.getFileOrFolder(Keys.realm.userService, "users.conf");\r
+ if (realmFile.exists()) {\r
+ // load the existing realm file\r
+ if (realmFile.getName().toLowerCase().endsWith(".properties")) {\r
+ // load the v0.5.0 - v0.7.0 properties-based realm file\r
+ defaultService = new FileUserService(realmFile);\r
+\r
+ // automatically create a users.conf realm file from the\r
+ // original users.properties file\r
+ File usersConfig = new File(realmFile.getParentFile(), "users.conf");\r
+ if (!usersConfig.exists()) {\r
+ logger.info(MessageFormat.format("Automatically creating {0} based on {1}",\r
+ usersConfig.getAbsolutePath(), realmFile.getAbsolutePath()));\r
+ ConfigUserService configService = new ConfigUserService(usersConfig);\r
+ for (String username : defaultService.getAllUsernames()) {\r
+ UserModel userModel = defaultService.getUserModel(username);\r
+ configService.updateUserModel(userModel);\r
+ }\r
+ }\r
+\r
+ // issue suggestion about switching to users.conf\r
+ logger.warn("Please consider using \"users.conf\" instead of the deprecated \"users.properties\" file");\r
+ } else if (realmFile.getName().toLowerCase().endsWith(".conf")) {\r
+ // load the config-based realm file\r
+ defaultService = new ConfigUserService(realmFile);\r
+ }\r
+ } else {\r
+ // Create a new realm file and add the default admin\r
+ // account. This is necessary for bootstrapping a dynamic\r
+ // environment like running on a cloud service.\r
+ // As of v0.8.0 the default realm file is ConfigUserService.\r
+ try {\r
+ realmFile = GitBlit.getFileOrFolder(Keys.realm.userService, "users.conf");\r
+ realmFile.createNewFile();\r
+ defaultService = new ConfigUserService(realmFile);\r
+ UserModel admin = new UserModel("admin");\r
+ admin.password = "admin";\r
+ admin.canAdmin = true;\r
+ admin.excludeFromFederation = true;\r
+ defaultService.updateUserModel(admin);\r
+ } catch (IOException x) {\r
+ logger.error(MessageFormat.format("COULD NOT CREATE REALM FILE {0}!", realmFile), x);\r
+ }\r
+ }\r
+\r
+ // call subclass setup\r
+ setupService(settings);\r
+ }\r
+\r
+ /**\r
+ * Subclasses must implement this method.\r
+ * \r
+ * @param settings\r
+ */\r
+ public abstract void setupService(IStoredSettings settings);\r
+\r
+ @Override\r
+ public boolean supportsCookies() {\r
+ return defaultService.supportsCookies();\r
+ }\r
+\r
+ @Override\r
+ public char[] getCookie(UserModel model) {\r
+ return defaultService.getCookie(model);\r
+ }\r
+\r
+ @Override\r
+ public UserModel authenticate(char[] cookie) {\r
+ return defaultService.authenticate(cookie);\r
+ }\r
+\r
+ @Override\r
+ public UserModel authenticate(String username, char[] password) {\r
+ return defaultService.authenticate(username, password);\r
+ }\r
+\r
+ @Override\r
+ public UserModel getUserModel(String username) {\r
+ return defaultService.getUserModel(username);\r
+ }\r
+\r
+ @Override\r
+ public boolean updateUserModel(UserModel model) {\r
+ return defaultService.updateUserModel(model);\r
+ }\r
+\r
+ @Override\r
+ public boolean updateUserModel(String username, UserModel model) {\r
+ return defaultService.updateUserModel(username, model);\r
+ }\r
+\r
+ @Override\r
+ public boolean deleteUserModel(UserModel model) {\r
+ return defaultService.deleteUserModel(model);\r
+ }\r
+\r
+ @Override\r
+ public boolean deleteUser(String username) {\r
+ return defaultService.deleteUser(username);\r
+ }\r
+\r
+ @Override\r
+ public List<String> getAllUsernames() {\r
+ return defaultService.getAllUsernames();\r
+ }\r
+\r
+ @Override\r
+ public List<String> getAllTeamNames() {\r
+ return defaultService.getAllTeamNames();\r
+ }\r
+\r
+ @Override\r
+ public List<String> getTeamnamesForRepositoryRole(String role) {\r
+ return defaultService.getTeamnamesForRepositoryRole(role);\r
+ }\r
+\r
+ @Override\r
+ public boolean setTeamnamesForRepositoryRole(String role, List<String> teamnames) {\r
+ return defaultService.setTeamnamesForRepositoryRole(role, teamnames);\r
+ }\r
+\r
+ @Override\r
+ public TeamModel getTeamModel(String teamname) {\r
+ return defaultService.getTeamModel(teamname);\r
+ }\r
+\r
+ @Override\r
+ public boolean updateTeamModel(TeamModel model) {\r
+ return defaultService.updateTeamModel(model);\r
+ }\r
+\r
+ @Override\r
+ public boolean updateTeamModel(String teamname, TeamModel model) {\r
+ return defaultService.updateTeamModel(teamname, model);\r
+ }\r
+\r
+ @Override\r
+ public boolean deleteTeamModel(TeamModel model) {\r
+ return defaultService.deleteTeamModel(model);\r
+ }\r
+\r
+ @Override\r
+ public boolean deleteTeam(String teamname) {\r
+ return defaultService.deleteTeam(teamname);\r
+ }\r
+\r
+ @Override\r
+ public List<String> getUsernamesForRepositoryRole(String role) {\r
+ return defaultService.getUsernamesForRepositoryRole(role);\r
+ }\r
+\r
+ @Override\r
+ public boolean setUsernamesForRepositoryRole(String role, List<String> usernames) {\r
+ return defaultService.setUsernamesForRepositoryRole(role, usernames);\r
+ }\r
+\r
+ @Override\r
+ public boolean renameRepositoryRole(String oldRole, String newRole) {\r
+ return defaultService.renameRepositoryRole(oldRole, newRole);\r
+ }\r
+\r
+ @Override\r
+ public boolean deleteRepositoryRole(String role) {\r
+ return defaultService.deleteRepositoryRole(role);\r
+ }\r
+}\r