View Javadoc

1   /*
2    * ------------------------------------------------------------------------------
3    * Hermes FTP Server
4    * Copyright (c) 2005-2007 Lars Behnke
5    * ------------------------------------------------------------------------------
6    * 
7    * This file is part of Hermes FTP Server.
8    * 
9    * Hermes FTP Server is free software; you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as published by
11   * the Free Software Foundation; either version 2 of the License, or
12   * (at your option) any later version.
13   * 
14   * Hermes FTP Server is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public License
20   * along with Hermes FTP Server; if not, write to the Free Software
21   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
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 }