package com.xcong.excoin.common.system.service;
|
|
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.asymmetric.Sign;
|
import cn.hutool.crypto.asymmetric.SignAlgorithm;
|
import com.xcong.excoin.common.exception.GlobalException;
|
import com.xcong.excoin.common.system.bean.LoginUserBean;
|
import com.xcong.excoin.modules.member.dao.MemberDao;
|
import com.xcong.excoin.modules.member.entity.MemberEntity;
|
import com.xcong.excoin.utils.MessageSourceUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* @Author wzy
|
* @Date 2020/5/11
|
* @email wangdoubleone@gmail.com
|
* @Version V1.0
|
**/
|
@Slf4j
|
@Service("userDetailsService")
|
public class UserDetailsServiceImpl implements UserDetailsService {
|
|
@Resource
|
private MemberDao memberDao;
|
|
@Override
|
public LoginUserBean loadUserByUsername(String username) throws UsernameNotFoundException {
|
log.info("#登陆账号:{}#", username);
|
List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
|
// GrantedAuthority grantedAuthority = new SimpleGrantedAuthority("ROLE_ADMIN");
|
// grantedAuthorities.add(grantedAuthority);
|
|
MemberEntity memberEntity = memberDao.selectMemberInfoByAccount(username);
|
if (memberEntity != null) {
|
memberEntity.setPassword(new BCryptPasswordEncoder().encode(memberEntity.getPassword()));
|
} else {
|
throw new UsernameNotFoundException("");
|
}
|
|
if (MemberEntity.ACCOUNT_STATUS_DISABLED == memberEntity.getAccountStatus()) {
|
throw new GlobalException(MessageSourceUtils.getString("member_service_0092"));
|
}
|
|
return new LoginUserBean(memberEntity, null, null);
|
}
|
}
|