KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > ejb > authentication > AbstractPluggableAuthenticator


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.ejb.authentication;
20
21 import java.rmi.*;
22 import java.rmi.server.*;
23 import java.util.*;
24 import javax.ejb.*;
25
26 import cowsultants.itracker.ejb.client.exceptions.*;
27 import cowsultants.itracker.ejb.client.interfaces.*;
28 import cowsultants.itracker.ejb.client.models.*;
29 import cowsultants.itracker.ejb.client.util.*;
30
31 /**
32   * This class provides a skeleton implementation of the PluggableAuthenticator interface.
33   * It can be extended to provide a new authentication module for ITracker reducing the amount
34   * of effort to implement the PluggableAuthenticator interface.
35   */

36 public abstract class AbstractPluggableAuthenticator implements PluggableAuthenticator, AuthenticationConstants {
37     private UserHandler userHandler = null;
38     private SystemConfiguration systemConfiguration = null;
39
40     public AbstractPluggableAuthenticator() {
41     }
42
43     /**
44       * This method should be overridden to determine if a user login is successful. The method
45       * should return a valid UserModel object.
46       * @param login the login the user/client provided
47       * @param authentication the user's authentication information, if known
48       * @param authType the type of authentication information being provided
49       * @param reqSource the source of the request (eg web, api)
50       * @return a UserModel if the login is successful
51       * @throws AuthenticatorException an exception if the login is unsuccessful, or an error occurs
52       */

53     public abstract UserModel checkLogin(String JavaDoc login, Object JavaDoc authentication, int authType, int reqSource) throws AuthenticatorException;
54
55     /**
56       * This method should be overridden to return all the permissions a user has in the
57       * authentication system. This list may then be augmented based on other attributes of
58       * the user, or project level options.
59       * @param user a UserModel object that contains the user to retrieve permissions for
60       * @param reqSource the source of the request (eg web, api)
61       * @return an array of PermissionModels
62       * @throws AuthenticatorException an error occurs
63       */

64     public abstract PermissionModel[] getUserPermissions(UserModel user, int reqSource) throws AuthenticatorException;
65
66     /**
67       * This method should be overridden to return an array of users that have certian permissions
68       * in the authentication system. This list must always include all super users, even if they
69       * do not explicitly have the required permission.
70       * @param permissions an array of PermissionModels that define which permissions in which
71                projects are required.
72       * @param requireAll true if the user must possess any of the permissions, false if only one is required
73       * @param activeOnly true if only users listed as active should be returned
74       * @param reqSource the source of the request (eg web, api)
75       * @return an array of UserModels
76       * @throws AuthenticatorException an error occurs
77       */

78     public abstract UserModel[] getUsersWithProjectPermission(PermissionModel[] permissions, boolean requireAll, boolean activeOnly, int reqSource) throws AuthenticatorException;
79
80     /**
81       * This method should be overridden to determine if a user is authorized to self register.
82       * @param user a UserModel object that contains the data the user submitted
83       * @param authentication the user's authentication information, if known
84       * @param authType the type of authentication information being provided
85       * @param reqSource the source of the request (eg web, api)
86       * @return a boolean whether the user should be allowed to register
87       * @throws AuthenticatorException an exception if an error occurs
88       */

89     public abstract boolean allowRegistration(UserModel user, Object JavaDoc authentication, int authType, int reqSource) throws AuthenticatorException;
90
91     /**
92       * This method should be overwritten to return if any new user profile should be allowed
93       * to be created.
94       * @param user a UserModel object that contains the data for the new user. If null,
95                then the request is being made for an unknown future user. For example,
96                the system may request this with an null user if it needs to know if the system
97                should even present the option to create a new user
98       * @param authentication the user's authentication information, if known
99       * @param authType the type of authentication information being provided
100       * @param reqSource the source of the request (eg web, api)
101       * @return a boolean whether the new profile creation is allowed
102       * @throws AuthenticatorException an exception if an error occurs
103       */

104     public abstract boolean allowProfileCreation(UserModel user, Object JavaDoc authentication, int authType, int reqSource) throws AuthenticatorException;
105
106     /**
107       * This method should be overridden to return if the particular user can have
108       * core profile information updates on the system.
109       * @param user a UserModel object that contains the current user data
110       * @param authentication the user's authentication information, if known
111       * @param authType the type of authentication information being provided
112       * @param reqSource the source of the request (eg web, api)
113       * @return a boolean whether the user's core profile information can be updated
114       * @throws AuthenticatorException an exception if an error occurs
115       * @see PluggableAuthentication#allowPasswordUpdates
116       * @see PluggableAuthentication#allowPermissionUpdates
117       * @see PluggableAuthentication#allowPreferenceUpdates
118       */

119     public abstract boolean allowProfileUpdates(UserModel user, Object JavaDoc authentication, int authType, int reqSource) throws AuthenticatorException;
120
121     /**
122       * This method should be overridden to return if the particular user profile can have
123       * password updates on the system.
124       * @param user a UserModel object that contains the current user data
125       * @param authentication the user's authentication information, if known
126       * @param authType the type of authentication information being provided
127       * @param reqSource the source of the request (eg web, api)
128       * @return a boolean whether the user's core profile information can be updated
129       * @throws AuthenticatorException an exception if an error occurs
130       * @see PluggableAuthentication#allowProfileUpdates
131       * @see PluggableAuthentication#allowPermissionUpdates
132       * @see PluggableAuthentication#allowPreferenceUpdates
133       */

134     public abstract boolean allowPasswordUpdates(UserModel user, Object JavaDoc authentication, int authType, int reqSource) throws AuthenticatorException;
135
136     /**
137       * This method should be overridden to return if the particular user profile can have
138       * permission updates on the system.
139       * information is allowed to be updated through ITracker.
140       * @param user a UserModel object that contains the current user data, or null if multiple users
141       * @param authentication the user's authentication information, if known
142       * @param authType the type of authentication information being provided
143       * @param reqSource the source of the request (eg web, api)
144       * @return a boolean whether the user's core profile information can be updated
145       * @throws AuthenticatorException an exception if an error occurs
146       * @see PluggableAuthentication#allowProfileUpdates
147       * @see PluggableAuthentication#allowPasswordUpdates
148       * @see PluggableAuthentication#allowPreferenceUpdates
149       */

150     public abstract boolean allowPermissionUpdates(UserModel user, Object JavaDoc authentication, int authType, int reqSource) throws AuthenticatorException;
151
152     /**
153       * This method should be implemented to determine if the particular user can have
154       * preferences updates on the system.
155       * @param user a UserModel object that contains the current user data
156       * @param authentication the user's authentication information, if known
157       * @param authType the type of authentication information being provided
158       * @param reqSource the source of the request (eg web, api)
159       * @return a boolean whether the user's core profile information can be updated
160       * @throws AuthenticatorException an exception if an error occurs
161       * @see PluggableAuthentication#allowProfileUpdates
162       * @see PluggableAuthentication#allowPasswordUpdates
163       * @see PluggableAuthentication#allowPermissionUpdates
164       */

165     public abstract boolean allowPreferenceUpdates(UserModel user, Object JavaDoc authentication, int authType, int reqSource) throws AuthenticatorException;
166
167     /**
168       * This method should be overridden to perform any updates that are necessary in the authentication
169       * system to support a new user. Any changes should be made directly to user model supplied to the
170       * method. The system will then update the information in the ITracker datastore. Only changes to the
171       * core profile information and password are made here. Any permission information for the new user
172       * whould be done through an updateProfile call.
173       * @param user a UserModel object that contains the profile information to be created
174       * @param authentication the user's authentication information, if known
175       * @param authType the type of authentication information being provided
176       * @param reqSource the source of the request (eg web, api)
177       * @return true if changes were made
178       * @throws AuthenticatorException an error occurs
179       * @see PluggableAuthenticator#updateProfile
180       */

181     public abstract boolean createProfile(UserModel user, Object JavaDoc authentication, int authType, int reqSource) throws AuthenticatorException;
182
183     /**
184       * This method should be overridden to perform any updates that are necessary in the authentication
185       * system to support the updated user information. This action will be called any time there are any
186       * updates to a user includeing core profile information, password information, permission information
187       * or preference changes. Any changes should be made directly to user model supplied to the method.
188       * @param user a UserModel object that contains the updated profile
189       * @param updateType the type of information that is being updated
190       * @param authentication the user's authentication information, if known
191       * @param authType the type of authentication information being provided
192       * @param reqSource the source of the request (eg web, api)
193       * @return true if changes were made
194       * @throws AuthenticatorException an exception if the login is unsuccessful, or an error occurs
195       */

196     public abstract boolean updateProfile(UserModel user, int updateType, Object JavaDoc authentication, int authType, int reqSource) throws AuthenticatorException;
197
198     /**
199       * This method is called after creating a new instance of the Authenticator. It supplies
200       * some default EJB objects that the authenticator can use.
201       */

202     public void initialize(HashMap values) {
203         if(values != null) {
204             Object JavaDoc userHandler = values.get("userHandler");
205             Object JavaDoc systemConfiguration = values.get("systemConfiguration");
206
207             if(userHandler instanceof UserHandler) {
208                 this.userHandler = (UserHandler) userHandler;
209             }
210             if(systemConfiguration instanceof SystemConfiguration) {
211                 this.systemConfiguration = (SystemConfiguration) systemConfiguration;
212             }
213         }
214     }
215
216     /**
217       * Returns a UserHandler session bean that can be used to call needed methods such
218       * as retrieving a user.
219       */

220     public UserHandler getUserHandler() throws AuthenticatorException {
221         if(userHandler == null || ! (userHandler instanceof UserHandler)) {
222             throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR);
223         }
224
225         return userHandler;
226     }
227
228     /**
229       * Returns an SystemConfiguration session bean that can be used to retreive properties
230       * that have been set in the system. These properties can be used to provide any
231       * needed configuration for the authenticator.
232       */

233     public SystemConfiguration getSystemConfiguration() throws AuthenticatorException {
234         if(systemConfiguration == null || ! (systemConfiguration instanceof SystemConfiguration)) {
235             throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR);
236         }
237
238         return systemConfiguration;
239     }
240 }
Popular Tags