Beispiel #1
0
  public boolean hasPermission(User user, Type type) {
    Permission perm = userPermissionMap.get(user.getUserId());
    if (perm != null && (perm.isPermissionSet(Type.ADMIN) || perm.isPermissionSet(type))) {
      return true;
    }

    return hasGroupPermission(user, type);
  }
Beispiel #2
0
  public List<Project> getUserProjects(User user) {
    ArrayList<Project> array = new ArrayList<Project>();
    for (Project project : projectsById.values()) {
      Permission perm = project.getUserPermission(user);

      if (perm != null && (perm.isPermissionSet(Type.ADMIN) || perm.isPermissionSet(Type.READ))) {
        array.add(project);
      }
    }
    return array;
  }
Beispiel #3
0
  public boolean hasGroupPermission(User user, Type type) {
    for (String group : user.getGroups()) {
      Permission perm = groupPermissionMap.get(group);
      if (perm != null) {
        if (perm.isPermissionSet(Type.ADMIN) || perm.isPermissionSet(type)) {
          return true;
        }
      }
    }

    return false;
  }
Beispiel #4
0
  public boolean hasUserPermission(User user, Type type) {
    Permission perm = userPermissionMap.get(user.getUserId());
    if (perm == null) {
      // Check group
      return false;
    }

    if (perm.isPermissionSet(Type.ADMIN) || perm.isPermissionSet(type)) {
      return true;
    }

    return false;
  }
Beispiel #5
0
 public List<String> getUsersWithPermission(Type type) {
   ArrayList<String> users = new ArrayList<String>();
   for (Map.Entry<String, Permission> entry : userPermissionMap.entrySet()) {
     Permission perm = entry.getValue();
     if (perm.isPermissionSet(type)) {
       users.add(entry.getKey());
     }
   }
   return users;
 }
Beispiel #6
0
  public List<Project> getUserProjectsByRegex(User user, String regexPattern) {
    List<Project> array = new ArrayList<Project>();
    Pattern pattern;
    try {
      pattern = Pattern.compile(regexPattern, Pattern.CASE_INSENSITIVE);
    } catch (PatternSyntaxException e) {
      logger.error("Bad regex pattern " + regexPattern);
      return array;
    }

    for (Project project : projectsById.values()) {
      Permission perm = project.getUserPermission(user);

      if (perm != null && (perm.isPermissionSet(Type.ADMIN) || perm.isPermissionSet(Type.READ))) {
        if (pattern.matcher(project.getName()).find()) {
          array.add(project);
        }
      }
    }
    return array;
  }