KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator 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 the Group interface. It restricts access of certain
38  * methods to those that have the proper permissions to administer this object.
39  */

40 public class GroupProxy implements Group {
41
42     /** Group object acting as proxy for. */
43     private Group group;
44     /** The authorization token used for gaining access to this proxy. */
45     private Authorization authorization;
46     /** The permissions for the group that correspond to the authorization. */
47     private ForumPermissions permissions;
48
49     public GroupProxy(Group group, Authorization authorization, ForumPermissions permissions) {
50         this.group = group;
51         this.authorization = authorization;
52         this.permissions = permissions;
53     }
54
55     public int getID() {
56         return group.getID();
57     }
58
59     public String JavaDoc getName() {
60         return group.getName();
61     }
62
63     public void setName(String JavaDoc name) throws UnauthorizedException {
64         if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.GROUP_ADMIN)) {
65             group.setName(name);
66         } else {
67             throw new UnauthorizedException();
68         }
69     }
70
71     public String JavaDoc getDescription() {
72         return group.getDescription();
73     }
74
75     public void setDescription(String JavaDoc description) throws UnauthorizedException {
76         if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.GROUP_ADMIN)) {
77             group.setDescription(description);
78         } else {
79             throw new UnauthorizedException();
80         }
81     }
82
83     public void addAdministrator(User user) throws UnauthorizedException {
84         if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.GROUP_ADMIN)) {
85             group.addAdministrator(user);
86         } else {
87             throw new UnauthorizedException();
88         }
89     }
90
91     public void removeAdministrator(User user) throws UnauthorizedException {
92         if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.GROUP_ADMIN)) {
93             group.removeAdministrator(user);
94         } else {
95             throw new UnauthorizedException();
96         }
97     }
98
99     public void addMember(User user) throws UnauthorizedException {
100         if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.GROUP_ADMIN)) {
101             group.addMember(user);
102         } else {
103             throw new UnauthorizedException();
104         }
105     }
106
107     public void removeMember(User user) throws UnauthorizedException {
108         if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.GROUP_ADMIN)) {
109             group.removeMember(user);
110         } else {
111             throw new UnauthorizedException();
112         }
113     }
114
115     public boolean isAdministrator(User user) {
116         return group.isAdministrator(user);
117     }
118
119     public boolean isMember(User user) {
120         return group.isMember(user);
121     }
122
123     public int getAdministratorCount() {
124         return group.getAdministratorCount();
125     }
126
127     public int getMemberCount() {
128         return group.getMemberCount();
129     }
130
131     public Iterator JavaDoc members() {
132         return group.members();
133     }
134
135     public Iterator JavaDoc administrators() {
136         return group.administrators();
137     }
138
139     public ForumPermissions getPermissions(Authorization authorization) {
140         return group.getPermissions(authorization);
141     }
142
143     public boolean hasPermission(int type) {
144         return permissions.get(type);
145     }
146 }
147
Popular Tags