diff --git a/docs/nacos/DEFAULT_GROUP.zip b/docs/nacos/DEFAULT_GROUP.zip index 6ea4bb058..8f407537c 100644 Binary files a/docs/nacos/DEFAULT_GROUP.zip and b/docs/nacos/DEFAULT_GROUP.zip differ 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", "*");