Simple role-based permission management of RBAC

Source: Internet
Author: User

Simple role-based permission management of RBAC

1. What is permission management? permission management refers to the subdivision of background functions and the management of jobs divided by different employees

How RBAC is implemented is managed by limiting the methods of different controllers and controllers.

To implement RBAC, three tables, one user table, one role table, and one permission table are required.

User table:

Id ****** role_id

Role table

Role_id ****** access_ids (record all accessible permission IDs)

Permission table

Access_id

Records the actions of all controllers or controllers.

2. How to control it? Just make a judgment in the parent class of the Controller or the initialization method of the controller.

$ Role_id = $ _ SESSION ['Role _ id'];

$ Role = $ db-> role-> findByPk ($ role_id );

$ Access = $ db-> access-> findAllByPk ($ role ['Access _ id']);

Obtain the Controller or controller method to be executed based on the vro class

$ M = current_method (); // obtain the method to be accessed

If (! In_array ($ m, $ access )){


Redirect ('/Index ');

}

This article permanently updates the link address:

Related Article

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.