KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nemesis > forum > proxy > ForumModeratorIteratorProxy


1 /*
2  * NEMESIS-FORUM.
3  * Copyright (C) 2002 David Laurent(lithium2@free.fr). All rights reserved.
4  *
5  * Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
6  *
7  * Copyright (C) 2001 Yasna.com. All rights reserved.
8  *
9  * Copyright (C) 2000 CoolServlets.com. All rights reserved.
10  *
11  * NEMESIS-FORUM. is free software; you can redistribute it and/or
12  * modify it under the terms of the Apache Software License, Version 1.1,
13  * or (at your option) any later version.
14  *
15  * NEMESIS-FORUM core framework, NEMESIS-FORUM backoffice, NEMESIS-FORUM frontoffice
16  * application are parts of NEMESIS-FORUM and are distributed under
17  * same terms of licence.
18  *
19  *
20  * NEMESIS-FORUM includes software developed by the Apache Software Foundation (http://www.apache.org/)
21  * and software developed by CoolServlets.com (http://www.coolservlets.com).
22  * and software developed by Yasna.com (http://www.yasna.com).
23  *
24  */

25 package org.nemesis.forum.proxy;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import org.nemesis.forum.Authorization;
31 import org.nemesis.forum.Forum;
32 import org.nemesis.forum.ForumPermissions;
33 import org.nemesis.forum.config.Constants;
34
35 /**
36  * Protection proxy for Forum Moderator iterators. This is a special case
37  * iterator proxy because users might not have read access to some of the
38  * forums that we need to proxy. The expected behavior is that only forums
39  * that users <b>do</b> have read access for will be returned. Therefore,
40  * we need to read in the results and only return an iterator for forums
41  * that the user can read.
42  */

43 public class ForumModeratorIteratorProxy extends IteratorProxy {
44
45     private ArrayList JavaDoc forums = new ArrayList JavaDoc();
46
47     public ForumModeratorIteratorProxy(Iterator JavaDoc iterator, Authorization authorization, ForumPermissions permissions) {
48         //Dummy call to super-class. This specialized iterator proxy doesn't
49
//use the superclass like the other iterators do.
50
super(iterator, authorization, permissions);
51
52         while (iterator.hasNext()) {
53             Forum forum = (Forum) iterator.next();
54             ForumPermissions forumPermissions = forum.getPermissions(authorization);
55             //Create a new permissions object with the combination of the
56
//permissions of this object and tempPermissions.
57
//Check and see if the user has READ permissions. If not, throw an
58
//an UnauthorizedException.
59
if (forumPermissions.get(Constants.SYSTEM_ADMIN)
60                 || forumPermissions.get(Constants.FORUM_ADMIN)
61                 || forumPermissions.get(Constants.MODERATOR)) {
62                 ForumProxy proxy = new ForumProxy(forum, authorization, forumPermissions);
63                 forums.add(proxy);
64             }
65         }
66
67         this.iterator = forums.listIterator();
68     }
69
70     public Object JavaDoc next() throws java.util.NoSuchElementException JavaDoc {
71         return iterator.next();
72     }
73 }
74
Popular Tags