| | |
| | | public boolean setRepositoryTeams(RepositoryModel repository, List<String> repositoryTeams) {
|
| | | return userService.setTeamnamesForRepositoryRole(repository.name, repositoryTeams);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Updates the TeamModel object for the specified name.
|
| | | *
|
| | |
| | | * @param team
|
| | | * @param isCreate
|
| | | */
|
| | | public void updateTeamModel(String teamname, TeamModel team, boolean isCreate) throws GitBlitException {
|
| | | public void updateTeamModel(String teamname, TeamModel team, boolean isCreate)
|
| | | throws GitBlitException {
|
| | | if (!teamname.equalsIgnoreCase(team.name)) {
|
| | | if (userService.getTeamModel(team.name) != null) {
|
| | | throw new GitBlitException(MessageFormat.format(
|
| | |
| | | throw new GitBlitException(isCreate ? "Failed to add team!" : "Failed to update team!");
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * Delete the team object with the specified teamname
|
| | | *
|
| | |
| | | "gitblit", null, "federationSets")));
|
| | | model.isFederated = getConfig(config, "isFederated", false);
|
| | | model.origin = config.getString("remote", "origin", "url");
|
| | | model.preReceiveScripts = new ArrayList<String>(Arrays.asList(config.getStringList(
|
| | | "gitblit", null, "preReceiveScript")));
|
| | | model.postReceiveScripts = new ArrayList<String>(Arrays.asList(config.getStringList(
|
| | | "gitblit", null, "postReceiveScript")));
|
| | | model.mailRecipients = new ArrayList<String>(Arrays.asList(config.getStringList(
|
| | | "gitblit", null, "mailRecipient")));
|
| | | }
|
| | | r.close();
|
| | | return model;
|
| | |
| | | config.setString("gitblit", null, "federationStrategy",
|
| | | repository.federationStrategy.name());
|
| | | config.setBoolean("gitblit", null, "isFederated", repository.isFederated);
|
| | | if (repository.preReceiveScripts != null) {
|
| | | config.setStringList("gitblit", null, "preReceiveScript", repository.preReceiveScripts);
|
| | | }
|
| | | if (repository.postReceiveScripts != null) {
|
| | | config.setStringList("gitblit", null, "postReceiveScript",
|
| | | repository.postReceiveScripts);
|
| | | }
|
| | | if (repository.mailRecipients != null) {
|
| | | config.setStringList("gitblit", null, "mailRecipient", repository.mailRecipients);
|
| | | }
|
| | | try {
|
| | | config.save();
|
| | | } catch (IOException e) {
|
| | |
| | | * @param subject
|
| | | * @param message
|
| | | */
|
| | | public void notifyAdministrators(String subject, String message) {
|
| | | public void sendEmailToAdministrators(String subject, String message) {
|
| | | try {
|
| | | Message mail = mailExecutor.createMessageForAdministrators();
|
| | | if (mail != null) {
|
| | | mail.setSubject(subject);
|
| | | mail.setText(message);
|
| | | mailExecutor.queue(mail);
|
| | | }
|
| | | } catch (MessagingException e) {
|
| | | logger.error("Messaging error", e);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * Notify users by email of something.
|
| | | * |
| | | * @param subject
|
| | | * @param message
|
| | | * @param toAddresses
|
| | | */
|
| | | public void sendEmail(String subject, String message, ArrayList<String> toAddresses) {
|
| | | this.sendEmail(subject, message, toAddresses.toArray(new String[0]));
|
| | | }
|
| | |
|
| | | /**
|
| | | * Notify users by email of something.
|
| | | * |
| | | * @param subject
|
| | | * @param message
|
| | | * @param toAddresses
|
| | | */
|
| | | public void sendEmail(String subject, String message, String... toAddresses) {
|
| | | try {
|
| | | Message mail = mailExecutor.createMessage(toAddresses);
|
| | | if (mail != null) {
|
| | | mail.setSubject(subject);
|
| | | mail.setText(message);
|
| | |
| | | *
|
| | | * @param settings
|
| | | */
|
| | | @SuppressWarnings("deprecation")
|
| | | public void configureContext(IStoredSettings settings, boolean startFederation) {
|
| | | logger.info("Reading configuration from " + settings.toString());
|
| | | this.settings = settings;
|
| | |
| | | loginService = (IUserService) realmClass.newInstance();
|
| | | }
|
| | | } 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.conf");
|
| | | if (realmFile.exists()) {
|
| | | // load the existing realm file
|
| | | 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);
|
| | | loginService = new UserServiceWrapper() {
|
| | | @Override
|
| | | public void setupService(IStoredSettings settings) {
|
| | | }
|
| | | } 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(
|
| | | MessageFormat.format("COULD NOT CREATE REALM FILE {0}!", realmFile), x);
|
| | | }
|
| | | }
|
| | | };
|
| | | }
|
| | | setUserService(loginService);
|
| | | mailExecutor = new MailExecutor(settings);
|