Commit 8cede6922c43eefb1ade6c1ad8831430c6165a05
1 parent
054c12eb
系统激活信息查询后台提交
Signed-off-by: TanYibin <5491541@qq.com>
Showing
1 changed file
with
49 additions
and
0 deletions
huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/LoginController.java
... | ... | @@ -74,9 +74,13 @@ import com.auth0.jwt.JWTVerifier; |
74 | 74 | import com.auth0.jwt.algorithms.Algorithm; |
75 | 75 | import com.auth0.jwt.exceptions.JWTVerificationException; |
76 | 76 | import com.auth0.jwt.exceptions.TokenExpiredException; |
77 | +import com.auth0.jwt.interfaces.DecodedJWT; | |
77 | 78 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
78 | 79 | import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
79 | 80 | |
81 | +import cn.hutool.core.date.DatePattern; | |
82 | +import cn.hutool.core.date.DateUnit; | |
83 | +import cn.hutool.core.date.DateUtil; | |
80 | 84 | import cn.hutool.core.util.RandomUtil; |
81 | 85 | import io.swagger.annotations.Api; |
82 | 86 | import io.swagger.annotations.ApiOperation; |
... | ... | @@ -200,6 +204,51 @@ public class LoginController { |
200 | 204 | // systemSync.sendSysAnnouncement(sysUser); |
201 | 205 | return result; |
202 | 206 | } |
207 | + | |
208 | + @ApiOperation("系统激活信息查询") | |
209 | + @GetMapping(value = "/querySystemActivationInfo") | |
210 | + public Result<?> querySystemActivationInfo() throws IOException { | |
211 | + Result<?> result = new Result(); | |
212 | + // 是否需要校验激活码 | |
213 | + if (applicationConfig.getCheckSystemActivationCode() == null) { | |
214 | + result.setSuccess(false); | |
215 | + result.setCode(499); | |
216 | + result.setMessage("是否检查系统激活码参数未启用"); | |
217 | + return result; | |
218 | + } | |
219 | + if (!applicationConfig.getCheckSystemActivationCode()) { | |
220 | + result.setSuccess(true); | |
221 | + result.setCode(200); | |
222 | + return result; | |
223 | + } | |
224 | + try { | |
225 | + String activationCode = huahengRedisUtil.get(HuahengJwtUtil.SYSTEM_ACTIVATION_CODE_KEY, String.class); | |
226 | + if (StringUtils.isEmpty(activationCode)) { | |
227 | + result.setSuccess(false); | |
228 | + result.setCode(499); | |
229 | + result.setMessage("系统激活码为空"); | |
230 | + return result; | |
231 | + } | |
232 | + // 验证激活码 | |
233 | + Algorithm algorithm = Algorithm.RSA256(new SystemRSA256Key().getPublicKey(), new SystemRSA256Key().getPrivateKey()); | |
234 | + JWTVerifier verifier = | |
235 | + JWT.require(algorithm).withClaim("operator", applicationConfig.getArtifactId()).withIssuer(applicationConfig.getArtifactId()).build(); | |
236 | + DecodedJWT decodedJWT = verifier.verify(activationCode); | |
237 | + Map<String, String> returnMap = new HashMap<String, String>(); | |
238 | + returnMap.put("audience", decodedJWT.getClaim("aud").asString()); | |
239 | + returnMap.put("expirationTime", DateUtil.format(decodedJWT.getClaim("exp").asDate(), DatePattern.NORM_DATE_PATTERN)); | |
240 | + return Result.OK("系统激活信息查询成功", returnMap); | |
241 | + } catch (TokenExpiredException e) { | |
242 | + result.setSuccess(false); | |
243 | + result.setCode(499); | |
244 | + result.setMessage("系统激活授权期限已到期"); | |
245 | + } catch (Exception e) { | |
246 | + result.setSuccess(false); | |
247 | + result.setCode(499); | |
248 | + result.setMessage("系统激活码无效"); | |
249 | + } | |
250 | + return result; | |
251 | + } | |
203 | 252 | |
204 | 253 | @ApiOperation("系统激活API") |
205 | 254 | @RequestMapping(value = "/systemActivation", method = RequestMethod.POST) |
... | ... |