In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 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.
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.