🎉 3.0.2.RELEASE 支持 Nacos2.0 长链接特性

This commit is contained in:
smallchill 2021-03-24 18:54:45 +08:00
parent 57882206d3
commit 917ca30b43
34 changed files with 188 additions and 71 deletions

View File

@ -1,9 +1,9 @@
<p align="center">
<img src="https://img.shields.io/badge/Release-V3.0.1-green.svg" alt="Downloads">
<img src="https://img.shields.io/badge/Release-V3.0.2-green.svg" alt="Downloads">
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" alt="Build Status">
<img src="https://img.shields.io/badge/license-Apache%202-blue.svg" alt="Build Status">
<img src="https://img.shields.io/badge/Spring%20Cloud-2020-blue.svg" alt="Coverage Status">
<img src="https://img.shields.io/badge/Spring%20Boot-2.4.2-blue.svg" alt="Downloads">
<img src="https://img.shields.io/badge/Spring%20Boot-2.4.4-blue.svg" alt="Downloads">
<a target="_blank" href="https://bladex.vip">
<img src="https://img.shields.io/badge/Author-Small%20Chill-ff69b4.svg" alt="Downloads">
</a>
@ -28,6 +28,9 @@
## 架构图
<img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/springblade-framework.png"/>
## 趋势图
<a href="https://whnb.wang/smallc/SpringBlade" rel="nofollow"><img src="https://whnb.wang/img/smallc/SpringBlade" alt="Stargazers over time"></a>
## 工程结构
```
SpringBlade

View File

@ -8,7 +8,7 @@
<parent>
<artifactId>SpringBlade</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<artifactId>blade-auth</artifactId>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>SpringBlade</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>SpringBlade</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -74,13 +74,30 @@
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</exclusion>
</exclusions>
<version>${alibaba.cloud.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<exclusions>
<exclusion>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</exclusion>
</exclusions>
<version>${alibaba.cloud.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>${alibaba.nacos.version}</version>
</dependency>
<!-- JWT -->
<dependency>
<groupId>io.jsonwebtoken</groupId>

View File

@ -20,7 +20,18 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.gateway.props.AuthProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.cors.reactive.CorsUtils;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;
/**
* 路由配置信息
@ -33,4 +44,38 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties({AuthProperties.class})
public class RouterFunctionConfiguration {
/**
* 这里为支持的请求头如果有自定义的header字段请自己添加
*/
private static final String ALLOWED_HEADERS = "X-Requested-With, Tenant-Id, Blade-Auth, Content-Type, Authorization, credential, X-XSRF-TOKEN, token, username, client, knfie4j-gateway-request, request-origion";
private static final String ALLOWED_METHODS = "GET,POST,PUT,DELETE,OPTIONS,HEAD";
private static final String ALLOWED_ORIGIN = "*";
private static final String ALLOWED_EXPOSE = "*";
private static final String MAX_AGE = "18000L";
/**
* 跨域配置
*/
@Bean
public WebFilter corsFilter() {
return (ServerWebExchange ctx, WebFilterChain chain) -> {
ServerHttpRequest request = ctx.getRequest();
if (CorsUtils.isCorsRequest(request)) {
ServerHttpResponse response = ctx.getResponse();
HttpHeaders headers = response.getHeaders();
headers.add("Access-Control-Allow-Headers", ALLOWED_HEADERS);
headers.add("Access-Control-Allow-Methods", ALLOWED_METHODS);
headers.add("Access-Control-Allow-Origin", ALLOWED_ORIGIN);
headers.add("Access-Control-Expose-Headers", ALLOWED_EXPOSE);
headers.add("Access-Control-Max-Age", MAX_AGE);
headers.add("Access-Control-Allow-Credentials", "true");
if (request.getMethod() == HttpMethod.OPTIONS) {
response.setStatusCode(HttpStatus.OK);
return Mono.empty();
}
}
return chain.filter(ctx);
};
}
}

View File

@ -32,6 +32,7 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@ -49,6 +50,7 @@ import java.nio.charset.StandardCharsets;
public class AuthFilter implements GlobalFilter, Ordered {
private final AuthProperties authProperties;
private final ObjectMapper objectMapper;
private final AntPathMatcher antPathMatcher = new AntPathMatcher();
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
@ -72,8 +74,8 @@ public class AuthFilter implements GlobalFilter, Ordered {
}
private boolean isSkip(String path) {
return AuthProvider.getDefaultSkipUrl().stream().map(url -> url.replace(AuthProvider.TARGET, AuthProvider.REPLACEMENT)).anyMatch(path::contains)
|| authProperties.getSkipUrl().stream().map(url -> url.replace(AuthProvider.TARGET, AuthProvider.REPLACEMENT)).anyMatch(path::contains);
return AuthProvider.getDefaultSkipUrl().stream().anyMatch(pattern -> antPathMatcher.match(pattern, path))
|| authProperties.getSkipUrl().stream().anyMatch(pattern -> antPathMatcher.match(pattern, path));
}
private Mono<Void> unAuth(ServerHttpResponse resp, String msg) {

View File

@ -0,0 +1,45 @@
package org.springblade.gateway.filter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import java.util.Arrays;
import java.util.stream.Collectors;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.addOriginalRequestUrl;
/**
* request过滤器
*
* @author lengleng
*/
@Component
public class RequestFilter implements GlobalFilter, Ordered {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest request = exchange.getRequest();
addOriginalRequestUrl(exchange, request.getURI());
String rawPath = request.getURI().getRawPath();
String newPath = "/" + Arrays.stream(StringUtils.tokenizeToStringArray(rawPath, "/"))
.skip(1L).collect(Collectors.joining("/"));
ServerHttpRequest newRequest = request.mutate()
.path(newPath)
.build();
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, newRequest.getURI());
return chain.filter(exchange.mutate().request(newRequest.mutate().build()).build());
}
@Override
public int getOrder() {
return -1000;
}
}

View File

@ -27,34 +27,32 @@ import java.util.List;
*/
public class AuthProvider {
public static String TARGET = "/**";
public static String REPLACEMENT = "";
public static String AUTH_KEY = TokenConstant.HEADER;
private static final List<String> defaultSkipUrl = new ArrayList<>();
private static final List<String> DEFAULT_SKIP_URL = new ArrayList<>();
static {
defaultSkipUrl.add("/example");
defaultSkipUrl.add("/token/**");
defaultSkipUrl.add("/captcha/**");
defaultSkipUrl.add("/actuator/health/**");
defaultSkipUrl.add("/v2/api-docs/**");
defaultSkipUrl.add("/auth/**");
defaultSkipUrl.add("/oauth/**");
defaultSkipUrl.add("/log/**");
defaultSkipUrl.add("/menu/routes");
defaultSkipUrl.add("/menu/auth-routes");
defaultSkipUrl.add("/tenant/info");
defaultSkipUrl.add("/order/create/**");
defaultSkipUrl.add("/storage/deduct/**");
defaultSkipUrl.add("/error/**");
defaultSkipUrl.add("/assets/**");
DEFAULT_SKIP_URL.add("/example");
DEFAULT_SKIP_URL.add("/token/**");
DEFAULT_SKIP_URL.add("/captcha/**");
DEFAULT_SKIP_URL.add("/actuator/health/**");
DEFAULT_SKIP_URL.add("/v2/api-docs/**");
DEFAULT_SKIP_URL.add("/auth/**");
DEFAULT_SKIP_URL.add("/oauth/**");
DEFAULT_SKIP_URL.add("/log/**");
DEFAULT_SKIP_URL.add("/menu/routes");
DEFAULT_SKIP_URL.add("/menu/auth-routes");
DEFAULT_SKIP_URL.add("/tenant/info");
DEFAULT_SKIP_URL.add("/order/create/**");
DEFAULT_SKIP_URL.add("/storage/deduct/**");
DEFAULT_SKIP_URL.add("/error/**");
DEFAULT_SKIP_URL.add("/assets/**");
}
/**
* 默认无需鉴权的API
*/
public static List<String> getDefaultSkipUrl() {
return defaultSkipUrl;
return DEFAULT_SKIP_URL;
}
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.springblade</groupId>
<artifactId>blade-ops</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>org.springblade</groupId>
<artifactId>blade-ops</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,11 +5,13 @@
<parent>
<artifactId>SpringBlade</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blade-ops</artifactId>
<name>${project.artifactId}</name>
<version>3.0.2</version>
<packaging>pom</packaging>
<modules>
<module>blade-admin</module>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,13 +5,13 @@
<parent>
<artifactId>SpringBlade</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blade-service-api</artifactId>
<name>${project.artifactId}</name>
<version>3.0.1</version>
<version>3.0.2</version>
<packaging>pom</packaging>
<description>SpringBlade 微服务API集合</description>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.springblade</groupId>
<artifactId>blade-service</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service</artifactId>
<groupId>org.springblade</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -7,12 +7,12 @@
<parent>
<groupId>org.springblade</groupId>
<artifactId>SpringBlade</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<artifactId>blade-service</artifactId>
<name>${project.artifactId}</name>
<version>3.0.1</version>
<version>3.0.2</version>
<packaging>pom</packaging>
<description>SpringBlade 微服务集合</description>

View File

@ -86,7 +86,7 @@ CMD java -Djava.security.egd=file:/dev/./urandom -jar app.jar --spring.profiles.
###5. 在工程根目录的docker-compose.yml下加入配置内容可参考如下
```
blade-gateway:
image: "${REGISTER}/blade/blade-gateway:${TAG}"
image: "${REGISTER}/blade-gateway:${TAG}"
ports:
- 80:80
networks:

