加免
Showing
6 changed files
with
69 additions
and
4 deletions
| ... | @@ -85,4 +85,9 @@ public class Upgrade extends BaseEntity { | ... | @@ -85,4 +85,9 @@ public class Upgrade extends BaseEntity { |
| 85 | */ | 85 | */ |
| 86 | private String constrain; | 86 | private String constrain; |
| 87 | 87 | ||
| 88 | /** | ||
| 89 | * 应用密钥 | ||
| 90 | */ | ||
| 91 | private String appSecret; | ||
| 92 | |||
| 88 | } | 93 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -55,4 +55,11 @@ public class UpgradeBo extends BaseBO { | ... | @@ -55,4 +55,11 @@ public class UpgradeBo extends BaseBO { |
| 55 | * 描述 | 55 | * 描述 |
| 56 | */ | 56 | */ |
| 57 | private String remark; | 57 | private String remark; |
| 58 | |||
| 59 | /** | ||
| 60 | * 应用密钥 | ||
| 61 | */ | ||
| 62 | private String appSecret; | ||
| 63 | |||
| 64 | |||
| 58 | } | 65 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -76,4 +76,10 @@ public class UpgradeVo { | ... | @@ -76,4 +76,10 @@ public class UpgradeVo { |
| 76 | * 强制升级(0否 1是) | 76 | * 强制升级(0否 1是) |
| 77 | */ | 77 | */ |
| 78 | private String constrain; | 78 | private String constrain; |
| 79 | |||
| 80 | /** | ||
| 81 | * 应用密钥 | ||
| 82 | */ | ||
| 83 | private String appSecret; | ||
| 84 | |||
| 79 | } | 85 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -10,6 +10,7 @@ import com.lego.core.domin.vo.CourseVo; | ... | @@ -10,6 +10,7 @@ import com.lego.core.domin.vo.CourseVo; |
| 10 | import com.lego.core.domin.vo.QuestionVo; | 10 | import com.lego.core.domin.vo.QuestionVo; |
| 11 | import com.lego.core.domin.vo.ResourceVo; | 11 | import com.lego.core.domin.vo.ResourceVo; |
| 12 | import com.lego.core.domin.vo.UpgradeVo; | 12 | import com.lego.core.domin.vo.UpgradeVo; |
| 13 | import com.lego.system.domain.vo.SysOssVo; | ||
| 13 | 14 | ||
| 14 | import java.rmi.ServerException; | 15 | import java.rmi.ServerException; |
| 15 | import java.util.List; | 16 | import java.util.List; |
| ... | @@ -42,6 +43,8 @@ public interface IUpgradeService { | ... | @@ -42,6 +43,8 @@ public interface IUpgradeService { |
| 42 | */ | 43 | */ |
| 43 | boolean addUpgrade(UpgradeBo UpgradeBo) throws ServerException; | 44 | boolean addUpgrade(UpgradeBo UpgradeBo) throws ServerException; |
| 44 | 45 | ||
| 46 | UpgradeVo getById(String id); | ||
| 47 | |||
| 45 | 48 | ||
| 46 | /** | 49 | /** |
| 47 | * 修改 | 50 | * 修改 | ... | ... |
| ... | @@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil; | ... | @@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil; |
| 5 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 5 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 6 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 6 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| 7 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 7 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| 8 | import com.lego.common.constant.CacheNames; | ||
| 8 | import com.lego.common.core.page.TableDataInfo; | 9 | import com.lego.common.core.page.TableDataInfo; |
| 9 | import com.lego.common.core.service.ConfigService; | 10 | import com.lego.common.core.service.ConfigService; |
| 10 | import com.lego.common.core.service.OssService; | 11 | import com.lego.common.core.service.OssService; |
| ... | @@ -23,6 +24,7 @@ import com.lego.core.service.*; | ... | @@ -23,6 +24,7 @@ import com.lego.core.service.*; |
| 23 | import com.lego.system.domain.vo.SysOssVo; | 24 | import com.lego.system.domain.vo.SysOssVo; |
| 24 | import com.lego.system.service.ISysOssService; | 25 | import com.lego.system.service.ISysOssService; |
| 25 | import lombok.RequiredArgsConstructor; | 26 | import lombok.RequiredArgsConstructor; |
| 27 | import org.springframework.cache.annotation.Cacheable; | ||
| 26 | import org.springframework.stereotype.Service; | 28 | import org.springframework.stereotype.Service; |
| 27 | 29 | ||
| 28 | import java.rmi.ServerException; | 30 | import java.rmi.ServerException; |
| ... | @@ -57,6 +59,7 @@ public class UpgradeServiceImpl implements IUpgradeService { | ... | @@ -57,6 +59,7 @@ public class UpgradeServiceImpl implements IUpgradeService { |
| 57 | resourceVo.setBuildingBlocks(buildingBlocks); | 59 | resourceVo.setBuildingBlocks(buildingBlocks); |
| 58 | 60 | ||
| 59 | List<CourseVo> courses = courseService.list(); | 61 | List<CourseVo> courses = courseService.list(); |
| 62 | resourceVo.setCourses(courses); | ||
| 60 | 63 | ||
| 61 | List<QuestionVo> questions = questionService.list(); | 64 | List<QuestionVo> questions = questionService.list(); |
| 62 | resourceVo.setQuestions(questions); | 65 | resourceVo.setQuestions(questions); |
| ... | @@ -64,8 +67,6 @@ public class UpgradeServiceImpl implements IUpgradeService { | ... | @@ -64,8 +67,6 @@ public class UpgradeServiceImpl implements IUpgradeService { |
| 64 | List<AdvertVo> adverts = advertService.list(); | 67 | List<AdvertVo> adverts = advertService.list(); |
| 65 | resourceVo.setAdverts(adverts); | 68 | resourceVo.setAdverts(adverts); |
| 66 | 69 | ||
| 67 | resourceVo.setCourses(courses); | ||
| 68 | |||
| 69 | String siteUrl = configService.getConfigValue("sys.site.url"); | 70 | String siteUrl = configService.getConfigValue("sys.site.url"); |
| 70 | SiteVo siteVo = new SiteVo(); | 71 | SiteVo siteVo = new SiteVo(); |
| 71 | siteVo.setUrl(siteUrl); | 72 | siteVo.setUrl(siteUrl); |
| ... | @@ -109,7 +110,16 @@ public class UpgradeServiceImpl implements IUpgradeService { | ... | @@ -109,7 +110,16 @@ public class UpgradeServiceImpl implements IUpgradeService { |
| 109 | public boolean addUpgrade(UpgradeBo UpgradeBo) { | 110 | public boolean addUpgrade(UpgradeBo UpgradeBo) { |
| 110 | Upgrade upgrade = BeanUtil.toBean(UpgradeBo, Upgrade.class); | 111 | Upgrade upgrade = BeanUtil.toBean(UpgradeBo, Upgrade.class); |
| 111 | upgrade.setId(null); | 112 | upgrade.setId(null); |
| 112 | return baseMapper.insert(upgrade) > 0; | 113 | int result = baseMapper.insert(upgrade); |
| 114 | getById(upgrade.getId()); | ||
| 115 | return result > 0; | ||
| 116 | } | ||
| 117 | |||
| 118 | @Cacheable(cacheNames = CacheNames.SYS_OSS, key = "#id") | ||
| 119 | @Override | ||
| 120 | public UpgradeVo getById(String id) { | ||
| 121 | UpgradeVo vo = baseMapper.selectVoById(id); | ||
| 122 | return vo; | ||
| 113 | } | 123 | } |
| 114 | 124 | ||
| 115 | /** | 125 | /** |
| ... | @@ -124,7 +134,9 @@ public class UpgradeServiceImpl implements IUpgradeService { | ... | @@ -124,7 +134,9 @@ public class UpgradeServiceImpl implements IUpgradeService { |
| 124 | public boolean updateUpgrade(UpgradeBo upgradeBo) throws ServerException { | 134 | public boolean updateUpgrade(UpgradeBo upgradeBo) throws ServerException { |
| 125 | checkExists(upgradeBo.getId()); | 135 | checkExists(upgradeBo.getId()); |
| 126 | Upgrade upgrade = BeanUtil.toBean(upgradeBo, Upgrade.class); | 136 | Upgrade upgrade = BeanUtil.toBean(upgradeBo, Upgrade.class); |
| 127 | return baseMapper.updateById(upgrade) > 0; | 137 | int result = baseMapper.updateById(upgrade); |
| 138 | getById(upgrade.getId()); | ||
| 139 | return result > 0; | ||
| 128 | } | 140 | } |
| 129 | 141 | ||
| 130 | /** | 142 | /** | ... | ... |
| 1 | package com.lego.framework.config; | 1 | package com.lego.framework.config; |
| 2 | 2 | ||
| 3 | import cn.dev33.satoken.context.SaHolder; | ||
| 4 | import cn.dev33.satoken.context.model.SaRequest; | ||
| 3 | import cn.dev33.satoken.dao.SaTokenDao; | 5 | import cn.dev33.satoken.dao.SaTokenDao; |
| 6 | import cn.dev33.satoken.exception.NotLoginException; | ||
| 4 | import cn.dev33.satoken.interceptor.SaInterceptor; | 7 | import cn.dev33.satoken.interceptor.SaInterceptor; |
| 5 | import cn.dev33.satoken.jwt.StpLogicJwtForSimple; | 8 | import cn.dev33.satoken.jwt.StpLogicJwtForSimple; |
| 6 | import cn.dev33.satoken.router.SaRouter; | 9 | import cn.dev33.satoken.router.SaRouter; |
| 7 | import cn.dev33.satoken.stp.StpInterface; | 10 | import cn.dev33.satoken.stp.StpInterface; |
| 8 | import cn.dev33.satoken.stp.StpLogic; | 11 | import cn.dev33.satoken.stp.StpLogic; |
| 9 | import cn.dev33.satoken.stp.StpUtil; | 12 | import cn.dev33.satoken.stp.StpUtil; |
| 13 | import com.lego.common.utils.EncryptUtils; | ||
| 14 | import com.lego.common.utils.StringUtils; | ||
| 10 | import com.lego.common.utils.spring.SpringUtils; | 15 | import com.lego.common.utils.spring.SpringUtils; |
| 11 | import com.lego.framework.config.properties.SecurityProperties; | 16 | import com.lego.framework.config.properties.SecurityProperties; |
| 12 | import com.lego.framework.handler.AllUrlHandler; | 17 | import com.lego.framework.handler.AllUrlHandler; |
| ... | @@ -16,9 +21,13 @@ import lombok.RequiredArgsConstructor; | ... | @@ -16,9 +21,13 @@ import lombok.RequiredArgsConstructor; |
| 16 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
| 17 | import org.springframework.context.annotation.Bean; | 22 | import org.springframework.context.annotation.Bean; |
| 18 | import org.springframework.context.annotation.Configuration; | 23 | import org.springframework.context.annotation.Configuration; |
| 24 | import org.springframework.util.CollectionUtils; | ||
| 19 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | 25 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
| 20 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | 26 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| 21 | 27 | ||
| 28 | import java.util.Arrays; | ||
| 29 | import java.util.List; | ||
| 30 | |||
| 22 | /** | 31 | /** |
| 23 | * sa-token 配置 | 32 | * sa-token 配置 |
| 24 | * | 33 | * |
| ... | @@ -30,6 +39,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ... | @@ -30,6 +39,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| 30 | public class SaTokenConfig implements WebMvcConfigurer { | 39 | public class SaTokenConfig implements WebMvcConfigurer { |
| 31 | 40 | ||
| 32 | private final SecurityProperties securityProperties; | 41 | private final SecurityProperties securityProperties; |
| 42 | private final PlusSaTokenDao plusSaTokenDao; | ||
| 33 | 43 | ||
| 34 | /** | 44 | /** |
| 35 | * 注册sa-token的拦截器 | 45 | * 注册sa-token的拦截器 |
| ... | @@ -46,7 +56,29 @@ public class SaTokenConfig implements WebMvcConfigurer { | ... | @@ -46,7 +56,29 @@ public class SaTokenConfig implements WebMvcConfigurer { |
| 46 | // 对未排除的路径进行检查 | 56 | // 对未排除的路径进行检查 |
| 47 | .check(() -> { | 57 | .check(() -> { |
| 48 | // 检查是否登录 是否有token | 58 | // 检查是否登录 是否有token |
| 59 | SaRequest request = SaHolder.getRequest(); | ||
| 60 | String version = request.getHeader("version"); | ||
| 61 | if(StringUtils.isNotBlank(version)) { | ||
| 62 | String token = StpUtil.getTokenValue(); | ||
| 63 | String secret = plusSaTokenDao.get(version); | ||
| 64 | String appSecret = EncryptUtils.decryptByAes(secret); | ||
| 65 | String explicitToken = EncryptUtils.decryptByAes(token,appSecret); | ||
| 66 | List<String> list = Arrays.asList(explicitToken.split("&")); | ||
| 67 | if(!CollectionUtils.isEmpty(list)){ | ||
| 68 | long time = System.currentTimeMillis(); | ||
| 69 | long period = time-Long.valueOf(list.get(0)); | ||
| 70 | if(period<60 && period>0){ | ||
| 71 | |||
| 72 | } | ||
| 73 | else{ | ||
| 74 | throw NotLoginException.newInstance("", "-2", "token 无效", token).setCode(403); | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
| 78 | else{ | ||
| 49 | StpUtil.checkLogin(); | 79 | StpUtil.checkLogin(); |
| 80 | } | ||
| 81 | |||
| 50 | 82 | ||
| 51 | // 有效率影响 用于临时测试 | 83 | // 有效率影响 用于临时测试 |
| 52 | // if (log.isDebugEnabled()) { | 84 | // if (log.isDebugEnabled()) { | ... | ... |
-
Please register or sign in to post a comment