All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.service.UserServiceImpl.ftl Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package <#if packageName??>${packageName}<#else >${afterEndBo.packageName}.service.security;

<#if isGeneratorBus?? && isGeneratorBus>
import <#if packageName??>${packageName}<#else >${afterEndBo.packageName}.common.entity.${folderName}.SystemAccountEntity;
import <#if packageName??>${packageName}<#else >${afterEndBo.packageName}.service.${folderName}.service.SystemAccountService;
import org.yes.tools.core.exception.YesBaseException;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

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}.common.vo.LoginUserVo;

import java.util.*;


@Service(value = "AdminUserServiceImpl")
public class UserServiceImpl implements UserDetailsService {

<#if isGeneratorBus?? && isGeneratorBus>
    @Autowired
    private SystemAccountService systemAccountService;


    @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<>();

        return createLoginUser(userInfo);
    }

    public UserDetails createLoginUser(Map user) {
        List maps = new ArrayList<>();
        return new LoginUserVo(user, maps);
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy