KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > Yasna > forum > UserProxy


1 /**
2  * Copyright (C) 2001 Yasna.com. All rights reserved.
3  *
4  * ===================================================================
5  * The Apache Software License, Version 1.1
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * 3. The end-user documentation included with the redistribution,
20  * if any, must include the following acknowledgment:
21  * "This product includes software developed by
22  * Yasna.com (http://www.yasna.com)."
23  * Alternately, this acknowledgment may appear in the software itself,
24  * if and wherever such third-party acknowledgments normally appear.
25  *
26  * 4. The names "Yazd" and "Yasna.com" must not be used to
27  * endorse or promote products derived from this software without
28  * prior written permission. For written permission, please
29  * contact yazd@yasna.com.
30  *
31  * 5. Products derived from this software may not be called "Yazd",
32  * nor may "Yazd" appear in their name, without prior written
33  * permission of Yasna.com.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL YASNA.COM OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of Yasna.com. For more information
51  * on Yasna.com, please see <http://www.yasna.com>.
52  */

53
54 /**
55  * Copyright (C) 2000 CoolServlets.com. All rights reserved.
56  *
57  * ===================================================================
58  * The Apache Software License, Version 1.1
59  *
60  * Redistribution and use in source and binary forms, with or without
61  * modification, are permitted provided that the following conditions
62  * are met:
63  *
64  * 1. Redistributions of source code must retain the above copyright
65  * notice, this list of conditions and the following disclaimer.
66  *
67  * 2. Redistributions in binary form must reproduce the above copyright
68  * notice, this list of conditions and the following disclaimer in
69  * the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3. The end-user documentation included with the redistribution,
73  * if any, must include the following acknowledgment:
74  * "This product includes software developed by
75  * CoolServlets.com (http://www.coolservlets.com)."
76  * Alternately, this acknowledgment may appear in the software itself,
77  * if and wherever such third-party acknowledgments normally appear.
78  *
79  * 4. The names "Jive" and "CoolServlets.com" must not be used to
80  * endorse or promote products derived from this software without
81  * prior written permission. For written permission, please
82  * contact webmaster@coolservlets.com.
83  *
84  * 5. Products derived from this software may not be called "Jive",
85  * nor may "Jive" appear in their name, without prior written
86  * permission of CoolServlets.com.
87  *
88  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
89  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
90  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
91  * DISCLAIMED. IN NO EVENT SHALL COOLSERVLETS.COM OR
92  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
93  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
94  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
95  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
96  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
97  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
98  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
99  * SUCH DAMAGE.
100  * ====================================================================
101  *
102  * This software consists of voluntary contributions made by many
103  * individuals on behalf of CoolServlets.com. For more information
104  * on CoolServlets.com, please see <http://www.coolservlets.com>.
105  */

106
107 package com.Yasna.forum;
108
109 import java.util.*;
110
111 /**
112  * Protection proxy for User objects.
113  *
114  * @see User
115  */

