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); }
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; }
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; }
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; }
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; }
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; }