mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-03 17:42:20 +08:00
docs:更新云环境的nacos配置
This commit is contained in:
parent
fce4185808
commit
89a8f983fd
Binary file not shown.
@ -25,6 +25,8 @@ import static com.youlai.common.constant.AuthConstants.AUTHORITY_PREFIX;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 网关自定义鉴权管理器
|
* 网关自定义鉴权管理器
|
||||||
|
* @author hxr
|
||||||
|
* @date 2021-06-07
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -6,7 +6,7 @@ import cn.hutool.json.JSONUtil;
|
|||||||
import com.nimbusds.jose.JWSObject;
|
import com.nimbusds.jose.JWSObject;
|
||||||
import com.youlai.common.constant.AuthConstants;
|
import com.youlai.common.constant.AuthConstants;
|
||||||
import com.youlai.common.result.ResultCode;
|
import com.youlai.common.result.ResultCode;
|
||||||
import com.youlai.gateway.util.WebUtils;
|
import com.youlai.gateway.util.ResponseUtils;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.logging.log4j.util.Strings;
|
import org.apache.logging.log4j.util.Strings;
|
||||||
@ -28,7 +28,7 @@ import reactor.core.publisher.Mono;
|
|||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
public class JwtGlobalFilter implements GlobalFilter, Ordered {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate redisTemplate;
|
private RedisTemplate redisTemplate;
|
||||||
@ -49,7 +49,7 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
&& HttpMethod.DELETE.toString().equals(request.getMethodValue()) // 删除方法
|
&& HttpMethod.DELETE.toString().equals(request.getMethodValue()) // 删除方法
|
||||||
&& HttpMethod.PUT.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为空不作处理
|
// 非JWT或者JWT为空不作处理
|
||||||
@ -66,7 +66,7 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
String jti = jsonObject.getStr(AuthConstants.JWT_JTI);
|
String jti = jsonObject.getStr(AuthConstants.JWT_JTI);
|
||||||
Boolean isBlack = redisTemplate.hasKey(AuthConstants.TOKEN_BLACKLIST_PREFIX + jti);
|
Boolean isBlack = redisTemplate.hasKey(AuthConstants.TOKEN_BLACKLIST_PREFIX + jti);
|
||||||
if (isBlack) {
|
if (isBlack) {
|
||||||
return WebUtils.writeErrorInfoToResponse(response, ResultCode.TOKEN_ACCESS_FORBIDDEN);
|
return ResponseUtils.writeErrorInfo(response, ResultCode.TOKEN_ACCESS_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 存在token且不是黑名单,request写入JWT的载体信息
|
// 存在token且不是黑名单,request写入JWT的载体信息
|
@ -3,11 +3,9 @@ package com.youlai.gateway.security;
|
|||||||
import cn.hutool.core.codec.Base64;
|
import cn.hutool.core.codec.Base64;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import com.youlai.common.constant.AuthConstants;
|
import com.youlai.common.constant.AuthConstants;
|
||||||
import com.youlai.common.result.ResultCode;
|
import com.youlai.common.result.ResultCode;
|
||||||
import com.youlai.gateway.security.AuthorizationManager;
|
import com.youlai.gateway.util.ResponseUtils;
|
||||||
import com.youlai.gateway.util.WebUtils;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.SneakyThrows;
|
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.ServerAuthenticationEntryPoint;
|
||||||
import org.springframework.security.web.server.authorization.ServerAccessDeniedHandler;
|
import org.springframework.security.web.server.authorization.ServerAccessDeniedHandler;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import sun.misc.BASE64Decoder;
|
|
||||||
import sun.security.rsa.RSAPublicKeyImpl;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.security.KeyFactory;
|
import java.security.KeyFactory;
|
||||||
import java.security.PublicKey;
|
|
||||||
import java.security.interfaces.RSAPublicKey;
|
import java.security.interfaces.RSAPublicKey;
|
||||||
import java.security.spec.RSAPublicKeySpec;
|
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -83,7 +75,7 @@ public class ResourceServerConfig {
|
|||||||
ServerAccessDeniedHandler accessDeniedHandler() {
|
ServerAccessDeniedHandler accessDeniedHandler() {
|
||||||
return (exchange, denied) -> {
|
return (exchange, denied) -> {
|
||||||
Mono<Void> mono = Mono.defer(() -> Mono.just(exchange.getResponse()))
|
Mono<Void> 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;
|
return mono;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -95,7 +87,7 @@ public class ResourceServerConfig {
|
|||||||
ServerAuthenticationEntryPoint authenticationEntryPoint() {
|
ServerAuthenticationEntryPoint authenticationEntryPoint() {
|
||||||
return (exchange, e) -> {
|
return (exchange, e) -> {
|
||||||
Mono<Void> mono = Mono.defer(() -> Mono.just(exchange.getResponse()))
|
Mono<Void> 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;
|
return mono;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -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.BlockRequestHandler;
|
||||||
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
|
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
|
@ -16,11 +16,10 @@ import java.nio.charset.Charset;
|
|||||||
/**
|
/**
|
||||||
* @Author haoxr
|
* @Author haoxr
|
||||||
* @Date 2021-01-29 13:30
|
* @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.setStatusCode(HttpStatus.OK);
|
||||||
response.getHeaders().set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
response.getHeaders().set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||||
response.getHeaders().set("Access-Control-Allow-Origin", "*");
|
response.getHeaders().set("Access-Control-Allow-Origin", "*");
|
Loading…
Reference in New Issue
Block a user