KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > auth > MVNForumPermissionFactory


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/auth/MVNForumPermissionFactory.java,v 1.9 2006/04/14 17:05:26 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.9 $
5  * $Date: 2006/04/14 17:05:26 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Minh Nguyen
39  * @author: Mai Nguyen
40  */

41 package com.mvnforum.auth;
42
43 import java.util.ArrayList JavaDoc;
44
45 import com.mvnforum.MVNForumConfig;
46 import com.mvnforum.MVNForumConstant;
47 import com.mvnforum.MyUtil;
48 import com.mvnforum.db.DAOFactory;
49 import com.mvnforum.db.MemberBean;
50 import net.myvietnam.mvncore.exception.*;
51
52 public class MVNForumPermissionFactory {
53
54     private MVNForumPermissionFactory() {
55     }
56
57     static MVNForumPermission getAnonymousPermission()
58         throws DatabaseException, AssertionException {
59
60         MVNForumPermissionImpl permission = new MVNForumPermissionImpl();
61
62         ArrayList JavaDoc permList = MVNForumPermissionWebHelper.getPermissionsForGroupGuest();
63         for (int i = 0; i < permList.size(); i++) {
64             int perm = ((Integer JavaDoc)permList.get(i)).intValue();
65             permission.setPermission(perm);
66         }
67
68         ArrayList JavaDoc forumPermList = MVNForumPermissionWebHelper.getPermissionsForGroupGuestInForums();
69         for (int i = 0; i < forumPermList.size(); i++) {
70             ForumPermission perm = (ForumPermission)forumPermList.get(i);
71             permission.setPermissionInForum(perm.getForumID(), perm.getPermission());
72         }
73
74         return permission;
75     }
76
77     public static MVNForumPermission getAuthenticatedPermission(int memberID)
78         throws DatabaseException, AssertionException, ObjectNotFoundException {
79
80         if (memberID == MVNForumConstant.MEMBER_ID_OF_GUEST || memberID == 0) {
81             throw new AssertionException("Cannot get authenticated permission for user Guest.");
82         }
83
84         MVNForumPermissionImpl permission = new MVNForumPermissionImpl();
85
86         ArrayList JavaDoc memberPermList = MVNForumPermissionWebHelper.getMemberPermissions(memberID);
87         for (int i = 0; i < memberPermList.size(); i++) {
88             int perm = ((Integer JavaDoc)memberPermList.get(i)).intValue();
89             permission.setPermission(perm);
90         }
91
92         ArrayList JavaDoc groupPermList = MVNForumPermissionWebHelper.getGroupPermissions(memberID);
93         for (int i = 0; i < groupPermList.size(); i++) {
94             int perm = ((Integer JavaDoc)groupPermList.get(i)).intValue();
95             permission.setPermission(perm);
96         }
97
98         ArrayList JavaDoc forumMemberPermList = MVNForumPermissionWebHelper.getMemberPermissionsInForums(memberID);
99         for (int i = 0; i < forumMemberPermList.size(); i++) {
100             ForumPermission perm = (ForumPermission)forumMemberPermList.get(i);
101             permission.setPermissionInForum(perm.getForumID(), perm.getPermission());
102         }
103
104         ArrayList JavaDoc forumGroupPermList = MVNForumPermissionWebHelper.getGroupPermissionsInForums(memberID);
105         for (int i = 0; i < forumGroupPermList.size(); i++) {
106             ForumPermission perm = (ForumPermission)forumGroupPermList.get(i);
107             permission.setPermissionInForum(perm.getForumID(), perm.getPermission());
108         }
109
110         // user after logined always have PERMISSION_AUTHENTICATED
111
permission.setPermission(MVNForumPermission.PERMISSION_AUTHENTICATED);
112
113         // now check if user account is activated or not
114
if (MVNForumConfig.getEnablePortlet() == false ) { // disable portlet, run only servlets
115
if ( DAOFactory.getMemberDAO().getActivateCode(memberID).equals(MemberBean.MEMBER_ACTIVATECODE_ACTIVATED)) {
116                 permission.setPermission(MVNForumPermission.PERMISSION_ACTIVATED);
117             }
118         }
119
120         // The Admin (id = 1) always has SystemAdmin permission
121
if (MyUtil.isRootAdminID(memberID)) {
122             permission.setPermission(MVNForumPermission.PERMISSION_SYSTEM_ADMIN);
123         }
124         return permission;
125     }
126 }
127
Popular Tags