Package com.gitblit

Examples of com.gitblit.IUserService


  @Override
  public UserManager start() {
    if (this.userService == null) {
      String realm = settings.getString(Keys.realm.userService, "${baseFolder}/users.conf");
      IUserService service = null;
      if (legacyBackingServices.containsKey(realm)) {
        // create the user service from the legacy config
        String realmKey = legacyBackingServices.get(realm);
        logger.warn("");
        logger.warn(Constants.BORDER2);
View Full Code Here


    }
    return this;
  }

  protected IUserService createUserService(File realmFile) {
    IUserService service = null;
    if (realmFile.getName().toLowerCase().endsWith(".conf")) {
      // config-based realm file
      service = new ConfigUserService(realmFile);
    }

    assert service != null;

    if (!realmFile.exists()) {
      // Create the Administrator account for a new realm file
      try {
        realmFile.createNewFile();
      } catch (IOException x) {
        logger.error(MessageFormat.format("COULD NOT CREATE REALM FILE {0}!", realmFile), x);
      }
      UserModel admin = new UserModel("admin");
      admin.password = "admin";
      admin.canAdmin = true;
      admin.excludeFromFederation = true;
      service.updateUserModel(admin);
    }

    return service;
  }
View Full Code Here

    }
    gitblitSettings = new FileSettings(file.getAbsolutePath());
    mail = new MailService(gitblitSettings);
    String us = gitblitSettings.getString(Keys.realm.userService, "${baseFolder}/users.conf");
    String ext = us.substring(us.lastIndexOf(".") + 1).toLowerCase();
    IUserService service = null;
    if (!ext.equals("conf") && !ext.equals("properties") && ext.contains("userservice")) {
      String realm = ext.substring(0, ext.indexOf("userservice"));
      us = gitblitSettings.getString(MessageFormat.format("realm.{0}.backingUserService", realm), "${baseFolder}/users.conf");
    }
