Jay
8 天以前 eca625c35d5ed64c98277d2f83963e46438f50ce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.iailab.framework.datapermission.config;
 
import com.iailab.framework.datapermission.core.rpc.DataPermissionRequestInterceptor;
import com.iailab.framework.datapermission.core.rpc.DataPermissionRpcWebFilter;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
 
import static com.iailab.framework.common.enums.WebFilterOrderEnum.TENANT_CONTEXT_FILTER;
 
 
/**
 * 数据权限针对 RPC 的自动配置类
 *
 * @author iailab
 */
@AutoConfiguration
@ConditionalOnClass(name = "feign.RequestInterceptor")
public class IailabDataPermissionRpcAutoConfiguration {
 
    @Bean
    public DataPermissionRequestInterceptor dataPermissionRequestInterceptor() {
        return new DataPermissionRequestInterceptor();
    }
 
    @Bean
    public FilterRegistrationBean<DataPermissionRpcWebFilter> dataPermissionRpcFilter() {
        FilterRegistrationBean<DataPermissionRpcWebFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new DataPermissionRpcWebFilter());
        registrationBean.setOrder(TENANT_CONTEXT_FILTER - 1); // 顺序没有绝对的要求,在租户 Filter 前面稳妥点
        return registrationBean;
    }
 
}