KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > server > store > UserStore


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2003 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.server.store;
20
21 import org.lucane.server.*;
22 import org.lucane.common.concepts.*;
23
24 import java.util.*;
25
26 public abstract class UserStore
27 {
28     /**
29      * Store a user
30      *
31      * @param user the UserConcept to store
32      */

33     public abstract void storeUser(UserConcept user) throws Exception JavaDoc;
34     
35     /**
36      * Update a user
37      *
38      * @param user the UserConcept to update
39      */

40     public abstract void updateUser(UserConcept user) throws Exception JavaDoc;
41
42     /**
43      * Remove a user
44      *
45      * @param user the UserConcept to remove from the store
46      */

47     public abstract void removeUser(UserConcept user) throws Exception JavaDoc;
48
49     /**
50      * Fetch a user by its login
51      *
52      * @param login the user to fetch
53      * @return the corresponding user or null
54      */

55     public abstract UserConcept getUser(String JavaDoc login) throws Exception JavaDoc;
56
57     /**
58      * Fetch all users
59      *
60      * @return an iterator listing all users
61      */

62     public abstract Iterator getAllUsers() throws Exception JavaDoc;
63     
64     /**
65      * Check wether a password is correct
66      *
67      * @param user the UserConcept
68      * @param passwd the password to check
69      * @return true if the password is correct.
70      */

71     public boolean checkUserPassword(UserConcept user, String JavaDoc passwd)
72     {
73         try {
74             return user.getPassword().equals(passwd);
75         } catch(Exception JavaDoc e) {
76             return false;
77         }
78     }
79     
80     /**
81      * Get all groups where a user is contained
82      *
83      * @param user the user
84      * @return an iterator listing all groups a user is in
85      */

86     public Iterator getAllUserGroups(UserConcept user)
87     throws Exception JavaDoc
88     {
89         ArrayList userGroups = new ArrayList();
90         GroupStore gm = Server.getInstance().getStore().getGroupStore();
91         
92         Iterator groups = gm.getAllGroups();
93         while(groups.hasNext())
94         {
95             GroupConcept group = (GroupConcept)groups.next();
96             if(group.hasUser(user))
97                 recurseGroups(group, userGroups);
98         }
99         
100         return userGroups.iterator();
101     }
102     
103     /**
104      * Recurse parents of a group to add them to the list
105      *
106      * @param group the root group
107      * @param groups the list of groups
108      */

109     private void recurseGroups(GroupConcept group, ArrayList groups)
110     {
111         if(group == null || groups.contains(group))
112             return;
113         
114         groups.add(group);
115         Iterator i = group.getParents();
116
117         while(i.hasNext())
118             recurseGroups((GroupConcept)i.next(), groups);
119     }
120 }
121
Popular Tags