1 53 54 106 107 package com.Yasna.forum; 108 109 import java.util.*; 110 111 116 public class UserProxy implements User { 117 118 private User user; 119 private Authorization authorization; 120 private ForumPermissions permissions; 121 122 125 public UserProxy(User user, Authorization authorization, 126 ForumPermissions permissions) 127 { 128 this.user = user; 129 this.authorization = authorization; 130 this.permissions = permissions; 131 } 132 133 public int getID() { 134 return user.getID(); 135 } 136 137 public boolean isAnonymous() { 138 return user.isAnonymous(); 139 } 140 141 public String getUsername() { 142 return user.getUsername(); 143 } 144 145 public String getName(){ 146 if (isNameVisible() || permissions.get(ForumPermissions.SYSTEM_ADMIN) || 147 permissions.get(ForumPermissions.USER_ADMIN)) 148 { 149 return user.getName(); 150 } 151 else { 152 return null; 153 } 154 } 155 156 public void setName(String name) throws UnauthorizedException { 157 if (permissions.get(ForumPermissions.SYSTEM_ADMIN) || 158 permissions.get(ForumPermissions.USER_ADMIN)) 159 { 160 user.setName(name); 161 } 162 else { 163 throw new UnauthorizedException(); 164 } 165 } 166 167 public boolean isNameVisible() { 168 return user.isNameVisible(); 169 } 170 171 public void setNameVisible(boolean visible) throws UnauthorizedException { 172 if (permissions.get(ForumPermissions.SYSTEM_ADMIN) || 173 permissions.get(ForumPermissions.USER_ADMIN)) 174 { 175 user.setNameVisible(visible); 176 } 177 else { 178 throw new UnauthorizedException(); 179 } 180 } 181 182 public void setPassword(String password) throws UnauthorizedException { 183 if (permissions.get(ForumPermissions.SYSTEM_ADMIN) || 184 permissions.get(ForumPermissions.USER_ADMIN)) 185 { 186 user.setPassword(password); 187 } 188 else { 189 throw new UnauthorizedException(); 190 } 191 } 192 193 public String getPasswordHash() throws UnauthorizedException { 194 if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) 195 { 196 return user.getPasswordHash(); 197 } 198 else { 199 throw new UnauthorizedException(); 200 } 201 } 202 203 public void setPasswordHash(String passwordHash) 204 throws UnauthorizedException 205 { 206 if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) 207 { 208 user.setPasswordHash(passwordHash); 209 } 210 else { 211 throw new UnauthorizedException(); 212 } 213 } 214 215 public String getEmail() { 216 if (isEmailVisible() || permissions.get(ForumPermissions.SYSTEM_ADMIN) || 217 permissions.get(ForumPermissions.USER_ADMIN)) 218 { 219 return user.getEmail(); 220 } 221 else { 222 return null; 223 } 224 } 225 226 public Calendar getLastLogin(){ 227 return user.getLastLogin(); 228 } 229 public Calendar getLastPost(){ 230 return user.getLastPost(); 231 } 232 public Locale getUserLocale(){ 233 return user.getUserLocale(); 234 } 235 public void setUserLocale(Locale locale) throws UnauthorizedException{ 236 if (permissions.get(ForumPermissions.SYSTEM_ADMIN) || 237 permissions.get(ForumPermissions.USER_ADMIN)) 238 { 239 user.setUserLocale(locale); 240 } 241 else { 242 throw new UnauthorizedException(); 243 } 244 245 } 246 public TimeZone getUserTimeZone(){ 247 return user.getUserTimeZone(); 248 } 249 public void setUserTimeZone(String timezone) throws UnauthorizedException{ 250 if (permissions.get(ForumPermissions.SYSTEM_ADMIN) || 251 permissions.get(ForumPermissions.USER_ADMIN)) 252 { 253 user.setUserTimeZone(timezone); 254 } 255 else { 256 throw new UnauthorizedException(); 257 } 258 259 } 260 public void setEmail(String email) throws UnauthorizedException { 261 if (permissions.get(ForumPermissions.SYSTEM_ADMIN) || 262 permissions.get(ForumPermissions.USER_ADMIN)) 263 { 264 user.setEmail(email); 265 } 266 else { 267 throw new UnauthorizedException(); 268 } 269 } 270 271 public boolean getThreadSubscribe() { 272 return user.getThreadSubscribe(); 273 } 274 275 public void setThreadSubscribe(boolean emailReply) throws UnauthorizedException { 276 if (permissions.get(ForumPermissions.SYSTEM_ADMIN) || 277 permissions.get(ForumPermissions.USER_ADMIN)) 278 { 279 user.setThreadSubscribe(emailReply); 280 } 281 else { 282 throw new UnauthorizedException(); 283 } 284 } 285 286 public boolean isEmailVisible() { 287 return user.isEmailVisible(); 288 } 289 290 public void setEmailVisible(boolean visible) throws UnauthorizedException { 291 if (permissions.get(ForumPermissions.SYSTEM_ADMIN) || 292 permissions.get(ForumPermissions.USER_ADMIN)) 293 { 294 user.setEmailVisible(visible); 295 } 296 else { 297 throw new UnauthorizedException(); 298 } 299 } 300 301 public String getProperty(String name) { 302 return user.getProperty(name); 303 } 304 305 public Enumeration propertyNames() { 306 return user.propertyNames(); 307 } 308 309 public void setProperty(String name, String value) { 310 user.setProperty(name, value); 311 } 312 313 public ForumPermissions getPermissions(Authorization authorization) { 314 return user.getPermissions(authorization); 315 } 316 317 public boolean hasPermission(int type) { 318 return permissions.get(type); 319 } 320 321 326 public String toString() { 327 return user.toString(); 328 } 329 } 330 | Popular Tags |