2f067e16 by chentao

token

1 parent f835cc59
......@@ -47,25 +47,25 @@ public class UpgradeController extends BaseController {
/**
* 新增
*
* @param UpgradeBo
* @param upgradeBo
* @return
*/
@RepeatSubmit()
@PostMapping()
public R<Void> addUpgrade(@RequestBody UpgradeBo UpgradeBo) throws ServerException {
return toAjax(service.addUpgrade(UpgradeBo));
public R<Void> addUpgrade(@RequestBody UpgradeBo upgradeBo) throws ServerException {
return toAjax(service.addUpgrade(upgradeBo));
}
/**
* 修改
*
* @param UpgradeBo
* @param upgradeBo
* @return
*/
@RepeatSubmit()
@PutMapping
public R<Void> updateUpgrade(@RequestBody UpgradeBo UpgradeBo) throws ServerException {
return toAjax(service.updateUpgrade(UpgradeBo));
public R<Void> updateUpgrade(@RequestBody UpgradeBo upgradeBo) throws ServerException {
return toAjax(service.updateUpgrade(upgradeBo));
}
/**
......
......@@ -45,6 +45,8 @@ public interface CacheNames {
*/
String SYS_OSS = "sys_oss#30d";
String VERSION_CODE = "version_code";
/**
* OSS配置
*/
......
......@@ -137,7 +137,10 @@ public class EncryptUtils {
* @return 解密后字符串
*/
public static String decryptByAes(String data) {
return decryptByAes(data, AES_SECRET);
if(StringUtils.isNotBlank(data)) {
return decryptByAes(data, AES_SECRET);
}
return "";
}
/**
......@@ -343,4 +346,10 @@ public class EncryptUtils {
return SmUtil.sm3(data);
}
public static void main(String[] args) {
String str = System.currentTimeMillis()+"&1915289501429309442";
System.out.println(encryptByAes(str,"abcdefghijklmnopqrstuvwx"));
}
}
......
......@@ -2,18 +2,12 @@ package com.lego.core.service;
import com.lego.common.core.page.TableDataInfo;
import com.lego.core.domin.bo.QuestionBo;
import com.lego.core.domin.bo.QuestionQueryBo;
import com.lego.core.domin.bo.UpgradeBo;
import com.lego.core.domin.bo.UpgradeQueryBo;
import com.lego.core.domin.vo.CourseVo;
import com.lego.core.domin.vo.QuestionVo;
import com.lego.core.domin.vo.ResourceVo;
import com.lego.core.domin.vo.UpgradeVo;
import com.lego.system.domain.vo.SysOssVo;
import java.rmi.ServerException;
import java.util.List;
/**
* APP升级Service接口
......@@ -43,8 +37,6 @@ public interface IUpgradeService {
*/
boolean addUpgrade(UpgradeBo UpgradeBo) throws ServerException;
UpgradeVo getById(String id);
/**
* 修改
......
......@@ -10,7 +10,9 @@ import com.lego.common.core.page.TableDataInfo;
import com.lego.common.core.service.ConfigService;
import com.lego.common.core.service.OssService;
import com.lego.common.utils.DateUtils;
import com.lego.common.utils.EncryptUtils;
import com.lego.common.utils.MessageUtils;
import com.lego.common.utils.redis.CacheUtils;
import com.lego.core.annotation.LanguageAnnotation;
import com.lego.core.domin.Course;
import com.lego.core.domin.Upgrade;
......@@ -91,6 +93,7 @@ public class UpgradeServiceImpl implements IUpgradeService {
.eq(Upgrade::getLanguage, language));
List<UpgradeVo> list = page.getRecords();
for (UpgradeVo vo : list) {
vo.setAppSecret(EncryptUtils.decryptByAes(vo.getAppSecret()));
if (StrUtil.isNotBlank(vo.getFileOssId())) {
SysOssVo oss = iSysOssService.getById(Long.valueOf(vo.getFileOssId()));
vo.setOssUrl(oss.getUrl());
......@@ -102,26 +105,20 @@ public class UpgradeServiceImpl implements IUpgradeService {
/**
* 新增
*
* @param UpgradeBo
* @param upgradeBo
* @return
*/
@Override
@LanguageAnnotation
public boolean addUpgrade(UpgradeBo UpgradeBo) {
Upgrade upgrade = BeanUtil.toBean(UpgradeBo, Upgrade.class);
public boolean addUpgrade(UpgradeBo upgradeBo) {
upgradeBo.setAppSecret(EncryptUtils.encryptByAes(upgradeBo.getAppSecret()));
Upgrade upgrade = BeanUtil.toBean(upgradeBo, Upgrade.class);
upgrade.setId(null);
int result = baseMapper.insert(upgrade);
getById(upgrade.getId());
CacheUtils.put(CacheNames.VERSION_CODE, upgrade.getId(), upgrade.getAppSecret());
return result > 0;
}
@Cacheable(cacheNames = CacheNames.SYS_OSS, key = "#id")
@Override
public UpgradeVo getById(String id) {
UpgradeVo vo = baseMapper.selectVoById(id);
return vo;
}
/**
* 修改
*
......@@ -133,9 +130,10 @@ public class UpgradeServiceImpl implements IUpgradeService {
@LanguageAnnotation
public boolean updateUpgrade(UpgradeBo upgradeBo) throws ServerException {
checkExists(upgradeBo.getId());
upgradeBo.setAppSecret(EncryptUtils.encryptByAes(upgradeBo.getAppSecret()));
Upgrade upgrade = BeanUtil.toBean(upgradeBo, Upgrade.class);
int result = baseMapper.updateById(upgrade);
getById(upgrade.getId());
CacheUtils.put(CacheNames.VERSION_CODE, upgrade.getId(), upgrade.getAppSecret());
return result > 0;
}
......
......@@ -10,8 +10,10 @@ import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpLogic;
import cn.dev33.satoken.stp.StpUtil;
import com.lego.common.constant.CacheNames;
import com.lego.common.utils.EncryptUtils;
import com.lego.common.utils.StringUtils;
import com.lego.common.utils.redis.CacheUtils;
import com.lego.common.utils.spring.SpringUtils;
import com.lego.framework.config.properties.SecurityProperties;
import com.lego.framework.handler.AllUrlHandler;
......@@ -39,7 +41,6 @@ import java.util.List;
public class SaTokenConfig implements WebMvcConfigurer {
private final SecurityProperties securityProperties;
private final PlusSaTokenDao plusSaTokenDao;
/**
* 注册sa-token的拦截器
......@@ -58,16 +59,23 @@ public class SaTokenConfig implements WebMvcConfigurer {
// 检查是否登录 是否有token
SaRequest request = SaHolder.getRequest();
String version = request.getHeader("version");
System.out.println("versioncode:"+version);
if(StringUtils.isNotBlank(version)) {
String token = StpUtil.getTokenValue();
String secret = plusSaTokenDao.get(version);
String token = request.getHeader("token");
System.out.println("token:"+token);
SaTokenDao plusSaTokenDao = saTokenDao();
String secret = CacheUtils.get(CacheNames.VERSION_CODE,version);
System.out.println("secret:"+secret);
String appSecret = EncryptUtils.decryptByAes(secret);
System.out.println("appSecret"+appSecret);
String explicitToken = EncryptUtils.decryptByAes(token,appSecret);
System.out.println("explicitToken"+explicitToken);
List<String> list = Arrays.asList(explicitToken.split("&"));
if(!CollectionUtils.isEmpty(list)){
long time = System.currentTimeMillis();
long period = time-Long.valueOf(list.get(0));
if(period<60 && period>0){
System.out.println("period:"+period);
if(period<60000 && period>0){
}
else{
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!