001: /*
002: * NEMESIS-FORUM.
003: * Copyright (C) 2002 David Laurent(lithium2@free.fr). All rights reserved.
004: *
005: * Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
006: *
007: * Copyright (C) 2001 Yasna.com. All rights reserved.
008: *
009: * Copyright (C) 2000 CoolServlets.com. All rights reserved.
010: *
011: * NEMESIS-FORUM. is free software; you can redistribute it and/or
012: * modify it under the terms of the Apache Software License, Version 1.1,
013: * or (at your option) any later version.
014: *
015: * NEMESIS-FORUM core framework, NEMESIS-FORUM backoffice, NEMESIS-FORUM frontoffice
016: * application are parts of NEMESIS-FORUM and are distributed under
017: * same terms of licence.
018: *
019: *
020: * NEMESIS-FORUM includes software developed by the Apache Software Foundation (http://www.apache.org/)
021: * and software developed by CoolServlets.com (http://www.coolservlets.com).
022: * and software developed by Yasna.com (http://www.yasna.com).
023: *
024: */
025: package org.nemesis.forum.proxy;
026:
027: import java.util.Iterator;
028:
029: import org.nemesis.forum.Authorization;
030: import org.nemesis.forum.ForumPermissions;
031: import org.nemesis.forum.Group;
032: import org.nemesis.forum.User;
033: import org.nemesis.forum.config.Constants;
034: import org.nemesis.forum.exception.UnauthorizedException;
035:
036: /**
037: * Protection proxy for the Group interface. It restricts access of certain
038: * methods to those that have the proper permissions to administer this object.
039: */
040: public class GroupProxy implements Group {
041:
042: /** Group object acting as proxy for. */
043: private Group group;
044: /** The authorization token used for gaining access to this proxy. */
045: private Authorization authorization;
046: /** The permissions for the group that correspond to the authorization. */
047: private ForumPermissions permissions;
048:
049: public GroupProxy(Group group, Authorization authorization,
050: ForumPermissions permissions) {
051: this .group = group;
052: this .authorization = authorization;
053: this .permissions = permissions;
054: }
055:
056: public int getID() {
057: return group.getID();
058: }
059:
060: public String getName() {
061: return group.getName();
062: }
063:
064: public void setName(String name) throws UnauthorizedException {
065: if (permissions.get(Constants.SYSTEM_ADMIN)
066: || permissions.get(Constants.GROUP_ADMIN)) {
067: group.setName(name);
068: } else {
069: throw new UnauthorizedException();
070: }
071: }
072:
073: public String getDescription() {
074: return group.getDescription();
075: }
076:
077: public void setDescription(String description)
078: throws UnauthorizedException {
079: if (permissions.get(Constants.SYSTEM_ADMIN)
080: || permissions.get(Constants.GROUP_ADMIN)) {
081: group.setDescription(description);
082: } else {
083: throw new UnauthorizedException();
084: }
085: }
086:
087: public void addAdministrator(User user)
088: throws UnauthorizedException {
089: if (permissions.get(Constants.SYSTEM_ADMIN)
090: || permissions.get(Constants.GROUP_ADMIN)) {
091: group.addAdministrator(user);
092: } else {
093: throw new UnauthorizedException();
094: }
095: }
096:
097: public void removeAdministrator(User user)
098: throws UnauthorizedException {
099: if (permissions.get(Constants.SYSTEM_ADMIN)
100: || permissions.get(Constants.GROUP_ADMIN)) {
101: group.removeAdministrator(user);
102: } else {
103: throw new UnauthorizedException();
104: }
105: }
106:
107: public void addMember(User user) throws UnauthorizedException {
108: if (permissions.get(Constants.SYSTEM_ADMIN)
109: || permissions.get(Constants.GROUP_ADMIN)) {
110: group.addMember(user);
111: } else {
112: throw new UnauthorizedException();
113: }
114: }
115:
116: public void removeMember(User user) throws UnauthorizedException {
117: if (permissions.get(Constants.SYSTEM_ADMIN)
118: || permissions.get(Constants.GROUP_ADMIN)) {
119: group.removeMember(user);
120: } else {
121: throw new UnauthorizedException();
122: }
123: }
124:
125: public boolean isAdministrator(User user) {
126: return group.isAdministrator(user);
127: }
128:
129: public boolean isMember(User user) {
130: return group.isMember(user);
131: }
132:
133: public int getAdministratorCount() {
134: return group.getAdministratorCount();
135: }
136:
137: public int getMemberCount() {
138: return group.getMemberCount();
139: }
140:
141: public Iterator members() {
142: return group.members();
143: }
144:
145: public Iterator administrators() {
146: return group.administrators();
147: }
148:
149: public ForumPermissions getPermissions(Authorization authorization) {
150: return group.getPermissions(authorization);
151: }
152:
153: public boolean hasPermission(int type) {
154: return permissions.get(type);
155: }
156: }
|