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;
26  
27  import java.util.List;
28  import java.util.Map;
29  
30  import net.sf.hermesftp.common.FtpSessionContext;
31  import net.sf.hermesftp.exception.FtpConfigException;
32  import net.sf.hermesftp.exception.FtpQuotaException;
33  import net.sf.hermesftp.usermanager.model.GroupDataList;
34  import net.sf.hermesftp.usermanager.model.UserData;
35  
36  /***
37   * Generic description of user management classes.
38   * 
39   * @author Lars Behnke
40   */
41  public interface UserManager {
42  
43      /***
44       * Registers the current user's resource consumption. That is, downloaded or uploaded bytes or
45       * files.
46       * 
47       * @param user The user name.
48       * @param limitName The name of the consumption type (resource limit).
49       * @param value The consumed resources.
50       * @throws FtpQuotaException Thrown if resource limit has been reached.
51       */
52      void updateIncrementalStatistics(String user, String limitName, long value) throws FtpQuotaException;
53  
54      /***
55       * Registers the current user's transfer rate. A mean value is calculated.
56       * 
57       * @param user The user name.
58       * @param avgKeyName The key of the transfer rate (resource limit).
59       * @param value The consumed resources.
60       */
61      void updateAverageStatistics(String user, String avgKeyName, long value);
62  
63      /***
64       * Checks the resource consumption of the passed users. Only the passed limits are condidered.
65       * 
66       * @param user The user name.
67       * @param limitNames The resource limits to condider.
68       * @throws FtpQuotaException Thrown if at least one limit has been reached.
69       */
70      void checkResourceConsumption(String user, String[] limitNames) throws FtpQuotaException;
71  
72      /***
73       * Returns the resource consumption statistics for a given user.
74       * 
75       * @param user The user.
76       * @return The statistics.
77       */
78      Map<String, Long> getUserStatistics(String user);
79  
80      /***
81       * Returns the logged statistics for all user and all available dates (since the server was
82       * started).
83       * 
84       * @return The statistics.
85       */
86      Map<String, Map<String, Long>> getAllStatistics();
87  
88      /***
89       * Returns object representations of all registered users.
90       * 
91       * @param username The user's name.
92       * @return The user data.
93       * @throws FtpConfigException Error in configuration.
94       */
95      UserData getUserData(String username) throws FtpConfigException;
96  
97      /***
98       * Returns object representations of all registered users.
99       * 
100      * @return The users.
101      * @throws FtpConfigException Error in configuration.
102      */
103     List<UserData> getUserDataList() throws FtpConfigException;
104 
105     /***
106      * Returns object representations of all groups the passed user belongs to.
107      * 
108      * @param username The user's name.
109      * @return The group data.
110      * @throws FtpConfigException Error in configuration.
111      */
112     GroupDataList getGroupDataList(String username) throws FtpConfigException;
113 
114     /***
115      * Validates the passed user credentials.
116      * 
117      * @param user The username.
118      * @param password The password
119      * @param ctx The context of the current session.
120      * @return True, if credentials are valid.
121      * @throws FtpConfigException Error on reading or processing a configuration file.
122      */
123     boolean authenticate(String user, String password, FtpSessionContext ctx) throws FtpConfigException;
124 
125     /***
126      * (Re)loads the configuration.
127      * 
128      * @throws FtpConfigException Error on reading or processing a configuration file.
129      */
130     void load() throws FtpConfigException;
131 
132     /***
133      * Checks if the configuration is loaded.
134      * 
135      * @return True, if configuration has already been loaded.
136      * @throws FtpConfigException Error on reading or processing a configuration file.
137      */
138     boolean isLoaded() throws FtpConfigException;
139 
140 }