⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perms.jsp

📁 jive3论坛开源 最新 有版主功能 jive3论坛开源 最新 有版主功能 jive3论坛开源 最新 有版主功能
💻 JSP
📖 第 1 页 / 共 3 页
字号:
<%--  -  - $RCSfile: perms.jsp,v $  - $Revision: 1.10.2.3 $  - $Date: 2003/06/16 21:04:24 $  -  - Copyright (C) 2002-2003 Jive Software. All rights reserved.  -  - This software is the proprietary information of Jive Software. Use is subject to license terms.  ---%><%@ page import="java.util.*,                 java.net.URLEncoder,                 com.jivesoftware.forum.*,                 com.jivesoftware.forum.util.*,                 com.jivesoftware.util.ParamUtils,                 com.jivesoftware.forum.database.DbForumFactory"    errorPage="error.jsp"%><%@ include file="global.jsp" %><%!	// Global variables, methods, etc    // ALL CONSTANTS REFERRED TO IN THIS FILE ARE DEFINED IN    // permMethods.jsp    static final Map permNames = new HashMap();    static {        permNames.put(new Long(READ_FORUM), "Read Forum");        permNames.put(new Long(CREATE_THREAD), "Create Thread");        permNames.put(new Long(CREATE_MESSAGE), "Create Message");        permNames.put(new Long(MODERATOR), "Moderator");        permNames.put(new Long(CREATE_MESSAGE_ATTACHMENT), "Create Attachment");        permNames.put(new Long(SYSTEM_ADMIN), "System Admin");        permNames.put(new Long(CAT_ADMIN), "Category Admin");        permNames.put(new Long(FORUM_ADMIN), "Forum Admin");        permNames.put(new Long(GROUP_ADMIN), "Group Admin");        permNames.put(new Long(USER_ADMIN), "User Admin");    }    // types of users/groups to give permissions to    static final int ANYBODY = 1;    static final int REGISTERED = 2;    static final int USER = 3;    static final int GROUP = 4;    // anonymous user & special user constants    static final long GUEST_ID = -1L;    static final long REGISTERED_ID = 0L;    private User parseUser(String key, UserManager userManager) {        int pos = key.lastIndexOf('_');        long userID = Long.parseLong(key.substring("cb_update_".length(), pos));        try {            return userManager.getUser(userID);        }        catch (NumberFormatException nfe) {}        catch (UserNotFoundException ignored) {}        return null;    }    private Group parseGroup(String key, GroupManager groupManager) {        int pos = key.lastIndexOf('_');        long groupID = Long.parseLong(key.substring("cb_update_".length(), pos));        try {            return groupManager.getGroup(groupID);        }        catch (NumberFormatException nfe) {}        catch (GroupNotFoundException ignored) {}        return null;    }    private Iterator getSortedIterator(Iterator iter, Comparator comparator) {        List list = new java.util.LinkedList();        while (iter.hasNext()) {            list.add(iter.next());        }        Collections.sort(list, comparator);        return list.iterator();    }    private SortedMap getUserPermMap(PermissionsManager permManager, long[] permGroup) {        TreeMap userPermMap = new TreeMap(JiveComparators.USER);        // for each perm type, get the Iterator of users with that perm        for (int i=0; i<permGroup.length; i++) {            Iterator usersWithPerm = permManager.usersWithPermission(permGroup[i]);            // for each perm, get the user associated with it and store it and the perm in            // the user perm map            while (usersWithPerm.hasNext()) {                User user = (User)usersWithPerm.next();                Permissions newPerm = new Permissions(permGroup[i]);                if (userPermMap.containsKey(user)) {                    newPerm = new Permissions((Permissions)userPermMap.get(user), newPerm);                }                userPermMap.put(user, newPerm);            }        }        return userPermMap;    }    private SortedMap getGroupPermMap(PermissionsManager permManager, long[] permGroup) {        TreeMap groupPermMap = new TreeMap(JiveComparators.GROUP);        // for each perm type, get the Iterator of users with that perm        for (int i=0; i<permGroup.length; i++) {            Iterator groupsWithPerm = permManager.groupsWithPermission(permGroup[i]);            // for each perm, get the user associated with it and store it and the perm in            // the user perm map            while (groupsWithPerm.hasNext()) {                Group group = (Group)groupsWithPerm.next();                Permissions newPerm = new Permissions(permGroup[i]);                if (groupPermMap.containsKey(group)) {                    newPerm = new Permissions((Permissions)groupPermMap.get(group), newPerm);                }                groupPermMap.put(group, newPerm);            }        }        return groupPermMap;    }%><%	// Permission check    if (!isSystemAdmin && !isForumAdmin && !isCatAdmin            && Version.getEdition() == Version.Edition.LITE) {        throw new UnauthorizedException("You don't have admin privileges to perform this operation.");    }    // Check to see what group of perms we're going to administer. We can    // either modify user & group perms or admin permissions.    int permGroup = ParamUtils.getIntParameter(request,"permGroup",-1);    if (permGroup != CONTENT_GROUP && permGroup != ADMIN_GROUP) {        throw new Exception("No permission group specified");    }    // Get parameters    long forumID = ParamUtils.getLongParameter(request,"forum",-1L);    long categoryID = ParamUtils.getLongParameter(request,"cat",-1L);    boolean remove = request.getParameter("remove") != null;    boolean add = request.getParameter("add") != null && !remove;    boolean cancel = request.getParameter("cancel") != null;    boolean doAdd = request.getParameter("doAdd") != null && !remove && !cancel;    boolean update = request.getParameter("update") != null;    boolean updatedPerms = ParamUtils.getBooleanParameter(request,"updatedPerms");    String objName = ParamUtils.getParameter(request,"objName");    long[] newPerms = ParamUtils.getLongParameters(request,"newperm",-1L);    String show = ParamUtils.getParameter(request,"show");    if (show == null) {        // show users by default        show = "users";    }    // also, make sure 'show' equals 'users' or 'groups' only:    if (!show.equals("users") && !show.equals("groups")) {        show = "users";    }    boolean isError = false;    // UserManager for getting and setting users or lists of users	UserManager userManager = forumFactory.getUserManager();    // GroupManager for getting and setting groups or list of groups	GroupManager groupManager = forumFactory.getGroupManager();    // Load the category    ForumCategory category = null;    if (categoryID != -1L) {        category = forumFactory.getForumCategory(categoryID);    }    // Load the forum    Forum forum = null;    if (forumID != -1L) {        forum = forumFactory.getForum(forumID);    }	// Get the permissions manager for the appropriate mode we're in:	PermissionsManager permManager = null;    if (category != null) {        permManager = category.getPermissionsManager();    }    else if (forum != null) {        permManager = forum.getPermissionsManager();    }    else {        permManager = forumFactory.getPermissionsManager();    }    // Create the group of permissions we're going to administer:    long[] permGroupDef = null;    if (permGroup == CONTENT_GROUP) {        permGroupDef = new long[] {            READ_FORUM, CREATE_THREAD, CREATE_MESSAGE, CREATE_MESSAGE_ATTACHMENT        };    }    else if (permGroup == ADMIN_GROUP) {        if (forum == null) {            if (category == null) {                permGroupDef = new long[] {                    SYSTEM_ADMIN, CAT_ADMIN, FORUM_ADMIN, USER_ADMIN, MODERATOR                };            }            else {                permGroupDef = new long[] {                    CAT_ADMIN, FORUM_ADMIN, /*USER_ADMIN,*/ MODERATOR                };            }        }        else {            permGroupDef = new long[] {                FORUM_ADMIN, MODERATOR            };        }    }    // Update permissions    if (update) {        // Build up a Map of the state the checkboxes were in:        Map oldPerms = new HashMap();        // Load the map from parameters in the request prefixed by "was"        for (Enumeration enum=request.getParameterNames(); enum.hasMoreElements(); ) {            String param = (String)enum.nextElement();            if (param.startsWith("was")) {                String key = param.substring(3,param.length()); // remove the "was"                try {                    oldPerms.put(key, new Long(Long.parseLong(request.getParameter(param))));                }                catch (NumberFormatException nfe) {}            }        }        // Now that we have an idea of what the permissions were, loop over them and compare        // with the new state of the check boxes. Based on what changed, add or remove perms.        // User permissions:        if ("users".equals(show)) {            // Iterate over old permissions            for (Iterator iter=oldPerms.keySet().iterator(); iter.hasNext(); ) {                // Get the old value                String key = (String)iter.next();                long oldValue = ((Long)oldPerms.get(key)).longValue();                // Get the new value - it's the param with the same name as the key                long newValue = ParamUtils.getLongParameter(request,key,-1L);                // If the new param was not found, so we need to remove the perm:                if (newValue == -1L) {                    if (key.indexOf("anon") > -1) {                        permManager.removeAnonymousUserPermission(oldValue);                    }                    else if (key.indexOf("reg") > -1) {                        permManager.removeRegisteredUserPermission(oldValue);                    }                    else {                        // get the user, remove the perm                        User user = parseUser(key, userManager);                        if (user != null) {                            permManager.removeUserPermission(user, oldValue);                        }                    }                }                // Otherwise, we need to add the permission:                else {                    // First check to see if the permission already exists. If it doesn't, add it.                    boolean anonExists = permManager.anonymousUserHasPermission(newValue);                    boolean regExists = permManager.registeredUserHasPermission(newValue);                    if (key.indexOf("anon") > -1) {                        if (!anonExists) {                            permManager.addAnonymousUserPermission(newValue);                        }                    }                    else if (key.indexOf("reg") > -1) {                        if (!regExists) {                            permManager.addRegisteredUserPermission(newValue);                        }                    }                    else {                        // get the user, add the perm                        User user = parseUser(key, userManager);                        if (user != null) {                            permManager.addUserPermission(user, oldValue);                        }                    }                }            }        }        // Group permissions        else if ("groups".equals(show)) {            // Basically the same scheme as above. Loop through old group perms compare            // them to what changed then add or remove permissions:            for (Iterator iter=oldPerms.keySet().iterator(); iter.hasNext(); ) {                // Old value                String key = (String)iter.next();                long oldValue = ((Long)oldPerms.get(key)).longValue();                // New valuje                long newValue = ParamUtils.getLongParameter(request,key,-1L);                // Needs to be removed:                if (newValue == -1L) {                    Group group = parseGroup(key, groupManager);                    permManager.removeGroupPermission(group, oldValue);                }                // Otherwise, perm needs to be added:                else {                    Group group = parseGroup(key, groupManager);                    if (group != null) {                        permManager.addGroupPermission(group, oldValue);                    }                }            }        }        if (!isError) {            // Done, so redirect:            response.sendRedirect("perms.jsp?cat="+categoryID+"&forum=" + forumID + "&permGroup="+permGroup+"&show="+show+"&updatedPerms=true");            return;        }    }    // Add a *new* user permission (not an update - that's handled above).    boolean addError = false;    if (doAdd) {        // Add a new user permission        if ("users".equals(show)) {            try {                User user = userManager.getUser(objName);                for (int i=0; i<newPerms.length; i++) {                    permManager.addUserPermission(user, newPerms[i]);                }            }            catch (UserNotFoundException unfe) {                addError = true;            }        }        // Add a new group permission        else if ("groups".equals(show)) {            try {                Group group = groupManager.getGroup(objName);                for (int i=0; i<newPerms.length; i++) {                    permManager.addGroupPermission(group, newPerms[i]);                }            }            catch (GroupNotFoundException gnfe) {                addError = true;            }        }        // If there were no errors, redirect        if (!addError) {            response.sendRedirect("perms.jsp?cat="+categoryID+"&forum=" + forumID + "&permGroup="+permGroup+"&show="+show);            return;        }    }    // Remove permissions - this is a removal of all user permissions for a particular    // user group.    if (remove) {        // loop thru all params, find the ones beginning with "cb_remove_". These are flags        // for users we want to remove. Build a list of these IDs:        List ids = new ArrayList();        for (Enumeration enum=request.getParameterNames(); enum.hasMoreElements(); ) {            String param = (String)enum.nextElement();            if (param.startsWith("cb_remove_")) {                try {                    ids.add(new Long(Long.parseLong(request.getParameter(param))));                } catch (NumberFormatException nfe) {}            }        }        // For each id found, delete all permissions for that user or group        for (int i=0; i<ids.size(); i++) {            long id = ((Long)ids.get(i)).longValue();            if ("users".equals(show)) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -