package com.kidgrow.order.service.impl;
|
|
import com.kidgrow.common.feign.UserService;
|
import com.kidgrow.common.model.LoginAppUser;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.security.authentication.DisabledException;
|
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
|
/**
|
* 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
|
*
|
* @Description: <br>
|
* @Project: <br>
|
* @CreateDate: Created in 2020/2/22 08:36 <br>
|
* @Author: <a href="4345453@kidgrow.com">liuke</a>
|
*/
|
@Slf4j
|
@Service
|
public class UserDetailServiceTestImpl {
|
@Resource
|
private UserService userService;
|
|
public UserDetails loadUserByUsername(String username) {
|
LoginAppUser loginAppUser = userService.findByUsername(username);
|
if (loginAppUser == null) {
|
throw new InternalAuthenticationServiceException("用户名或密码错误");
|
}
|
|
return checkUser(loginAppUser);
|
}
|
|
private LoginAppUser checkUser(LoginAppUser loginAppUser) {
|
if (loginAppUser != null && !loginAppUser.isEnabled()) {
|
throw new DisabledException("用户已作废");
|
}
|
return loginAppUser;
|
}
|
}
|