5
5
import org .apache .commons .collections4 .CollectionUtils ;
6
6
import org .apache .commons .collections4 .MapUtils ;
7
7
import org .apache .commons .lang3 .StringUtils ;
8
+ import org .lowcoder .domain .encryption .EncryptionService ;
8
9
import org .lowcoder .domain .plugin .client .dto .DatasourcePluginDefinition ;
9
10
import org .lowcoder .domain .plugin .client .dto .GetPluginDynamicConfigRequestDTO ;
10
11
import org .lowcoder .infra .js .NodeServerClient ;
30
31
31
32
import static org .lowcoder .sdk .constants .GlobalContext .REQUEST ;
32
33
34
+ import com .fasterxml .jackson .databind .ObjectMapper ;
35
+
33
36
@ Slf4j
34
37
@ RequiredArgsConstructor
35
38
@ Component
@@ -46,12 +49,15 @@ public class DatasourcePluginClient implements NodeServerClient {
46
49
47
50
private final CommonConfigHelper commonConfigHelper ;
48
51
private final NodeServerHelper nodeServerHelper ;
52
+ private final EncryptionService encryptionService ;
49
53
50
54
private static final String PLUGINS_PATH = "plugins" ;
51
55
private static final String RUN_PLUGIN_QUERY = "runPluginQuery" ;
52
56
private static final String VALIDATE_PLUGIN_DATA_SOURCE_CONFIG = "validatePluginDataSourceConfig" ;
53
57
private static final String GET_PLUGIN_DYNAMIC_CONFIG = "getPluginDynamicConfig" ;
54
58
59
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ();
60
+
55
61
public Mono <List <Object >> getPluginDynamicConfigSafely (List <GetPluginDynamicConfigRequestDTO > getPluginDynamicConfigRequestDTOS ) {
56
62
return getPluginDynamicConfig (getPluginDynamicConfigRequestDTOS )
57
63
.onErrorResume (throwable -> {
@@ -119,21 +125,37 @@ public Flux<DatasourcePluginDefinition> getDatasourcePluginDefinitions() {
119
125
@ SuppressWarnings ("unchecked" )
120
126
public Mono <QueryExecutionResult > executeQuery (String pluginName , Object queryDsl , List <Map <String , Object >> context , Object datasourceConfig ) {
121
127
return getAcceptLanguage ()
122
- .flatMap (language -> WEB_CLIENT
123
- .post ()
124
- .uri (nodeServerHelper .createUri (RUN_PLUGIN_QUERY ))
125
- .header (HttpHeaders .ACCEPT_LANGUAGE , language )
126
- .bodyValue (Map .of ("pluginName" , pluginName , "dsl" , queryDsl , "context" , context , "dataSourceConfig" , datasourceConfig ))
127
- .exchangeToMono (response -> {
128
- if (response .statusCode ().is2xxSuccessful ()) {
129
- return response .bodyToMono (Map .class )
130
- .map (map -> map .get ("result" ))
131
- .map (QueryExecutionResult ::success );
132
- }
133
- return response .bodyToMono (Map .class )
134
- .map (map -> MapUtils .getString (map , "message" ))
135
- .map (QueryExecutionResult ::errorWithMessage );
136
- }));
128
+ .flatMap (language -> {
129
+ try {
130
+ Map <String , Object > body = Map .of (
131
+ "pluginName" , pluginName ,
132
+ "dsl" , queryDsl ,
133
+ "context" , context ,
134
+ "dataSourceConfig" , datasourceConfig
135
+ );
136
+ String json = OBJECT_MAPPER .writeValueAsString (body );
137
+ String encrypted = encryptionService .encryptStringForNodeServer (json );
138
+ return WEB_CLIENT
139
+ .post ()
140
+ .uri (nodeServerHelper .createUri (RUN_PLUGIN_QUERY ))
141
+ .header (HttpHeaders .ACCEPT_LANGUAGE , language )
142
+ .header ("X-Encrypted" , "true" ) // Optional: custom header to indicate encryption
143
+ .bodyValue (encrypted )
144
+ .exchangeToMono (response -> {
145
+ if (response .statusCode ().is2xxSuccessful ()) {
146
+ return response .bodyToMono (Map .class )
147
+ .map (map -> map .get ("result" ))
148
+ .map (QueryExecutionResult ::success );
149
+ }
150
+ return response .bodyToMono (Map .class )
151
+ .map (map -> MapUtils .getString (map , "message" ))
152
+ .map (QueryExecutionResult ::errorWithMessage );
153
+ });
154
+ } catch (Exception e ) {
155
+ log .error ("Encryption error" , e );
156
+ return Mono .error (new ServerException ("Encryption error" ));
157
+ }
158
+ });
137
159
}
138
160
139
161
@ SuppressWarnings ("unchecked" )
0 commit comments