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

📄 abstractpermission.java

📁 easy to use, easy to setup bulletin board (forum)
💻 JAVA
字号:
/*
 * Copyright (C) 2002 by MyVietnam.net
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * All copyright notices regarding mvnForum
 * must remain intact in the scripts and in the outputted HTML
 * The "powered by" text/logo with a link back to
 * http://www.mvnForum.com and http://www.MyVietnam.net in the footer of the pages MUST
 * remain visible when the pages are viewed on the internet or intranet.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Support can be obtained from support forums at:
 * http://www.mvnForum.com/mvnforum/index
 *
 * Correspondence and Marketing Questions can be sent to:
 * info@MyVietnam.net
 *
 * @author: Minh Nguyen  minhnn@MyVietnam.net
 * @author: Mai  Nguyen  mai.nh@MyVietnam.net
 */
package net.myvietnam.mvnplugin.mvnforum.auth;

import net.myvietnam.mvncore.exception.BadInputException;
import net.myvietnam.mvncore.exception.NotLoginException;

public abstract class AbstractPermission implements MVNForumPermission {

    public static final int[] globalPermissionArray =
        {
            PERMISSION_SYSTEM_ADMIN,
            PERMISSION_FORUM_ADMIN,
            PERMISSION_FORUM_MODERATOR,
            PERMISSION_LIMITED_USER,
            PERMISSION_NORMAL_USER,
            PERMISSION_POWER_USER
        };

    public static final int[] forumPermissionArray =
        {
            PERMISSION_FORUM_ADMIN,
            PERMISSION_FORUM_MODERATOR,
            PERMISSION_LIMITED_USER,
            PERMISSION_NORMAL_USER,
            PERMISSION_POWER_USER
        };

/**************************************************************************
 * global permissions variables
 **************************************************************************/
    protected boolean authenticated = false;

    protected boolean login         = false;

    protected boolean adminSystem   = false;

    protected boolean newForum      = false;

    protected boolean editForum     = false;

    protected boolean deleteForum   = false;

    protected boolean newCategory   = false;

    protected boolean editCategory  = false;

    protected boolean deleteCategory= false;

    protected boolean sendMail      = false;

    protected boolean useAvatar     = false;

    protected boolean useMessage    = false;

/**************************************************************************
 * individual forum permissions variables
 **************************************************************************/
    /** @todo change to array or List */
    protected boolean readPost      = false;

    protected boolean newThread     = false;

    protected boolean newPost       = false;

    protected boolean editPost      = false;

    protected boolean deletePost    = false;

    protected boolean newPoll       = false;

    protected boolean editPoll      = false;

    protected boolean deletePoll    = false;

    protected boolean useAttachment = false;

    protected boolean getAttachment = false;

    /**
     * constructor
     */
    protected AbstractPermission() {
    }

/**************************************************************************
 * The below methods are static methods
 **************************************************************************/

    public static String getDescription(int permission) throws BadInputException {
        String desc = "";

        switch (permission) {
            case PERMISSION_SYSTEM_ADMIN:
                desc = "System Admin";
                break;

            case PERMISSION_FORUM_ADMIN:
                desc = "Forum Admin";
                break;

            case PERMISSION_FORUM_MODERATOR:
                desc = "Forum Moderator";
                break;

            case PERMISSION_LIMITED_USER:
                desc = "Limited User";
                break;

            case PERMISSION_NORMAL_USER:
                desc = "Normal User";
                break;

            case PERMISSION_POWER_USER:
                desc = "Power User";
                break;

            default:
                throw new BadInputException("Currently dont support permission = " + permission);
        }//switch

        return desc;
    }

/**************************************************************************
 * Special permissions methods
 **************************************************************************/

    public boolean isAuthenticated() {
        return authenticated;
    }
    public void ensureIsAuthenticated() throws AuthenticationException {
        if (authenticated == false) {
            throw new AuthenticationException(NotLoginException.NOT_LOGIN);
        }
    }

/**************************************************************************
 * global permissions methods
 **************************************************************************/

    public boolean canLogin() {
        return login;
    }
    public void ensureCanLogin() throws AuthenticationException {
        if (login == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canAdminSystem() {
        return adminSystem;
    }
    public void ensureCanAdminSystem() throws AuthenticationException {
        if (adminSystem == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canNewForum() {
        return newForum;
    }
    public void ensureCanNewForum() throws AuthenticationException {
        if (newForum == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canEditForum() {
        return editForum;
    }
    public void ensureCanEditForum() throws AuthenticationException {
        if (editForum == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canDeleteForum() {
        return deleteForum;
    }
    public void ensureCanDeleteForum() throws AuthenticationException {
        if (deleteForum == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canNewCategory() {
        return newCategory;
    }
    public void ensureCanNewCategory() throws AuthenticationException {
        if (newCategory == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canEditCategory() {
        return editCategory;
    }
    public void ensureCanEditCategory() throws AuthenticationException {
        if (editCategory == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canDeleteCategory() {
        return deleteCategory;
    }
    public void ensureCanDeleteCategory() throws AuthenticationException {
        if (deleteCategory == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canSendMail() {
        return sendMail;
    }
    public void ensureCanSendMail() throws AuthenticationException {
        if (sendMail == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canUseAvatar() {
        return useAvatar;
    }
    public void ensureCanUseAvatar() throws AuthenticationException {
        if (useAvatar == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canUseMessage() {
        return useMessage;
    }
    public void ensureCanUseMessage() throws AuthenticationException {
        if (useMessage == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }


/**************************************************************************
 * individual forum permissions methods
 **************************************************************************/
    /** @todo change to array or List */

    public boolean canReadPost(int forumID) {
        return readPost;
    }
    public void ensureCanReadPost(int forumID) throws AuthenticationException {
        if (canReadPost(forumID) == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canNewThread(int forumID) {
        return newThread;
    }
    public void ensureCanNewThread(int forumID) throws AuthenticationException {
        if (canNewThread(forumID) == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canNewPost(int forumID) {
        return newPost;
    }
    public void ensureCanNewPost(int forumID) throws AuthenticationException {
        if (canNewPost(forumID) == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canEditPost(int forumID) {
        return editPost;
    }
    public void ensureCanEditPost(int forumID) throws AuthenticationException {
        if (canEditPost(forumID) == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canDeletePost(int forumID) {
        return deletePost;
    }
    public void ensureCanDeletePost(int forumID) throws AuthenticationException {
        if (canDeletePost(forumID) == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canNewPoll(int forumID) {
        return newPoll;
    }
    public void ensureCanNewPoll(int forumID) throws AuthenticationException {
        if (canNewPoll(forumID) == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canEditPoll(int forumID) {
        return editPoll;
    }
    public void ensureCanEditPoll(int forumID) throws AuthenticationException {
        if (canEditPoll(forumID) == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canDeletePoll(int forumID) {
        return deletePoll;
    }
    public void ensureCanDeletePoll(int forumID) throws AuthenticationException {
        if (canDeletePoll(forumID) == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canUseAttachment(int forumID) {
        return useAttachment;
    }
    public void ensureCanUseAttachment(int forumID) throws AuthenticationException {
        if (canUseAttachment(forumID) == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

    public boolean canGetAttachment(int forumID) {
        return getAttachment;
    }
    public void ensureCanGetAttachment(int forumID) throws AuthenticationException {
        if (canGetAttachment(forumID) == false) {
            throw new AuthenticationException(NotLoginException.NOT_ENOUGH_RIGHTS);
        }
    }

}

⌨️ 快捷键说明

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