thinkphp教程之RBAC详解2之RBAC类内容和使用流程讲解
RBAC类简单描述
RBAC类有几个方法:
1。authenticate()// 认证方法,检查是否传入用户模型
你需要在配置文件中定义USER_AUTH_MODEL,一般值是User,这个是你的用户表名称,根据实际情况填写。
2。saveAccessList($authId=null)//用于检测用户权限的方法,并保存到Session中
3。getRecordAccessList($authId=null,$module='')// 取得模块的所属记录访问权限列表 返回有权限的记录ID数组
4。checkAccess() //检查当前操作是否需要认证
5。checkLogin()// 登录检查这个是很重要的方法,我们会用了检测用户是否登录
6。AccessDecision($appName=APP_NAME)//权限认证的过滤器方法
7。getAccessList($authId)//取得当前认证号的所有权限列表
8.getModuleAccessList($authId,$module)// 读取模块所属的记录访问权限
官方类文件注释比较详细,我也就不再赘述。主要讲解一下实际用法。
上一次我已经说了第一步是建好相关表和配置文件,接下来才是写代码。这里先补充一下,配置文件参数实例: 'USER_AUTH_ON' => true, //开启认证<br>
'USER_AUTH_TYPE' => 1, //用户认证使用SESSION标记<br>
'USER_AUTH_KEY' => 'authId', //设置认证SESSION的标记名称<br>
'ADMIN_AUTH_KEY' => 'admin', //管理员用户标记<br>
'USER_AUTH_MODEL' => 'User', //验证用户的表模型u_user<br>
'AUTH_PWD_ENCODER' => 'md5', //用户认证密码加密方式<br>
'USER_AUTH_GATEWAY' => '/Public/login',//默认的认证网关<br>
'NOT_AUTH_MODULE' => 'Public,Index', //默认不需要认证的模块'A,B,C'<br>
'REQUIRE_AUTH_MODULE' => '', //默认需要认证的模块<br>
'NOT_AUTH_ACTION' => '', //默认不需要认证的动作<br>
'REQUIRE_AUTH_ACTION' => '', //默认需要认证的动作<br>
'GUEST_AUTH_ON' => false, //是否开启游客授权访问<br>
'GUEST_AUTH_ID' => 0, //游客标记 <br>
'RBAC_ROLE_TABLE' => 'tao_role', //角色表<br>
'RBAC_USER_TABLE' => 'tao_role_user', //角色分配表<br>
'RBAC_ACCESS_TABLE' => 'tao_access', //权限分配表<br>
'RBAC_NODE_TABLE' => 'tao_node', //节点表
你在conf文件夹下的config.php中需写入以上配置参数。
接下来我讲解一下,RBAC的验证流程,首先用户访问某个页面,程序判断是否为公开,不是则跳转到登录页面。登录成功,判断是否有权限访问,没有提示权限错误信息。同样点击某项操作或者模块也是检测是否有权限。结合上面那个类,第一步其实我们是判断访问的操作或者模块是在公开访问的模块组,或者说在不需要验证的模块组,即判断C('NOT_AUTH_MODULE')中有没有该模块,有则为公开组不需要登录,反之跳转到登录页面。登录页面执行checkLogin方法,验证通过跳转到默认首页。在用户操作链接时触发AccessDecision方法,其实这个方法内部调用了检查权限的checkAccess方法,有权限继续操作,没有提示错误。(注:这里其实是先判断了当前用户属于哪个用户组,然后判断用户组具有哪些权限)
基本上RBAC就是这么一个使用过程。下一讲通过实例代码说明,不明白的加我QQ:544828662,或者去我博客http://blog.kisscn.com留言
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Learn about Python programming with introductory code examples Python is an easy-to-learn, yet powerful programming language. For beginners, it is very important to understand the introductory code examples of Python programming. This article will provide you with some concrete code examples to help you get started quickly. Print HelloWorldprint("HelloWorld") This is the simplest code example in Python. The print() function is used to output the specified content

PHP variables store values during program runtime and are crucial for building dynamic and interactive WEB applications. This article takes an in-depth look at PHP variables and shows them in action with 10 real-life examples. 1. Store user input $username=$_POST["username"];$passWord=$_POST["password"]; This example extracts the username and password from the form submission and stores them in variables for further processing. 2. Set the configuration value $database_host="localhost";$database_username="username";$database_pa

Title: From Beginner to Mastery: Code Implementation of Commonly Used Data Structures in Go Language Data structures play a vital role in programming and are the basis of programming. In the Go language, there are many commonly used data structures, and mastering the implementation of these data structures is crucial to becoming a good programmer. This article will introduce the commonly used data structures in the Go language and give corresponding code examples to help readers from getting started to becoming proficient in these data structures. 1. Array Array is a basic data structure, a group of the same type

How to use PHP to write the inventory management function code in the inventory management system. Inventory management is an indispensable part of many enterprises. For companies with multiple warehouses, the inventory management function is particularly important. By properly managing and tracking inventory, companies can allocate inventory between different warehouses, optimize operating costs, and improve collaboration efficiency. This article will introduce how to use PHP to write code for inventory warehouse management functions, and provide you with relevant code examples. 1. Establish the database before starting to write the code for the inventory warehouse management function.

The simplest code example of Java bubble sort Bubble sort is a common sorting algorithm. Its basic idea is to gradually adjust the sequence to be sorted into an ordered sequence through the comparison and exchange of adjacent elements. Here is a simple Java code example that demonstrates how to implement bubble sort: publicclassBubbleSort{publicstaticvoidbubbleSort(int[]arr){int

"Go Language Programming Examples: Code Examples in Web Development" With the rapid development of the Internet, Web development has become an indispensable part of various industries. As a programming language with powerful functions and superior performance, Go language is increasingly favored by developers in web development. This article will introduce how to use Go language for Web development through specific code examples, so that readers can better understand and use Go language to build their own Web applications. 1. Simple HTTP Server First, let’s start with a

Huawei Cloud Edge Computing Interconnection Guide: Java Code Samples to Quickly Implement Interfaces With the rapid development of IoT technology and the rise of edge computing, more and more enterprises are beginning to pay attention to the application of edge computing. Huawei Cloud provides edge computing services, providing enterprises with highly reliable computing resources and a convenient development environment, making edge computing applications easier to implement. This article will introduce how to quickly implement the Huawei Cloud edge computing interface through Java code. First, we need to prepare the development environment. Make sure you have the Java Development Kit installed (

Java Selection Sorting Method Code Writing Guide and Examples Selection sorting is a simple and intuitive sorting algorithm. The idea is to select the smallest (or largest) element from the unsorted elements each time and exchange it until all elements are sorted. This article will provide a code writing guide for selection sorting, and attach specific Java sample code. Algorithm Principle The basic principle of selection sort is to divide the array to be sorted into two parts, sorted and unsorted. Each time, the smallest (or largest) element is selected from the unsorted part and placed at the end of the sorted part. Repeat the above
