In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use SpringSecurity to dynamically load user role permissions to achieve login and authentication functions. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
I. the basic knowledge of dynamic data login verification
In the previous article, we have introduced the formLogin login authentication mode of Spring Security, the authority control management model of RBAC, and parsed the login authentication logic source code of Spring Security, and so on. All our user, role, and permission information is written in the configuration file, but in the actual business system, this information is usually stored in the database table of the RBAC permission model. Let's review the core concepts:
The permission model of RBAC can obtain one or more roles assigned to the user from the user, and multiple permissions of the role can be obtained from the user's role. The role information and permission information of a user can be obtained through the association query. In the article on source code parsing, we know that if we don't want users, roles, and permissions to be written in the configuration. We should implement the interface between UserDetails and UserDetailsService to dynamically load this information from the database or other storage.
The above is a summary of some core basic knowledge, if you are not very clear about this knowledge, it is recommended that you read on to this article. If it is still difficult to understand after reading this article, it is recommended that you read the previous article.
II. Interface between UserDetails and UserDetailsService
The UserDetailsService interface has a method called loadUserByUsername, which we implement to dynamically load user, role, and permission information. Function see the meaning of the name: load the user through the user name. The return value of this method is UserDetails. UserDetails is the user information, that is, the user name, password, and permissions that the user has.
Let's take a look at the methods of the UserDetails interface.
Public interface UserDetails extends Serializable {/ / get the user's permission set Collection
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.