diff --git a/pig-common/pig-common-core/src/main/resources/META-INF/spring.factories b/pig-common/pig-common-core/src/main/resources/META-INF/spring.factories index 05d43238df785668cad272af6d87ad2a82dcb23a..6cce8b4783ef8ba4fce5d80fa51777ee40dec704 100755 --- a/pig-common/pig-common-core/src/main/resources/META-INF/spring.factories +++ b/pig-common/pig-common-core/src/main/resources/META-INF/spring.factories @@ -2,6 +2,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.pig4cloud.pig.common.core.config.JacksonConfig,\ com.pig4cloud.pig.common.core.config.RedisTemplateConfig,\ com.pig4cloud.pig.common.core.config.RestTemplateConfig,\ - com.pig4cloud.pig.common.core.exception.GlobalExceptionHandler,\ com.pig4cloud.pig.common.core.util.SpringContextHolder,\ com.pig4cloud.pig.common.core.mybatis.WebMvcConfig diff --git a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/GlobalExceptionHandler.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/GlobalExceptionHandlerResolver.java similarity index 83% rename from pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/GlobalExceptionHandler.java rename to pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/GlobalExceptionHandlerResolver.java index 373f05eadcb72d8909b9b1b473ea1f8bb1263abd..f21cfacdeb2aee7c33c0bbad2925bd69196da538 100755 --- a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/GlobalExceptionHandler.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/GlobalExceptionHandlerResolver.java @@ -16,11 +16,12 @@ * */ -package com.pig4cloud.pig.common.core.exception; +package com.pig4cloud.pig.common.security.component; import com.pig4cloud.pig.common.core.util.R; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; +import org.springframework.security.access.AccessDeniedException; import org.springframework.validation.BindException; import org.springframework.validation.FieldError; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -37,7 +38,7 @@ import java.util.List; */ @Slf4j @RestControllerAdvice -public class GlobalExceptionHandler { +public class GlobalExceptionHandlerResolver { /** * 全局异常. * @@ -51,6 +52,19 @@ public class GlobalExceptionHandler { return R.failed(e); } + /** + * AccessDeniedException + * + * @param e the e + * @return R + */ + @ExceptionHandler(AccessDeniedException.class) + @ResponseStatus(HttpStatus.FORBIDDEN) + public R handleAccessDeniedException(AccessDeniedException e) { + log.warn("拒绝授权异常信息 ex={}", e.getLocalizedMessage()); + return R.failed(e.getLocalizedMessage()); + } + /** * validation Exception (以json形式传参) * @@ -64,6 +78,7 @@ public class GlobalExceptionHandler { log.warn(fieldErrors.get(0).getDefaultMessage()); return R.failed(fieldErrors.get(0).getDefaultMessage()); } + /** * validation Exception (以form-data形式传参) *