View File

@ -69,7 +69,7 @@ knife4j:
swagger:
title: SpringBlade 接口文档系统
description: SpringBlade 接口文档系统
version: 3.0.1
version: 3.0.2
license: Powered By SpringBlade
licenseUrl: https://bladex.vip
terms-of-service-url: https://bladex.vip

13
pom.xml
View File

@ -5,12 +5,12 @@
<groupId>org.springblade</groupId>
<artifactId>SpringBlade</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<packaging>pom</packaging>
<properties>
<blade.tool.version>3.0.1</blade.tool.version>
<blade.project.version>3.0.1</blade.project.version>
<blade.tool.version>3.0.2</blade.tool.version>
<blade.project.version>3.0.2</blade.project.version>
<java.version>1.8</java.version>
<maven.plugin.version>3.8.1</maven.plugin.version>
@ -21,12 +21,13 @@
<captcha.version>1.6.2</captcha.version>
<easyexcel.version>2.2.6</easyexcel.version>
<mica.auto.version>1.2.5</mica.auto.version>
<alibaba.cloud.version>2.2.5.RC2</alibaba.cloud.version>
<alibaba.cloud.version>2.2.5.RELEASE</alibaba.cloud.version>
<alibaba.nacos.version>2.0.0</alibaba.nacos.version>
<spring.boot.admin.version>2.3.1</spring.boot.admin.version>
<spring.plugin.version>2.0.0.RELEASE</spring.plugin.version>
<spring.boot.version>2.4.2</spring.boot.version>
<spring.cloud.version>2020.0.1</spring.cloud.version>
<spring.boot.version>2.4.4</spring.boot.version>
<spring.cloud.version>2020.0.2</spring.cloud.version>
<spring.platform.version>Cairo-SR8</spring.platform.version>
<!-- 推荐使用Harbor -->

