Helius
2020-06-02 be6979a915b64b831526baf9052726b5bb5cf152
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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 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("账号已被禁用");
        }
 
        return new LoginUserBean(memberEntity, null, null);
    }
}