KickJava   Java API By Example, From Geeks To Geeks.

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


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.Forum;
31 import org.nemesis.forum.ForumPermissions;
32 import org.nemesis.forum.Group;
33 import org.nemesis.forum.ProfileManager;
34 import org.nemesis.forum.User;
35 import org.nemesis.forum.config.Constants;
36 import org.nemesis.forum.exception.GroupAlreadyExistsException;
37 import org.nemesis.forum.exception.GroupNotFoundException;
38 import org.nemesis.forum.exception.UnauthorizedException;
39 import org.nemesis.forum.exception.UserAlreadyExistsException;
40 import org.nemesis.forum.exception.UserNotFoundException;
41 /**
42  * Protection proxy for the ProfileManager class. It restricts access to
43  * protected methods by throwing UnauthorizedExceptions when necessary.
44  *
45  * @see ProfileManager
46  */

47 public class ProfileManagerProxy implements ProfileManager {
48
49     private ProfileManager profileManager;
50     private Authorization authorization;
51     private ForumPermissions permissions;
52
53     /**
54      * Creates a new ProfileManagerProxy.
55      */

56     public ProfileManagerProxy(
57         ProfileManager profileManager,
58         Authorization authorization,
59         ForumPermissions permissions) {
60         this.profileManager = profileManager;
61         this.authorization = authorization;
62         this.permissions = permissions;
63     }
64
65     public User createUser(String JavaDoc username, String JavaDoc password, String JavaDoc email)
66         throws UserAlreadyExistsException {
67         return profileManager.createUser(username, password, email);
68     }
69
70     public Group createGroup(String JavaDoc name)
71         throws UnauthorizedException, GroupAlreadyExistsException {
72         if (permissions.get(Constants.SYSTEM_ADMIN)) {
73             Group group = profileManager.createGroup(name);
74             return new GroupProxy(group, authorization, permissions);
75         } else {
76             throw new UnauthorizedException();
77         }
78     }
79
80     public User getUser(int userID) throws UserNotFoundException {
81         User user = profileManager.getUser(userID);
82         ForumPermissions userPermissions = user.getPermissions(authorization);
83         ForumPermissions newPermissions =
84             new ForumPermissions(permissions, userPermissions);
85         return new UserProxy(user, authorization, newPermissions);
86     }
87
88     public User getUser(String JavaDoc username) throws UserNotFoundException {
89         User user = profileManager.getUser(username);
90         ForumPermissions userPermissions = user.getPermissions(authorization);
91         ForumPermissions newPermissions =
92             new ForumPermissions(permissions, userPermissions);
93         return new UserProxy(user, authorization, newPermissions);
94     }
95
96     public User getAnonymousUser() {
97         return profileManager.getAnonymousUser();
98     }
99
100     public User getSpecialUser() {
101         return profileManager.getSpecialUser();
102     }
103
104     public Group getGroup(int groupID) throws GroupNotFoundException {
105         Group group = profileManager.getGroup(groupID);
106         ForumPermissions groupPermissions = group.getPermissions(authorization);
107         ForumPermissions newPermissions =
108             new ForumPermissions(permissions, groupPermissions);
109         return new GroupProxy(group, authorization, newPermissions);
110     }
111
112     public Group getGroup(String JavaDoc name) throws GroupNotFoundException {
113         Group group = profileManager.getGroup(name);
114         ForumPermissions groupPermissions = group.getPermissions(authorization);
115         ForumPermissions newPermissions =
116             new ForumPermissions(permissions, groupPermissions);
117         return new GroupProxy(group, authorization, newPermissions);
118     }
119
120     public void deleteUser(User user) throws UnauthorizedException {
121         if (permissions.get(Constants.SYSTEM_ADMIN)) {
122             profileManager.deleteUser(user);
123         } else {
124             throw new UnauthorizedException();
125         }
126     }
127
128     public void deleteGroup(Group group) throws UnauthorizedException {
129         if (permissions.get(Constants.SYSTEM_ADMIN)) {
130             profileManager.deleteGroup(group);
131         } else {
132             throw new UnauthorizedException();
133         }
134     }
135
136     public int getUserCount() {
137         return profileManager.getUserCount();
138     }
139
140     public int getGroupCount() {
141         return profileManager.getGroupCount();
142     }
143
144     public Iterator JavaDoc users() {
145         Iterator JavaDoc iterator = profileManager.users();
146         return new UserIteratorProxy(iterator, authorization, permissions);
147     }
148
149     public Iterator JavaDoc users(int startIndex, int numResults) {
150         Iterator JavaDoc iterator = profileManager.users(startIndex, numResults);
151         return new UserIteratorProxy(iterator, authorization, permissions);
152     }
153
154     public Iterator JavaDoc groups() {
155         Iterator JavaDoc iterator = profileManager.groups();
156         return new GroupIteratorProxy(iterator, authorization, permissions);
157     }
158
159     public Iterator JavaDoc groups(int startIndex, int numResults) {
160         Iterator JavaDoc iterator = profileManager.groups(startIndex, numResults);
161         return new GroupIteratorProxy(iterator, authorization, permissions);
162     }
163
164     public int userMessageCount(User user, Forum forum) {
165         return profileManager.userMessageCount(user, forum);
166     }
167
168     public Iterator JavaDoc userMessages(User user, Forum forum) {
169         Iterator JavaDoc iterator = profileManager.userMessages(user, forum);
170         return new MessageIteratorProxy(iterator, authorization, permissions);
171     }
172 }
173
Popular Tags