In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 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 customize user authentication in springSecurity. 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.
First of all, I need to declare in the xml file. I want to customize the user's authentication class, that is, I want to query from the database myself.
After configuring the custom file, implement it in the module that needs the custom authentication class.
UserDetailsService
Package com.qingmu2.core.service;import com.alibaba.dubbo.config.annotation.Reference;import com.qingmu2.core.pojo.seller.Seller;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.security.core.GrantedAuthority;import org.springframework.security.core.authority.SimpleGrantedAuthority;import org.springframework.security.core.userdetails.User;import org.springframework.security.core.userdetails.UserDetails;import org.springframework.security.core.userdetails.UserDetailsService;import org.springframework.security.core.userdetails.UsernameNotFoundException;import java.util.ArrayList Import java.util.HashMap;import java.util.HashSet;import java.util.List;/** * custom authentication class * @ Auther:qingmu * @ Description: down-to-earth, only to stand out * @ Date:Created in 8:33 2019-5-31 * / public class UserDetailServiceImpl implements UserDetailsService {private SellerService sellerService; public UserDetailServiceImpl () {} @ Override public UserDetails loadUserByUsername (String username) throws UsernameNotFoundException {Seller seller = sellerService.findOne (username) If (null vendor approval) {/ / determine whether a merchant is approved or not. If ("1" .equals (seller.getStatus () {/ / create a collection to store permissions HashSet authorities = new HashSet (); authorities.add (new SimpleGrantedAuthority ("ROLE_SELLER")); / / return the user's information to the authentication class return new User (username,seller.getPassword (), authorities);}} / / if there is no such user, return null return null;} public UserDetailServiceImpl (SellerService sellerService) {this.sellerService = sellerService } public SellerService getSellerService () {return sellerService;} public void setSellerService (SellerService sellerService) {this.sellerService = sellerService;}}
This is the end of this article on "how to customize springSecurity user authentication". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.