Skip to content

Commit 210f292

Browse files
committed
backward compatible encryption option
1 parent cdd86d4 commit 210f292

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/encryption/EncryptionServiceImpl.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ public class EncryptionServiceImpl implements EncryptionService {
2020

2121
@Autowired
2222
public EncryptionServiceImpl(
23-
CommonConfig commonConfig,
24-
@Value("${lowcoder.node-server.password}") String password,
25-
@Value("${lowcoder.node-server.salt}") String salt
23+
CommonConfig commonConfig
2624
) {
2725
Encrypt encrypt = commonConfig.getEncrypt();
2826
String saltInHex = Hex.encodeHexString(encrypt.getSalt().getBytes());
2927
this.textEncryptor = Encryptors.text(encrypt.getPassword(), saltInHex);
30-
String saltInHexForNodeServer = Hex.encodeHexString(salt.getBytes());
31-
this.textEncryptorForNodeServer = Encryptors.text(password, saltInHexForNodeServer);
28+
String saltInHexForNodeServer = Hex.encodeHexString(commonConfig.getJsExecutor().getSalt().getBytes());
29+
this.textEncryptorForNodeServer = Encryptors.text(commonConfig.getJsExecutor().getPassword(), saltInHexForNodeServer);
3230
}
3331

3432
@Override

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/plugin/client/DatasourcePluginClient.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.lowcoder.domain.plugin.client.dto.GetPluginDynamicConfigRequestDTO;
1111
import org.lowcoder.infra.js.NodeServerClient;
1212
import org.lowcoder.infra.js.NodeServerHelper;
13+
import org.lowcoder.sdk.config.CommonConfig;
1314
import org.lowcoder.sdk.config.CommonConfigHelper;
1415
import org.lowcoder.sdk.exception.ServerException;
1516
import org.lowcoder.sdk.models.DatasourceTestResult;
@@ -48,6 +49,7 @@ public class DatasourcePluginClient implements NodeServerClient {
4849
.build();
4950

5051
private final CommonConfigHelper commonConfigHelper;
52+
private final CommonConfig commonConfig;
5153
private final NodeServerHelper nodeServerHelper;
5254
private final EncryptionService encryptionService;
5355

@@ -134,13 +136,23 @@ public Mono<QueryExecutionResult> executeQuery(String pluginName, Object queryDs
134136
"dataSourceConfig", datasourceConfig
135137
);
136138
String json = OBJECT_MAPPER.writeValueAsString(body);
137-
String encrypted = encryptionService.encryptStringForNodeServer(json);
138-
return WEB_CLIENT
139+
140+
boolean encryptionEnabled = commonConfig.getJsExecutor().isEncrypted();
141+
String payload;
142+
WebClient.RequestBodySpec requestSpec = WEB_CLIENT
139143
.post()
140144
.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)
145+
.header(HttpHeaders.ACCEPT_LANGUAGE, language);
146+
147+
if (encryptionEnabled) {
148+
payload = encryptionService.encryptStringForNodeServer(json);
149+
requestSpec = requestSpec.header("X-Encrypted", "true");
150+
} else {
151+
payload = json;
152+
}
153+
154+
return requestSpec
155+
.bodyValue(payload)
144156
.exchangeToMono(response -> {
145157
if (response.statusCode().is2xxSuccessful()) {
146158
return response.bodyToMono(Map.class)

server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/config/CommonConfig.java

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ public long getMaxAgeInSeconds() {
147147
@Data
148148
public static class JsExecutor {
149149
private String host;
150+
private String password;
151+
private String salt;
152+
private boolean isEncrypted;
150153
}
151154

152155
@Data

server/api-service/lowcoder-server/src/main/resources/application-debug.yaml

+4-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ common:
3737
cookie-name: LOWCODER_DEBUG_TOKEN
3838
js-executor:
3939
host: "http://127.0.0.1:6060"
40+
password: ${LOWCODER_NODE_SERVICE_SECRET:lowcoderpwd}
41+
salt: ${LOWCODER_NODE_SERVICE_SECRET_SALT:lowcodersalt}
42+
is-encrypted: ${LOWCODER_NODE_SERVICE_ENCRYPTED:false}
4043
workspace:
4144
mode: ${LOWCODER_WORKSPACE_MODE:SAAS}
4245
plugin-dirs:
@@ -61,9 +64,4 @@ logging:
6164
org.lowcoder: debug
6265

6366
default:
64-
query-timeout: ${LOWCODER_DEFAULT_QUERY_TIMEOUT:10s}
65-
66-
lowcoder:
67-
node-server:
68-
password: ${LOWCODER_NODE_SERVICE_SECRET:lowcoderpwd}
69-
salt: ${LOWCODER_NODE_SERVICE_SECRET_SALT:lowcodersalt}
67+
query-timeout: ${LOWCODER_DEFAULT_QUERY_TIMEOUT:10s}

server/api-service/lowcoder-server/src/main/resources/application.yaml

+4-6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ common:
7474
corsAllowedDomainString: ${LOWCODER_CORS_DOMAINS:*}
7575
js-executor:
7676
host: ${LOWCODER_NODE_SERVICE_URL:http://127.0.0.1:6060}
77+
password: ${LOWCODER_NODE_SERVICE_SECRET:lowcoderpwd}
78+
salt: ${LOWCODER_NODE_SERVICE_SECRET_SALT:lowcodersalt}
79+
is-encrypted: ${LOWCODER_NODE_SERVICE_ENCRYPTED:false}
7780
max-query-request-size: ${LOWCODER_MAX_REQUEST_SIZE:20m}
7881
max-query-response-size: ${LOWCODER_MAX_REQUEST_SIZE:20m}
7982
max-upload-size: ${LOWCODER_MAX_REQUEST_SIZE:20m}
@@ -129,9 +132,4 @@ management:
129132
redis:
130133
enabled: true
131134
diskspace:
132-
enabled: false
133-
134-
lowcoder:
135-
node-server:
136-
password: ${LOWCODER_NODE_SERVICE_SECRET:lowcoderpwd}
137-
salt: ${LOWCODER_NODE_SERVICE_SECRET_SALT:lowcodersalt}
135+
enabled: false

0 commit comments

Comments
 (0)