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

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

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
