From 1ae369855ba448bc2562ebbbe59a89e42b8c53b0 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期二, 19 十月 2021 17:23:14 +0800 Subject: [PATCH] update 优化 多账号体系用户行为监听逻辑 --- ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java | 30 +++++++++++++++++++++++++++--- 1 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java index 9cf69ff..a96450c 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java @@ -1,5 +1,8 @@ package com.ruoyi.framework.web.exception; +import cn.dev33.satoken.exception.NotLoginException; +import cn.dev33.satoken.exception.NotPermissionException; +import cn.dev33.satoken.exception.NotRoleException; import cn.hutool.http.HttpStatus; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.exception.DemoModeException; @@ -7,7 +10,6 @@ import com.ruoyi.common.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.security.access.AccessDeniedException; import org.springframework.validation.BindException; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -30,8 +32,8 @@ /** * 鏉冮檺鏍¢獙寮傚父 */ - @ExceptionHandler(AccessDeniedException.class) - public AjaxResult handleAccessDeniedException(AccessDeniedException e, HttpServletRequest request) + @ExceptionHandler(NotPermissionException.class) + public AjaxResult handleAccessDeniedException(NotPermissionException e, HttpServletRequest request) { String requestURI = request.getRequestURI(); log.error("璇锋眰鍦板潃'{}',鏉冮檺鏍¢獙澶辫触'{}'", requestURI, e.getMessage()); @@ -39,6 +41,28 @@ } /** + * 瑙掕壊鏍¢獙寮傚父 + */ + @ExceptionHandler(NotRoleException.class) + public AjaxResult handleAccessDeniedException(NotRoleException e, HttpServletRequest request) + { + String requestURI = request.getRequestURI(); + log.error("璇锋眰鍦板潃'{}',瑙掕壊鏍¢獙澶辫触'{}'", requestURI, e.getMessage()); + return AjaxResult.error(HttpStatus.HTTP_FORBIDDEN, "娌℃湁瑙掕壊锛岃鑱旂郴绠$悊鍛樻巿鏉�"); + } + + /** + * 璁よ瘉澶辫触 + */ + @ExceptionHandler(NotLoginException.class) + public AjaxResult handleAccessDeniedException(NotLoginException e, HttpServletRequest request) + { + String requestURI = request.getRequestURI(); + log.error("璇锋眰璁块棶锛歿}锛岃璇佸け璐ワ紝鏃犳硶璁块棶绯荤粺璧勬簮", requestURI, e.getMessage()); + return AjaxResult.error(HttpStatus.HTTP_UNAUTHORIZED, StringUtils.format("璇锋眰璁块棶锛歿}锛岃璇佸け璐ワ紝鏃犳硶璁块棶绯荤粺璧勬簮", requestURI)); + } + + /** * 璇锋眰鏂瑰紡涓嶆敮鎸� */ @ExceptionHandler(HttpRequestMethodNotSupportedException.class) -- Gitblit v1.9.3