KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > usergroup > LDAPUserGroupManager


1 package org.enhydra.shark.usergroup;
2
3 import org.enhydra.shark.api.*;
4
5 import org.enhydra.shark.api.internal.usergroup.*;
6 import org.enhydra.shark.api.internal.working.CallbackUtilities;
7
8 import java.util.*;
9
10 /**
11  * Used for managing users, groups and their relations.
12  *
13  * @author Sasa Bojanic, Vladimir Puskas
14  *
15  */

16 public class LDAPUserGroupManager implements UserGroupManager {
17
18    // LDAP client for connection to server defined within config file
19
private LDAPClient ldapClient;
20
21    private CallbackUtilities cus;
22
23    /**
24     * Method configure is called at Shark start up, to configure
25     * implementation of LDAP UserGroupManager.
26     *
27     * @param cus an instance of CallbackUtilities used to get
28     * properties for configuring usergroup manager in Shark.
29     *
30     * @exception RootException thrown if configuring doesn't succeed.
31     */

32    public void configure (CallbackUtilities cus) throws RootException {
33       this.cus=cus;
34       ldapClient=new LDAPClient(cus);
35    }
36
37    /**
38     * Returns Ids of all user groups.
39     *
40     * @param t user transaction.
41     * @return List of user group Ids.
42     *
43     * @throws RootException If something unexpected happens.
44     */

45    public List getAllGroupnames (UserTransaction t) throws RootException {
46       try {
47          return ldapClient.getAllOrganizationalUnitEntries();
48       } catch (Throwable JavaDoc ex) {
49          throw new RootException(ex);
50       }
51    }
52
53    /**
54     * Returns Ids of all users.
55     *
56     * @param t user transaction.
57     * @return List of user Ids.
58     *
59     * @throws RootException If something unexpected happens.
60     */

61    public List getAllUsers (UserTransaction t) throws RootException {
62       try{
63          return ldapClient.getAllUserEntries();
64       } catch (Throwable JavaDoc ex) {
65          throw new RootException(ex);
66       }
67    }
68
69    /**
70     * Returns all usernames that belong to the given group.
71     *
72     * @param t user transaction.
73     * @param groupName name of the given group.
74     * @return List of all usernames that belong to given group.
75     *
76     * @throws RootException If something unexpected happens.
77     */

78    public List getAllUsers (UserTransaction t,String JavaDoc groupName) throws RootException {
79       try {
80          return ldapClient.getAllUserEntries(groupName);
81       } catch (Throwable JavaDoc ex) {
82          throw new RootException(ex);
83       }
84    }
85
86    /**
87     * Returns all users that belong to the given groups.
88     *
89     * @param t user transaction.
90     * @param groupNames names of the given groups.
91     * @return List of all users that belong to given groups.
92     *
93     * @throws RootException If something unexpected happens.
94     */

95    public List getAllUsers (UserTransaction t,List groupNames) throws RootException {
96       try{
97          Iterator it=groupNames.iterator();
98          List ret=new ArrayList();
99          while (it.hasNext()){
100             String JavaDoc groupName=(String JavaDoc)it.next();
101             ret.addAll(ldapClient.getAllUserEntries(groupName));
102          }
103          return ret;
104       } catch (Throwable JavaDoc ex) {
105          throw new RootException(ex);
106       }
107    }
108    /**
109     * Returns all users that are immediate children of the given group.
110     *
111     * @param t user transaction.
112     * @param groupName name of the given group.
113     * @return List of all immediate (direct) users that belong to the given
114     * group.
115     *
116     * @throws RootException If something unexpected happens.
117     */

118    public List getAllImmediateUsers (UserTransaction t,String JavaDoc groupName) throws RootException {
119       try {
120          return ldapClient.getAllImmediateUserEntries(groupName);
121       } catch (Throwable JavaDoc ex) {
122          throw new RootException(ex);
123       }
124    }
125
126    /**
127     * Returns all groups that belong to the given group.
128     *
129     * @param t user transaction.
130     * @param groupName name of the given group.
131     * @return List of all groups that belong to the given group.
132     *
133     * @throws RootException If something unexpected happens.
134     */

135    public List getAllSubgroups (UserTransaction t, String JavaDoc groupName) throws RootException {
136      try {
137          return ldapClient.getAllSubOrganizationalUnitEntries(groupName);
138       } catch (Throwable JavaDoc ex) {
139          throw new RootException(ex);
140       }
141     }
142
143    /**
144     * Returns all groups that belong to the given groups.
145     *
146     * @param t user transaction.
147     * @param groupNames names of the given groups.
148     * @return List of all groups that belong to the given groups.
149     *
150     * @throws RootException If something unexpected happens.
151     */

152    public List getAllSubgroups (UserTransaction t, List groupNames) throws RootException {
153       try{
154          Iterator it=groupNames.iterator();
155          List ret=new ArrayList();
156          while (it.hasNext()){
157             String JavaDoc groupName=(String JavaDoc)it.next();
158             ret.addAll(ldapClient.getAllSubOrganizationalUnitEntries(groupName));
159          }
160          return ret;
161       } catch (Throwable JavaDoc ex) {
162          throw new RootException(ex);
163       }
164    }
165
166    /**
167     * Returns all groups that are immediate children of the given group
168     * (which are on the first level bellow the level of the given group).
169     *
170     * @param t user transaction.
171     * @param groupName name of the given group.
172     * @return List of all groups that are immediate children of the given group.
173     *
174     * @throws RootException If something unexpected happens.
175     */

176    public List getAllImmediateSubgroups (UserTransaction t, String JavaDoc groupName) throws RootException {
177      try {
178          return ldapClient.getAllImmediateSubOrganizationalUnitEntries(groupName);
179       } catch (Throwable JavaDoc ex) {
180          throw new RootException(ex);
181       }
182     }
183
184    /**
185     * Creates a new user group.
186     *
187     * @param t user transaction.
188     * @param groupName name of the given group.
189     * @param description group description.
190     *
191     * @throws RootException If something unexpected happens.
192     */

193    public void createGroup (UserTransaction t,String JavaDoc groupName,String JavaDoc description) throws RootException {
194       throw new RootException("Not implemented");
195    }
196
197    /**
198     * Removes user group.
199     *
200     * @param t user transaction.
201     * @param groupName name of the given group.
202     *
203     * @throws RootException If something unexpected happens.
204     */

205    public void removeGroup (UserTransaction t,String JavaDoc groupName) throws RootException {
206       throw new RootException("Not implemented");
207    }
208
209    /**
210     * Returns true if user group with given name exists.
211     *
212     * @param t user transaction.
213     * @param groupName name of the given group.
214     * @return true if user group exists, otherwise false.
215     *
216     * @throws RootException If something unexpected happens.
217     */

218    public boolean doesGroupExist (UserTransaction t,String JavaDoc groupName) throws RootException {
219       try {
220          return ldapClient.doesGroupExist(groupName);
221       } catch (Throwable JavaDoc ex) {
222          throw new RootException(ex);
223       }
224    }
225
226    /**
227     * Returns true if group <i>subgroupName</i> is subgroup of group <i>groupName</i>.
228     *
229     * @param t user transaction.
230     * @param groupName name of the given group.
231     * @param subgroupName name of the given subgroup.
232     * @return true if group <i>subgroupName</i> is subgroup of group <i>groupName</i>,
233     * otherwise false.
234     *
235     * @throws RootException If something unexpected happens.
236     */

237    public boolean doesGroupBelongToGroup (UserTransaction t,String JavaDoc groupName, String JavaDoc subgroupName) throws RootException {
238       try {
239          return ldapClient.doesGroupBelongToGroup(groupName,subgroupName);
240       } catch (Throwable JavaDoc ex) {
241          throw new RootException(ex);
242       }
243    }
244
245    /**
246     * Allows administrator to update data about group.
247     *
248     * @param t user transaction.
249     * @param groupName name of the given group.
250     * @param description group description.
251     *
252     * @throws RootException If something unexpected happens.
253     */

254    public void updateGroup (UserTransaction t,String JavaDoc groupName,String JavaDoc description) throws RootException {
255       throw new RootException("Not implemented");
256    }
257
258    /**
259     * Adds an existing group <i>subgroupName</i> to the group <i>groupName</i>.
260     *
261     * @param t user transaction.
262     * @param groupName name of the given group.
263     * @param subgroupName name of the given subgroup to be added.
264     *
265     * @throws RootException If something unexpected happens.
266     */

267    public void addGroupToGroup (UserTransaction t,String JavaDoc groupName,String JavaDoc subgroupName) throws RootException {
268       throw new RootException("Not implemented");
269    }
270
271    /**
272     * Removes group <i>subgroupName</i> from the group <i>groupName</i>.
273     *
274     * @param t user transaction.
275     * @param groupName name of the given group.
276     * @param subgroupName name of the given subgroup to be removed.
277     *
278     * @throws RootException If something unexpected happens.
279     */

280    public void removeGroupFromGroup (UserTransaction t,String JavaDoc groupName,String JavaDoc subgroupName) throws RootException {
281       throw new RootException("Not implemented");
282    }
283
284    /**
285     * Deletes group <i>groupName</i> and all its child groups that don't belong
286     * to any other group except this one.
287     *
288     * @param t user transaction.
289     * @param groupName name of the given group.
290     *
291     * @throws RootException If something unexpected happens.
292     */

293    public void removeGroupTree (UserTransaction t,String JavaDoc groupName) throws RootException {
294       throw new RootException("Not implemented");
295    }
296
297    /**
298     * Removes all users from group <i>group</i> that don't belong to any other
299     * group except this one.
300     *
301     * @param t user transaction.
302     * @param groupName name of the given group.
303     *
304     * @throws RootException If something unexpected happens.
305     */

306    public void removeUsersFromGroupTree (UserTransaction t,String JavaDoc groupName) throws RootException {
307       throw new RootException("Not implemented");
308    }
309
310    /**
311     * Moves group <i>subgroupName</i> from the group <i>currentParentGroup</i> to
312     * group <i>newParentGroup</i>.
313     *
314     * @param t user transaction.
315     * @param currentParentGroup current group that contains group subgroupName.
316     * @param newParentGroup new group where group subgroupName will be moved to.
317     * @param subgroupName subgroup that will be moved.
318     *
319     * @throws RootException If something unexpected happens.
320     */

321    public void moveGroup (UserTransaction t,String JavaDoc currentParentGroup,String JavaDoc newParentGroup,String JavaDoc subgroupName) throws RootException{
322       throw new RootException("Not implemented");
323    }
324
325    /**
326     * Returns a group description.
327     *
328     * @param t user transaction.
329     * @param groupName name of the given group.
330     * @return Group description.
331     *
332     * @throws RootException If something unexpected happens.
333     */

334    public String JavaDoc getGroupDescription (UserTransaction t,String JavaDoc groupName) throws RootException {
335       try {
336          return ldapClient.getGroupAttribute(groupName,ldapClient.getLDAPOptions().getGroupDescriptionAttributeName());
337       } catch (Throwable JavaDoc ex) {
338          throw new RootException(ex);
339       }
340    }
341
342
343    /**
344     * Adds an existing user with a given username to the given group.
345     *
346     * @param t user transaction.
347     * @param groupName name of the given group.
348     * @param username username used to uniquely identify shark user.
349     *
350     * @throws RootException If something unexpected happens.
351     */

352    public void addUserToGroup (UserTransaction t,String JavaDoc groupName,String JavaDoc username) throws RootException {
353       throw new RootException("Not implemented");
354    }
355
356    /**
357     * Removes the user from the group.
358     *
359     * @param t user transaction.
360     * @param groupName name of the given group.
361     * @param username username used to uniquely identify shark user.
362     *
363     * @throws RootException If something unexpected happens.
364     */

365    public void removeUserFromGroup (UserTransaction t,String JavaDoc groupName,String JavaDoc username) throws RootException {
366       throw new RootException("Not implemented");
367    }
368
369    /**
370     * Moves user <i>username</i> from the group <i>currentGroup</i> to group
371     * <i>newGroup</i>.
372     *
373     * @param t user transaction.
374     * @param currentGroup current group that contains the user.
375     * @param newGroup new group where the user will be moved to.
376     * @param username the user that will be moved.
377     *
378     * @throws RootException If something unexpected happens.
379     */

380    public void moveUser (UserTransaction t,String JavaDoc currentGroup,String JavaDoc newGroup,String JavaDoc username) throws RootException {
381       throw new RootException("Not implemented");
382    }
383
384    /**
385     * Returns true if the given user belongs to the given group.
386     *
387     * @param t user transaction.
388     * @param groupName name of the given group.
389     * @param username username used to uniquely identify shark user.
390     * @return true if the given user belongs to the given group, otherwise
391     * false.
392     *
393     * @throws RootException If something unexpected happens.
394     */

395    public boolean doesUserBelongToGroup (UserTransaction t,String JavaDoc groupName,String JavaDoc username) throws RootException {
396       try {
397          return ldapClient.doesUserBelongToGroup(groupName,username);
398       } catch (Throwable JavaDoc ex) {
399          throw new RootException(ex);
400       }
401    }
402
403    /**
404     * Allows administrator to create new user. After its creation, the client
405     * application will always be able to log onto shark using username and
406     * password defined for the user.
407     *
408     * @param t user transaction.
409     * @param groupName groupName used to uniquely identify group -
410     * this parameter is mandatory.
411     * @param username username used to uniquely identify user -
412     * this parameter is mandatory.
413     * @param password password used to authenticate -
414     * this parameter is mandatory.
415     * @param firstName the user's first name.
416     * @param lastName the user's last name.
417     * @param emailAddress email address of the user.
418     *
419     * @throws RootException If something unexpected happens (i.e the user with
420     * given username already exists).
421     */

422    public void createUser (UserTransaction t,String JavaDoc groupName,String JavaDoc username, String JavaDoc password, String JavaDoc firstName, String JavaDoc lastName, String JavaDoc emailAddress) throws RootException {
423       throw new RootException("Not implemented");
424    }
425
426    /**
427     * Allows administrator to update data about user.
428     *
429     * @param t user transaction.
430     * @param username username used to uniquely identify user -
431     * this parameter is mandatory.
432     * @param firstName the user's first name.
433     * @param lastName the user's last name.
434     * @param emailAddress email address of the user.
435     *
436     * @throws RootException If something unexpected happens (i.e the user with
437     * given username does not exist).
438     */

439    public void updateUser (UserTransaction t, String JavaDoc username, String JavaDoc firstName, String JavaDoc lastName, String JavaDoc emailAddress) throws RootException {
440       throw new RootException("Not implemented");
441    }
442
443    /**
444     * Allows administrator to remove the user.
445     *
446     * @param t user transaction.
447     * @param username username used to uniquely identify user.
448     *
449     * @throws RootException If something unexpected happens (i.e the user with
450     * given username does not exist, or this is a user that can't be removed).
451     */

452    public void removeUser (UserTransaction t,String JavaDoc username) throws RootException {
453       throw new RootException("Not implemented");
454    }
455
456    /**
457     * Returns true if user with given username exists.
458     *
459     * @param t user transaction.
460     * @param username username of the shark user.
461     * @return true if the user with the given username exists, otherwise false.
462     *
463     * @throws RootException If something unexpected happens.
464     */

465    public boolean doesUserExist (UserTransaction t,String JavaDoc username) throws RootException {
466       try {
467          return ldapClient.doesUserExist(username);
468       } catch (Throwable JavaDoc ex) {
469          throw new RootException(ex);
470       }
471    }
472
473    /**
474     * Sets user password.
475     *
476     * @param t user transaction.
477     * @param username username of the shark user.
478     * @param password new password of the shark user.
479     *
480     * @throws RootException If something unexpected happens.
481     */

482    public void setPassword (UserTransaction t,String JavaDoc username,String JavaDoc password) throws RootException {
483       throw new RootException("Not implemented");
484    }
485
486    /**
487     * Returns string representing the real name for the shark user with the
488     * given username (first and last name).
489     *
490     * @param t user transaction.
491     * @param username username of the shark user.
492     * @return Real name of the shark user.
493     *
494     * @throws RootException If something unexpected happens.
495     */

496    public String JavaDoc getUserRealName (UserTransaction t,String JavaDoc username) throws RootException {
497       try {
498          return ldapClient.getUserAttribute(username,ldapClient.getLDAPOptions().getUserRealNameAttributeName());
499       } catch (Throwable JavaDoc ex) {
500          throw new RootException(ex);
501       }
502    }
503
504    /**
505     * Returns string representing user's first name.
506     *
507     * @param t user transaction.
508     * @param username username of the shark user.
509     * @return First name of the shark user.
510     *
511     * @throws RootException If something unexpected happens.
512     */

513    public String JavaDoc getUserFirstName (UserTransaction t,String JavaDoc username) throws RootException {
514       try {
515          return ldapClient.getUserAttribute(username,ldapClient.getLDAPOptions().getUserFirstNameAttributeName());
516       } catch (Throwable JavaDoc ex) {
517          throw new RootException(ex);
518       }
519    }
520
521    /**
522     * Returns string representing user's last name.
523     *
524     * @param t user transaction.
525     * @param username username of the shark user.
526     * @return Last name of the shark user.
527     *
528     * @throws RootException If something unexpected happens.
529     */

530    public String JavaDoc getUserLastName (UserTransaction t,String JavaDoc username) throws RootException {
531       try {
532          return ldapClient.getUserAttribute(username,ldapClient.getLDAPOptions().getUserLastNameAttributeName());
533       } catch (Throwable JavaDoc ex) {
534          throw new RootException(ex);
535       }
536    }
537
538    /**
539     * Returns string representing email address for the user with the given
540     * username.
541     *
542     * @param t user transaction.
543     * @param username username of the shark user.
544     * @return Email of the shark user.
545     *
546     */

547    public String JavaDoc getUserEMailAddress (UserTransaction t,String JavaDoc username) throws RootException {
548       try {
549          return ldapClient.getUserAttribute(username,ldapClient.getLDAPOptions().getUserEmailAttributeName());
550       } catch (Throwable JavaDoc ex) {
551          throw new RootException(ex);
552       }
553    }
554
555
556 }
557
Popular Tags