templates.service.UserServiceImpl.ftl Maven / Gradle / Ivy
package <#if packageName??>${packageName}<#else >${afterEndBo.packageName}#if>.service.security;
<#if isGeneratorBus?? && isGeneratorBus>
import <#if packageName??>${packageName}<#else >${afterEndBo.packageName}#if>.common.entity.${folderName}.SystemAccountEntity;
import <#if packageName??>${packageName}<#else >${afterEndBo.packageName}#if>.service.${folderName}.service.SystemAccountService;
import org.yes.tools.core.exception.YesBaseException;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
#if>
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import <#if packageName??>${packageName}<#else >${afterEndBo.packageName}#if>.common.vo.LoginUserVo;
import java.util.*;
@Service(value = "AdminUserServiceImpl")
public class UserServiceImpl implements UserDetailsService {
<#if isGeneratorBus?? && isGeneratorBus>
@Autowired
private SystemAccountService systemAccountService;
#if>
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
<#if isGeneratorBus?? && isGeneratorBus>
SystemAccountEntity systemAccount = systemAccountService.getById(username);
if (Objects.isNull(systemAccount)) {
throw new YesBaseException("401", "token无效");
}
if (systemAccount.getStatus().equals(2)) {
throw new YesBaseException("账号已禁用");
}
JSONObject userInfo = (JSONObject) JSONObject.toJSON(systemAccount);
<#else >
//TODO 例子
// AccountEntity account = accountService.getById(username);
// if (Objects.isNull(account)) {
// throw new YesBaseException("401", "非法token");
// }
// if (account.getStatus().equals(2)) {
// throw new YesBaseException("账号已禁用");
// }
// JSONObject userInfo = (JSONObject) JSONObject.toJSON(account);
Map userInfo = new HashMap<>();
#if>
return createLoginUser(userInfo);
}
public UserDetails createLoginUser(Map user) {
List