1 53 54 106 107 package com.Yasna.forum; 108 109 import com.Yasna.forum.util.ClientIP; 110 111 import java.util.*; 112 114 118 public class ForumFactoryProxy extends ForumFactory { 119 120 private ForumFactory factory; 121 private Authorization authorization; 122 private ForumPermissions permissions; 123 124 public ForumFactoryProxy(ForumFactory factory, Authorization authorization, 125 ForumPermissions permissions) 126 { 127 this.factory = factory; 128 this.authorization = authorization; 129 this.permissions = permissions; 130 } 131 132 public Forum createForum(String name, String description, 133 boolean moderated, int forumGroupID,boolean article) 134 throws UnauthorizedException, ForumAlreadyExistsException 135 { 136 if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) { 137 Forum newForum = factory.createForum(name, description, 138 moderated, forumGroupID,article); 139 return new ForumProxy(newForum, authorization, permissions); 140 } 141 else { 142 throw new UnauthorizedException(); 143 } 144 } 145 146 public void deleteForum(Forum forum) throws UnauthorizedException { 147 if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) { 148 factory.deleteForum(forum); 149 } 150 else { 151 throw new UnauthorizedException(); 152 } 153 } 154 155 public void deleteCategory(Category category) throws UnauthorizedException { 156 if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) { 157 factory.deleteCategory(category); 158 } 159 else { 160 throw new UnauthorizedException(); 161 } 162 } 163 164 public Forum getForum(int forumID) throws ForumNotFoundException, 165 UnauthorizedException 166 { 167 Forum forum = factory.getForum(forumID); 168 ForumPermissions forumPermissions = forum.getPermissions(authorization); 169 ForumPermissions newPermissions = 172 new ForumPermissions(permissions, forumPermissions); 173 if (!( 176 newPermissions.get(ForumPermissions.READ) || 177 newPermissions.get(ForumPermissions.FORUM_ADMIN) || 178 newPermissions.get(ForumPermissions.SYSTEM_ADMIN) 179 )) 180 { 181 throw new UnauthorizedException(); 182 } 183 return new ForumProxy(forum, authorization, newPermissions); 184 } 185 186 public Forum getForum(String name) throws ForumNotFoundException, 187 UnauthorizedException 188 { 189 Forum forum = factory.getForum(name); 190 ForumPermissions forumPermissions = forum.getPermissions(authorization); 191 ForumPermissions newPermissions = 194 new ForumPermissions(permissions, forumPermissions); 195 if (!( 198 newPermissions.get(ForumPermissions.READ) || 199 newPermissions.get(ForumPermissions.FORUM_ADMIN) || 200 newPermissions.get(ForumPermissions.SYSTEM_ADMIN) 201 )) 202 { 203 throw new UnauthorizedException(); 204 } 205 return new ForumProxy(forum, authorization, newPermissions); 206 } 207 208 public int getForumCount() { 209 return factory.getForumCount(); 210 } 211 212 public Iterator categories() { 213 return new CategoryIteratorProxy(factory.categories(), authorization, permissions); 214 } 215 216 public Category getCategory(int categoryID) throws CategoryNotFoundException, 217 UnauthorizedException 218 { 219 Category category = factory.getCategory(categoryID); 220 return new CategoryProxy(category, authorization, permissions); 222 } 223 224 public Category getCategory(String name) throws CategoryNotFoundException, 225 UnauthorizedException 226 { 227 Category category = factory.getCategory(name); 228 return new CategoryProxy(category, authorization, permissions); 230 } 231 232 public Category createCategory(String name, String description) 233 throws UnauthorizedException, CategoryAlreadyExistsException 234 { 235 if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) { 236 Category newCategory = factory.createCategory(name, description); 237 return new CategoryProxy(newCategory, authorization, permissions); 238 } 239 else { 240 throw new UnauthorizedException(); 241 } 242 } 243 244 public Iterator forums() { 245 return new ForumIteratorProxy(factory.forums(), authorization, permissions,false); 246 } 247 public Iterator forumsWithArticlesForums(){ 248 return new ForumIteratorProxy(factory.forums(), authorization, permissions,true); 249 } 250 public Iterator forumsModeration() { 251 return new ForumModeratorIteratorProxy(factory.forums(), authorization, permissions); 252 } 253 254 public ProfileManager getProfileManager() { 255 ProfileManager profileManager = factory.getProfileManager(); 256 return new ProfileManagerProxy(profileManager, authorization, permissions); 257 } 258 259 public SearchIndexer getSearchIndexer() throws UnauthorizedException { 260 if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) { 261 return factory.getSearchIndexer(); 262 } 263 else { 264 throw new UnauthorizedException(); 265 } 266 } 267 268 public int [] usersWithPermission(int permissionType) 269 throws UnauthorizedException 270 { 271 if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) { 272 return factory.usersWithPermission(permissionType); 273 } 274 else { 275 throw new UnauthorizedException(); 276 } 277 } 278 279 public int[] groupsWithPermission(int permissionType) 280 throws UnauthorizedException 281 { 282 if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) { 283 return factory.groupsWithPermission(permissionType); 284 } 285 else { 286 throw new UnauthorizedException(); 287 } 288 } 289 290 public ForumPermissions getPermissions(Authorization authorization) { 291 return factory.getPermissions(authorization); 292 } 293 294 public boolean hasPermission(int type) { 295 return permissions.get(type); 296 } 297 298 307 public ForumFactory getUnderlyingForumFactory() 308 throws UnauthorizedException 309 { 310 if (permissions.get(ForumPermissions.SYSTEM_ADMIN)) { 311 return factory; 312 } 313 else { 314 throw new UnauthorizedException(); 315 } 316 } 317 public Query createQuery(){ 318 return factory.createQuery(); 319 } 320 public void BlackListIP(ClientIP cip,boolean add) throws UnauthorizedException{ 321 if (permissions.get(ForumPermissions.SYSTEM_ADMIN) || permissions.get(ForumPermissions.FORUM_ADMIN) || permissions.get(ForumPermissions.MODERATOR)) { 322 factory.BlackListIP(cip,add); 323 } 324 else { 325 throw new UnauthorizedException(); 326 } 327 } 328 public boolean isBlackListed(ClientIP cip){ 329 return factory.isBlackListed(cip); 330 } 331 public ForumThread getArticleThread(String pageKey,Forum forumID) throws ForumThreadNotFoundException,UnauthorizedException{ 332 return new ForumThreadProxy(factory.getArticleThread(pageKey,forumID),authorization,permissions); 333 } 334 public Iterator getThreadTypeIterator(){ 335 return factory.getThreadTypeIterator(); 336 } 337 public ThreadType getThreadType(int typeid){ 338 return factory.getThreadType(typeid); 339 } 340 public Iterator getSessionList(){ 341 return factory.getSessionList(); 342 } 343 public int getYesterdayUserCount(){ 344 return factory.getYesterdayUserCount(); 345 } 346 347 } 348 | Popular Tags |