View Full Code Here

  @Override
  public UserManager start() {
    if (this.userService == null) {
      String realm = settings.getString(Keys.realm.userService, "${baseFolder}/users.conf");
      IUserService service = null;
      if (legacyBackingServices.containsKey(realm)) {
        // create the user service from the legacy config
        String realmKey = legacyBackingServices.get(realm);
        logger.warn("");
        logger.warn(Constants.BORDER2);
View Full Code Here

    }
    return this;
  }

  protected IUserService createUserService(File realmFile) {
    IUserService service = null;
    if (realmFile.getName().toLowerCase().endsWith(".conf")) {
      // config-based realm file
      service = new ConfigUserService(realmFile);
    }

    assert service != null;

    if (!realmFile.exists()) {
      // Create the Administrator account for a new realm file
      try {
        realmFile.createNewFile();
      } catch (IOException x) {
        logger.error(MessageFormat.format("COULD NOT CREATE REALM FILE {0}!", realmFile), x);
      }
      UserModel admin = new UserModel("admin");
      admin.password = "admin";
      admin.canAdmin = true;
      admin.excludeFromFederation = true;
      service.updateUserModel(admin);
    }

    return service;
  }
View Full Code Here

      gitblit.updateConfiguration(r, repository);
      r.close();
    }

    IUserService userService = null;

    try {
      // Pull USERS
      // TeamModels are automatically pulled because they are contained
      // within the UserModel. The UserService creates unknown teams
      // and updates existing teams.
      Collection<UserModel> users = FederationUtils.getUsers(registration);
      if (users != null && users.size() > 0) {
        File realmFile = new File(registrationFolderFile, registration.name + "_users.conf");
        realmFile.delete();
        userService = new ConfigUserService(realmFile);
        for (UserModel user : users) {
          userService.updateUserModel(user.username, user);

          // merge the origin permissions and origin accounts into
          // the user accounts of this Gitblit instance
          if (registration.mergeAccounts) {
            // reparent all repository permissions if the local
            // repositories are stored within subfolders
            if (!StringUtils.isEmpty(registrationFolder)) {
              if (user.permissions != null) {
                // pulling from >= 1.2 version
                Map<String, AccessPermission> copy = new HashMap<String, AccessPermission>(user.permissions);
                user.permissions.clear();
                for (Map.Entry<String, AccessPermission> entry : copy.entrySet()) {
                  user.setRepositoryPermission(registrationFolder + "/" + entry.getKey(), entry.getValue());
                }
              } else {
                // pulling from <= 1.1 version
                List<String> permissions = new ArrayList<String>(user.repositories);
                user.repositories.clear();
                for (String permission : permissions) {
                  user.addRepositoryPermission(registrationFolder + "/" + permission);
                }
              }
            }

            // insert new user or update local user
            UserModel localUser = gitblit.getUserModel(user.username);
            if (localUser == null) {
              // create new local user
              gitblit.addUser(user);
            } else {
              // update repository permissions of local user
              if (user.permissions != null) {
                // pulling from >= 1.2 version
                Map<String, AccessPermission> copy = new HashMap<String, AccessPermission>(user.permissions);
                for (Map.Entry<String, AccessPermission> entry : copy.entrySet()) {
                  localUser.setRepositoryPermission(entry.getKey(), entry.getValue());
                }
              } else {
                // pulling from <= 1.1 version
                for (String repository : user.repositories) {
                  localUser.addRepositoryPermission(repository);
                }
              }
              localUser.password = user.password;
              localUser.canAdmin = user.canAdmin;
              gitblit.reviseUser(localUser.username, localUser);
            }

            for (String teamname : gitblit.getAllTeamNames()) {
              TeamModel team = gitblit.getTeamModel(teamname);
              if (user.isTeamMember(teamname) && !team.hasUser(user.username)) {
                // new team member
                team.addUser(user.username);
                gitblit.updateTeamModel(teamname, team);
              } else if (!user.isTeamMember(teamname) && team.hasUser(user.username)) {
                // remove team member
                team.removeUser(user.username);
                gitblit.updateTeamModel(teamname, team);
              }

              // update team repositories
              TeamModel remoteTeam = user.getTeam(teamname);
              if (remoteTeam != null) {
                if (remoteTeam.permissions != null) {
                  // pulling from >= 1.2
                  for (Map.Entry<String, AccessPermission> entry : remoteTeam.permissions.entrySet()){
                    team.setRepositoryPermission(entry.getKey(), entry.getValue());
                  }
                  gitblit.updateTeamModel(teamname, team);
                } else if (!ArrayUtils.isEmpty(remoteTeam.repositories)) {
                  // pulling from <= 1.1
                  team.addRepositoryPermissions(remoteTeam.repositories);
                  gitblit.updateTeamModel(teamname, team);
                }
              }
            }
          }
        }
      }
    } catch (ForbiddenException e) {
      // ignore forbidden exceptions
    } catch (IOException e) {
      logger.warn(MessageFormat.format(
          "Failed to retrieve USERS from federated gitblit ({0} @ {1})",
          registration.name, registration.url), e);
    }

    try {
      // Pull TEAMS
      // We explicitly pull these even though they are embedded in
      // UserModels because it is possible to use teams to specify
      // mailing lists or push scripts without specifying users.
      if (userService != null) {
        Collection<TeamModel> teams = FederationUtils.getTeams(registration);
        if (teams != null && teams.size() > 0) {
          for (TeamModel team : teams) {
            userService.updateTeamModel(team);
          }
        }
      }
    } catch (ForbiddenException e) {
      // ignore forbidden exceptions
View Full Code Here

  @Test
  public void testConfigUserService() throws IOException {
    File file = new File("us-test.conf");
    file.delete();
    IUserService service = new ConfigUserService(file);
    testUsers(service);
    testTeams(service);
    file.delete();
  }
View Full Code Here

TOP

Related Classes of com.gitblit.IUserService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.