|
|
@ -8,17 +8,21 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
|
|
|
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
|
|
|
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
|
|
|
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenPageReqVO;
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenPageReqVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserBaseVO;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2RefreshTokenDO;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2RefreshTokenDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2AccessTokenMapper;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2AccessTokenMapper;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2RefreshTokenMapper;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2RefreshTokenMapper;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.redis.oauth2.OAuth2AccessTokenRedisDAO;
|
|
|
|
import cn.iocoder.yudao.module.system.dal.redis.oauth2.OAuth2AccessTokenRedisDAO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
@ -44,6 +48,9 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private OAuth2ClientService oauth2ClientService;
|
|
|
|
private OAuth2ClientService oauth2ClientService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private AdminUserService adminUserService;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public OAuth2AccessTokenDO createAccessToken(Long userId, Integer userType, String clientId, List<String> scopes) {
|
|
|
|
public OAuth2AccessTokenDO createAccessToken(Long userId, Integer userType, String clientId, List<String> scopes) {
|
|
|
@ -139,7 +146,16 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
|
|
|
|
.setClientId(clientDO.getClientId()).setScopes(refreshTokenDO.getScopes())
|
|
|
|
.setClientId(clientDO.getClientId()).setScopes(refreshTokenDO.getScopes())
|
|
|
|
.setRefreshToken(refreshTokenDO.getRefreshToken())
|
|
|
|
.setRefreshToken(refreshTokenDO.getRefreshToken())
|
|
|
|
.setExpiresTime(LocalDateTime.now().plusSeconds(clientDO.getAccessTokenValiditySeconds()));
|
|
|
|
.setExpiresTime(LocalDateTime.now().plusSeconds(clientDO.getAccessTokenValiditySeconds()));
|
|
|
|
accessTokenDO.setTenantId(TenantContextHolder.getTenantId()); // 手动设置租户编号,避免缓存到 Redis 的时候,无对应的租户编号
|
|
|
|
// 手动设置租户编号,避免缓存到 Redis 的时候,无对应的租户编号
|
|
|
|
|
|
|
|
accessTokenDO.setTenantId(TenantContextHolder.getTenantId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Long userId = accessTokenDO.getUserId();
|
|
|
|
|
|
|
|
AdminUserDO user = adminUserService.getUser(userId);
|
|
|
|
|
|
|
|
System.out.println(user);
|
|
|
|
|
|
|
|
Integer whiteList = user.getWhiteList();
|
|
|
|
|
|
|
|
if (whiteList == 0){
|
|
|
|
|
|
|
|
accessTokenDO.setExpiresTime(LocalDateTime.now().plus(1, ChronoUnit.YEARS));
|
|
|
|
|
|
|
|
}
|
|
|
|
oauth2AccessTokenMapper.insert(accessTokenDO);
|
|
|
|
oauth2AccessTokenMapper.insert(accessTokenDO);
|
|
|
|
// 记录到 Redis 中
|
|
|
|
// 记录到 Redis 中
|
|
|
|
oauth2AccessTokenRedisDAO.set(accessTokenDO);
|
|
|
|
oauth2AccessTokenRedisDAO.set(accessTokenDO);
|
|
|
|