View File

@ -1,2 +1,2 @@
REGISTER=192.168.0.157/blade
TAG=3.0.1
TAG=3.0.2

View File

@ -10,6 +10,8 @@ port(){
firewall-cmd --add-port=88/tcp --permanent
firewall-cmd --add-port=8000/tcp --permanent
firewall-cmd --add-port=8848/tcp --permanent
firewall-cmd --add-port=9848/tcp --permanent
firewall-cmd --add-port=9849/tcp --permanent
firewall-cmd --add-port=8858/tcp --permanent
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --add-port=3379/tcp --permanent

View File

@ -1,7 +1,7 @@
version: '3'
services:
nacos:
image: nacos/nacos-server:1.3.2
image: nacos/nacos-server:2.0.0
hostname: "nacos-standalone"
environment:
- MODE=standalone
@ -10,12 +10,14 @@ services:
- /docker/nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties
ports:
- 8848:8848
- 9848:9848
- 9849:9849
networks:
blade_net:
ipv4_address: 172.30.0.48
sentinel:
image: bladex/sentinel-dashboard:1.7.2
image: bladex/sentinel-dashboard:1.8.0
hostname: "sentinel"
ports:
- 8858:8858
@ -63,7 +65,7 @@ services:
- blade_net
blade-admin:
image: "${REGISTER}/blade/blade-admin:${TAG}"
image: "${REGISTER}/blade-admin:${TAG}"
ports:
- 7002:7002
privileged: true
@ -72,7 +74,7 @@ services:
- blade_net
blade-swagger:
image: "${REGISTER}/blade/blade-swagger:${TAG}"
image: "${REGISTER}/blade-swagger:${TAG}"
ports:
- 18000:18000
privileged: true
@ -81,7 +83,7 @@ services:
- blade_net
blade-gateway1:
image: "${REGISTER}/blade/blade-gateway:${TAG}"
image: "${REGISTER}/blade-gateway:${TAG}"
privileged: true
restart: always
networks:
@ -89,7 +91,7 @@ services:
ipv4_address: 172.30.0.81
blade-gateway2:
image: "${REGISTER}/blade/blade-gateway:${TAG}"
image: "${REGISTER}/blade-gateway:${TAG}"
privileged: true
restart: always
networks:
@ -97,7 +99,7 @@ services:
ipv4_address: 172.30.0.82
blade-auth1:
image: "${REGISTER}/blade/blade-auth:${TAG}"
image: "${REGISTER}/blade-auth:${TAG}"
privileged: true
restart: always
networks:
@ -105,7 +107,7 @@ services:
ipv4_address: 172.30.0.91
blade-auth2:
image: "${REGISTER}/blade/blade-auth:${TAG}"
image: "${REGISTER}/blade-auth:${TAG}"
privileged: true
restart: always
networks:
@ -113,7 +115,7 @@ services:
ipv4_address: 172.30.0.92
blade-report:
image: "${REGISTER}/blade/blade-report:${TAG}"
image: "${REGISTER}/blade-report:${TAG}"
privileged: true
restart: always
networks:
@ -121,35 +123,35 @@ services:
ipv4_address: 172.30.0.98
blade-log:
image: "${REGISTER}/blade/blade-log:${TAG}"
image: "${REGISTER}/blade-log:${TAG}"
privileged: true
restart: always
networks:
- blade_net
blade-desk:
image: "${REGISTER}/blade/blade-desk:${TAG}"
image: "${REGISTER}/blade-desk:${TAG}"
privileged: true
restart: always
networks:
- blade_net
blade-user:
image: "${REGISTER}/blade/blade-user:${TAG}"
image: "${REGISTER}/blade-user:${TAG}"
privileged: true
restart: always
networks:
- blade_net
blade-system:
image: "${REGISTER}/blade/blade-system:${TAG}"
image: "${REGISTER}/blade-system:${TAG}"
privileged: true
restart: always
networks:
- blade_net
blade-resource:
image: "${REGISTER}/blade/blade-resource:${TAG}"
image: "${REGISTER}/blade-resource:${TAG}"
privileged: true
restart: always
networks: