001: /**
002: * Copyright (C) 2001 Yasna.com. All rights reserved.
003: *
004: * ===================================================================
005: * The Apache Software License, Version 1.1
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution,
020: * if any, must include the following acknowledgment:
021: * "This product includes software developed by
022: * Yasna.com (http://www.yasna.com)."
023: * Alternately, this acknowledgment may appear in the software itself,
024: * if and wherever such third-party acknowledgments normally appear.
025: *
026: * 4. The names "Yazd" and "Yasna.com" must not be used to
027: * endorse or promote products derived from this software without
028: * prior written permission. For written permission, please
029: * contact yazd@yasna.com.
030: *
031: * 5. Products derived from this software may not be called "Yazd",
032: * nor may "Yazd" appear in their name, without prior written
033: * permission of Yasna.com.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL YASNA.COM OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: *
049: * This software consists of voluntary contributions made by many
050: * individuals on behalf of Yasna.com. For more information
051: * on Yasna.com, please see <http://www.yasna.com>.
052: */
053:
054: /**
055: * Copyright (C) 2000 CoolServlets.com. All rights reserved.
056: *
057: * ===================================================================
058: * The Apache Software License, Version 1.1
059: *
060: * Redistribution and use in source and binary forms, with or without
061: * modification, are permitted provided that the following conditions
062: * are met:
063: *
064: * 1. Redistributions of source code must retain the above copyright
065: * notice, this list of conditions and the following disclaimer.
066: *
067: * 2. Redistributions in binary form must reproduce the above copyright
068: * notice, this list of conditions and the following disclaimer in
069: * the documentation and/or other materials provided with the
070: * distribution.
071: *
072: * 3. The end-user documentation included with the redistribution,
073: * if any, must include the following acknowledgment:
074: * "This product includes software developed by
075: * CoolServlets.com (http://www.coolservlets.com)."
076: * Alternately, this acknowledgment may appear in the software itself,
077: * if and wherever such third-party acknowledgments normally appear.
078: *
079: * 4. The names "Jive" and "CoolServlets.com" must not be used to
080: * endorse or promote products derived from this software without
081: * prior written permission. For written permission, please
082: * contact webmaster@coolservlets.com.
083: *
084: * 5. Products derived from this software may not be called "Jive",
085: * nor may "Jive" appear in their name, without prior written
086: * permission of CoolServlets.com.
087: *
088: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
089: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
090: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
091: * DISCLAIMED. IN NO EVENT SHALL COOLSERVLETS.COM OR
092: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
093: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
094: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
095: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
096: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
097: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
098: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
099: * 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: */package com.Yasna.forum;
106:
107: import java.util.*;
108:
109: //JDK1.1// import com.sun.java.util.collections.*;
110:
111: /**
112: * Protection proxy for the ProfileManager class. It restricts access to
113: * protected methods by throwing UnauthorizedExceptions when necessary.
114: *
115: * @see ProfileManager
116: */
117: public class ProfileManagerProxy implements ProfileManager {
118:
119: private ProfileManager profileManager;
120: private Authorization authorization;
121: private ForumPermissions permissions;
122:
123: /**
124: * Creates a new ProfileManagerProxy.
125: */
126: public ProfileManagerProxy(ProfileManager profileManager,
127: Authorization authorization, ForumPermissions permissions) {
128: this .profileManager = profileManager;
129: this .authorization = authorization;
130: this .permissions = permissions;
131: }
132:
133: public User createUser(String username, String password,
134: String email) throws UserAlreadyExistsException {
135: return profileManager.createUser(username, password, email);
136: }
137:
138: public boolean activateUser(int UserID, String Code) {
139: return profileManager.activateUser(UserID, Code);
140: }
141:
142: public Group createGroup(String name) throws UnauthorizedException,
143: GroupAlreadyExistsException {
144: if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) {
145: Group group = profileManager.createGroup(name);
146: return new GroupProxy(group, authorization, permissions);
147: } else {
148: throw new UnauthorizedException();
149: }
150: }
151:
152: public User getUser(int userID) throws UserNotFoundException {
153: User user = profileManager.getUser(userID);
154: ForumPermissions userPermissions = user
155: .getPermissions(authorization);
156: ForumPermissions newPermissions = new ForumPermissions(
157: permissions, userPermissions);
158: return new UserProxy(user, authorization, newPermissions);
159: }
160:
161: public User getUser(String username) throws UserNotFoundException {
162: User user = profileManager.getUser(username);
163: ForumPermissions userPermissions = user
164: .getPermissions(authorization);
165: ForumPermissions newPermissions = new ForumPermissions(
166: permissions, userPermissions);
167: return new UserProxy(user, authorization, newPermissions);
168: }
169:
170: public User getAnonymousUser() {
171: return profileManager.getAnonymousUser();
172: }
173:
174: public User getSpecialUser() {
175: return profileManager.getSpecialUser();
176: }
177:
178: public Group getGroup(int groupID) throws GroupNotFoundException {
179: Group group = profileManager.getGroup(groupID);
180: ForumPermissions groupPermissions = group
181: .getPermissions(authorization);
182: ForumPermissions newPermissions = new ForumPermissions(
183: permissions, groupPermissions);
184: return new GroupProxy(group, authorization, newPermissions);
185: }
186:
187: public Group getGroup(String name) throws GroupNotFoundException {
188: Group group = profileManager.getGroup(name);
189: ForumPermissions groupPermissions = group
190: .getPermissions(authorization);
191: ForumPermissions newPermissions = new ForumPermissions(
192: permissions, groupPermissions);
193: return new GroupProxy(group, authorization, newPermissions);
194: }
195:
196: public void deleteUser(User user) throws UnauthorizedException {
197: if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) {
198: profileManager.deleteUser(user);
199: } else {
200: throw new UnauthorizedException();
201: }
202: }
203:
204: public void deleteGroup(Group group) throws UnauthorizedException {
205: if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) {
206: profileManager.deleteGroup(group);
207: } else {
208: throw new UnauthorizedException();
209: }
210: }
211:
212: public int getUserCount() {
213: return profileManager.getUserCount();
214: }
215:
216: public int getGroupCount() {
217: return profileManager.getGroupCount();
218: }
219:
220: public Iterator users() {
221: Iterator iterator = profileManager.users();
222: return new UserIteratorProxy(iterator, authorization,
223: permissions);
224: }
225:
226: public Iterator users(int startIndex, int numResults) {
227: Iterator iterator = profileManager
228: .users(startIndex, numResults);
229: return new UserIteratorProxy(iterator, authorization,
230: permissions);
231: }
232:
233: public Iterator groups() {
234: Iterator iterator = profileManager.groups();
235: return new GroupIteratorProxy(iterator, authorization,
236: permissions);
237: }
238:
239: public Iterator groups(int startIndex, int numResults) {
240: Iterator iterator = profileManager.groups(startIndex,
241: numResults);
242: return new GroupIteratorProxy(iterator, authorization,
243: permissions);
244: }
245:
246: public int userMessageCount(User user, Forum forum) {
247: return profileManager.userMessageCount(user, forum);
248: }
249:
250: public Iterator userMessages(User user, Forum forum, int start,
251: int numResults) {
252: Iterator iterator = profileManager.userMessages(user, forum,
253: start, numResults);
254: return new MessageIteratorProxy(iterator, authorization,
255: permissions);
256: }
257: }
|