feat 同步商业版代码

This commit is contained in:
bootx
2025-04-27 21:46:54 +08:00
parent 36a6901f8e
commit 3ec34a191c
1067 changed files with 19660 additions and 26251 deletions

View File

@@ -1,6 +1,6 @@
package cn.bootx.platform.starter.auth.exception;
import cn.bootx.platform.core.exception.BizInfoException;
import cn.bootx.platform.core.exception.BizException;
import static cn.bootx.platform.core.code.CommonErrorCode.AUTHENTICATION_FAIL;
@@ -10,14 +10,14 @@ import static cn.bootx.platform.core.code.CommonErrorCode.AUTHENTICATION_FAIL;
* @author xxm
* @since 2021/12/22
*/
public class NotLoginException extends BizInfoException {
public class NotLoginException extends BizException {
public NotLoginException(String msg) {
super(AUTHENTICATION_FAIL, msg);
}
public NotLoginException() {
super(AUTHENTICATION_FAIL, "未登录");
super(AUTHENTICATION_FAIL, "用户未登录");
}
}

View File

@@ -3,10 +3,15 @@ package cn.bootx.platform.starter.auth.handler;
import cn.bootx.platform.core.code.CommonCode;
import cn.bootx.platform.core.rest.Res;
import cn.bootx.platform.core.rest.result.Result;
import cn.bootx.platform.starter.auth.exception.NotLoginException;
import cn.bootx.platform.starter.auth.exception.RouterCheckException;
import cn.dev33.satoken.exception.SaTokenException;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -21,6 +26,26 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class SaExceptionHandler {
/**
* 未登录返回401
*/
@ExceptionHandler(NotLoginException.class)
public ResponseEntity<Result<Void>> handleNotLoginException(NotLoginException ex){
log.info(ex.getMessage(), ex);
Result<Void> result = Res.response(ex.getCode(), ex.getMessage(), MDC.get(CommonCode.TRACE_ID));
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(result);
}
/**
* 路径无权访问
*/
@ExceptionHandler(RouterCheckException.class)
public ResponseEntity<Result<Void>> handleBusinessException(RouterCheckException ex) {
log.info(ex.getMessage(), ex);
Result<Void> result = Res.response(ex.getCode(), ex.getMessage(), MDC.get(CommonCode.TRACE_ID));
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(result);
}
/**
* sa鉴权业务异常
*/

View File

@@ -3,6 +3,7 @@ package cn.bootx.platform.starter.auth.handler;
import cn.bootx.platform.common.spring.util.WebServletUtil;
import cn.bootx.platform.starter.auth.exception.RouterCheckException;
import cn.bootx.platform.starter.auth.service.RouterCheck;
import cn.bootx.platform.starter.auth.util.SecurityUtil;
import cn.dev33.satoken.fun.SaFunction;
import cn.dev33.satoken.router.SaRouter;
import lombok.RequiredArgsConstructor;
@@ -42,6 +43,9 @@ public class SaRouteHandler implements InitializingBean {
SaRouter.stop();
}
else {
// 如果未登录, 提示未登录
SecurityUtil.getUserId();
// 已经登录提示没有权限
log.warn("{} 没有对应的权限", WebServletUtil.getPath());
throw new RouterCheckException();
}