KickJava   Java API By Example, From Geeks To Geeks.

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


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.services.JahiaService;
18 import org.jahia.utils.Base64;
19
20 import java.security.MessageDigest JavaDoc;
21 import java.security.NoSuchAlgorithmException JavaDoc;
22 import java.util.Properties JavaDoc;
23 import java.util.Set JavaDoc;
24 import java.util.Vector JavaDoc;
25
26
27 /**
28  * The user manager is responsible to manage all the users in the Jahia
29  * environment.
30  * blablabla .. sait pas quoi dire ....
31  *
32  * @author Fulco Houkes
33  * @version 2.0
34  */

35 public abstract class JahiaUserManagerProvider extends JahiaService {
36     /**
37      * Guest user unique identification name.
38      * Each usermanager should create this special user, who is assigned
39      * automatically for each anonymous session internally in Jahia.
40      */

41     public static final String JavaDoc GUEST_USERNAME = "guest";
42
43
44     //-------------------------------------------------------------------------
45
/**
46      * This is the method that creates a new user in the system, with all the
47      * specified attributes.
48      *
49      * @param username User identification name.
50      * @param password User password
51      * @param attributes User additional parameters. If the user has no additional
52      * attributes, give a NULL pointer to this parameter.
53      */

54     public abstract JahiaUser createUser (String JavaDoc name, String JavaDoc password, String JavaDoc userKey, int siteID,
55                                           Properties JavaDoc properties);
56
57
58     //-------------------------------------------------------------------------
59
/**
60      * This method removes a user from the system. All the user's attributes are
61      * remove, and also all the related objects belonging to the user. On success,
62      * true is returned and the user parameter is not longer valid. Return false
63      * on any failure.
64      *
65      * @param user reference on the user to be deleted.
66      */

67     public abstract boolean deleteUser (JahiaUser user);
68
69
70     /**
71      * Performs a login of the specified user.
72      *
73      * @param userKey the user identifier defined in this service properties
74      * @param userPassword the password of the user
75      *
76      * @return boolean true if the login succeeded, false otherwise
77      */

78     public abstract boolean login (String JavaDoc userKey, String JavaDoc userPassword);
79
80     //-------------------------------------------------------------------------
81
/**
82      * Load all the user data and attributes. On success a reference on the user
83      * is returned, otherwise NULL is returned.
84      *
85      * @param int site id
86      * @param username User's identification name.
87      *
88      * @return Return a reference on a new created jahiaUser object.
89      */

90     public abstract JahiaUser lookupUser (int siteID, String JavaDoc name);
91
92     public abstract JahiaUser lookupUser (String JavaDoc name, String JavaDoc searchAttributeName);
93     
94     //-------------------------------------------------------------------------
95
/**
96      * Load all the user data and attributes. On success a reference on the user
97      * is returned, otherwise NULL is returned.
98      *
99      * @return Return a reference on a new created jahiaUser object.
100      */

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

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

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

132     public abstract Vector JavaDoc getUserList (int siteID);
133
134     //-------------------------------------------------------------------------
135
/**
136      * This method return all users' keys in the system.
137      *
138      * @return Return a vector of strings holding the user identification key .
139      */

140     public abstract Vector JavaDoc getUserList ();
141
142
143     /**
144      * Find users according to a table of name=value properties. If the left
145      * side value is "*" for a property then it will be tested against all the
146      * properties. ie *=test* will match every property that starts with "test"
147      *
148      * @param siteID site identifier
149      * @param searchCriterias a Properties object that contains search criterias
150      * in the format name,value (for example "*"="*" or "username"="*test*") or
151      * null to search without criterias
152      *
153      * @return Set a set of JahiaUser elements that correspond to those
154      * search criterias
155      */

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

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

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

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

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

242     public abstract JahiaDOMObject getUserPropsAsDOM (int siteID)
243         throws JahiaException;
244
245     /**
246      * This method indicates that any internal cache for a provider should be
247      * updated because the value has changed and needs to be transmitted to the
248      * other nodes in a clustering environment.
249      * @param jahiaGroup JahiaGroup the group to be updated in the cache.
250      */

251     public abstract void updateCache(JahiaUser jahiaUser);
252
253 }
254
Popular Tags