product:1)网关转发;2)完善配置类

This commit is contained in:
YunaiV 2023-10-22 17:07:28 +08:00
parent 6653c074fa
commit df7d49a8b1
7 changed files with 97 additions and 2 deletions

View File

@ -84,6 +84,19 @@ spring:
- Path=/admin-api/mp/**
filters:
- RewritePath=/admin-api/mp/v3/api-docs, /v3/api-docs
## member-server 服务
- id: product-admin-api # 路由的编号
uri: grayLb://product-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/product/**
filters:
- RewritePath=/admin-api/product/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v3/api-docs
- id: product-app-api # 路由的编号
uri: grayLb://product-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/app-api/product/**
filters:
- RewritePath=/app-api/product/v3/api-docs, /v3/api-docs
x-forwarded:
prefix-enabled: false # 避免 Swagger 重复带上额外的 /admin-api/system 前缀
@ -110,3 +123,6 @@ knife4j:
- name: mp-server
service-name: mp-server
url: /admin-api/mp/v3/api-docs
- name: member-server
service-name: member-server
url: /admin-api/member/v3/api-docs

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.product.enums;
import cn.iocoder.yudao.framework.common.enums.RpcConstants;
/**
* API 相关的枚举
*
* @author 芋道源码
*/
public class ApiConstants {
/**
* 服务名
*
* 注意需要保证和 spring.application.name 保持一致
*/
public static final String NAME = "product-server";
public static final String PREFIX = RpcConstants.RPC_API_PREFIX + "/product";
public static final String VERSION = "1.0.0";
}

View File

@ -0,0 +1,11 @@
package cn.iocoder.yudao.module.product.framework.rpc.config;
import cn.iocoder.yudao.module.member.api.level.MemberLevelApi;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@EnableFeignClients(clients = {MemberUserApi.class, MemberLevelApi.class})
public class RpcConfiguration {
}

View File

@ -0,0 +1,4 @@
/**
* 占位
*/
package cn.iocoder.yudao.module.product.framework.rpc;

View File

@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.product.framework.security.config;
import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer;
import cn.iocoder.yudao.module.product.enums.ApiConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
/**
* Member 模块的 Security 配置
*/
@Configuration("productSecurityConfiguration")
public class SecurityConfiguration {
@Bean("productAuthorizeRequestsCustomizer")
public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {
return new AuthorizeRequestsCustomizer() {
@Override
public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) {
// Swagger 接口文档
registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据
.antMatchers("/swagger-ui.html").permitAll(); // Swagger UI
// Spring Boot Actuator 的安全配置
registry.antMatchers("/actuator").anonymous()
.antMatchers("/actuator/**").anonymous();
// Druid 监控
registry.antMatchers("/druid/**").anonymous();
// RPC 服务的安全配置
registry.antMatchers(ApiConstants.PREFIX + "/**").permitAll();
}
};
}
}

View File

@ -0,0 +1,4 @@
/**
* 占位
*/
package cn.iocoder.yudao.module.product.framework.security.core;

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.member.framework.security.config;
import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import cn.iocoder.yudao.module.member.enums.ApiConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@ -13,7 +13,7 @@ import org.springframework.security.config.annotation.web.configurers.Expression
@Configuration("memberSecurityConfiguration")
public class SecurityConfiguration {
@Bean("payAuthorizeRequestsCustomizer")
@Bean("memberAuthorizeRequestsCustomizer")
public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {
return new AuthorizeRequestsCustomizer() {