xiangpei
2024-07-09 9a7ee496344f044c89deddb70600b7e4d6017e1f
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
package com.ycl.jxkg.service.impl;
 
import com.ycl.jxkg.config.property.SystemConfig;
import com.ycl.jxkg.domain.entity.User;
import com.ycl.jxkg.service.AuthenticationService;
import com.ycl.jxkg.service.UserService;
import com.ycl.jxkg.utils.RsaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
 
@Service
public class AuthenticationServiceImpl implements AuthenticationService {
 
    private final SystemConfig systemConfig;
 
    @Autowired
    public AuthenticationServiceImpl(SystemConfig systemConfig) {
        this.systemConfig = systemConfig;
    }
 
    @Override
    public boolean authUser(User user, String username, String password) {
        if (user == null) {
            return false;
        }
        String encodePwd = user.getPassword();
        if (null == encodePwd || encodePwd.length() == 0) {
            return false;
        }
        String pwd = pwdDecode(encodePwd);
        return pwd.equals(password);
    }
 
    @Override
    public String pwdEncode(String password) {
        return RsaUtil.rsaEncode(systemConfig.getPwdKey().getPublicKey(), password);
    }
 
    @Override
    public String pwdDecode(String encodePwd) {
        return RsaUtil.rsaDecode(systemConfig.getPwdKey().getPrivateKey(), encodePwd);
    }
 
 
}