ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java
@@ -13,8 +13,8 @@ import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.framework.config.properties.CaptchaProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -42,18 +42,8 @@ @Autowired private RedisCache redisCache; // éªè¯ç ç±»å @Value("${captcha.captchaType}") private String captchaType; // éªè¯ç ç±»å« @Value("${captcha.captchaCategory}") private String captchaCategory; // æ°åéªè¯ç 使° @Value("${captcha.captchaNumberLength}") private int numberLength; // å符éªè¯ç é¿åº¦ @Value("${captcha.captchaCharLength}") private int charLength; @Autowired private CaptchaProperties captchaProperties; /** * çæéªè¯ç @@ -67,17 +57,17 @@ // çæéªè¯ç CodeGenerator codeGenerator; AbstractCaptcha captcha; switch (captchaType) { switch (captchaProperties.getType()) { case "math": codeGenerator = new MathGenerator(numberLength); codeGenerator = new MathGenerator(captchaProperties.getNumberLength()); break; case "char": codeGenerator = new RandomGenerator(charLength); codeGenerator = new RandomGenerator(captchaProperties.getCharLength()); break; default: throw new IllegalArgumentException("éªè¯ç ç±»åå¼å¸¸"); } switch (captchaCategory) { switch (captchaProperties.getCategory()) { case "line": captcha = lineCaptcha; break; @@ -92,9 +82,9 @@ } captcha.setGenerator(codeGenerator); captcha.createCode(); if ("math".equals(captchaType)) { if ("math".equals(captchaProperties.getType())) { code = getCodeResult(captcha.getCode()); } else if ("char".equals(captchaType)) { } else if ("char".equals(captchaProperties.getType())) { code = captcha.getCode(); } redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); @@ -105,6 +95,7 @@ } private String getCodeResult(String capStr) { int numberLength = captchaProperties.getNumberLength(); int a = Convert.toInt(StrUtil.sub(capStr, 0, numberLength).trim()); char operator = capStr.charAt(numberLength); int b = Convert.toInt(StrUtil.sub(capStr, numberLength + 1, numberLength + 1 + numberLength).trim()); ruoyi-admin/src/main/resources/application.yml
@@ -15,13 +15,13 @@ captcha: # éªè¯ç ç±»å math æ°ç»è®¡ç® char å符éªè¯ captchaType: math type: math # line çº¿æ®µå¹²æ° circle ååå¹²æ° shear ææ²å¹²æ° captchaCategory: circle category: circle # æ°åéªè¯ç 使° captchaNumberLength: 1 numberLength: 1 # å符éªè¯ç é¿åº¦ captchaCharLength: 4 charLength: 4 # å¼åç¯å¢é ç½® server: @@ -187,8 +187,6 @@ swagger: # æ¯å¦å¼å¯swagger enabled: true # 请æ±åç¼ pathMapping: /dev-api # æ é¢ title: 'æ é¢ï¼RuoYi-Vue-Plusåå°ç®¡çç³»ç»_æ¥å£ææ¡£' # æè¿° @@ -206,7 +204,7 @@ urlPatterns: /system/*,/monitor/*,/tool/* # å ¨å±çº¿ç¨æ± ç¸å ³é ç½® threadPoolConfig: thread-pool: # æ¯å¦å¼å¯çº¿ç¨æ± enabled: false # æ ¸å¿çº¿ç¨æ± å¤§å° ruoyi-common/pom.xml
@@ -145,6 +145,11 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- èªå¨çæYMLé ç½®å ³èJSONæä»¶ --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> </dependency> </dependencies> ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java
@@ -3,7 +3,8 @@ import cn.hutool.core.util.StrUtil; import com.ruoyi.common.filter.RepeatableFilter; import com.ruoyi.common.filter.XssFilter; import org.springframework.beans.factory.annotation.Value; import com.ruoyi.framework.config.properties.XssProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -15,41 +16,33 @@ /** * Filteré ç½® * * @author ruoyi * @author Lion Li */ @Configuration public class FilterConfig { @Value("${xss.enabled}") private String enabled; public class FilterConfig { @Value("${xss.excludes}") private String excludes; @Autowired private XssProperties xssProperties; @Value("${xss.urlPatterns}") private String urlPatterns; @SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({"rawtypes", "unchecked"}) @Bean public FilterRegistrationBean xssFilterRegistration() { public FilterRegistrationBean xssFilterRegistration() { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setDispatcherTypes(DispatcherType.REQUEST); registration.setFilter(new XssFilter()); registration.addUrlPatterns(StrUtil.split(urlPatterns, ",")); registration.addUrlPatterns(StrUtil.split(xssProperties.getUrlPatterns(), ",")); registration.setName("xssFilter"); registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE); Map<String, String> initParameters = new HashMap<String, String>(); initParameters.put("excludes", excludes); initParameters.put("enabled", enabled); initParameters.put("excludes", xssProperties.getExcludes()); initParameters.put("enabled", xssProperties.getEnabled()); registration.setInitParameters(initParameters); return registration; } @SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({"rawtypes", "unchecked"}) @Bean public FilterRegistrationBean someFilterRegistration() { public FilterRegistrationBean someFilterRegistration() { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(new RepeatableFilter()); registration.addUrlPatterns("/*"); ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java
ÎļþÃû´Ó ruoyi-admin/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java ÐÞ¸Ä @@ -1,4 +1,4 @@ package com.ruoyi.web.core.config; package com.ruoyi.framework.config; import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; import com.ruoyi.common.config.RuoYiConfig; @@ -37,12 +37,6 @@ */ @Autowired private RuoYiConfig ruoyiConfig; /** * 设置请æ±çç»ä¸åç¼ */ @Value("${swagger.pathMapping}") private String pathMapping; /** * æ é¢ ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java
@@ -1,8 +1,9 @@ package com.ruoyi.framework.config; import com.ruoyi.common.utils.Threads; import com.ruoyi.framework.config.properties.ThreadPoolProperties; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -21,43 +22,31 @@ @Configuration public class ThreadPoolConfig { // æ ¸å¿çº¿ç¨æ± å¤§å° @Value("${threadPoolConfig.corePoolSize}") private int corePoolSize; // æå¤§å¯å建ççº¿ç¨æ° @Value("${threadPoolConfig.maxPoolSize}") private int maxPoolSize; // éåæå¤§é¿åº¦ @Value("${threadPoolConfig.queueCapacity}") private int queueCapacity; // çº¿ç¨æ± ç»´æ¤çº¿ç¨æå 许çç©ºé²æ¶é´ @Value("${threadPoolConfig.keepAliveSeconds}") private int keepAliveSeconds; // çº¿ç¨æ± 对æç»ä»»å¡(æ 线ç¨å¯ç¨)çå¤ççç¥ @Value("${threadPoolConfig.rejectedExecutionHandler}") private String rejectedExecutionHandler; @Autowired private ThreadPoolProperties threadPoolProperties; @Bean(name = "threadPoolTaskExecutor") @ConditionalOnProperty(prefix = "threadPoolTaskExecutor", name = "enabled", havingValue = "true") public ThreadPoolTaskExecutor threadPoolTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setMaxPoolSize(maxPoolSize); executor.setCorePoolSize(corePoolSize); executor.setQueueCapacity(queueCapacity); executor.setKeepAliveSeconds(keepAliveSeconds); executor.setMaxPoolSize(threadPoolProperties.getMaxPoolSize()); executor.setCorePoolSize(threadPoolProperties.getCorePoolSize()); executor.setQueueCapacity(threadPoolProperties.getQueueCapacity()); executor.setKeepAliveSeconds(threadPoolProperties.getKeepAliveSeconds()); RejectedExecutionHandler handler; if (rejectedExecutionHandler.equals("CallerRunsPolicy")) { handler = new ThreadPoolExecutor.CallerRunsPolicy(); } else if (rejectedExecutionHandler.equals("DiscardOldestPolicy")) { handler = new ThreadPoolExecutor.DiscardOldestPolicy(); } else if (rejectedExecutionHandler.equals("DiscardPolicy")) { handler = new ThreadPoolExecutor.DiscardPolicy(); } else { handler = new ThreadPoolExecutor.AbortPolicy(); switch (threadPoolProperties.getRejectedExecutionHandler()) { case "CallerRunsPolicy": handler = new ThreadPoolExecutor.CallerRunsPolicy(); break; case "DiscardOldestPolicy": handler = new ThreadPoolExecutor.DiscardOldestPolicy(); break; case "DiscardPolicy": handler = new ThreadPoolExecutor.DiscardPolicy(); break; default: handler = new ThreadPoolExecutor.AbortPolicy(); break; } executor.setRejectedExecutionHandler(handler); return executor; @@ -68,7 +57,7 @@ */ @Bean(name = "scheduledExecutorService") protected ScheduledExecutorService scheduledExecutorService() { return new ScheduledThreadPoolExecutor(corePoolSize, return new ScheduledThreadPoolExecutor(threadPoolProperties.getCorePoolSize(), new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build()) { @Override protected void afterExecute(Runnable r, Throwable t) { ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/CaptchaProperties.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,24 @@ package com.ruoyi.framework.config.properties; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; /** * éªè¯ç é ç½®å±æ§ * * @author Lion Li */ @Data @Component @ConfigurationProperties(prefix = "captcha") public class CaptchaProperties { // éªè¯ç ç±»å private String type; // éªè¯ç ç±»å« private String category; // æ°åéªè¯ç 使° private Integer numberLength; // å符éªè¯ç é¿åº¦ private Integer charLength; } ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/DruidProperties.java
@@ -1,76 +1,54 @@ package com.ruoyi.framework.config.properties; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import com.alibaba.druid.pool.DruidDataSource; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; /** * druid é ç½®å±æ§ * * @author ruoyi * * @author Lion Li */ @Data @Configuration public class DruidProperties { @Value("${spring.datasource.druid.initialSize}") @ConfigurationProperties(prefix = "spring.datasource.druid") public class DruidProperties { /** åå§è¿æ¥æ° */ private int initialSize; @Value("${spring.datasource.druid.minIdle}") /** æå°è¿æ¥æ± æ°é */ private int minIdle; @Value("${spring.datasource.druid.maxActive}") /** æå¤§è¿æ¥æ± æ°é */ private int maxActive; @Value("${spring.datasource.druid.maxWait}") /** é ç½®è·åè¿æ¥çå¾ è¶ æ¶çæ¶é´ */ private int maxWait; @Value("${spring.datasource.druid.timeBetweenEvictionRunsMillis}") /** é ç½®é´éå¤ä¹ æè¿è¡ä¸æ¬¡æ£æµï¼æ£æµéè¦å ³éç空é²è¿æ¥ï¼å使¯æ¯«ç§ */ private int timeBetweenEvictionRunsMillis; @Value("${spring.datasource.druid.minEvictableIdleTimeMillis}") /** é ç½®ä¸ä¸ªè¿æ¥å¨æ± 䏿å°çåçæ¶é´ï¼å使¯æ¯«ç§ */ private int minEvictableIdleTimeMillis; @Value("${spring.datasource.druid.maxEvictableIdleTimeMillis}") /** é ç½®ä¸ä¸ªè¿æ¥å¨æ± 䏿大çåçæ¶é´ï¼å使¯æ¯«ç§ */ private int maxEvictableIdleTimeMillis; @Value("${spring.datasource.druid.validationQuery}") /** é ç½®æ£æµè¿æ¥æ¯å¦ææ */ private String validationQuery; @Value("${spring.datasource.druid.testWhileIdle}") /** åå§è¿æ¥æ° */ private boolean testWhileIdle; @Value("${spring.datasource.druid.testOnBorrow}") /** åå§è¿æ¥æ° */ private boolean testOnBorrow; @Value("${spring.datasource.druid.testOnReturn}") /** åå§è¿æ¥æ° */ private boolean testOnReturn; public DruidDataSource dataSource(DruidDataSource datasource) { /** é ç½®åå§å大å°ãæå°ãæå¤§ */ public DruidDataSource dataSource(DruidDataSource datasource) { datasource.setInitialSize(initialSize); datasource.setMaxActive(maxActive); datasource.setMinIdle(minIdle); /** é ç½®è·åè¿æ¥çå¾ è¶ æ¶çæ¶é´ */ datasource.setMaxWait(maxWait); /** é ç½®é´éå¤ä¹ æè¿è¡ä¸æ¬¡æ£æµï¼æ£æµéè¦å ³éç空é²è¿æ¥ï¼å使¯æ¯«ç§ */ datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); /** é ç½®ä¸ä¸ªè¿æ¥å¨æ± 䏿å°ãæå¤§çåçæ¶é´ï¼å使¯æ¯«ç§ */ datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis); /** * ç¨æ¥æ£æµè¿æ¥æ¯å¦ææçsqlï¼è¦æ±æ¯ä¸ä¸ªæ¥è¯¢è¯å¥ï¼å¸¸ç¨select 'x'ã妿validationQuery为nullï¼testOnBorrowãtestOnReturnãtestWhileIdleé½ä¸ä¼èµ·ä½ç¨ã */ datasource.setValidationQuery(validationQuery); /** 建议é 置为trueï¼ä¸å½±åæ§è½ï¼å¹¶ä¸ä¿è¯å®å ¨æ§ãç³è¯·è¿æ¥çæ¶åæ£æµï¼å¦æç©ºé²æ¶é´å¤§äºtimeBetweenEvictionRunsMillisï¼æ§è¡validationQueryæ£æµè¿æ¥æ¯å¦ææã */ datasource.setTestWhileIdle(testWhileIdle); /** ç³è¯·è¿æ¥æ¶æ§è¡validationQueryæ£æµè¿æ¥æ¯å¦ææï¼åäºè¿ä¸ªé ç½®ä¼é使§è½ã */ datasource.setTestOnBorrow(testOnBorrow); /** å½è¿è¿æ¥æ¶æ§è¡validationQueryæ£æµè¿æ¥æ¯å¦ææï¼åäºè¿ä¸ªé ç½®ä¼é使§è½ã */ datasource.setTestOnReturn(testOnReturn); return datasource; } ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,36 @@ package com.ruoyi.framework.config.properties; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; /** * éªè¯ç é ç½®å±æ§ * * @author Lion Li */ @Data @Component @ConfigurationProperties(prefix = "swagger") public class SwaggerProperties { /** * éªè¯ç ç±»å */ private Boolean enabled; /** * éªè¯ç ç±»å« */ private String title; /** * æ°åéªè¯ç 使° */ private String description; /** * å符éªè¯ç é¿åº¦ */ private String version; } ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/ThreadPoolProperties.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,47 @@ package com.ruoyi.framework.config.properties; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; /** * éªè¯ç é ç½®å±æ§ * * @author Lion Li */ @Data @Component @ConfigurationProperties(prefix = "thread-pool") public class ThreadPoolProperties { /** * æ¯å¦å¼å¯çº¿ç¨æ± */ private boolean enabled; /** * æ ¸å¿çº¿ç¨æ± å¤§å° */ private int corePoolSize; /** * æå¤§å¯å建ççº¿ç¨æ° */ private int maxPoolSize; /** * éåæå¤§é¿åº¦ */ private int queueCapacity; /** * çº¿ç¨æ± ç»´æ¤çº¿ç¨æå 许çç©ºé²æ¶é´ */ private int keepAliveSeconds; /** * çº¿ç¨æ± 对æç»ä»»å¡(æ 线ç¨å¯ç¨)çå¤ççç¥ */ private String rejectedExecutionHandler; } ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/TokenProperties.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,26 @@ package com.ruoyi.framework.config.properties; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @Data @Component @ConfigurationProperties(prefix = "token") public class TokenProperties { /** * 令çèªå®ä¹æ è¯ */ private String header; /** * 令çç§é¥ */ private String secret; /** * ä»¤çæææï¼é»è®¤30åéï¼ */ private int expireTime; } ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/XssProperties.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,32 @@ package com.ruoyi.framework.config.properties; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; /** * éªè¯ç é ç½®å±æ§ * * @author Lion Li */ @Data @Component @ConfigurationProperties(prefix = "xss") public class XssProperties { /** * è¿æ»¤å¼å ³ */ private String enabled; /** * æé¤é¾æ¥ï¼å¤ä¸ªç¨éå·åéï¼ */ private String excludes; /** * å¹é 龿¥ */ private String urlPatterns; } ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java
@@ -10,11 +10,11 @@ import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.ip.AddressUtils; import com.ruoyi.common.utils.ip.IpUtils; import com.ruoyi.framework.config.properties.TokenProperties; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; @@ -25,22 +25,10 @@ /** * tokenéªè¯å¤ç * * @author ruoyi * @author Lion Li */ @Component public class TokenService { // 令çèªå®ä¹æ è¯ @Value("${token.header}") private String header; // 令çç§é¥ @Value("${token.secret}") private String secret; // ä»¤çæææï¼é»è®¤30åéï¼ @Value("${token.expireTime}") private int expireTime; public class TokenService { protected static final long MILLIS_SECOND = 1000; @@ -51,17 +39,18 @@ @Autowired private RedisCache redisCache; @Autowired private TokenProperties tokenProperties; /** * è·åç¨æ·èº«ä»½ä¿¡æ¯ * * @return ç¨æ·ä¿¡æ¯ */ public LoginUser getLoginUser(HttpServletRequest request) { public LoginUser getLoginUser(HttpServletRequest request) { // è·åè¯·æ±æºå¸¦ç令ç String token = getToken(request); if (Validator.isNotEmpty(token)) { if (Validator.isNotEmpty(token)) { Claims claims = parseToken(token); // è§£æå¯¹åºçæé以åç¨æ·ä¿¡æ¯ String uuid = (String) claims.get(Constants.LOGIN_USER_KEY); @@ -75,10 +64,8 @@ /** * è®¾ç½®ç¨æ·èº«ä»½ä¿¡æ¯ */ public void setLoginUser(LoginUser loginUser) { if (Validator.isNotNull(loginUser) && Validator.isNotEmpty(loginUser.getToken())) { public void setLoginUser(LoginUser loginUser) { if (Validator.isNotNull(loginUser) && Validator.isNotEmpty(loginUser.getToken())) { refreshToken(loginUser); } } @@ -86,10 +73,8 @@ /** * å é¤ç¨æ·èº«ä»½ä¿¡æ¯ */ public void delLoginUser(String token) { if (Validator.isNotEmpty(token)) { public void delLoginUser(String token) { if (Validator.isNotEmpty(token)) { String userKey = getTokenKey(token); redisCache.deleteObject(userKey); } @@ -101,8 +86,7 @@ * @param loginUser ç¨æ·ä¿¡æ¯ * @return 令ç */ public String createToken(LoginUser loginUser) { public String createToken(LoginUser loginUser) { String token = IdUtil.fastUUID(); loginUser.setToken(token); setUserAgent(loginUser); @@ -119,12 +103,10 @@ * @param loginUser * @return 令ç */ public void verifyToken(LoginUser loginUser) { public void verifyToken(LoginUser loginUser) { long expireTime = loginUser.getExpireTime(); long currentTime = System.currentTimeMillis(); if (expireTime - currentTime <= MILLIS_MINUTE_TEN) { if (expireTime - currentTime <= MILLIS_MINUTE_TEN) { refreshToken(loginUser); } } @@ -134,13 +116,12 @@ * * @param loginUser ç»å½ä¿¡æ¯ */ public void refreshToken(LoginUser loginUser) { public void refreshToken(LoginUser loginUser) { loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); loginUser.setExpireTime(loginUser.getLoginTime() + tokenProperties.getExpireTime() * MILLIS_MINUTE); // æ ¹æ®uuidå°loginUserç¼å String userKey = getTokenKey(loginUser.getToken()); redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); redisCache.setCacheObject(userKey, loginUser, tokenProperties.getExpireTime(), TimeUnit.MINUTES); } /** @@ -148,8 +129,7 @@ * * @param loginUser ç»å½ä¿¡æ¯ */ public void setUserAgent(LoginUser loginUser) { public void setUserAgent(LoginUser loginUser) { UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent")); String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); loginUser.setIpaddr(ip); @@ -164,11 +144,10 @@ * @param claims æ°æ®å£°æ * @return 令ç */ private String createToken(Map<String, Object> claims) { private String createToken(Map<String, Object> claims) { String token = Jwts.builder() .setClaims(claims) .signWith(SignatureAlgorithm.HS512, secret).compact(); .signWith(SignatureAlgorithm.HS512, tokenProperties.getSecret()).compact(); return token; } @@ -178,10 +157,9 @@ * @param token 令ç * @return æ°æ®å£°æ */ private Claims parseToken(String token) { private Claims parseToken(String token) { return Jwts.parser() .setSigningKey(secret) .setSigningKey(tokenProperties.getSecret()) .parseClaimsJws(token) .getBody(); } @@ -192,8 +170,7 @@ * @param token 令ç * @return ç¨æ·å */ public String getUsernameFromToken(String token) { public String getUsernameFromToken(String token) { Claims claims = parseToken(token); return claims.getSubject(); } @@ -204,18 +181,15 @@ * @param request * @return token */ private String getToken(HttpServletRequest request) { String token = request.getHeader(header); if (Validator.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) { private String getToken(HttpServletRequest request) { String token = request.getHeader(tokenProperties.getHeader()); if (Validator.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) { token = token.replace(Constants.TOKEN_PREFIX, ""); } return token; } private String getTokenKey(String uuid) { private String getTokenKey(String uuid) { return Constants.LOGIN_TOKEN_KEY + uuid; } }