1 25 package org.nemesis.forum.proxy; 26 27 import java.util.Iterator ; 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 40 public class GroupProxy implements Group { 41 42 43 private Group group; 44 45 private Authorization authorization; 46 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 getName() { 60 return group.getName(); 61 } 62 63 public void setName(String 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 getDescription() { 72 return group.getDescription(); 73 } 74 75 public void setDescription(String 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 members() { 132 return group.members(); 133 } 134 135 public Iterator 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 |