This commit is contained in:
冷冷 committed 2020-07-13 17:15:27 +08:00
1 parent 0adbc36a3d
commit 1a1ae4dbcb
5 files changed
+20 -6

No files matched your search

@@ -1,5 +1,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.pig4cloud.pigx.common.security.component.GlobalExceptionHandlerResolver,\
com.pig4cloud.pigx.common.security.component.PigxTokenEnhancer,\
com.pig4cloud.pigx.common.security.component.PigxSecurityInnerAspect,\
com.pig4cloud.pigx.common.security.listener.AuthenticationFailureEventListener,\
+5
View File
@@ -26,5 +26,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!--oauth server 依赖-->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
</dependencies>
</project>
@@ -15,10 +15,12 @@
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.security.component;
package com.pig4cloud.pigx.common.sentinel.handle;
import com.alibaba.csp.sentinel.Tracer;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.SpringSecurityMessageSource;
@@ -32,12 +34,17 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.List;
/**
* <p>
* 全局异常处理器结合sentinel 全局异常处理器不能作用在 oauth server https://gitee.com/log4j/pig/issues/I1M2TJ
* </p>
*
* @author lengleng
* @date 2018/8/30 全局异常处理器
* @date 2020-06-29
*/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandlerResolver {
@ConditionalOnExpression("!'${security.oauth2.client.clientId}'.isEmpty()")
public class GlobalBizExceptionHandler {
/**
* 全局异常.
@@ -48,6 +55,9 @@ public class GlobalExceptionHandlerResolver {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R handleGlobalException(Exception e) {
log.error("全局异常信息 ex={}", e.getMessage(), e);
// 业务异常交由 sentinel 记录
Tracer.trace(e);
return R.failed(e.getLocalizedMessage());
}
@@ -1,2 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.pig4cloud.pigx.common.sentinel.SentinelAutoConfiguration
com.pig4cloud.pigx.common.sentinel.SentinelAutoConfiguration,\
com.pig4cloud.pigx.common.sentinel.handle.GlobalBizExceptionHandler
@@ -106,7 +106,6 @@ public class GeneratorServiceImpl implements GeneratorService {
List<GenFormConf> formConfList = genFormConfMapper.selectList(Wrappers.<GenFormConf>lambdaQuery()
.eq(GenFormConf::getTableName, genConfig.getTableName()).orderByDesc(GenFormConf::getCreateTime));
DynamicDataSourceContextHolder.push(genConfig.getDsName());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);