1 25 package org.nemesis.forum.proxy; 26 27 import java.util.Enumeration ; 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 41 public class UserProxy implements User { 42 43 private User user; 44 private Authorization authorization; 45 private ForumPermissions permissions; 46 47 50 public UserProxy(User user, Authorization authorization, ForumPermissions permissions) { 51 this.user = user; 52 this.authorization = authorization; 53 this.permissions = permissions; 54 } 55 56 public int getID() { 57 return user.getID(); 58 } 59 60 public boolean isAnonymous() { 61 return user.isAnonymous(); 62 } 63 64 public String getUsername() { 65 return user.getUsername(); 66 } 67 68 public String getName() { 69 if (isNameVisible() 70 || permissions.get(Constants.SYSTEM_ADMIN) 71 || permissions.get(Constants.USER_ADMIN)) { 72 return user.getName(); 73 } else { 74 return null; 75 } 76 } 77 78 public void setName(String name) throws UnauthorizedException { 79 if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.USER_ADMIN)) { 80 user.setName(name); 81 } else { 82 throw new UnauthorizedException(); 83 } 84 } 85 86 public boolean isNameVisible() { 87 return user.isNameVisible(); 88 } 89 90 public void setNameVisible(boolean visible) throws UnauthorizedException { 91 if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.USER_ADMIN)) { 92 user.setNameVisible(visible); 93 } else { 94 throw new UnauthorizedException(); 95 } 96 } 97 98 public void setPassword(String password) throws UnauthorizedException { 99 if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.USER_ADMIN)) { 100 user.setPassword(password); 101 } else { 102 throw new UnauthorizedException(); 103 } 104 } 105 106 public String getPasswordHash() throws UnauthorizedException { 107 if (permissions.get(Constants.SYSTEM_ADMIN)) { 108 return user.getPasswordHash(); 109 } else { 110 throw new UnauthorizedException(); 111 } 112 } 113 114 public void setPasswordHash(String passwordHash) throws UnauthorizedException { 115 if (permissions.get(Constants.SYSTEM_ADMIN)) { 116 user.setPasswordHash(passwordHash); 117 } else { 118 throw new UnauthorizedException(); 119 } 120 } 121 122 public String getEmail() { 123 if (isEmailVisible() 124 || permissions.get(Constants.SYSTEM_ADMIN) 125 || permissions.get(Constants.USER_ADMIN)) { 126 return user.getEmail(); 127 } else { 128 return null; 129 } 130 } 131 132 public void setEmail(String email) throws UnauthorizedException { 133 if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.USER_ADMIN)) { 134 user.setEmail(email); 135 } else { 136 throw new UnauthorizedException(); 137 } 138 } 139 140 public boolean isEmailVisible() { 141 return user.isEmailVisible(); 142 } 143 144 public void setEmailVisible(boolean visible) throws UnauthorizedException { 145 if (permissions.get(Constants.SYSTEM_ADMIN) || permissions.get(Constants.USER_ADMIN)) { 146 user.setEmailVisible(visible); 147 } else { 148 throw new UnauthorizedException(); 149 } 150 } 151 152 public String getProperty(String name) { 153 return user.getProperty(name); 154 } 155 156 public Enumeration propertyNames() { 157 return user.propertyNames(); 158 } 159 160 public void setProperty(String name, String value) { 161 user.setProperty(name, value); 162 } 163 164 public ForumPermissions getPermissions(Authorization authorization) { 165 return user.getPermissions(authorization); 166 } 167 168 public boolean hasPermission(int type) { 169 return permissions.get(type); 170 } 171 172 public boolean isAdministratorInGroup(Group group) { 174 return user.isAdministratorInGroup(group); 175 } 176 177 public boolean isMemberInGroup(Group group) { 178 return user.isMemberInGroup(group); 179 } 180 181 public int getGroupAdministratorCount() { 182 return user.getGroupAdministratorCount(); 183 } 184 185 public int getGroupCount() { 186 return user.getGroupCount(); 187 } 188 189 190 191 196 public String toString() { 197 return user.toString(); 198 } 199 } 200 | Popular Tags |