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);
|
}
|
|
|
}
|