Permission design (lower), permission design (

Source: Internet
Author: User

Permission design (lower), permission design (
What is permission management?

Generally, as long as a user participates in a system, permission management is required, especially for some background management systems,

Permission management can control user access to the system. According to security rules or related policies, users can access related resources that are only authorized by themselves (such as menus or page resources)

Permission management consists of user authentication and authorization.

User Authentication

User Authentication. In other words, authentication is performed during logon to verify the validity of the user's identity.

The most common method for user authentication:

1. User Name + Password

2. Mobile phone number + Verification Code

3. Certificate verification

Let's take a look at the flowchart:

 

 

User authorization

User authorization: permission access control. After a user passes authentication, the system controls the user's access to resources, and the user has the resource access permission to access the resources.

 

Database Model

In the previous article, five tables are actually from six tables. However, since Table Resources in Chapter 6 can be integrated, five tables can be used to avoid redundancy, the simplest permission control is composed of at least five tables.

Subject (account, password)

Permission (permission name, Resource Name, resource access address)

Role (role name)

Relationship between roles and permissions (role id and permission id)

Subject and role relationship (subject id and role id)

 

Assign Permissions

The user must be assigned the corresponding permissions to access the corresponding resources. The permission information must be saved.

Write user information, permission management, and user-assigned permission information to the database (permission Data Model)

 

 

Role-Based Access Control

It is to determine whether the user is a project manager or an ordinary employee. The accessed resources are different.

For example

If (user. role = [pm]) {

// Access

}

If (user. role! = [Pm]) {

// Access

}

This operation is fine, but it is not easy to maintain. Once the permission is changed, the Code must be changed.

Resource-Based Access Control

If (user have [pm]) {

// Access

} Else if (user have [boss]) {

// Access

}

In this way, you only need to configure permissions for the user and grant the corresponding resources to the user, so that the user can access the service without having to modify the code every time, which increases the maintainability.

 

Implement url-based Interception

Example: Use spring MVC interceptor

Intercept the corresponding url. configure a private intercept list for the url. The intercepted list must be verified,

After entering the interceptor verification, check whether the token information exists. If the token does not exist, the interception will return to the web login page, or the json error message will be sent to the mobile phone end.

At the same time, you need to determine whether the resource can be accessed during the verification. You can query the database resource information for the first time and cache it to the session or redis.

Use the permission management framework

1. spring security (currently, even spring has abandoned this framework because it is too heavy. Now it embraces Apache Shiro)

2. Shiro (to be continued ...)

 

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.