1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sf.hermesftp.usermanager.model;
26
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30
31 import net.sf.hermesftp.common.FtpConstants;
32 import net.sf.hermesftp.exception.FtpConfigException;
33
34 /***
35 * Data of a user group.
36 *
37 * @author Behnke
38 */
39 public class GroupDataList {
40
41 private List<GroupData> list = Collections.synchronizedList(new ArrayList<GroupData>());
42
43 /***
44 * Adds group data.
45 *
46 * @param data group data.
47 */
48 public void addGroup(GroupData data) {
49 list.add(data);
50 }
51
52 /***
53 * Clears all group data from the list.
54 */
55 public void clear() {
56 list.clear();
57 }
58
59 /***
60 * Returns the group of a given name.
61 *
62 * @param name The group name.
63 * @return The group or null.
64 */
65 public GroupData getGroup(String name) {
66 if (name == null) {
67 return null;
68 }
69 for (GroupData data : list) {
70 if (data.getName().equalsIgnoreCase(name)) {
71 return data;
72 }
73 }
74 return null;
75 }
76
77 /***
78 * The upper limit of the constraints named by the passed key.
79 *
80 * @param key The name of the constraint.
81 * @return The value.
82 */
83 public long getUpperLimit(String key) {
84 long limit = -1;
85 for (GroupData data : list) {
86 long l = data.getLimit(key);
87 if (l < 0) {
88 return l;
89 }
90 limit = Math.max(l, limit);
91
92 }
93 return limit;
94 }
95
96 /***
97 * The permission on a given path.
98 *
99 * @param path The path to check.
100 * @param username The user that wants to access the path.
101 * @param ftproot The absolute ftp root directory.
102 * @return The permission constant.
103 * @throws FtpConfigException Error in configuration.
104 */
105 public int getPermission(String path, String username, String ftproot) throws FtpConfigException {
106 int result = FtpConstants.PRIV_NONE;
107 for (GroupData groupData : list) {
108 int permission = groupData.getPermission(path, ftproot, username);
109 result = Math.max(result, permission);
110 }
111 return result;
112
113 }
114
115 }