01: /*
02: * Copyright (c) 2005 Your Corporation. All Rights Reserved.
03: */
04: package com.technoetic.xplanner.security.auth;
05:
06: import com.technoetic.xplanner.domain.Person;
07: import com.technoetic.xplanner.security.AuthenticationException;
08:
09: import java.util.Collection;
10: import java.util.HashSet;
11: import java.util.Iterator;
12:
13: //DEBT duplicate with the Authorizer.getPeopleWithPermissionOnProject
14: //DEBT Move the query to get all people to be cached in PermissionCache (to be renamed SecurityCache) and replace all hard coded usage of the people query
15: public class PermissionHelper {
16: public static Collection getPeopleWithProjectRole(String projectId,
17: Collection people) throws AuthenticationException {
18: int projectOid = Integer.parseInt(projectId);
19: Collection peopleToShow = new HashSet();
20:
21: if (showFilterOnProject(projectOid)) {
22: Iterator i = people.iterator();
23: while (i.hasNext()) {
24: Person p = (Person) i.next();
25: if (isProjectAccessibleByPerson(projectOid, p)) {
26: peopleToShow.add(p);
27: }
28: }
29: } else {
30: peopleToShow.addAll(people);
31: }
32: return peopleToShow;
33: }
34:
35: private static boolean isProjectAccessibleByPerson(int projectOid,
36: Person p) throws AuthenticationException {
37: return SystemAuthorizer.get().hasPermission(projectOid,
38: p.getId(), "system.project", projectOid, "read%");
39: }
40:
41: private static boolean showFilterOnProject(int projectOid) {
42: return projectOid > 0;
43: }
44: }
|