Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
f08fe241
提交
f08fe241
authored
6月 11, 2022
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
2. tenant 组件:feign 调用时,通过 header 透传 Tenant 信息
上级
ca6e7a45
隐藏空白字符变更
内嵌
并排
正在显示
17 个修改的文件
包含
125 行增加
和
18 行删除
+125
-18
http-client.env.json
http-client.env.json
+1
-0
RpcConstants.java
...cn/iocoder/yudao/framework/common/enums/RpcConstants.java
+17
-0
pom.xml
yudao-framework/yudao-spring-boot-starter-biz-tenant/pom.xml
+7
-0
YudaoTenantRpcAutoConfiguration.java
...mework/tenant/config/YudaoTenantRpcAutoConfiguration.java
+17
-0
TenantRequestInterceptor.java
...o/framework/tenant/core/rpc/TenantRequestInterceptor.java
+25
-0
TenantSecurityWebFilter.java
...amework/tenant/core/security/TenantSecurityWebFilter.java
+8
-0
TenantContextWebFilter.java
...dao/framework/tenant/core/web/TenantContextWebFilter.java
+0
-2
spring.factories
...r-biz-tenant/src/main/resources/META-INF/spring.factories
+1
-0
pom.xml
yudao-framework/yudao-spring-boot-starter-security/pom.xml
+6
-6
LoginUserRequestInterceptor.java
...mework/security/core/rpc/LoginUserRequestInterceptor.java
+5
-0
WebFrameworkUtils.java
...oder/yudao/framework/web/core/util/WebFrameworkUtils.java
+1
-1
pom.xml
yudao-gateway/pom.xml
+2
-2
application.yaml
yudao-gateway/src/main/resources/application.yaml
+8
-0
ApiConstants.java
...ava/cn/iocoder/yudao/module/infra/enums/ApiConstants.java
+3
-1
pom.xml
yudao-module-infra/yudao-module-infra-biz/pom.xml
+4
-0
TmpConfiguration.java
...ocoder/yudao/module/infra/framework/TmpConfiguration.java
+17
-5
ApiConstants.java
...va/cn/iocoder/yudao/module/system/enums/ApiConstants.java
+3
-1
没有找到文件。
http-client.env.json
浏览文件 @
f08fe241
...
...
@@ -14,6 +14,7 @@
"gateway"
:
{
"baseUrl"
:
"http://127.0.0.1:48080/admin-api"
,
"systemBaseUrl"
:
"http://127.0.0.1:48080/admin-api"
,
"infaBaseUrl"
:
"http://127.0.0.1:48080/admin-api"
,
"token"
:
"test1"
,
"adminTenentId"
:
"1"
,
...
...
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/RpcConstants.java
0 → 100644
浏览文件 @
f08fe241
package
cn
.
iocoder
.
yudao
.
framework
.
common
.
enums
;
/**
* RPC 相关的枚举
*
* 虽然放在 yudao-spring-boot-starter-rpc 会相对合适,但是每个 API 模块需要使用到,所以暂时只好放在此处
*
* @author 芋道源码
*/
public
class
RpcConstants
{
/**
* RPC API 的前缀
*/
public
static
final
String
RPC_API_PREFIX
=
"/rpc-api"
;
}
yudao-framework/yudao-spring-boot-starter-biz-tenant/pom.xml
浏览文件 @
f08fe241
...
...
@@ -38,6 +38,13 @@
<artifactId>
yudao-spring-boot-starter-redis
</artifactId>
</dependency>
<!-- RPC 远程调用相关 -->
<dependency>
<groupId>
cn.iocoder.cloud
</groupId>
<artifactId>
yudao-spring-boot-starter-rpc
</artifactId>
<optional>
true
</optional>
</dependency>
<!-- Job 定时任务相关 -->
<dependency>
<groupId>
cn.iocoder.cloud
</groupId>
...
...
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantRpcAutoConfiguration.java
0 → 100644
浏览文件 @
f08fe241
package
cn
.
iocoder
.
yudao
.
framework
.
tenant
.
config
;
import
cn.iocoder.yudao.framework.tenant.core.rpc.TenantRequestInterceptor
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
@ConditionalOnProperty
(
prefix
=
"yudao.tenant"
,
value
=
"enable"
,
matchIfMissing
=
true
)
// 允许使用 yudao.tenant.enable=false 禁用多租户
public
class
YudaoTenantRpcAutoConfiguration
{
@Bean
public
TenantRequestInterceptor
tenantRequestInterceptor
()
{
return
new
TenantRequestInterceptor
();
}
}
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/rpc/TenantRequestInterceptor.java
0 → 100644
浏览文件 @
f08fe241
package
cn
.
iocoder
.
yudao
.
framework
.
tenant
.
core
.
rpc
;
import
cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder
;
import
cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils
;
import
feign.RequestInterceptor
;
import
feign.RequestTemplate
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
web
.
core
.
util
.
WebFrameworkUtils
.
HEADER_TENANT_ID
;
/**
* Tenant 的 RequestInterceptor 实现类:Feign 请求时,将 {@link TenantContextHolder} 设置到 header 中,继续透传给被调用的服务
*
* @author 芋道源码
*/
public
class
TenantRequestInterceptor
implements
RequestInterceptor
{
@Override
public
void
apply
(
RequestTemplate
requestTemplate
)
{
Long
tenantId
=
TenantContextHolder
.
getTenantId
();
if
(
tenantId
!=
null
)
{
requestTemplate
.
header
(
HEADER_TENANT_ID
,
String
.
valueOf
(
tenantId
));
}
}
}
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/security/TenantSecurityWebFilter.java
浏览文件 @
f08fe241
package
cn
.
iocoder
.
yudao
.
framework
.
tenant
.
core
.
security
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.iocoder.yudao.framework.common.enums.RpcConstants
;
import
cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants
;
import
cn.iocoder.yudao.framework.common.pojo.CommonResult
;
import
cn.iocoder.yudao.framework.common.util.servlet.ServletUtils
;
...
...
@@ -53,6 +55,12 @@ public class TenantSecurityWebFilter extends ApiRequestFilter {
this
.
tenantFrameworkService
=
tenantFrameworkService
;
}
@Override
protected
boolean
shouldNotFilter
(
HttpServletRequest
request
)
{
return
super
.
shouldNotFilter
(
request
)
&&
!
StrUtil
.
startWithAny
(
request
.
getRequestURI
(),
RpcConstants
.
RPC_API_PREFIX
);
// 因为 RPC API 也会透传租户编号
}
@Override
protected
void
doFilterInternal
(
HttpServletRequest
request
,
HttpServletResponse
response
,
FilterChain
chain
)
throws
ServletException
,
IOException
{
...
...
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/web/TenantContextWebFilter.java
浏览文件 @
f08fe241
...
...
@@ -18,8 +18,6 @@ import java.io.IOException;
*/
public
class
TenantContextWebFilter
extends
OncePerRequestFilter
{
private
static
final
String
HEADER_TENANT_ID
=
"tenant-id"
;
@Override
protected
void
doFilterInternal
(
HttpServletRequest
request
,
HttpServletResponse
response
,
FilterChain
chain
)
throws
ServletException
,
IOException
{
...
...
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/resources/META-INF/spring.factories
浏览文件 @
f08fe241
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.iocoder.yudao.framework.tenant.config.YudaoTenantRpcAutoConfiguration,\
cn.iocoder.yudao.framework.tenant.config.YudaoTenantAutoConfiguration
yudao-framework/yudao-spring-boot-starter-security/pom.xml
浏览文件 @
f08fe241
...
...
@@ -44,18 +44,18 @@
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
<!--
业务组件
-->
<!--
RPC 远程调用相关
-->
<dependency>
<groupId>
cn.iocoder.cloud
</groupId>
<artifactId>
yudao-
module-system-api
</artifactId>
<!-- 需要使用它,进行 Token 的校验 --
>
<
version>
${revision}
</version
>
<artifactId>
yudao-
spring-boot-starter-rpc
</artifactId
>
<
optional>
true
</optional
>
</dependency>
<!--
RPC 远程调用相关
-->
<!--
业务组件
-->
<dependency>
<groupId>
cn.iocoder.cloud
</groupId>
<artifactId>
yudao-
spring-boot-starter-rpc
</artifactId
>
<
optional>
true
</optional
>
<artifactId>
yudao-
module-system-api
</artifactId>
<!-- 需要使用它,进行 Token 的校验 --
>
<
version>
${revision}
</version
>
</dependency>
</dependencies>
...
...
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/rpc/LoginUserRequestInterceptor.java
浏览文件 @
f08fe241
...
...
@@ -6,6 +6,11 @@ import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import
feign.RequestInterceptor
;
import
feign.RequestTemplate
;
/**
* LoginUser 的 RequestInterceptor 实现类:Feign 请求时,将 {@link LoginUser} 设置到 header 中,继续透传给被调用的服务
*
* @author 芋道源码
*/
public
class
LoginUserRequestInterceptor
implements
RequestInterceptor
{
@Override
...
...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java
浏览文件 @
f08fe241
...
...
@@ -23,7 +23,7 @@ public class WebFrameworkUtils {
private
static
final
String
REQUEST_ATTRIBUTE_COMMON_RESULT
=
"common_result"
;
p
rivate
static
final
String
HEADER_TENANT_ID
=
"tenant-id"
;
p
ublic
static
final
String
HEADER_TENANT_ID
=
"tenant-id"
;
private
static
WebProperties
properties
;
...
...
yudao-gateway/pom.xml
浏览文件 @
f08fe241
...
...
@@ -37,8 +37,8 @@
<!-- RPC 远程调用相关 -->
<dependency>
<groupId>
cn.iocoder
.cloud
</groupId>
<artifactId>
yudao-spring-boot-starter-rpc
</artifactId>
<groupId>
org.springframework
.cloud
</groupId>
<artifactId>
spring-cloud-starter-loadbalancer
</artifactId>
</dependency>
<!-- Registry 注册中心相关 -->
...
...
yudao-gateway/src/main/resources/application.yaml
浏览文件 @
f08fe241
...
...
@@ -15,3 +15,11 @@ spring:
uri
:
grayLb://system-server
predicates
:
# 断言,作为路由的匹配条件,对应 RouteDefinition 数组
-
Path=/app-api/system/**
-
id
:
infra-admin-api
# 路由的编号
uri
:
grayLb://infra-server
predicates
:
# 断言,作为路由的匹配条件,对应 RouteDefinition 数组
-
Path=/admin-api/infra/**
-
id
:
infra-app-api
# 路由的编号
uri
:
grayLb://infra-server
predicates
:
# 断言,作为路由的匹配条件,对应 RouteDefinition 数组
-
Path=/app-api/infra/**
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ApiConstants.java
浏览文件 @
f08fe241
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
enums
;
import
cn.iocoder.yudao.framework.common.enums.RpcConstants
;
/**
* API 相关的枚举
*
...
...
@@ -14,7 +16,7 @@ public class ApiConstants {
*/
public
static
final
String
NAME
=
"infra-server"
;
public
static
final
String
PREFIX
=
"/rpc-api
/system"
;
public
static
final
String
PREFIX
=
RpcConstants
.
RPC_API_PREFIX
+
"
/system"
;
public
static
final
String
VERSION
=
"1.0.0"
;
...
...
yudao-module-infra/yudao-module-infra-biz/pom.xml
浏览文件 @
f08fe241
...
...
@@ -42,6 +42,10 @@
<groupId>
cn.iocoder.cloud
</groupId>
<artifactId>
yudao-spring-boot-starter-biz-operatelog
</artifactId>
</dependency>
<dependency>
<groupId>
cn.iocoder.cloud
</groupId>
<artifactId>
yudao-spring-boot-starter-biz-tenant
</artifactId>
</dependency>
<!-- Web 相关 -->
<dependency>
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/TmpConfiguration.java
浏览文件 @
f08fe241
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
framework
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService
;
import
cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.operatelog.core.dto.OperateLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.operatelog.core.service.OperateLogFrameworkService
;
import
cn.iocoder.yudao.
module.infra.api.file.FileApi
;
import
cn.iocoder.yudao.
framework.tenant.core.service.TenantFrameworkService
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
java.util.List
;
import
java.util.concurrent.Future
;
@Configuration
...
...
@@ -25,4 +22,19 @@ public class TmpConfiguration {
};
}
@Bean
public
TenantFrameworkService
tenantFrameworkService
()
{
return
new
TenantFrameworkService
()
{
@Override
public
List
<
Long
>
getTenantIds
()
{
return
null
;
}
@Override
public
void
validTenant
(
Long
id
)
{
}
};
}
}
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ApiConstants.java
浏览文件 @
f08fe241
package
cn
.
iocoder
.
yudao
.
module
.
system
.
enums
;
import
cn.iocoder.yudao.framework.common.enums.RpcConstants
;
/**
* API 相关的枚举
*
...
...
@@ -14,7 +16,7 @@ public class ApiConstants {
*/
public
static
final
String
NAME
=
"system-server"
;
public
static
final
String
PREFIX
=
"/rpc-api
/system"
;
public
static
final
String
PREFIX
=
RpcConstants
.
RPC_API_PREFIX
+
"
/system"
;
public
static
final
String
VERSION
=
"1.0.0"
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论