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.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 import net.sf.hermesftp.common.FtpConstants;
33 import net.sf.hermesftp.exception.FtpConfigException;
34
35 /***
36 * Model data of a user group including the configured limits and path permissions. Note that the
37 * order of the configured permission entries is important, since the first path match provides the
38 * permission value.
39 *
40 * @author Lars Behnke
41 */
42 public class GroupData {
43
44 /***
45 * Control code for unlimited.
46 */
47 public static final long UNLIMITED = -1;
48
49 private String name;
50
51 private Map<String, Long> limits;
52
53 private List<PermissionData> permissions;
54
55 /***
56 * Getter method for the java bean <code>limits</code>.
57 *
58 * @return Returns the value of the java bean <code>limits</code>.
59 */
60 public Map<String, Long> getLimits() {
61 if (limits == null) {
62 limits = new HashMap<String, Long>();
63 }
64 return limits;
65 }
66
67 /***
68 * Convenience method for returning the limit specified by the passed name.
69 *
70 * @param name The limit name.
71 * @return The value.
72 */
73 public long getLimit(String name) {
74 Long limit = (Long) getLimits().get(name);
75 if (limit == null || limit.longValue() == UNLIMITED) {
76 return Long.MAX_VALUE;
77 } else {
78 return limit.longValue();
79 }
80 }
81
82 /***
83 * Getter method for the java bean <code>permissions</code>.
84 *
85 * @return Returns the value of the java bean <code>permissions</code>.
86 */
87 public List<PermissionData> getPermissions() {
88 if (permissions == null) {
89 permissions = new ArrayList<PermissionData>();
90 }
91 return permissions;
92 }
93
94 /***
95 * Returns the group permission on the passed path.
96 *
97 * @param path The path to check.
98 * @param ftproot The FTP root folder.
99 * @param user The user's name.
100 * @return The permission.
101 * @throws FtpConfigException Error on reading or processing a configuration file.
102 */
103 public int getPermission(String path, String ftproot, String user) throws FtpConfigException {
104 for (PermissionData permission : getPermissions()) {
105 if (permission.matches(path, ftproot, user)) {
106 return permission.getPermission();
107 }
108
109 }
110 return FtpConstants.PRIV_NONE;
111 }
112
113 /***
114 * Getter method for the java bean <code>name</code>.
115 *
116 * @return Returns the value of the java bean <code>name</code>.
117 */
118 public String getName() {
119 return name;
120 }
121
122 /***
123 * Setter method for the java bean <code>name</code>.
124 *
125 * @param name The value of name to set.
126 */
127 public void setName(String name) {
128 this.name = name;
129 }
130
131 }