提交 | 用户 | 时间
|
325d2f
|
1 |
package com.iailab.framework.datapermission.core.rpc; |
H |
2 |
|
|
3 |
import com.iailab.framework.datapermission.core.annotation.DataPermission; |
|
4 |
import com.iailab.framework.datapermission.core.aop.DataPermissionContextHolder; |
|
5 |
import feign.RequestInterceptor; |
|
6 |
import feign.RequestTemplate; |
|
7 |
|
|
8 |
/** |
|
9 |
* DataPermission 的 RequestInterceptor 实现类:Feign 请求时,将 {@link DataPermission} 设置到 header 中,继续透传给被调用的服务 |
|
10 |
* |
|
11 |
* 注意:由于 {@link DataPermission} 不支持序列化和反序列化,所以暂时只能传递它的 enable 属性 |
|
12 |
* |
4d4165
|
13 |
* @author iailab |
325d2f
|
14 |
*/ |
H |
15 |
public class DataPermissionRequestInterceptor implements RequestInterceptor { |
|
16 |
|
|
17 |
public static final String ENABLE_HEADER_NAME = "data-permission-enable"; |
|
18 |
|
|
19 |
@Override |
|
20 |
public void apply(RequestTemplate requestTemplate) { |
|
21 |
DataPermission dataPermission = DataPermissionContextHolder.get(); |
|
22 |
if (dataPermission != null && Boolean.FALSE.equals(dataPermission.enable())) { |
|
23 |
requestTemplate.header(ENABLE_HEADER_NAME, "false"); |
|
24 |
} |
|
25 |
} |
|
26 |
|
|
27 |
} |