Hands-on implementation of Java Permissions (1)-shiro Introduction

Source: Internet
Author: User

Function Introduction Authentication: Identity authentication/Login. Verify that the user has the corresponding identity;
Authorization: Authorization, which is permission validation. Verify that an authenticated user has a permission;
It is common to verify that a user has a role.

or fine-grained validation of a  
session Manager: Session Management. That is, the user login is a session, before the exit, all its letter  
cryptography: Encryption to protect the security of your data. such as password encrypted storage to the database, rather than plaintext storage,  
web support:web support, can be easily integrated into the WEB environment.  
caching: Cache, for example, after a user logs on. The user information, the roles/permissions they have, do not need to be checked every time, so they can  
concurrency:shiro supports concurrent authentication for multithreaded applications, such as opening a thread with a thread that can  
testing: to provide testing support;  
run as: Allow a user to pretend to be interviewed for the identity of another user (assuming they agree); 
remember Me: Remember me. This is a very common feature, that is, once logged in, the next time you do not have to login  
.




Subject: Main body. The ability to see that the subject can be a "user" that can interact with the application regardless of what;
SecurityManager: Equivalent to Dispatcherservlet in SPRINGMVC or Struts2
Filterdispatcher; is the heart of Shiro; All detailed interactions are controlled by SecurityManager;
Manages all Subject, and is responsible for authentication and authorization, and session, cache management.


Authenticator: The authenticator, which is responsible for the principal authentication, is an extension point, assuming that the user believes that the Shiro default
Not good. Be able to define the implementation yourself. It requires a certification strategy (authentication strategy). That is, when the user is counted
The certification passed;

Authrizer: An authorization, or an Access controller. Used to determine whether the subject has permission to perform the corresponding operation;
User access to what features are in the app;
Realm: Able to have 1 or more realms that can be thought of as a secure Entity data source, which is used to obtain security entities;
Can be a JDBC implementation. It can also be an LDAP implementation. Or a memory implementation, etc.; NOTE: Shiro
Do not know where your users/permissions are stored and in what format. So we generally need to implement ourselves in the application
Realm.
SessionManager: Assuming that the Servlet should know the concept of the session, the session needs someone to manage it.
Its life cycle, this component is SessionManager, and Shiro not only enough in the WEB environment, but also
Can be used in the environment such as ordinary javase environment, EJB and so on, all of them, Shiro abstract a Session of his own
To manage the data that interacts between the subject and the app. Such words. For example, we use the WEB environment, just started to be a
Web server, and then to the EJB server, when you want to put two server session data in one place,
At this point, you can implement your own distributed session (such as putting data into Memcached server);
Sessiondao:: DAO Everyone has used, data access to ask the object. A CRUD for a conversation, for example, we want to put the session
Save to the database, you can implement your own Sessiondao. By writing to a database such as JDBC, for example, to
The Session is placed in the Memcached. Be able to achieve their own Memcached Sessiondao; in addition Sessiondao
Cache can be used to improve performance;
CacheManager: Cache controller. To manage caches such as users, roles, permissions, and so on. Since these data are basically
Very little to change, put in the cache to improve the performance of the interview
Cryptography:password module, Shiro improves some of the common cryptographic components used for such password encryption/decryption.
The Shiro architecture and its components have been realized. Next, learn the components of Shiro.BASIC Table Structure Resource: Represents a menu element, a page button element, and so on. The menu element is used to display the interface menu, and the page button is an action that can be performed on each page, such as adding, changing, deleting a button, and using type to differentiate the element type (for example, menu. button for buttons), priority is the ordering of elements. such as the menu display order; permission represents the permission; If the user menu uses user:*. That is, after the menu is licensed to the user. The user has the user:* permission, if the user added button to use User:create, that is, the user added button authorization to the user, the user has user:create permission. Available indicates whether the resource is available. If the menu is displayed/not displayed.
Role: role represents the character identifier. such as admin, used for background inference. Description represents a description of a role, such as a super administrator, used for front-end display to the user; Resource_ids represents a list of resources owned by the role, that is, the list of permissions that the role has (display roles), that is, the role is a collection of permission strings. Available indicates whether the role is available.



Organizational structure: Name indicates the organization names. Priority is the sort of organization, that is, the order of display; available Indicates whether the organization is available.

