View Javadoc

1   package org.apache.turbine.services.security.passive;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.List;
23  
24  import org.apache.commons.configuration.Configuration;
25  
26  import org.apache.torque.util.Criteria;
27  
28  import org.apache.turbine.om.security.User;
29  import org.apache.turbine.services.security.UserManager;
30  import org.apache.turbine.util.security.DataBackendException;
31  import org.apache.turbine.util.security.EntityExistsException;
32  import org.apache.turbine.util.security.PasswordMismatchException;
33  import org.apache.turbine.util.security.UnknownEntityException;
34  
35  /***
36   * Void user manager can be used where no data storage is needed
37   * by the application.
38   * It's methods don't provide any useful functionality  except throwing
39   * DataBackendExceptions. Security service will be still able to create
40   * anonymous User objects when this UserManager is used.
41   *
42   * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
43   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
44   * @version $Id: PassiveUserManager.java 534527 2007-05-02 16:10:59Z tv $
45   */
46  public class PassiveUserManager implements UserManager
47  {
48      /***
49       * Initializes the UserManager
50       *
51       * @param conf A Configuration object to init this Manager
52       */
53      public void init(Configuration conf)
54      {
55          // GNDN
56      }
57  
58      /***
59       * Check whether a specified user's account exists.
60       *
61       * The login name is used for looking up the account.
62       *
63       * @param user The user to be checked.
64       * @return true if the specified account exists
65       * @throws DataBackendException if there was an error accessing the data backend.
66       */
67      public boolean accountExists(User user)
68              throws DataBackendException
69      {
70          throw new DataBackendException("PassiveUserManager knows no users");
71      }
72  
73      /***
74       * Check whether a specified user's account exists.
75       *
76       * The login name is used for looking up the account.
77       *
78       * @param userName The name of the user to be checked.
79       * @return true if the specified account exists
80       * @throws DataBackendException if there was an error accessing the data backend.
81       */
82      public boolean accountExists(String userName)
83              throws DataBackendException
84      {
85          throw new DataBackendException("PassiveUserManager knows no users");
86      }
87  
88      /***
89       * Retrieve a user from persistent storage using username as the
90       * key.
91       *
92       * @param username the name of the user.
93       * @return an User object.
94       * @exception UnknownEntityException if the user's record does not
95       *            exist in the database.
96       * @exception DataBackendException if there is a problem accessing the
97       *            storage.
98       */
99      public User retrieve(String username)
100             throws UnknownEntityException, DataBackendException
101     {
102         throw new DataBackendException("PassiveUserManager knows no users");
103     }
104 
105     /***
106      * Retrieve a user from persistent storage using the primary key
107      *
108      * @param key The primary key object
109      * @return an User object.
110      * @throws UnknownEntityException if the user's record does not
111      *         exist in the database.
112      * @throws DataBackendException if there is a problem accessing the
113      *         storage.
114      */
115     public User retrieveById(Object key)
116             throws UnknownEntityException, DataBackendException
117     {
118         throw new DataBackendException("PassiveUserManager knows no users");
119     }
120 
121     /***
122      * Retrieve a set of users that meet the specified criteria.
123      *
124      * As the keys for the criteria, you should use the constants that
125      * are defined in {@link User} interface, plus the names
126      * of the custom attributes you added to your user representation
127      * in the data storage. Use verbatim names of the attributes -
128      * without table name prefix in case of DB implementation.
129      *
130      * @param criteria The criteria of selection.
131      * @return a List of users meeting the criteria.
132      * @throws DataBackendException if there is a problem accessing the
133      *         storage.
134      * @deprecated Use <a href="#retrieveList">retrieveList</a> instead.
135      */
136     public User[] retrieve(Criteria criteria)
137             throws DataBackendException
138     {
139         throw new DataBackendException("PassiveUserManager knows no users");
140     }
141 
142     /***
143      * Retrieve a set of users that meet the specified criteria.
144      *
145      * As the keys for the criteria, you should use the constants that
146      * are defined in {@link User} interface, plus the names
147      * of the custom attributes you added to your user representation
148      * in the data storage. Use verbatim names of the attributes -
149      * without table name prefix in case of DB implementation.
150      *
151      * @param criteria The criteria of selection.
152      * @return a List of users meeting the criteria.
153      * @throws DataBackendException if there is a problem accessing the
154      *         storage.
155      */
156     public List retrieveList(Criteria criteria)
157             throws DataBackendException
158     {
159         throw new DataBackendException("PassiveUserManager knows no users");
160     }
161 
162     /***
163      * Retrieve a user from persistent storage using username as the
164      * key, and authenticate the user. The implementation may chose
165      * to authenticate to the server as the user whose data is being
166      * retrieved.
167      *
168      * @param username the name of the user.
169      * @param password the user supplied password.
170      * @return an User object.
171      * @exception PasswordMismatchException if the supplied password was
172      *            incorrect.
173      * @exception UnknownEntityException if the user's record does not
174      *            exist in the database.
175      * @exception DataBackendException if there is a problem accessing the
176      *            storage.
177      */
178     public User retrieve(String username, String password)
179             throws PasswordMismatchException, UnknownEntityException,
180             DataBackendException
181     {
182         throw new DataBackendException("PassiveUserManager knows no users");
183     }
184 
185     /***
186      * Save an User object to persistent storage. User's record is
187      * required to exist in the storage.
188      *
189      * @param user an User object to store.
190      * @exception UnknownEntityException if the user's record does not
191      *            exist in the database.
192      * @exception DataBackendException if there is a problem accessing the
193      *            storage.
194      */
195     public void store(User user)
196             throws UnknownEntityException, DataBackendException
197     {
198         throw new DataBackendException("PassiveUserManager does not support saving user data");
199     }
200 
201     /***
202      * Saves User data when the session is unbound. The user account is required
203      * to exist in the storage.
204      *
205      * LastLogin, AccessCounter, persistent pull tools, and any data stored
206      * in the permData hashtable that is not mapped to a column will be saved.
207      *
208      * @exception UnknownEntityException if the user's account does not
209      *            exist in the database.
210      * @exception DataBackendException if there is a problem accessing the
211      *            storage.
212      */
213     public void saveOnSessionUnbind(User user)
214             throws UnknownEntityException, DataBackendException
215     {
216         throw new DataBackendException("PassiveUserManager does not support saving user data");
217     }
218 
219     /***
220      * Authenticate an User with the specified password. If authentication
221      * is successful the method returns nothing. If there are any problems,
222      * exception was thrown.
223      *
224      * @param user an User object to authenticate.
225      * @param password the user supplied password.
226      * @exception PasswordMismatchException if the supplied password was
227      *            incorrect.
228      * @exception UnknownEntityException if the user's record does not
229      *            exist in the database.
230      * @exception DataBackendException if there is a problem accessing the
231      *            storage.
232      */
233     public void authenticate(User user, String password)
234             throws PasswordMismatchException, UnknownEntityException,
235             DataBackendException
236     {
237         throw new DataBackendException("PassiveUserManager knows no users");
238     }
239 
240     /***
241      * Creates new user account with specified attributes.
242      *
243      * @param user the object describing account to be created.
244      * @param initialPassword The password to use for the object creation
245      *
246      * @throws DataBackendException if there was an error accessing the data backend.
247      * @throws EntityExistsException if the user account already exists.
248      */
249     public void createAccount(User user, String initialPassword)
250             throws EntityExistsException, DataBackendException
251     {
252         throw new DataBackendException("PassiveUserManager does not support"
253                 + " creating accounts");
254     }
255 
256     /***
257      * Removes an user account from the system.
258      *
259      * @param user the object describing the account to be removed.
260      * @throws DataBackendException if there was an error accessing the data backend.
261      * @throws UnknownEntityException if the user account is not present.
262      */
263     public void removeAccount(User user)
264             throws UnknownEntityException, DataBackendException
265     {
266         throw new DataBackendException("PassiveUserManager does not support removing accounts");
267     }
268 
269     /***
270      * Change the password for an User.
271      *
272      * @param user an User to change password for.
273      * @param oldPassword the current password supplied by the user.
274      * @param newPassword the current password requested by the user.
275      * @exception PasswordMismatchException if the supplied password was
276      *            incorrect.
277      * @exception UnknownEntityException if the user's record does not
278      *            exist in the database.
279      * @exception DataBackendException if there is a problem accessing the
280      *            storage.
281      */
282     public void changePassword(User user, String oldPassword,
283                                String newPassword)
284             throws PasswordMismatchException, UnknownEntityException,
285             DataBackendException
286     {
287         throw new DataBackendException("PassiveUserManager does not support setting passwords");
288     }
289 
290     /***
291      * Forcibly sets new password for an User.
292      *
293      * This is supposed by the administrator to change the forgotten or
294      * compromised passwords. Certain implementatations of this feature
295      * would require administrative level access to the authenticating
296      * server / program.
297      *
298      * @param user an User to change password for.
299      * @param password the new password.
300      * @exception UnknownEntityException if the user's record does not
301      *            exist in the database.
302      * @exception DataBackendException if there is a problem accessing the
303      *            storage.
304      */
305     public void forcePassword(User user, String password)
306             throws UnknownEntityException, DataBackendException
307     {
308         throw new DataBackendException("PassiveUserManager does not support setting passwords");
309     }
310 }