|
1 | 1 | package com.datamate.gateway.filter; |
2 | 2 |
|
| 3 | +import com.terrabase.enterprise.api.UserManagementService; |
3 | 4 | import com.terrabase.enterprise.api.dto.LoginUserDto; |
4 | | -import com.terrabase.enterprise.api.sdk.TerrabaseSDK; |
5 | | -import com.terrabase.enterprise.api.sdk.TerrabaseSDKConfig; |
6 | | -import jakarta.annotation.PostConstruct; |
7 | 5 | import lombok.extern.slf4j.Slf4j; |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; |
8 | 7 | import org.springframework.beans.factory.annotation.Value; |
9 | 8 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
10 | 9 | import org.springframework.cloud.gateway.filter.GlobalFilter; |
|
15 | 14 | /** |
16 | 15 | * 用户信息过滤器 |
17 | 16 | * |
18 | | - * @since 2025/12/22 |
19 | 17 | */ |
20 | 18 | @Slf4j |
21 | 19 | @Component |
22 | 20 | public class UserContextFilter implements GlobalFilter { |
23 | | - @Value("${terrabase.jar.path:/opt/terrabase}") |
24 | | - private String jarPath; |
25 | | - |
26 | 21 | @Value("${commercial.switch:false}") |
27 | 22 | private boolean isCommercial; |
28 | 23 |
|
29 | | - private TerrabaseSDK terrabaseSDK; |
30 | | - |
31 | | - @PostConstruct |
32 | | - public void init() { |
33 | | - TerrabaseSDKConfig sdkConfig = TerrabaseSDKConfig.createDefault(); |
34 | | - sdkConfig.setJarPath(jarPath); |
35 | | - terrabaseSDK = TerrabaseSDK.init(sdkConfig); |
36 | | - } |
| 24 | + @Autowired |
| 25 | + private UserManagementService userManagementService; |
37 | 26 |
|
38 | 27 | @Override |
39 | 28 | public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { |
40 | 29 | if (!isCommercial) { |
41 | 30 | return chain.filter(exchange); |
42 | 31 | } |
43 | 32 | try { |
44 | | - LoginUserDto loginUserDto = terrabaseSDK.userManagement().getCurrentUserInfo().getData().getFirst(); |
| 33 | + LoginUserDto loginUserDto = userManagementService.getCurrentUserInfo().getData().getFirst(); |
45 | 34 | } catch (Exception e) { |
46 | 35 | log.error("get current user info error", e); |
47 | 36 | return chain.filter(exchange); |
|
0 commit comments