001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/auth/MVNForumPermissionFactory.java,v 1.26 2007/10/09 11:09:12 lexuanttkhtn Exp $
003: * $Author: lexuanttkhtn $
004: * $Revision: 1.26 $
005: * $Date: 2007/10/09 11:09:12 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Minh Nguyen
039: * @author: Mai Nguyen
040: */
041: package com.mvnforum.auth;
042:
043: import java.util.*;
044:
045: import net.myvietnam.mvncore.exception.DatabaseException;
046: import net.myvietnam.mvncore.exception.ObjectNotFoundException;
047: import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
048:
049: import com.mvnforum.*;
050: import com.mvnforum.db.*;
051:
052: public class MVNForumPermissionFactory {
053:
054: private MVNForumPermissionFactory() {
055: }
056:
057: static MVNForumPermission getAnonymousPermission()
058: throws DatabaseException {
059:
060: MVNForumPermissionImpl permission = new MVNForumPermissionImpl();
061:
062: ArrayList permList = MVNForumPermissionWebHelper
063: .getPermissionsForGroupGuest();
064: for (int i = 0; i < permList.size(); i++) {
065: int perm = ((Integer) permList.get(i)).intValue();
066: permission.setPermission(perm);
067: }
068:
069: ArrayList forumPermList = MVNForumPermissionWebHelper
070: .getPermissionsForGroupGuestInForums();
071: for (int i = 0; i < forumPermList.size(); i++) {
072: ForumPermission perm = (ForumPermission) forumPermList
073: .get(i);
074: permission.setPermissionInForum(perm.getForumID(), perm
075: .getPermission());
076: }
077:
078: return permission;
079: }
080:
081: public static MVNForumPermission getAuthenticatedPermission(
082: MemberBean memberBean) throws DatabaseException,
083: ObjectNotFoundException {
084:
085: int memberID = memberBean.getMemberID();
086:
087: if (memberID == MVNForumConstant.MEMBER_ID_OF_GUEST
088: || memberID == 0) {
089: throw new AssertionError(
090: "Cannot get authenticated permission for user Guest.");
091: }
092:
093: MVNForumPermissionImpl permission = new MVNForumPermissionImpl();
094:
095: ArrayList memberPermList = MVNForumPermissionWebHelper
096: .getMemberPermissions(memberID);
097: for (int i = 0; i < memberPermList.size(); i++) {
098: int perm = ((Integer) memberPermList.get(i)).intValue();
099: permission.setPermission(perm);
100: }
101:
102: ArrayList groupPermList = MVNForumPermissionWebHelper
103: .getGroupPermissions(memberID);
104: for (int i = 0; i < groupPermList.size(); i++) {
105: int perm = ((Integer) groupPermList.get(i)).intValue();
106: permission.setPermission(perm);
107: }
108:
109: ArrayList forumMemberPermList = MVNForumPermissionWebHelper
110: .getMemberPermissionsInForums(memberID);
111: for (int i = 0; i < forumMemberPermList.size(); i++) {
112: ForumPermission perm = (ForumPermission) forumMemberPermList
113: .get(i);
114: permission.setPermissionInForum(perm.getForumID(), perm
115: .getPermission());
116: }
117:
118: ArrayList forumGroupPermList = MVNForumPermissionWebHelper
119: .getGroupPermissionsInForums(memberID);
120: for (int i = 0; i < forumGroupPermList.size(); i++) {
121: ForumPermission perm = (ForumPermission) forumGroupPermList
122: .get(i);
123: permission.setPermissionInForum(perm.getForumID(), perm
124: .getPermission());
125: }
126:
127: Collection groupsContainMember = DAOFactory.getGroupsDAO()
128: .getMyGroups(memberID);
129: permission.setGroupsContainMember(groupsContainMember);
130:
131: if (MvnCoreServiceFactory.getMvnCoreService()
132: .getEnvironmentService().isMVNCMS()) {
133: ArrayList cmsGroupPermList = MVNCmsPermissionWebHelper
134: .getGroupPermissionsInStepWithChannel(memberID);
135: for (int i = 0; i < cmsGroupPermList.size(); i++) {
136: CmsPermission perm = (CmsPermission) cmsGroupPermList
137: .get(i);
138: if (perm.getChannelID() == 0) {
139: permission.setPermissionInStep(perm.getStepID(),
140: perm.getPermission());
141: } else {
142: permission.setPermissionInStepInChannel(perm
143: .getStepID(), perm.getChannelID(), perm
144: .getPermission());
145: }
146: }
147: }
148:
149: // get list of forums owned by this member
150: String memberName = memberBean.getMemberName();
151: Collection listForums = MyUtil
152: .getForumsOwnedByMemberName(memberName);
153:
154: // set permissions for list of forums
155: for (Iterator iter = listForums.iterator(); iter.hasNext();) {
156: ForumBean forumBean = (ForumBean) iter.next();
157: int forumID = forumBean.getForumID();
158: permission.setPermissionInForum(forumID,
159: MVNForumPermission.PERMISSION_FORUM_ADMIN);
160: }
161:
162: // After user login always have PERMISSION_AUTHENTICATED
163: permission
164: .setPermission(MVNForumPermission.PERMISSION_AUTHENTICATED);
165:
166: // now check if user account is activated or not
167: if (MvnCoreServiceFactory.getMvnCoreService()
168: .getEnvironmentService().isPortlet() == false) { // disable portlet, run only servlets
169: if (DAOFactory.getMemberDAO().getActivateCode(memberID)
170: .equals(MemberBean.MEMBER_ACTIVATECODE_ACTIVATED)) {
171: permission
172: .setPermission(MVNForumPermission.PERMISSION_ACTIVATED);
173: }
174: }
175:
176: if (MVNForumConfig.getAlwaysActivation()) {
177: permission
178: .setPermission(MVNForumPermission.PERMISSION_ACTIVATED);
179: }
180:
181: // The Admin (id = 1) always has SystemAdmin permission
182: if (MyUtil.isRootAdminID(memberID)) {
183: permission
184: .setPermission(MVNForumPermission.PERMISSION_SYSTEM_ADMIN);
185: }
186: return permission;
187: }
188: }
|