Ejemplo n.º 1
0
  /** Reads the properties file and rebuilds the in-memory cookie lookup table. */
  @Override
  protected synchronized Properties read() {
    long lastRead = lastModified();
    Properties allUsers = super.read();
    if (lastRead != lastModified()) {
      // reload hash cache
      cookies.clear();
      teams.clear();

      for (String username : allUsers.stringPropertyNames()) {
        String value = allUsers.getProperty(username);
        String[] roles = value.split(",");
        if (username.charAt(0) == '@') {
          // team definition
          TeamModel team = new TeamModel(username.substring(1));
          List<String> repositories = new ArrayList<String>();
          List<String> users = new ArrayList<String>();
          List<String> mailingLists = new ArrayList<String>();
          List<String> preReceive = new ArrayList<String>();
          List<String> postReceive = new ArrayList<String>();
          for (String role : roles) {
            if (role.charAt(0) == '!') {
              users.add(role.substring(1));
            } else if (role.charAt(0) == '&') {
              mailingLists.add(role.substring(1));
            } else if (role.charAt(0) == '^') {
              preReceive.add(role.substring(1));
            } else if (role.charAt(0) == '%') {
              postReceive.add(role.substring(1));
            } else {
              repositories.add(role);
            }
          }
          team.addRepositories(repositories);
          team.addUsers(users);
          team.addMailingLists(mailingLists);
          teams.put(team.name.toLowerCase(), team);
        } else {
          // user definition
          String password = roles[0];
          cookies.put(
              StringUtils.getSHA1(username.toLowerCase() + password), username.toLowerCase());
        }
      }
    }
    return allUsers;
  }