KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > usermanager > JahiaUserManagerService


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 package org.jahia.services.usermanager;
14
15 import org.jahia.data.JahiaDOMObject;
16 import org.jahia.exceptions.JahiaException;
17 import org.jahia.exceptions.JahiaInitializationException;
18 import org.jahia.services.JahiaInitializableService;
19 import org.jahia.settings.SettingsBean;
20 import org.jahia.utils.Base64;
21
22 import java.security.MessageDigest JavaDoc;
23 import java.security.NoSuchAlgorithmException JavaDoc;
24 import java.util.Properties JavaDoc;
25 import java.util.Set JavaDoc;
26 import java.util.Vector JavaDoc;
27
28
29 /**
30  * The user manager is responsible to manage all the users in the Jahia
31  * environment.
32  * The is the general interface that Jahia code uses to offer user management
33  * services throughout the product (administration, login, ACL popups, etc..)
34  *
35  * @author Fulco Houkes
36  * @version 2.0
37  */

38 public abstract class JahiaUserManagerService extends JahiaInitializableService {
39     /**
40      * Guest user unique identification name.
41      * Each usermanager should create this special user, who is assigned
42      * automatically for each anonymous session internally in Jahia.
43      */

44     public static final String JavaDoc GUEST_USERNAME = "guest";
45
46     public abstract void init (SettingsBean jSettings)
47             throws JahiaInitializationException;
48
49     /**
50      * Returns a vector of UserManagerProviderBean object describing the
51      * available user management providers
52      *
53      * @return result a Vector of UserManagerProviderBean objects that describe
54      * the providers. This will never be null but may be empty if no providers
55      * are available.
56      */

57     public abstract Vector JavaDoc getProviderList ();
58
59     //-------------------------------------------------------------------------
60
/**
61      * This is the method that creates a new user in the system, with all the
62      * specified attributes.
63      *
64      * @param username User identification name.
65      * @param password User password
66      * @param attributes User additional parameters. If the user has no additional
67      * attributes, give a NULL pointer to this parameter.
68      */

69     public abstract JahiaUser createUser (String JavaDoc name, String JavaDoc password,
70                                           String JavaDoc userKey, int siteID,
71                                           Properties JavaDoc properties);
72
73
74     //-------------------------------------------------------------------------
75
/**
76      * This method removes a user from the system. All the user's attributes are
77      * remove, and also all the related objects belonging to the user. On success,
78      * true is returned and the user parameter is not longer valid. Return false
79      * on any failure.
80      *
81      * @param user reference on the user to be deleted.
82      */

83     public abstract boolean deleteUser (JahiaUser user);
84
85
86     //-------------------------------------------------------------------------
87
/**
88      * Load all the user data and attributes. On success a reference on the user
89      * is returned, otherwise NULL is returned.
90      *
91      * @param int site id
92      * @param username User's identification name.
93      *
94      * @return Return a reference on a new created jahiaUser object.
95      */

96     public abstract JahiaUser lookupUser (int siteID, String JavaDoc name);
97
98
99     //-------------------------------------------------------------------------
100
/**
101      * Load all the user data and attributes. On success a reference on the user
102      * is returned, otherwise NULL is returned.
103      *
104      * @return Return a reference on a new created jahiaUser object.
105      */

106     public abstract JahiaUser lookupUser (String JavaDoc userKey);
107
108
109     //-------------------------------------------------------------------------
110
/**
111      * This function checks into the system if the username has already been
112      * assigned to another user.
113      *
114      * @param username User login name.
115      *
116      * @return Return true if the specified username has not been assigned yet,
117      * return false on any failure.
118      */

119     public abstract boolean userExists (int siteID, String JavaDoc name);
120
121     //-------------------------------------------------------------------------
122
/**
123      * This method returns the list of all the user names registed into the system.
124      *
125      * @return Return a vector of strings holding the user identification names.
126      */

127     public abstract Vector JavaDoc getUsernameList (int siteID);
128
129
130
131     //-------------------------------------------------------------------------
132
/**
133      * This method returns the list of this site's users' keys.
134      *
135      * @return Return a vector of strings holding the user identification key .
136      */

137     public abstract Vector JavaDoc getUserList (int siteID);
138
139     //-------------------------------------------------------------------------
140
/**
141      * This method return all users' keys in the system.
142      *
143      * @return Return a vector of strings holding the user identification key .
144      */

145     public abstract Vector JavaDoc getUserList ();
146
147
148     /**
149      * Performs a login of the specified user.
150      *
151      * @param userKey the user identifier defined in this service properties
152      * @param userPassword the password of the user
153      *
154      * @return boolean true if the login succeeded, false otherwise
155      */

156     public abstract boolean login (String JavaDoc userKey, String JavaDoc userPassword);
157
158     //--------------------------------------------------------------------------
159
// FH 29 Mar. 2001
160
// Initial implementation
161
//
162
/**
163      * Encrypt the specified password using the SHA algorithm.
164      *
165      * @param password String representation of a password.
166      *
167      * @return Return a String representation of the password encryption. Return
168      * null on any failure.
169      */

170     public static String JavaDoc encryptPassword (String JavaDoc password) {
171
172         if (password == null) {
173             return null;
174         }
175
176         if (password.length () == 0) {
177             return null;
178         }
179
180         String JavaDoc result = null;
181
182         try {
183             MessageDigest JavaDoc md = MessageDigest.getInstance ("SHA-1");
184             if (md != null) {
185                 md.reset ();
186                 md.update (password.getBytes ());
187                 result = new String JavaDoc (Base64.encode (md.digest ()));
188             }
189             md = null;
190         } catch (NoSuchAlgorithmException JavaDoc ex) {
191             result = null;
192         }
193
194         return result;
195     }
196
197
198     //-------------------------------------------------------------------------
199
/**
200      * Return the number of user in the system.
201      *
202      * @return Return the number of users in the system.
203      */

204     public abstract int getNbUsers ()
205             throws JahiaException;
206
207     //-------------------------------------------------------------------------
208
/**
209      * Return the number of user for a gived site
210      *
211      * @return Return the number of users in the system.
212      */

213     public abstract int getNbUsers (int siteID)
214             throws JahiaException;
215
216
217     //--------------------------------------------------------------------------
218
/**
219      * return a DOM document of all users of a site
220      *
221      * @param int the site id
222      *
223      * @return JahiaDOMObject a DOM representation of this object
224      *
225      * @author NK
226      */

227     public abstract JahiaDOMObject getUsersAsDOM (String JavaDoc providerName, int siteID)
228             throws JahiaException;
229
230
231     //--------------------------------------------------------------------------
232
/**
233      * return a DOM document of all user props of a site
234      *
235      * @param int the site id
236      *
237      * @return JahiaDOMObject a DOM representation of this object
238      *
239      * @author NK
240      */

241     public abstract JahiaDOMObject getUserPropsAsDOM (String JavaDoc providerName, int siteID)
242             throws JahiaException;
243
244     /**
245      * Find users according to a table of name=value properties. If the left
246      * side value is "*" for a property then it will be tested against all the
247      * properties. ie *=test* will match every property that starts with "test"
248      *
249      * @param siteID site identifier
250      * @param searchCriterias a Properties object that contains search criterias
251      * in the format name,value (for example "*"="*" or "username"="*test*") or
252      * null to search without criterias
253      *
254      * @return Vector a vector of JahiaUser elements that correspond to those
255      * search criterias
256      */

257     public abstract Set JavaDoc searchUsers (int siteID, Properties JavaDoc searchCriterias);
258
259     /**
260      * Find users according to a table of name=value properties. If the left
261      * side value is "*" for a property then it will be tested against all the
262      * properties. ie *=test* will match every property that starts with "test"
263      *
264      * @param providerKey key of the provider in which to search, may be
265      * obtained by calling getProviderList()
266      * @param siteID site identifier
267      * @param searchCriterias a Properties object that contains search criterias
268      * in the format name,value (for example "*"="*" or "username"="*test*") or
269      * null to search without criterias
270      *
271      * @return Set a set of JahiaUser elements that correspond to those
272      * search criterias
273      */

274     public abstract Set JavaDoc searchUsers (String JavaDoc providerKey, int siteID,
275                                      Properties JavaDoc searchCriterias);
276
277     /**
278      * This method indicates that any internal cache for a provider should be
279      * updated because the value has changed and needs to be transmitted to the
280      * other nodes in a clustering environment.
281      * @param jahiaGroup JahiaGroup the group to be updated in the cache.
282      */

283     public abstract void updateCache(JahiaUser jahiaUser);
284
285 }
286
Popular Tags