KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nemesis > forum > proxy > UserProxy


1 /*
2  * NEMESIS-FORUM.
3  * Copyright (C) 2002 David Laurent(lithium2@free.fr). All rights reserved.
4  *
5  * Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
6  *
7  * Copyright (C) 2001 Yasna.com. All rights reserved.
8  *
9  * Copyright (C) 2000 CoolServlets.com. All rights reserved.
10  *
11  * NEMESIS-FORUM. is free software; you can redistribute it and/or
12  * modify it under the terms of the Apache Software License, Version 1.1,
13  * or (at your option) any later version.
14  *
15  * NEMESIS-FORUM core framework, NEMESIS-FORUM backoffice, NEMESIS-FORUM frontoffice
16  * application are parts of NEMESIS-FORUM and are distributed under
17  * same terms of licence.
18  *
19  *
20  * NEMESIS-FORUM includes software developed by the Apache Software Foundation (http://www.apache.org/)
21  * and software developed by CoolServlets.com (http://www.coolservlets.com).
22  * and software developed by Yasna.com (http://www.yasna.com).
23  *
24  */

25 package org.nemesis.forum.proxy;
26
27 import java.util.Enumeration JavaDoc;
28
29 import org.nemesis.forum.Authorization;
30 import org.nemesis.forum.ForumPermissions;
31 import org.nemesis.forum.Group;
32 import org.nemesis.forum.User;
33 import org.nemesis.forum.config.Constants;
34 import org.nemesis.forum.exception.UnauthorizedException;
35
36 /**
37  * Protection proxy for User objects.
38  *
39  * @see User
40  */

41 public class UserProxy implements User {
42
43     private User user;
44     private Authorization authorization;
45     private ForumPermissions permissions;
46
47     /**
48      * Create a new UserProxy.
49      */

50     public UserProxy(User user, Authorization authorization, ForumPermissions permissions) {
51         this.user = user;
52         this.authorization = authorization;
53         this.permissions = permissions;
54     }
55
56     public int getID() {
57         return user.getID();
58     }
59
60     public boolean isAnonymous() {
61         return user.isAnonymous();
62     }
63
64     public String JavaDoc getUsername() {
65         return user.getUsername();
66     }
67
68     public String JavaDoc getName() {
69         if (isNameVisible()
70             || permissions.get(Constants.SYSTEM_ADMIN)
71             || permissions.get(Constants.USER_ADMIN)) {
72             return user.getName();
73         } else {
74             return null;
75         }
76     }
77
78     public void setName(String JavaDoc name) throws UnauthorizedException {
79         if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.USER_ADMIN)) {
80             user.setName(name);
81         } else {
82             throw new UnauthorizedException();
83         }
84     }
85
86     public boolean isNameVisible() {
87         return user.isNameVisible();
88     }
89
90     public void setNameVisible(boolean visible) throws UnauthorizedException {
91         if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.USER_ADMIN)) {
92             user.setNameVisible(visible);
93         } else {
94             throw new UnauthorizedException();
95         }
96     }
97
98     public void setPassword(String JavaDoc password) throws UnauthorizedException {
99         if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.USER_ADMIN)) {
100             user.setPassword(password);
101         } else {
102             throw new UnauthorizedException();
103         }
104     }
105
106     public String JavaDoc getPasswordHash() throws UnauthorizedException {
107         if (permissions.get(Constants.SYSTEM_ADMIN)) {
108             return user.getPasswordHash();
109         } else {
110             throw new UnauthorizedException();
111         }
112     }
113
114     public void setPasswordHash(String JavaDoc passwordHash) throws UnauthorizedException {
115         if (permissions.get(Constants.SYSTEM_ADMIN)) {
116             user.setPasswordHash(passwordHash);
117         } else {
118             throw new UnauthorizedException();
119         }
120     }
121
122     public String JavaDoc getEmail() {
123         if (isEmailVisible()
124             || permissions.get(Constants.SYSTEM_ADMIN)
125             || permissions.get(Constants.USER_ADMIN)) {
126             return user.getEmail();
127         } else {
128             return null;
129         }
130     }
131
132     public void setEmail(String JavaDoc email) throws UnauthorizedException {
133         if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.USER_ADMIN)) {
134             user.setEmail(email);
135         } else {
136             throw new UnauthorizedException();
137         }
138     }
139
140     public boolean isEmailVisible() {
141         return user.isEmailVisible();
142     }
143
144     public void setEmailVisible(boolean visible) throws UnauthorizedException {
145         if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.USER_ADMIN)) {
146             user.setEmailVisible(visible);
147         } else {
148             throw new UnauthorizedException();
149         }
150     }
151
152     public String JavaDoc getProperty(String JavaDoc name) {
153         return user.getProperty(name);
154     }
155
156     public Enumeration JavaDoc propertyNames() {
157         return user.propertyNames();
158     }
159
160     public void setProperty(String JavaDoc name, String JavaDoc value) {
161         user.setProperty(name, value);
162     }
163
164     public ForumPermissions getPermissions(Authorization authorization) {
165         return user.getPermissions(authorization);
166     }
167
168     public boolean hasPermission(int type) {
169         return permissions.get(type);
170     }
171     
172     //*******AJOUT
173
public boolean isAdministratorInGroup(Group group) {
174         return user.isAdministratorInGroup(group);
175     }
176
177     public boolean isMemberInGroup(Group group) {
178         return user.isMemberInGroup(group);
179     }
180
181     public int getGroupAdministratorCount() {
182         return user.getGroupAdministratorCount();
183     }
184
185     public int getGroupCount() {
186         return user.getGroupCount();
187     }
188     
189     
190     
191     /**
192      * Converts the object to a String by returning the usernamename.
193      * This functionality is primarily for Java applications that might be
194      * accessing CoolForum objects through a GUI.
195      */

196     public String JavaDoc toString() {
197         return user.toString();
198     }
199 }
200
Popular Tags