Also bask in my RBAC system (III): background management program source code and usage demonstration

Source: Internet
Author: User

Source code download

Originally intended to provide the entire framework togetherProgramSource code. But how to open the source code is not clear about which Protocol to use. Therefore, first put the source code of the Background Management Section and provide a demonstration. Familiar with the use of the source code, it should be better.

A little nonsense (this irrelevant technology can be skipped without reading): this series has been put on writing for a long time, but it has never been written (to put it bluntly, it is relatively lazy ), I always want to wait for maturity. Some friends want to seeSource codeIs not released, not because it is conservative, but because it is afraid of being said after the releaseCodeBad. After the system is mature, I feel that RBAC is outdated and I am sorry to continue. However, I recently saw some discussions about RBAC in the garden.ArticleThe system is open-source and charged. Although they are the same for processing permissions, their implementation methods are different. Therefore, I don't even think about the code, but I still hope to provide you with another idea. After all, a person has limited energy. If a friend in the garden is interested in this aspect and can provide some ideas and technical suggestions, it would be better.

Next to the question, let's take a look at the demo page of the system.

Here we will demonstrate the background management program of the B/S structure. Originally, a C/S structure background management program was required, but there was no c/s project and there was no such requirement, so there was no motivation.

1. Log On As a user.

That's nothing to say.

 2. Welcome window.

You can add content as needed.

 3. User Management

(1) provides management functions such as adding, deleting, and resetting passwords.

(2) You can click the "role" button to set the role to which the user belongs.

(3) You can click the "Group" button to set the user group.

4. group management.

Provides management functions such as adding and deleting groups.

5. role management

(1) provides management functions such as adding and deleting roles.

(2) You can use the "permission settings" button to set the permissions of a role. In this demonstration, only the basic permissions of RBAC are added, and no business permissions are added.

 

 

The method is also very simple.

First, set different roles and set corresponding permissions for each role. After adding a user to a specified role, the user has the permissions of this role. A user can join multiple roles at the same time, and the user permissions can be accumulated for multiple roles.

Grouping is complex and involves secondary development.

 

The following describes how to use this system in a real project.

1. Add the data table required by the system to the actual project database

Note: The databases of this RBAC system are debugged on SQL Server 2008, so it is not guaranteed that other databases are supported (SQL Server 2005 should also be fine ). To support other data sources, you need to write a new Dal layer.

First, you need to add the data tables and data required by the system to the actual project database, and execute the database creation script under "document project \ modeling folder" to create the data table and generate the basic data.

(1) 1. SQL Server database creation script createdb. SQL: This script is used to create data tables.

(2) 3-1.sqlserver data initialization (basic data). SQL: This script is used to generate the basic data required by the system. Without such data, the system will crash when running. This script cannot be executed together with the next script.

(3) 3-2.sqlserver data initialization (Basic Data + basic permissions ). SQL: This script is used to generate the basic data required by the system, and then generate the permission definitions required in the "background management program" demonstrated earlier. In this way, you can directly use the "background management program" without generating a new permission definition. This script cannot be executed together with the previous one.

2. Define project Permissions

After creating a database, you must first define all the permissions required for the project. Use the permission Configuration tool ksrbac.privilegeconfigtool.exe under the "Privilege config toolfolder" to complete this task.

(1) define a Resource Group

Grouping resources is not required. When there are too many resources, you can use resource groups to better locate the resources. In this example, a resource group is created for the resources involved in the background permission management in "background management program. In practical projects, you can create resource groups and sub-groups based on the functional categories in the project to subdivide resources.

(2) define Resources

All resources involved in the project can be defined here. In this example, four resources are defined in "background management program" to correspond to three functions and logon windows in the program.

(3) define operations

You can defineAllResourceAllOperation type. All permission-related operations in the project must be defined here before they can be used.

(4) define Permissions

With resources and operation types, you can define specific permissions. In this example, all the permissions used in "background management program" are used. Note that only the permissions used in the project need to be checked. For example, if the resource "(LOGIN) background" is selected, you only need to check "execute ", you do not need to check "add" or "delete", because the actual project only checks whether the user has the permission to log on to the background, it does not check whether the user can add or delete the backend (just a backend, how to manage the deletion? ^_^ ).

(5) generate a permission File

After the permissions are defined and saved, the database has the permission to define data. Each permission has a corresponding data. However, it is stored in the guid format, which is time-consuming and is not feasible for direct use. Therefore, the "generate enumeration code" function is used to generate C # enumeration code. Then, you can retrieve the specific permissions by name. During running, the system automatically converts the name to guid to determine the specific permission.

For example, you only need to enter (koalastudio. RBAC.) privilege. baseprivilege. User. Add to add this permission to indicate this permission.

Because the permission definitions of each project are different, each project must generate the permission code for the RBAC system. In the background management program, this code is stored in the privilege. CS file under app_code. In actual use, it can be stored in any file or the namespace can be modified.

 

3. Import the DLL file generated by RBAC system

Reference the DLL file under "document project \ dllreference folder" in the actual project.

(1) ksrbac. BLL. dll

(2) ksrbac. entity. dll

(3) ksrbac. idal. dll

(4) ksrbac. classfactory. dll

(5) ksrbac. rbacmanager. dll

 

4. Import the "background management program" to the Project

(1) copy the content in the "ksrbac Manager \ demo for webform folder" to the root directory of the actual project. Do not overwrite the existing files in the project.

(2) Add the following fields to the project's web. config:

<Configuration>
<Deleetask>
<Add key = "ksrbac_dalfile" value = "ksrbac. sqlserverdal"/>
<Add key = "ksrbac_dataaccesslayer" value = "sqlserverdal"/>
</Appsettings>

......

</Configuration>

 5. Run "background management program"

Set "Management \ default. aspx file" as the start page. Run the command to see the effect.

The background management program is only an implementation of this RBAC system and is separate from the RBAC framework.

The "background management system" described in this article is only a front-end implementation of this RBAC framework, not a necessary part of this RBAC framework. That is to say, you only need to add the RBAC framework file (9 DLL files) to the project to program permissions, this RBAC framework can be called only when the "backend management system" of the demo is not used. This gives users a great degree of freedom, and users do not need to be subject to certain restrictions during use.

The "background management system" provided here is designed based on the background management requirements in my project and facilitates future project development. You can also design your own background management permissions, add or remove some permissions to make them more suitable for you (you need to modify the foreground at the same time, such as removing group permission control, the grouping page of the foreground should also remove or revoke the permission Verification Section), or simply develop a new front-end page. If you already have your own background and do not want to use this permission management system, you can also directly call this RBAC framework in the background to complete permission verification.

Because I am not very good at front-end design, the front-end program provided only guarantees the implementation of functions, and there are many problems that have not been solved in the areas of input verification, operation interface, layout design, and aesthetics, you are welcome to make suggestions. For bugs in the program, please inform me in time so that I can fix them. If you have modified or improved the "background management program" and want to send it to me, I will be able to steal it.

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.