Custom login control class Demo

public class UserDetailServiceImpl implements UserDetailsService {

    // 使用xml注入
    private SellerService sellerService;

    public void setSellerService(SellerService sellerService) {
        this.sellerService = sellerService;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (username == null || "".equals(username)) {
            return null;
        }
        Seller seller = sellerService.findByName(username);
        if(seller != null) {
            List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
            GrantedAuthority grantedAuthority = new SimpleGrantedAuthority("ROLE_SELLER");
            grantedAuthorities.add(grantedAuthority);
            return new User(username, seller.getPassword(), grantedAuthorities);
        }
        return null;
    }
}

Guess you like

Origin www.cnblogs.com/zhz-8919/p/11256960.html