Table of Contents
回复内容:

权限设计问题

Jun 06, 2016 pm 08:09 PM
java mysql php

使用了rbac模式设计权限,现在有种情况。
普通a用户发表一个帖子,
a拥有对这个帖子的编辑,删除,查看权限。
普通b用户,拥有查看权限
小编c用户,拥有对这个帖子的编辑,删除,查看权限。
编辑,删除,查看权限都有对应的按钮,有权限就显示,没有就不显示。
应该怎么设计呢?
例如,编辑按钮对应的是一个按钮,操作节点设计成一个,节点的功能有对自己的主题编辑,对他人的主题编辑。

回复内容:

使用了rbac模式设计权限,现在有种情况。
普通a用户发表一个帖子,
a拥有对这个帖子的编辑,删除,查看权限。
普通b用户,拥有查看权限
小编c用户,拥有对这个帖子的编辑,删除,查看权限。
编辑,删除,查看权限都有对应的按钮,有权限就显示,没有就不显示。
应该怎么设计呢?
例如,编辑按钮对应的是一个按钮,操作节点设计成一个,节点的功能有对自己的主题编辑,对他人的主题编辑。

通常对自己的数据进行编辑、删除是不需要进行权限管理的。因为一般来说网站是划分前后台的,普通用户在前台操作时几乎不用考虑权限问题,是谁的谁就能管理。
详细解释起来很麻烦,你先思考一下,我觉得你主要是陷入误区了。

我这样解释一下:
已 “编辑主题” 和 “编辑我的主题” 为例 用真值表的方式模拟如下:
有 编辑主题 权限 , 有 “编辑我的主题” 权限: T
有 编辑主题 权限 , 无 “编辑我的主题” 权限: T
无 编辑主题 权限 , 有 “编辑我的主题” 权限: 做isAuth检查并返回 isAuth检查结果
无 编辑主题 权限 , 无 “编辑我的主题” 权限: F

那么现在取消 编辑我的主题 权限设置,用isAuth检查代替,真值表为相同结果:
有 编辑主题 权限 , isAuth = T: T
有 编辑主题 权限 , isAuth = F: T
无 编辑主题 权限 , isAuth = T: T
无 编辑主题 权限 , isAuth = F: F

你肯定说了,有的地方就算是用户通过 isAuth 检查也不让他用,此类操作不做isAuth检查不就行了吗?

<code>class Controller {
    protected $_allowIfIsAuth = false;
    public function afterDispatch() {
        if (! $user->hasPermission('permission_name')) {
            if (! ($this->_allowIfIsAuth && $user->isAuth('auth_id'))) {
                return false;
            }
        }
        return true;
    }
}</code>
Copy after login

<code>CREATE TABLE `app_user` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `gmt_create` datetime NOT NULL COMMENT '数据新增时间',
  `creator` varchar(128) NOT NULL DEFAULT '0' COMMENT '创建者',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '数据修改时间',
  `modifier` varchar(128) NOT NULL DEFAULT '0' COMMENT '修改者',
  `is_deleted` char(1) NOT NULL DEFAULT 'n' COMMENT '是否逻辑删除,默认为n',
  `ha_id` varchar(64) DEFAULT NULL COMMENT '会员统一ID',
  `buc_id` varchar(64) DEFAULT NULL COMMENT '员工统一ID',
  `work_no` varchar(64) DEFAULT NULL COMMENT '工号',
  `status` varchar(32) DEFAULT NULL COMMENT '状态',
  `user_type` varchar(32) DEFAULT NULL COMMENT '用户类型',
  `user_name` varchar(128) DEFAULT NULL COMMENT '用户名称',
  `email` varchar(64) DEFAULT NULL COMMENT 'E-mail',
  `mobile` varchar(32) DEFAULT NULL COMMENT '手机',
  `phone` varchar(32) DEFAULT NULL COMMENT '电话',
  `home_page_url` varchar(128) DEFAULT NULL COMMENT '主页URL',
  `user_no` varchar(128) DEFAULT NULL COMMENT '用户编号',
  `login_id` varchar(128) DEFAULT NULL COMMENT '登录ID',
  PRIMARY KEY (`id`),
  KEY `idx_workno` (`work_no`,`is_deleted`),
  KEY `login_id` (`login_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1774 DEFAULT CHARSET=utf8 COMMENT='系统用户';

CREATE TABLE `app_role` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `gmt_create` datetime NOT NULL COMMENT '数据新增时间',
  `creator` varchar(128) NOT NULL DEFAULT '0' COMMENT '创建者',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '数据修改时间',
  `modifier` varchar(128) NOT NULL DEFAULT '0' COMMENT '修改者',
  `is_deleted` char(1) NOT NULL DEFAULT 'n' COMMENT '是否逻辑删除,默认为n',
  `role_name` varchar(64) DEFAULT NULL COMMENT '角色名称',
  `role_type` varchar(32) DEFAULT NULL COMMENT '角色类型',
  `home_page_url` varchar(128) DEFAULT NULL COMMENT '主页URL',
  PRIMARY KEY (`id`),
  KEY `idx_rolename` (`role_name`,`is_deleted`)
) ENGINE=InnoDB AUTO_INCREMENT=1065 DEFAULT CHARSET=utf8 COMMENT='系统角色';

CREATE TABLE `app_role_org_user` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `gmt_create` datetime NOT NULL COMMENT '数据新增时间',
  `creator` varchar(128) NOT NULL DEFAULT '0' COMMENT '创建者',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '数据修改时间',
  `modifier` varchar(128) NOT NULL DEFAULT '0' COMMENT '修改者',
  `is_deleted` char(1) NOT NULL DEFAULT 'n' COMMENT '是否逻辑删除,默认为n',
  `role_id` bigint(20) DEFAULT NULL COMMENT '角色ID',
  `org_id` bigint(20) DEFAULT NULL COMMENT '组织ID',
  `user_id` bigint(20) DEFAULT NULL COMMENT '用户ID',
  `home_page_url` varchar(500) DEFAULT NULL COMMENT '主页URL',
  `access_org_path` varchar(256) DEFAULT NULL COMMENT '授权组织路径',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18658 DEFAULT CHARSET=utf8 COMMENT='系统用户组织角色';
</code>
Copy after login

存一个全局常量标识用户,并分用户组分配不同的功能,具体可以看一下one think的思路one think

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1658
14
PHP Tutorial
1257
29
C# Tutorial
1231
24
MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

What does 'platform independence' mean in the context of Java? What does 'platform independence' mean in the context of Java? Apr 23, 2025 am 12:05 AM

Java's platform independence means that the code written can run on any platform with JVM installed without modification. 1) Java source code is compiled into bytecode, 2) Bytecode is interpreted and executed by the JVM, 3) The JVM provides memory management and garbage collection functions to ensure that the program runs on different operating systems.

How does MySQL differ from Oracle? How does MySQL differ from Oracle? Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

Choosing Between MySQL and Oracle: A Decision Guide Choosing Between MySQL and Oracle: A Decision Guide Apr 20, 2025 am 12:02 AM

Choosing MySQL or Oracle depends on project requirements: 1. MySQL is suitable for small and medium-sized applications and Internet projects because of its open source, free and ease of use; 2. Oracle is suitable for core business systems of large enterprises because of its powerful, stable and advanced functions, but at a high cost.

See all articles