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: */package com.Yasna.forum;
053:
054: import java.util.Date;
055: import java.util.Iterator;
056: import java.util.Enumeration;
057:
058: /**
059: * A protection proxy for Categories. A proxy has a set of permissions that are
060: * specified at creation time of the proxy. Subsequently, those permissions
061: * are use to restrict access to protected Category methods. If a user does
062: * not have the right to execute a particular method, and UnauthorizedException
063: * is thrown.
064: *
065: */
066: public class CategoryProxy implements Category {
067:
068: private Category category;
069: private Authorization authorization;
070: private ForumPermissions permissions;
071:
072: /**
073: * Creates a new CategoryProxy object.
074: *
075: * @param category the category to protect by proxy
076: * @param authorization the user's authorization token
077: * @param permissions the permissions to use with this proxy.
078: */
079: public CategoryProxy(Category category,
080: Authorization authorization, ForumPermissions permissions) {
081: this .category = category;
082: this .authorization = authorization;
083: this .permissions = permissions;
084: }
085:
086: //** Methods from interface below**//
087: public String getName() {
088: return category.getName();
089: }
090:
091: public int getOrder() {
092: return category.getOrder();
093: }
094:
095: public void setOrder(int param) throws UnauthorizedException {
096: if (permissions.isSystemOrForumAdmin()) {
097: category.setOrder(param);
098: } else {
099: throw new UnauthorizedException();
100: }
101: }
102:
103: public int getID() {
104: return category.getID();
105: }
106:
107: public String getDescription() {
108: return category.getDescription();
109: }
110:
111: public Date getCreationDate() {
112: return category.getCreationDate();
113: }
114:
115: public Date getModifiedDate() {
116: return category.getModifiedDate();
117: }
118:
119: public void setModifiedDate(Date modifiedDate)
120: throws UnauthorizedException {
121: if (permissions.isSystemOrForumAdmin()) {
122: category.setModifiedDate(modifiedDate);
123: } else {
124: throw new UnauthorizedException();
125: }
126: }
127:
128: public void setCreationDate(Date creationDate)
129: throws UnauthorizedException {
130: if (permissions.isSystemOrForumAdmin()) {
131: category.setCreationDate(creationDate);
132: } else {
133: throw new UnauthorizedException();
134: }
135: }
136:
137: public void setName(String name) throws UnauthorizedException,
138: CategoryAlreadyExistsException {
139: if (permissions.isSystemOrForumAdmin()) {
140: category.setName(name);
141: } else {
142: throw new UnauthorizedException();
143: }
144: }
145:
146: public void setDescription(String description)
147: throws UnauthorizedException {
148: if (permissions.isSystemOrForumAdmin()) {
149: category.setDescription(description);
150: } else {
151: throw new UnauthorizedException();
152: }
153: }
154:
155: public Iterator forumGroups() {
156: Iterator iterator = category.forumGroups();
157: return new ForumGroupIteratorProxy(iterator, authorization,
158: permissions);
159: }
160:
161: public ForumGroup getForumGroup(int forumGroupID)
162: throws ForumGroupNotFoundException {
163: ForumGroup forumGroup = category.getForumGroup(forumGroupID);
164: //Apply protection proxy and return.
165: return new ForumGroupProxy(forumGroup, authorization,
166: permissions);
167: }
168:
169: public void deleteForumGroup(ForumGroup forumGroup)
170: throws UnauthorizedException {
171: if (permissions.isSystemOrForumAdmin()) {
172: category.deleteForumGroup(forumGroup);
173: } else {
174: throw new UnauthorizedException();
175: }
176: }
177:
178: public ForumGroup createForumGroup(String name, String description)
179: throws UnauthorizedException {
180: if (permissions.isSystemOrForumAdmin()) {
181: ForumGroup forumGroup = category.createForumGroup(name,
182: description);
183: return new ForumGroupProxy(forumGroup, authorization,
184: permissions);
185: } else {
186: throw new UnauthorizedException();
187: }
188: }
189:
190: }
|