An analysis of the application of Apache Shiro in Web projects

Source: Internet
Author: User
Tags resource

User Rights model

Before we uncover the Shiro veil, we need to recognize the user rights model. The user privilege model mentioned in this paper refers to the data model used to express user information and user rights information. Which proves "Who are you?" "," How much protected resources can you access? ”。 In order to realize a more flexible user rights data model, the user information is usually represented by a single entity, and the user rights information is represented by two entities.

User information in Loginaccount indicates that the simplest user information may contain only the username LoginName and password password two properties. The actual application may contain information such as whether the user is disabled and whether the user's information expires.

User rights information with role and Permission, the role and Permission constitute a many-to-many relationship. Permission can be understood as an operation on a resource, role can be simply understood as a set of Permission.

A many-to-many relationship is formed between user information and role. means that the same user can have multiple role, and a role can be owned by more than one user.

Figure 1. User Rights model

Certification and authorization

Shiro Authentication and authorization process

The resources that are protected by Shiro will be authenticated and authorized. You can use Shiro to protect URLs by referring to the "Integration with Spring" section.

A user accesses a URL protected by Shiro, such as http://host/security/action.do.

Shiro first check whether the user has passed the certification, if not passed the authentication check, then jump to the login page, otherwise authorize the inspection. The authentication process needs to obtain the user and the password information through the Realm, usually we realize the JDBC Realm, at this time the user authentication needs the information from the database obtains. If the cache is used, the first time the user information is fetched from the cache.

After the certification passed the Shiro authorization check, authorization check also need to obtain user permission information through Realm. The user rights information required by Shiro includes role or Permission, either one or both, depending on the configuration of the protected resource. If the user rights information does not contain the role or Permission required by Shiro, the authorization does not pass. You can access the resource for the protected URL only if the authorization passes, otherwise you will jump to the unauthorized page.

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.