Ultra-simple RBAC implementation

Source: Internet
Author: User
Provides various official and user-released code examples and code reference. You are welcome to exchange and learn the ultra-simple RBAC implementation.
Transform the official RBAC and provide powerful role permissions. /**
+ ----------------------------------------------------------
* Obtain the list of all permissions for the current authentication number.
+ ----------------------------------------------------------
* @ Param integer $ authId user ID
+ ----------------------------------------------------------
* @ Access public
+ ----------------------------------------------------------
*/
Static public function getAccessList ($ authId)
{
// Echo"
"; Print_r ($ authId); exit;
// Database-based permission data
$ Db = Db: getInstance (C ('rbac _ DB_DSN '));
$ Auth_type = C ("AUTH_TYPE ");
$ Table = array ('role' => C ("DB_PREFIX "). C ('rbac _ ROLE_TABLE '), 'user' => C ("DB_PREFIX "). C ('rbac _ USER_TABLE '), 'access' => C ("DB_PREFIX "). C ('rbac _ ACCESS_TABLE '), 'node' => C ("DB_PREFIX "). C ('rbac _ NODE_TABLE '));
$ SQL = "select node. auth_type, node. id, node. action, node. action_name, node. module, node. module_name from ".
$ Table ['role']. "as role ,".
$ Table ['user']. "as user ,".
$ Table ['access']. "as access ,".
$ Table ['node']. "as node ".
"Where user. u_id = '{$ authId}' and user. role_id = role. id and access. role_id = role. id and role. status = 1 and access. node_id = node. id and node. status = 1 ";

$ Apps = $ db-> query ($ SQL );
Require_once ('./Conf/Admin/authoritys. php ');
$ Access = array ();
Foreach ($ apps as $ key => $ app)
{
$ AppId = $ app ['id'];
$ Module_name = $ app ['module'];
$ Action_name = $ app ['action'];
$ O_module_name = strtoupper ($ module_name );
$ O_action_name = strtoupper ($ action_name );
$ L_module_name = strtolower ($ module_name );
$ L_action_name = strtolower ($ action_name );

// Read project module Permissions
If ($ app ['auth _ type'] = 0) // node authorization
{
$ Access [$ o_module_name] [$ o_action_name] = true;

If (isset ($ authoritys ['all'] [$ l_action_name])
{
$ Authoritys_list = $ authoritys ['all'] [$ l_action_name];
Foreach ($ authoritys_list as $ authority_item)
{
$ Access [$ o_module_name] [strtoupper ($ authority_item)] = true;
}
}

If (isset ($ authoritys ['actions'] [$ l_module_name] [$ l_action_name])
{
$ Authoritys_list = $ authoritys ['actions'] [$ l_module_name] [$ l_action_name];
Foreach ($ authoritys_list as $ authority_item)
{
$ Access [$ o_module_name] [strtoupper ($ authority_item)] = true;
}
}
}

If ($ app ['auth _ type'] = 1) // module authorization
{
$ Access [$ o_module_name] [strtoupper ($ auth_type [$ app ['auth _ type'])] = true;
}

If ($ app ['auth _ type'] = 2) // operation authorization
{
$ Access [strtoupper ($ auth_type [$ app ['auth _ type'])] [$ o_action_name] = true;
}
}

// Modules that do not require authentication
If (! Empty ($ authoritys ['no']) & is_array ($ authoritys ['no']) {
Foreach ($ authoritys ['no'] as $ module_name => $ action_name ){
$ O_module_name = strtoupper ($ module_name );
$ O_action_name = strtoupper (key ($ action_name ));
Foreach ($ action_name as $ keymodule => $ valaction ){
$ Keymodule = strtoupper ($ keymodule );
$ Access [$ o_module_name] [$ keymodule] = true;
}
}

}
Return $ access;
}

Huicms.zip (8.45 KB download: 75 times)

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.