mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-10-14 13:50:25 +00:00
feat 同步商业版代码
This commit is contained in:
@@ -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, "用户未登录");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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鉴权业务异常
|
||||
*/
|
||||
|
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user