From 89a8f983fd8b6cd27c4905e6ace4c9a73ac2d3b6 Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Mon, 7 Jun 2021 21:06:00 +0800 Subject: [PATCH] =?UTF-8?q?docs:=E6=9B=B4=E6=96=B0=E4=BA=91=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E7=9A=84nacos=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/nacos/DEFAULT_GROUP.zip | Bin 7778 -> 7803 bytes .../security/AuthorizationManager.java | 2 ++ ...GlobalFilter.java => JwtGlobalFilter.java} | 8 ++++---- .../security/ResourceServerConfig.java | 14 +++----------- .../SentinelConfiguration.java | 2 +- .../{WebUtils.java => ResponseUtils.java} | 5 ++--- 6 files changed, 12 insertions(+), 19 deletions(-) rename youlai-gateway/src/main/java/com/youlai/gateway/security/{AuthGlobalFilter.java => JwtGlobalFilter.java} (90%) rename youlai-gateway/src/main/java/com/youlai/gateway/{config => sentinel}/SentinelConfiguration.java (96%) rename youlai-gateway/src/main/java/com/youlai/gateway/util/{WebUtils.java => ResponseUtils.java} (89%) diff --git a/docs/nacos/DEFAULT_GROUP.zip b/docs/nacos/DEFAULT_GROUP.zip index 6ea4bb058a148c8ddd2699820ae830b13c955f23..8f407537c4f0ff4eea79f6e4a39157ceb5f594e4 100644 GIT binary patch delta 3073 zcmZvecT|(f8pb0vNEJhoPUw*iN)t?^MViz=K&1*IY^YL%7@C40qJ}Ec7eqoABV9lw zi7cQ5F-nu(rT2DGmb-U7_nSYSGiQGD%$#?=dFLIuuycXQ)R3A61o-)R7d~NvP`MXY zsK(GRyB8A7^#@5aJJbL`GuDTR=hY+)GtJ@Xt92lX`lq@w8607f@VM)NhnNJmflVB9 z+w!s(847Bgw6+miyJ1sRG#VogR@t!@3kUsxYb`_PphKa(QBTl`*mo43Dts zDY(31-=q{^vP(NiIR%7FJf;kV45_R%ZnW7kuPvHYEAR#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*+piWt4a7hx^nsCxQ$I<^`fWnq?EjL3|B`H8;a^@m z`kSYz^go`AQ`_W@{zg8OMkD{;{l)!la!3D5cAWfoZdH;oGX6X0)$(@Gj{Y9>Pgng> z{GfpSzXs=DEf?TOER|8+vB@#qzM~!e-R3{_^FKCkh%(SaDu175=gM~!W68z+b4%VI NuiuXoj7$Dp{SP>cZdL#Q diff --git a/youlai-gateway/src/main/java/com/youlai/gateway/security/AuthorizationManager.java b/youlai-gateway/src/main/java/com/youlai/gateway/security/AuthorizationManager.java index 1be71ea39..5ba894a9f 100644 --- a/youlai-gateway/src/main/java/com/youlai/gateway/security/AuthorizationManager.java +++ b/youlai-gateway/src/main/java/com/youlai/gateway/security/AuthorizationManager.java @@ -25,6 +25,8 @@ import static com.youlai.common.constant.AuthConstants.AUTHORITY_PREFIX; /** * 网关自定义鉴权管理器 + * @author hxr + * @date 2021-06-07 */ @Component @AllArgsConstructor diff --git a/youlai-gateway/src/main/java/com/youlai/gateway/security/AuthGlobalFilter.java b/youlai-gateway/src/main/java/com/youlai/gateway/security/JwtGlobalFilter.java similarity index 90% rename from youlai-gateway/src/main/java/com/youlai/gateway/security/AuthGlobalFilter.java rename to youlai-gateway/src/main/java/com/youlai/gateway/security/JwtGlobalFilter.java index c2cf4d806..593cd353c 100644 --- a/youlai-gateway/src/main/java/com/youlai/gateway/security/AuthGlobalFilter.java +++ b/youlai-gateway/src/main/java/com/youlai/gateway/security/JwtGlobalFilter.java @@ -6,7 +6,7 @@ import cn.hutool.json.JSONUtil; import com.nimbusds.jose.JWSObject; import com.youlai.common.constant.AuthConstants; import com.youlai.common.result.ResultCode; -import com.youlai.gateway.util.WebUtils; +import com.youlai.gateway.util.ResponseUtils; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.logging.log4j.util.Strings; @@ -28,7 +28,7 @@ import reactor.core.publisher.Mono; */ @Component @Slf4j -public class AuthGlobalFilter implements GlobalFilter, Ordered { +public class JwtGlobalFilter implements GlobalFilter, Ordered { @Autowired private RedisTemplate redisTemplate; @@ -49,7 +49,7 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered { && HttpMethod.DELETE.toString().equals(request.getMethodValue()) // 删除方法 && HttpMethod.PUT.toString().equals(request.getMethodValue()) // 修改方法 ) { - return WebUtils.writeErrorInfoToResponse(response, ResultCode.FORBIDDEN_OPERATION); + return ResponseUtils.writeErrorInfo(response, ResultCode.FORBIDDEN_OPERATION); } // 非JWT或者JWT为空不作处理 @@ -66,7 +66,7 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered { String jti = jsonObject.getStr(AuthConstants.JWT_JTI); Boolean isBlack = redisTemplate.hasKey(AuthConstants.TOKEN_BLACKLIST_PREFIX + jti); if (isBlack) { - return WebUtils.writeErrorInfoToResponse(response, ResultCode.TOKEN_ACCESS_FORBIDDEN); + return ResponseUtils.writeErrorInfo(response, ResultCode.TOKEN_ACCESS_FORBIDDEN); } // 存在token且不是黑名单,request写入JWT的载体信息 diff --git a/youlai-gateway/src/main/java/com/youlai/gateway/security/ResourceServerConfig.java b/youlai-gateway/src/main/java/com/youlai/gateway/security/ResourceServerConfig.java index 76e61ad3e..8e9e79447 100644 --- a/youlai-gateway/src/main/java/com/youlai/gateway/security/ResourceServerConfig.java +++ b/youlai-gateway/src/main/java/com/youlai/gateway/security/ResourceServerConfig.java @@ -3,11 +3,9 @@ package com.youlai.gateway.security; import cn.hutool.core.codec.Base64; import cn.hutool.core.convert.Convert; import cn.hutool.core.io.IoUtil; -import cn.hutool.core.util.ArrayUtil; import com.youlai.common.constant.AuthConstants; import com.youlai.common.result.ResultCode; -import com.youlai.gateway.security.AuthorizationManager; -import com.youlai.gateway.util.WebUtils; +import com.youlai.gateway.util.ResponseUtils; import lombok.AllArgsConstructor; import lombok.Setter; import lombok.SneakyThrows; @@ -28,16 +26,10 @@ import org.springframework.security.web.server.SecurityWebFilterChain; import org.springframework.security.web.server.ServerAuthenticationEntryPoint; import org.springframework.security.web.server.authorization.ServerAccessDeniedHandler; import reactor.core.publisher.Mono; -import sun.misc.BASE64Decoder; -import sun.security.rsa.RSAPublicKeyImpl; import java.io.InputStream; -import java.io.ObjectInputStream; -import java.math.BigInteger; import java.security.KeyFactory; -import java.security.PublicKey; import java.security.interfaces.RSAPublicKey; -import java.security.spec.RSAPublicKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.List; @@ -83,7 +75,7 @@ public class ResourceServerConfig { ServerAccessDeniedHandler accessDeniedHandler() { return (exchange, denied) -> { Mono mono = Mono.defer(() -> Mono.just(exchange.getResponse())) - .flatMap(response -> WebUtils.writeErrorInfoToResponse(response, ResultCode.ACCESS_UNAUTHORIZED)); + .flatMap(response -> ResponseUtils.writeErrorInfo(response, ResultCode.ACCESS_UNAUTHORIZED)); return mono; }; } @@ -95,7 +87,7 @@ public class ResourceServerConfig { ServerAuthenticationEntryPoint authenticationEntryPoint() { return (exchange, e) -> { Mono mono = Mono.defer(() -> Mono.just(exchange.getResponse())) - .flatMap(response -> WebUtils.writeErrorInfoToResponse(response, ResultCode.TOKEN_INVALID_OR_EXPIRED)); + .flatMap(response -> ResponseUtils.writeErrorInfo(response, ResultCode.TOKEN_INVALID_OR_EXPIRED)); return mono; }; } diff --git a/youlai-gateway/src/main/java/com/youlai/gateway/config/SentinelConfiguration.java b/youlai-gateway/src/main/java/com/youlai/gateway/sentinel/SentinelConfiguration.java similarity index 96% rename from youlai-gateway/src/main/java/com/youlai/gateway/config/SentinelConfiguration.java rename to youlai-gateway/src/main/java/com/youlai/gateway/sentinel/SentinelConfiguration.java index 8d55160af..59389d615 100644 --- a/youlai-gateway/src/main/java/com/youlai/gateway/config/SentinelConfiguration.java +++ b/youlai-gateway/src/main/java/com/youlai/gateway/sentinel/SentinelConfiguration.java @@ -1,4 +1,4 @@ -package com.youlai.gateway.config; +package com.youlai.gateway.sentinel; import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler; import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager; diff --git a/youlai-gateway/src/main/java/com/youlai/gateway/util/WebUtils.java b/youlai-gateway/src/main/java/com/youlai/gateway/util/ResponseUtils.java similarity index 89% rename from youlai-gateway/src/main/java/com/youlai/gateway/util/WebUtils.java rename to youlai-gateway/src/main/java/com/youlai/gateway/util/ResponseUtils.java index efb7b1936..8551d3fcf 100644 --- a/youlai-gateway/src/main/java/com/youlai/gateway/util/WebUtils.java +++ b/youlai-gateway/src/main/java/com/youlai/gateway/util/ResponseUtils.java @@ -16,11 +16,10 @@ import java.nio.charset.Charset; /** * @Author haoxr * @Date 2021-01-29 13:30 - * @Version 1.0.0 */ -public class WebUtils { +public class ResponseUtils { - public static Mono writeErrorInfoToResponse(ServerHttpResponse response,ResultCode resultCode){ + public static Mono writeErrorInfo(ServerHttpResponse response, ResultCode resultCode){ response.setStatusCode(HttpStatus.OK); response.getHeaders().set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); response.getHeaders().set("Access-Control-Allow-Origin", "*");