User: Username represents the user name, Role_ids represents a list of roles owned by the user, the ability to obtain a list of their permission strings through the role, and locked indicates whether the user is locked out.



Shiro System Architecture Subject: The subject, can see the subject can be no matter what can interact with the application of the "user";
SecurityManager: Equivalent to Dispatcherservlet in SPRINGMVC or Struts2
Filterdispatcher; is the heart of Shiro. All detailed interactions are controlled through SecurityManager. it tube
Manages all Subject, and is responsible for authentication and authorization, and session, cache management.


Authenticator: The authenticator, which is responsible for the principal authentication, is an extension point. Assume that the user believes that the Shiro default
It is not good to be able to define its own implementation, it needs authentication policy (authentication strategy), that is, when the user
the certification passed;
Authrizer: An authorization, or an Access controller. Used to determine whether the principal has permission to perform the corresponding operation. That control
User access to what features are in the app;
Realm: Capable of 1 or more realms. Can be thought of as a security Entity data source. That is used to obtain a security entity;
Can be a JDBC implementation, or it can be an LDAP implementation, or a memory implementation, etc.; NOTE: Shiro
Do not know where your users/permissions are stored and in what format. So we generally need to implement ourselves in the application
Realm;
SessionManager: Assuming that the Servlet should know the concept of the session, the session needs someone to manage it.
Its life cycle, this component is SessionManager. Shiro is not only sufficient in the WEB environment, but also
Can be used in the environment such as ordinary javase environment, EJB and so on. All of it, Shiro an abstraction of his own Session.
To manage the data that interacts between the subject and the application, for example, in a WEB environment. Just started out as a
Web server, and then the EJB server. At this point, you want to put two server session data in one place,
At this point, you can implement your own distributed session (such as putting data into Memcached server);
Sessiondao: DAO has been used by everyone. Data Access object, used for session CRUD, for example we want to put the session
Save to the database, you can implement your own Sessiondao, write to the database by using JDBC, for example, to
The Session is put into the Memcached, can realize their own Memcached Sessiondao, another Sessiondao
Caches can be cached using the cache. To improve performance.
CacheManager: Cache controller to manage caches such as users, roles, permissions, and so on, since these data are basically
Very little to change, put in the cache to improve the performance of the interview
Cryptography:password module, Shiro improves some of the common cryptographic components used for such password encryption/decryption.Shiro User Process Shiro not to maintain the user, maintenance rights, these need we to design/provide, and then through
The corresponding interfaces are injected to the Shiro.
For a good frame, from the outside view should
It has easy-to-use APIs, and the API contract understands. From the inside, it should have an extensible
Architecture, which is easy to insert user-defined implementations, because no frame can meet all the requirements.
First of all. Let's take a look at Shiro from the outside, that is, from an application perspective, to see how to use Shiro to complete the work. Such as
:
You can see that the object that the app code interacts directly with is subject. That is to say Shiro's external API core is subject;
The meaning of each of its APIs:
Subject: Main body. Represents the current "user", this user is not necessarily a detailed person. Interacting with the current app
No matter what is Subject, such as web crawler. Robots, etc., is an abstract concept. All Subject are bound
To SecurityManager. All interactions with Subject will be entrusted to SecurityManager, who can recognize the Subject
to be a façade; SecurityManager is the actual runner.
SecurityManager: Security Manager, that is, all security-related operations will interact with SecurityManager;
And it manages all the Subject. Be able to see that it is the core of the Shiro, it is responsible for the other components described behind
Interaction, assuming that you have learned SPRINGMVC, you can think of it as a dispatcherservlet front-end controller;

Realm:: Domain. Shiro from the Realm to obtain security data (such as users, roles, permissions), that is, SecurityManager
You want to verify the user identity. Then it needs to get the corresponding user from realm to determine whether the user's identity is legitimate, also need to get the user's corresponding role/permissions from realm to verify whether the user can operate;
Into DataSource. That is, a secure data source.



That means for us. One of the simplest Shiro applications:
1, the application code through the Subject for authentication and authorization. and Subject paid SecurityManager;
2, we need to give Shiro SecurityManager to inject Realm, so that SecurityManager can get legal
Users and their permissions are inferred.


Click to open link

Hands-on implementation of Java Permissions (1)-shiro Introduction

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.