📄 authcheck.java
字号:
/* * 作者: 胡李青 * qq: 31703299 * Copyright (c) 2007 huliqing * 主页 http://www.tbuy.biz/ * 你可以免费使用该软件,未经许可请勿作用于任何商业目的,如有技术问题请与本人联系! * * 该类主要用于设置用户的操作权限 */package biz.tbuy.bbs;import biz.tbuy.bbs.bean.BaseBean;/** * @author huliqing * <p><b>qq:</b>31703299 * <p><b>E-mail:</b> * <a href="mailto:huliqing.cn@gmail.com">huliqing.cn@gmail.com</a> * <p><b>Homepage:</b> * <a href="http://www.tbuy.biz/">http://www.tbuy.biz/</a> */public class AuthCheck extends BaseBean{ public AuthCheck() {} /** * 检查用户是否有权限查看该主题(如果该主题已经设置了阅读限制) */ /* public boolean isPermitViewTopic(TopicModel topic) { if (!getVisitor().isLogin()) { Utils.addErrorMessage(getBundle(), "该主题设置了阅读限制,请先登录!"); return false; } if (topic.getAuthType().equals(BBSGroups.READER_AUTH_LOGIN)) { return true; } else if (topic.getAuthType().equals(BBSGroups.READER_AUTH_GROUPS)){ String userId = getVisitor().getUser().getId(); // 如果是“作者”“管理员”“版主” -> true if (userId.equals(topic.getByUser()) || getComApplication().isAdmin(userId) || getBBSApplication().isMaster(userId, topic.getByForum())) { return true; } // 否则需要相关的用户组 String[] groups = topic.getAuthGroups().split(","); if (groups.length > 0) { String group = this.getBBSSession().getGroup(); for (int i = 0; i < groups.length; i++) { if (group.equals(groups[i])) { return true; } } } } Utils.addErrorMessage(getBundle(), "对不起,阅览限制!你所在的用户组无法浏览该主题"); return false; } */ /** * 通过主题及用户的id以确认用户是否有权限修改该主题 * @param topic 主题的TopicModel * @return true 如果该用户有权限更新该主题,否则返回false */ /* public boolean isPermitUpdateTopic(TopicModel topic) { if (!getVisitor().isLogin()) { return false; } String userId = getVisitor().getUser().getId(); // 1 如果userId为该topic的作者则直接返回true if (topic.getByUser().equals(userId)) { return true; } // 2 如果userId为该topic所属的讨论区的版主,也返回true if (getBBSApplication().isMaster(userId, topic.getByForum())) { return true; } // 3 如果userId为admin即管理员,也返回true if (getComApplication().isAdmin(userId)) { return true; } return false; } */ /** * 检查用户是否有权限编辑已经锁住的贴子 * @param topic 已经被锁住的贴子! * @return true 有权限 false无权限 */ /* public boolean isPermitUpdateTopicByLocked(TopicModel topic) { if (!getVisitor().isLogin()) { return false; } String userId = getVisitor().getUser().getId(); // 如果userId为admin即管理员 -> true if (getComApplication().isAdmin(userId)) { return true; } // 如果userId为该topic所属的讨论区的版主,-> true if (getBBSApplication().isMaster(userId, topic.getByForum())) { return true; } return false; } */ /** * 检查用户是否有权限锁贴,或解锁贴子 * @param topic 被解锁或锁的贴子 * @return true 有权限 false无权限 */ /* public boolean isPermitLockTopic(TopicModel topic) { if (!getVisitor().isLogin()) { return false; } String userId = getVisitor().getUser().getId(); // 如果是管理员,-> true if (getComApplication().isAdmin(userId)) { return true; } // 如果是版规类型,而用户又非管理员,则 -> false; if (topic.getType() == BBSGroups.TYPE_RULE && !getComApplication().isAdmin(userId)) { return false; } // 如果是该讨论区的版主 -> true if (getBBSApplication().isMaster(userId, topic.getByForum())) { return true; } return false; } */ /** * 检查用户是否有权限发表所选择的主题类型 * 主题类型包括:0主题,90公告,100版规 * @param type 用户所要发表主题的类型 * @param forumId 用户所选择的讨论区ID,可用于判断是否为该讨论区的版主 * @return true 如果用户获得发表相应主题类型的权限,否则返回false; */ /* public boolean isPermitPostType(int type, int forumId) { if (!getVisitor().isLogin()) { return false; } String userId = getVisitor().getUser().getId(); if (type == BBSGroups.TYPE_TOPIC) { return true; } if (getComApplication().isAdmin(userId)) { return true; } if (getBBSApplication().isMaster(userId, forumId) && type != BBSGroups.TYPE_RULE) { return true; } return false; } */ /** * 通过reply信息及相应的用户id,判断该用户是否有权限修改或编辑该 * 回复信息,拥有权限的为:作者,相应的版主,管理员 * @param reply 相应的回复信息 * @return true 如果用户有权限修改该回复信息,否则返回false; */ /* public boolean isPermitUpdateReply(ReplyModel reply) { if (!getVisitor().isLogin()) { return false; } String userId = getVisitor().getUser().getId(); // 如果是作者 if (reply.getByUser().equals(userId)) { return true; } // 如果是管理员 if (getComApplication().isAdmin(userId)) { return true; } // 如果是该forum的版主 TopicModel topic = TopicAction.getTopicsById(reply.getByTopic()); if (getBBSApplication().isMaster(userId, topic.getByForum())) { return true; } return false; } */ /** * 检查是否需要在post.jsp页面中显示“主题类型”选项, * 以供用户选择所要发布的主题类型,如:版规,公告,置顶等 * 默认只有身份为:admin,master的用户才显示 * @return true 可以显示,false则不应该显示 */ /* public boolean isPermitShowPostType() { if (!getVisitor().isLogin()) { return false; } String userId = getVisitor().getUser().getId(); if (getComApplication().isAdmin(userId) || getBBSApplication().isMaster(userId)) { return true; } return false; } */ /** * 检查用户是否有权限删除相应的收藏信息 * @param storage 所收藏的StorageModel * @param user 删除者 * @return true 如果该user有权限,否则false; */ public boolean isPermitDeleteStorage(StorageModel storage, String user) { if (!getVisitor().isLogin()) { return false; } // 如果是该用户所收藏,当然有权限 if (storage.getByUser().equals(user)) { return true; } // 如果是系统管理员,也有权限 if (getComApplication().isAdmin(user)) { return true; } return false; } /** * 判断是否允许上传文件 * 1.如果全局设置为不允许,则false; * 2.检查当前讨论区是否允许上传文件,不允许则false * @param forumId */ public boolean isPermitUploadFile(int forumId) { // 1 if (!getComApplication().isUpload()) { return false; } return true; } /** * 通过topic,及其回复信息创建authenticator,该方法暂时载入与topic相同的权限 * @param topic 主题信息 * @param reply 该主题信息的回复信息 * @return authenticator 当前用户相对于该reply的最终权限 */ /* public static Authenticator createAuthenticator(TopicModel topic, ReplyModel reply) { Authenticator authenticator = null; String id = getVisitor().getUser().getId(); if (getComApplication().isAdmin(id)) { authenticator = getAdminAuth(); // 载入admin权限 }else if (getBBSApplication().isMaster(id, topic.getByForum())) { authenticator = getMasterAuth();// 载入版主权限 } else { authenticator = createAuthenticator(topic); // 载入topic权限 } return authenticator; }*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -