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.Enumeration;
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 User objects.
038: *
039: * @see User
040: */
041: public class UserProxy implements User {
042:
043: private User user;
044: private Authorization authorization;
045: private ForumPermissions permissions;
046:
047: /**
048: * Create a new UserProxy.
049: */
050: public UserProxy(User user, Authorization authorization,
051: ForumPermissions permissions) {
052: this .user = user;
053: this .authorization = authorization;
054: this .permissions = permissions;
055: }
056:
057: public int getID() {
058: return user.getID();
059: }
060:
061: public boolean isAnonymous() {
062: return user.isAnonymous();
063: }
064:
065: public String getUsername() {
066: return user.getUsername();
067: }
068:
069: public String getName() {
070: if (isNameVisible() || permissions.get(Constants.SYSTEM_ADMIN)
071: || permissions.get(Constants.USER_ADMIN)) {
072: return user.getName();
073: } else {
074: return null;
075: }
076: }
077:
078: public void setName(String name) throws UnauthorizedException {
079: if (permissions.get(Constants.SYSTEM_ADMIN)
080: || permissions.get(Constants.USER_ADMIN)) {
081: user.setName(name);
082: } else {
083: throw new UnauthorizedException();
084: }
085: }
086:
087: public boolean isNameVisible() {
088: return user.isNameVisible();
089: }
090:
091: public void setNameVisible(boolean visible)
092: throws UnauthorizedException {
093: if (permissions.get(Constants.SYSTEM_ADMIN)
094: || permissions.get(Constants.USER_ADMIN)) {
095: user.setNameVisible(visible);
096: } else {
097: throw new UnauthorizedException();
098: }
099: }
100:
101: public void setPassword(String password)
102: throws UnauthorizedException {
103: if (permissions.get(Constants.SYSTEM_ADMIN)
104: || permissions.get(Constants.USER_ADMIN)) {
105: user.setPassword(password);
106: } else {
107: throw new UnauthorizedException();
108: }
109: }
110:
111: public String getPasswordHash() throws UnauthorizedException {
112: if (permissions.get(Constants.SYSTEM_ADMIN)) {
113: return user.getPasswordHash();
114: } else {
115: throw new UnauthorizedException();
116: }
117: }
118:
119: public void setPasswordHash(String passwordHash)
120: throws UnauthorizedException {
121: if (permissions.get(Constants.SYSTEM_ADMIN)) {
122: user.setPasswordHash(passwordHash);
123: } else {
124: throw new UnauthorizedException();
125: }
126: }
127:
128: public String getEmail() {
129: if (isEmailVisible() || permissions.get(Constants.SYSTEM_ADMIN)
130: || permissions.get(Constants.USER_ADMIN)) {
131: return user.getEmail();
132: } else {
133: return null;
134: }
135: }
136:
137: public void setEmail(String email) throws UnauthorizedException {
138: if (permissions.get(Constants.SYSTEM_ADMIN)
139: || permissions.get(Constants.USER_ADMIN)) {
140: user.setEmail(email);
141: } else {
142: throw new UnauthorizedException();
143: }
144: }
145:
146: public boolean isEmailVisible() {
147: return user.isEmailVisible();
148: }
149:
150: public void setEmailVisible(boolean visible)
151: throws UnauthorizedException {
152: if (permissions.get(Constants.SYSTEM_ADMIN)
153: || permissions.get(Constants.USER_ADMIN)) {
154: user.setEmailVisible(visible);
155: } else {
156: throw new UnauthorizedException();
157: }
158: }
159:
160: public String getProperty(String name) {
161: return user.getProperty(name);
162: }
163:
164: public Enumeration propertyNames() {
165: return user.propertyNames();
166: }
167:
168: public void setProperty(String name, String value) {
169: user.setProperty(name, value);
170: }
171:
172: public ForumPermissions getPermissions(Authorization authorization) {
173: return user.getPermissions(authorization);
174: }
175:
176: public boolean hasPermission(int type) {
177: return permissions.get(type);
178: }
179:
180: //*******AJOUT
181: public boolean isAdministratorInGroup(Group group) {
182: return user.isAdministratorInGroup(group);
183: }
184:
185: public boolean isMemberInGroup(Group group) {
186: return user.isMemberInGroup(group);
187: }
188:
189: public int getGroupAdministratorCount() {
190: return user.getGroupAdministratorCount();
191: }
192:
193: public int getGroupCount() {
194: return user.getGroupCount();
195: }
196:
197: /**
198: * Converts the object to a String by returning the usernamename.
199: * This functionality is primarily for Java applications that might be
200: * accessing CoolForum objects through a GUI.
201: */
202: public String toString() {
203: return user.toString();
204: }
205: }
|