springboot升级至3.2.5
This commit is contained in:
1 parent
7fe5e09eeb
commit
46d343fe4a
17 files changed
+73
-77
No files matched your search
@@ -27,6 +27,10 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
@@ -35,10 +39,6 @@
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
@@ -60,14 +60,9 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-web-servlet</artifactId>
|
||||
<version>${sentinel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-transport-simple-http</artifactId>
|
||||
<version>${sentinel.version}</version>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
<version>${alibaba-sentinel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
|
||||
+1
-16
@@ -3,14 +3,13 @@ package cn.crabc.core.app.config;
|
||||
import cn.crabc.core.app.filter.ApiFilter;
|
||||
import cn.crabc.core.app.filter.AuthInterceptor;
|
||||
import cn.crabc.core.app.filter.JwtInterceptor;
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
|
||||
|
||||
/**
|
||||
* 注册拦截器
|
||||
@@ -56,18 +55,4 @@ public class InterceptorConfig implements WebMvcConfigurer {
|
||||
registration.setOrder(-1);
|
||||
return registration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 限流过滤器
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public FilterRegistrationBean sentinelFilterRegistration() {
|
||||
FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
|
||||
registration.setFilter(new CommonFilter());
|
||||
registration.addUrlPatterns("/api/web/*");
|
||||
registration.setName("sentinelFilter");
|
||||
registration.setOrder(1);
|
||||
return registration;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -10,11 +10,12 @@ import cn.crabc.core.app.util.Result;
|
||||
import cn.crabc.core.app.util.SQLUtil;
|
||||
import cn.crabc.core.app.util.UserThreadLocal;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
+1
-1
@@ -6,11 +6,11 @@ import cn.crabc.core.app.service.system.IBaseAppService;
|
||||
import cn.crabc.core.datasource.util.PageInfo;
|
||||
import cn.crabc.core.app.util.Result;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
+8
-5
@@ -5,10 +5,10 @@ import cn.crabc.core.app.entity.param.UserParam;
|
||||
import cn.crabc.core.app.service.system.IBaseUserService;
|
||||
import cn.crabc.core.app.util.*;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.util.Base64Utils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -38,13 +38,16 @@ public class SysUserController {
|
||||
if (userInfo == null) {
|
||||
return Result.error("账号或密码错误!");
|
||||
}
|
||||
String pwd = new String(Base64Utils.decodeFromString(UserParam.getPassword()), StandardCharsets.UTF_8);
|
||||
String pwd = new String(Base64.decodeBase64(UserParam.getPassword()), StandardCharsets.UTF_8);
|
||||
String md5 = Md5Utils.hash(pwd).toUpperCase();
|
||||
if (!userInfo.getPassword().equals(md5)) {
|
||||
return Result.error("账号或密码错误!");
|
||||
}
|
||||
Map<String, Object> user = new HashMap<>();
|
||||
String token = JwtUtil.createToken(userInfo.getUserId(), userInfo.getUsername());
|
||||
if (token == null) {
|
||||
return Result.error("登录失败");
|
||||
}
|
||||
user.put("expires", 3600);
|
||||
user.put("access_token", token);
|
||||
user.put("refresh_token", UUID.randomUUID().toString().replace("-", ""));
|
||||
@@ -84,12 +87,12 @@ public class SysUserController {
|
||||
if (userInfo == null) {
|
||||
return Result.error("账号不存在!");
|
||||
}
|
||||
String pwd = new String(Base64Utils.decodeFromString(user.getPassword()), StandardCharsets.UTF_8);
|
||||
String pwd = new String(Base64.decodeBase64(user.getPassword()), StandardCharsets.UTF_8);
|
||||
String md5Pwd = Md5Utils.hash(pwd).toUpperCase();
|
||||
if (!userInfo.getPassword().equals(md5Pwd)) {
|
||||
return Result.error("原密码错误!");
|
||||
}
|
||||
String newPwd = new String(Base64Utils.decodeFromString(user.getNewPassword()), StandardCharsets.UTF_8);
|
||||
String newPwd = new String(Base64.decodeBase64(user.getNewPassword()), StandardCharsets.UTF_8);
|
||||
String newMd5Pwd = Md5Utils.hash(newPwd).toUpperCase();
|
||||
userInfo.setPassword(newMd5Pwd);
|
||||
iBaseUserService.updateUser(userInfo);
|
||||
@@ -103,7 +106,7 @@ public class SysUserController {
|
||||
*/
|
||||
@PostMapping("/register")
|
||||
public Result register(@RequestBody UserParam user){
|
||||
String pwd = new String(Base64Utils.decodeFromString(user.getPassword()), StandardCharsets.UTF_8);
|
||||
String pwd = new String(Base64.decodeBase64(user.getPassword()), StandardCharsets.UTF_8);
|
||||
String md5 = Md5Utils.hash(pwd).toUpperCase();
|
||||
user.setPassword(md5);
|
||||
BaseUser baseUser = new BaseUser();
|
||||
|
||||
+1
-1
@@ -3,13 +3,13 @@ package cn.crabc.core.app.exception;
|
||||
import cn.crabc.core.app.util.Result;
|
||||
import cn.crabc.core.datasource.exception.CustomException;
|
||||
import cn.crabc.core.spi.PluginException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 异常统一返回处理
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package cn.crabc.core.app.filter;
|
||||
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ApiFilter implements Filter {
|
||||
|
||||
@@ -7,11 +7,12 @@ import cn.crabc.core.app.enums.ApiAuthEnum;
|
||||
import cn.crabc.core.app.service.system.IBaseApiLogService;
|
||||
import cn.crabc.core.app.util.ApiThreadLocal;
|
||||
import cn.crabc.core.app.util.HmacSHAUtils;
|
||||
import cn.crabc.core.app.util.IPUtil;
|
||||
import cn.crabc.core.app.util.RequestUtils;
|
||||
import cn.crabc.core.datasource.enums.ErrorStatusEnum;
|
||||
import cn.crabc.core.datasource.exception.CustomException;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -20,9 +21,6 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+5
-4
@@ -1,11 +1,12 @@
|
||||
package cn.crabc.core.app.filter;
|
||||
|
||||
import jakarta.servlet.ReadListener;
|
||||
import jakarta.servlet.ServletInputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequestWrapper;
|
||||
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
||||
|
||||
import javax.servlet.ReadListener;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,13 +5,12 @@ import cn.crabc.core.app.util.UserThreadLocal;
|
||||
import cn.crabc.core.datasource.enums.ErrorStatusEnum;
|
||||
import cn.crabc.core.datasource.exception.CustomException;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 登录拦截器
|
||||
*
|
||||
|
||||
+1
-1
@@ -10,13 +10,13 @@ import cn.crabc.core.app.util.UserThreadLocal;
|
||||
import cn.crabc.core.datasource.driver.DataSourceManager;
|
||||
import cn.crabc.core.spi.bean.BaseDataSource;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
|
||||
+3
-2
@@ -12,6 +12,7 @@ import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -36,6 +37,7 @@ public class BaseFlowRuleServiceImpi implements IBaseFlowRuleService {
|
||||
@Autowired
|
||||
private BaseGroupMapper baseGroupMapper;
|
||||
|
||||
@PostConstruct
|
||||
@Scheduled(cron = "*/50 * * * * ?")
|
||||
public void task() {
|
||||
initFlowRule();
|
||||
@@ -47,8 +49,7 @@ public class BaseFlowRuleServiceImpi implements IBaseFlowRuleService {
|
||||
List<FlowRule> rules = new ArrayList<>();
|
||||
List<BaseFlowRule> flowList = this.getCacheFlowList();
|
||||
for (BaseFlowRule flow : flowList) {
|
||||
FlowRule rule = new FlowRule();
|
||||
rule.setResource("/api/web/"+flow.getApiPath());
|
||||
FlowRule rule = new FlowRule("/api/web/"+flow.getApiPath());
|
||||
rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
|
||||
rule.setCount(flow.getFlowCount());
|
||||
rule.setId(flow.getApiId());
|
||||
|
||||
@@ -2,11 +2,12 @@ package cn.crabc.core.app.util;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Jwt工具类
|
||||
@@ -16,8 +17,7 @@ import java.util.Map;
|
||||
public class JwtUtil {
|
||||
private static String header = "Authorization";
|
||||
// 令牌秘钥
|
||||
private static String secret = "crabc";
|
||||
private static int expireTime;
|
||||
private static String secret = "crabcjfakdjfaldjflkadjlafjaldkjlaflkalk";
|
||||
public static final String TOKEN_PREFIX = "bearer ";
|
||||
|
||||
/**
|
||||
@@ -35,10 +35,22 @@ public class JwtUtil {
|
||||
* 生成令牌
|
||||
*/
|
||||
public static String createToken(Map<String, Object> claims) {
|
||||
String token = Jwts.builder()
|
||||
.setClaims(claims)
|
||||
.signWith(SignatureAlgorithm.HS512, secret).compact();
|
||||
return token;
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
try {
|
||||
return Jwts.builder()
|
||||
.header()
|
||||
.add("typ", "JWT")
|
||||
.add("alg", "HS256")
|
||||
.and()
|
||||
.claims(claims)
|
||||
// 令牌ID
|
||||
.id(uuid)
|
||||
.signWith(Keys.hmacShaKeyFor(secret.getBytes()))
|
||||
.compact();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,11 +62,11 @@ public class JwtUtil {
|
||||
public static Claims parseToken(String token) {
|
||||
try {
|
||||
return Jwts.parser()
|
||||
.setSigningKey(secret)
|
||||
.parseClaimsJws(token)
|
||||
.getBody();
|
||||
.verifyWith(Keys.hmacShaKeyFor(secret.getBytes()))
|
||||
.build()
|
||||
.parseSignedClaims(token).getPayload();
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.crabc.core.starter.CrabcConfiguration
|
||||
+1
@@ -0,0 +1 @@
|
||||
cn.crabc.core.starter.CrabcConfiguration
|
||||
@@ -17,20 +17,21 @@
|
||||
|
||||
<properties>
|
||||
<!-- crabc 版本-->
|
||||
<revision>2.8.6</revision>
|
||||
<java.version>11</java.version>
|
||||
<revision>3.0.0</revision>
|
||||
<java.version>21</java.version>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring-boot.version>2.7.17</spring-boot.version>
|
||||
<spring-boot.mybatis.version>2.3.1</spring-boot.mybatis.version>
|
||||
<pagehelper.boot.version>1.4.7</pagehelper.boot.version>
|
||||
<spring-boot.druid.version>1.2.16</spring-boot.druid.version>
|
||||
<fastjson.version>2.0.25</fastjson.version>
|
||||
<jwt.version>0.9.1</jwt.version>
|
||||
<commons-pool2.version>2.11.1</commons-pool2.version>
|
||||
<spring-boot.version>3.2.5</spring-boot.version>
|
||||
<spring-boot.mybatis.version>3.0.3</spring-boot.mybatis.version>
|
||||
<pagehelper.boot.version>2.1.0</pagehelper.boot.version>
|
||||
<spring-boot.druid.version>1.2.22</spring-boot.druid.version>
|
||||
<fastjson.version>2.0.49</fastjson.version>
|
||||
<jwt.version>0.12.5</jwt.version>
|
||||
<commons-pool2.version>2.12.0</commons-pool2.version>
|
||||
<sentinel.version>1.8.6</sentinel.version>
|
||||
<easyexcel.version>3.3.2</easyexcel.version>
|
||||
<alibaba-sentinel.version>2023.0.1.0</alibaba-sentinel.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@@ -52,6 +53,7 @@
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
<parameters>true</parameters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- 统一 revision 版本 -->
|
||||
|
||||
Reference in new issue
Block a user