116 public class UserProxy implements User {
117
118     private User user;
119     private Authorization authorization;
120     private ForumPermissions permissions;
121
122     /**
123      * Create a new UserProxy.
124      */

125     public UserProxy(User user, Authorization authorization,
126             ForumPermissions permissions)
127     {
128         this.user = user;
129         this.authorization = authorization;
130         this.permissions = permissions;
131     }
132
133     public int getID() {
134         return user.getID();
135     }
136
137     public boolean isAnonymous() {
138         return user.isAnonymous();
139     }
140
141     public String JavaDoc getUsername() {
142         return user.getUsername();
143     }
144
145     public String JavaDoc getName(){
146         if (isNameVisible() || permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
147                 permissions.get(ForumPermissions.USER_ADMIN))
148         {
149             return user.getName();
150         }
151         else {
152             return null;
153         }
154     }
155
156     public void setName(String JavaDoc name) throws UnauthorizedException {
157         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
158                permissions.get(ForumPermissions.USER_ADMIN))
159         {
160             user.setName(name);
161         }
162         else {
163             throw new UnauthorizedException();
164         }
165     }
166
167     public boolean isNameVisible() {
168         return user.isNameVisible();
169     }
170
171     public void setNameVisible(boolean visible) throws UnauthorizedException {
172         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
173                permissions.get(ForumPermissions.USER_ADMIN))
174         {
175             user.setNameVisible(visible);
176         }
177         else {
178             throw new UnauthorizedException();
179         }
180     }
181
182     public void setPassword(String JavaDoc password) throws UnauthorizedException {
183         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
184                permissions.get(ForumPermissions.USER_ADMIN))
185         {
186             user.setPassword(password);
187         }
188         else {
189             throw new UnauthorizedException();
190         }
191     }
192
193     public String JavaDoc getPasswordHash() throws UnauthorizedException {
194         if (permissions.get(ForumPermissions.SYSTEM_ADMIN))
195         {
196             return user.getPasswordHash();
197         }
198         else {
199             throw new UnauthorizedException();
200         }
201     }
202
203     public void setPasswordHash(String JavaDoc passwordHash)
204             throws UnauthorizedException
205     {
206         if (permissions.get(ForumPermissions.SYSTEM_ADMIN))
207         {
208             user.setPasswordHash(passwordHash);
209         }
210         else {
211             throw new UnauthorizedException();
212         }
213     }
214
215     public String JavaDoc getEmail() {
216         if (isEmailVisible() || permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
217                 permissions.get(ForumPermissions.USER_ADMIN))
218         {
219             return user.getEmail();
220         }
221         else {
222             return null;
223         }
224     }
225
226     public Calendar getLastLogin(){
227         return user.getLastLogin();
228     }
229     public Calendar getLastPost(){
230         return user.getLastPost();
231     }
232     public Locale getUserLocale(){
233         return user.getUserLocale();
234     }
235     public void setUserLocale(Locale locale) throws UnauthorizedException{
236         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
237                permissions.get(ForumPermissions.USER_ADMIN))
238         {
239             user.setUserLocale(locale);
240         }
241         else {
242             throw new UnauthorizedException();
243         }
244
245     }
246     public TimeZone getUserTimeZone(){
247         return user.getUserTimeZone();
248     }
249     public void setUserTimeZone(String JavaDoc timezone) throws UnauthorizedException{
250         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
251                permissions.get(ForumPermissions.USER_ADMIN))
252         {
253             user.setUserTimeZone(timezone);
254         }
255         else {
256             throw new UnauthorizedException();
257         }
258
259     }
260     public void setEmail(String JavaDoc email) throws UnauthorizedException {
261         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
262                permissions.get(ForumPermissions.USER_ADMIN))
263         {
264             user.setEmail(email);
265         }
266         else {
267             throw new UnauthorizedException();
268         }
269     }
270
271     public boolean getThreadSubscribe() {
272         return user.getThreadSubscribe();
273     }
274
275     public void setThreadSubscribe(boolean emailReply) throws UnauthorizedException {
276         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
277                permissions.get(ForumPermissions.USER_ADMIN))
278         {
279             user.setThreadSubscribe(emailReply);
280         }
281         else {
282             throw new UnauthorizedException();
283         }
284     }
285
286     public boolean isEmailVisible() {
287         return user.isEmailVisible();
288     }
289
290     public void setEmailVisible(boolean visible) throws UnauthorizedException {
291         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
292                permissions.get(ForumPermissions.USER_ADMIN))
293         {
294             user.setEmailVisible(visible);
295         }
296         else {
297             throw new UnauthorizedException();
298         }
299     }
300
301     public String JavaDoc getProperty(String JavaDoc name) {
302         return user.getProperty(name);
303     }
304
305     public Enumeration propertyNames() {
306         return user.propertyNames();
307     }
308
309     public void setProperty(String JavaDoc name, String JavaDoc value) {
310         user.setProperty(name, value);
311     }
312
313     public ForumPermissions getPermissions(Authorization authorization) {
314         return user.getPermissions(authorization);
315     }
316
317     public boolean hasPermission(int type) {
318         return permissions.get(type);
319     }
320
321     /**
322      * Converts the object to a String by returning the usernamename.
323      * This functionality is primarily for Java applications that might be
324      * accessing CoolForum objects through a GUI.
325      */

326     public String JavaDoc toString() {
327         return user.toString();
328     }
329 }
330
Popular Tags