feat:网关
This commit is contained in:
23
pom.xml
23
pom.xml
@@ -3,9 +3,9 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.xiang</groupId>
|
<groupId>com.xiang.pom</groupId>
|
||||||
<artifactId>xservice-basic</artifactId>
|
<artifactId>xmc-web-starter</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
@@ -69,18 +69,17 @@
|
|||||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.xiang</groupId>
|
<groupId>com.xiang.starter</groupId>
|
||||||
<artifactId>xservice-parent-starter</artifactId>
|
<artifactId>xmc-common</artifactId>
|
||||||
<version>2.0</version>
|
<version>1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.xiang</groupId>
|
<!-- <groupId>com.xiang</groupId>-->
|
||||||
<artifactId>xservice-security-starter</artifactId>
|
<!-- <artifactId>xservice-security-starter</artifactId>-->
|
||||||
<version>1.0-SNAPSHOT</version>
|
<!-- <version>1.0-SNAPSHOT</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
package com.xiang.xservice.gateway.service.config;
|
//package com.xiang.xservice.gateway.service.config;
|
||||||
|
//
|
||||||
import org.springframework.context.annotation.Bean;
|
//import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
//import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
|
//import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
|
||||||
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
//import org.springframework.security.config.web.server.ServerHttpSecurity;
|
||||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
//import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||||
|
//
|
||||||
@Configuration
|
//@Configuration
|
||||||
@EnableWebFluxSecurity
|
//@EnableWebFluxSecurity
|
||||||
public class GatewaySecurityConfig {
|
//public class GatewaySecurityConfig {
|
||||||
|
//
|
||||||
@Bean
|
// @Bean
|
||||||
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
// public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
|
||||||
http
|
// http
|
||||||
.authorizeExchange(exchanges -> exchanges
|
// .authorizeExchange(exchanges -> exchanges
|
||||||
// ✅ 网关全放行
|
// // ✅ 网关全放行
|
||||||
.anyExchange().permitAll()
|
// .anyExchange().permitAll()
|
||||||
)
|
// )
|
||||||
.csrf(ServerHttpSecurity.CsrfSpec::disable); // 禁用 CSRF
|
// .csrf(ServerHttpSecurity.CsrfSpec::disable); // 禁用 CSRF
|
||||||
|
//
|
||||||
return http.build();
|
// return http.build();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.xiang.xservice.gateway.service.core;
|
package com.xiang.xservice.gateway.service.core;
|
||||||
|
|
||||||
import com.xiang.xservice.security.utils.TokenUtils;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
@@ -17,9 +15,6 @@ import reactor.core.publisher.Mono;
|
|||||||
@Component
|
@Component
|
||||||
public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TokenUtils tokenUtils;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
ServerHttpRequest request = exchange.getRequest();
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
@@ -39,18 +34,6 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
|
|||||||
return exchange.getResponse().setComplete();
|
return exchange.getResponse().setComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
// try {
|
|
||||||
// if (!tokenUtils.validateToken(token)) {
|
|
||||||
// log.warn("❌ Token 校验失败: {}", token);
|
|
||||||
// exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
|
|
||||||
// return exchange.getResponse().setComplete();
|
|
||||||
// }
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// log.error("❌ Token 校验异常", e);
|
|
||||||
// exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
|
|
||||||
// return exchange.getResponse().setComplete();
|
|
||||||
// }
|
|
||||||
|
|
||||||
log.info("✅ Token 校验通过: {}", token);
|
log.info("✅ Token 校验通过: {}", token);
|
||||||
return chain.filter(exchange);
|
return chain.filter(exchange);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user