Skip to content

Commit b1b7e2f

Browse files
committed
fix
1 parent ed07970 commit b1b7e2f

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaSink.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,16 @@ private void customizeClient(final String nodeUrl, final PipeParameters paramete
331331
final IdentityProvider provider;
332332
final String userName =
333333
parameters.getStringByKeys(CONNECTOR_IOTDB_USER_KEY, SINK_IOTDB_USER_KEY);
334+
final String password =
335+
parameters.getStringOrDefault(
336+
Arrays.asList(CONNECTOR_IOTDB_PASSWORD_KEY, SINK_IOTDB_PASSWORD_KEY),
337+
CONNECTOR_IOTDB_PASSWORD_DEFAULT_VALUE);
334338
provider =
335339
Objects.nonNull(userName)
336-
? new UsernameProvider(
337-
userName,
338-
parameters.getStringByKeys(CONNECTOR_IOTDB_PASSWORD_KEY, SINK_IOTDB_PASSWORD_KEY))
340+
? new UsernameProvider(userName, password)
339341
: new AnonymousProvider();
340342
client = new IoTDBOpcUaClient(nodeUrl, policy, provider);
341-
new ClientRunner(client).run();
343+
new ClientRunner(client, password).run();
342344
}
343345

344346
@Override

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/client/ClientRunner.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ public class ClientRunner {
5151
private final CompletableFuture<OpcUaClient> future = new CompletableFuture<>();
5252

5353
private final IoTDBOpcUaClient configurableUaClient;
54+
private final String password;
5455

55-
public ClientRunner(IoTDBOpcUaClient configurableUaClient) {
56+
public ClientRunner(final IoTDBOpcUaClient configurableUaClient, final String password) {
5657
this.configurableUaClient = configurableUaClient;
58+
this.password = password;
5759
}
5860

5961
private OpcUaClient createClient() throws Exception {
@@ -66,10 +68,11 @@ private OpcUaClient createClient() throws Exception {
6668

6769
final File pkiDir = securityTempDir.resolve("pki").toFile();
6870

69-
logger.info("security dir: " + securityTempDir.toAbsolutePath());
71+
logger.info("security dir: {}", securityTempDir.toAbsolutePath());
7072
logger.info("security pki dir: {}", pkiDir.getAbsolutePath());
7173

72-
final IoTDBKeyStoreLoaderClient loader = new IoTDBKeyStoreLoaderClient().load(securityTempDir);
74+
final IoTDBKeyStoreLoaderClient loader =
75+
new IoTDBKeyStoreLoaderClient().load(securityTempDir, password.toCharArray());
7376

7477
final DefaultTrustListManager trustListManager = new DefaultTrustListManager(pkiDir);
7578

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/client/IoTDBKeyStoreLoaderClient.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,20 @@ class IoTDBKeyStoreLoaderClient {
4242
Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
4343

4444
private static final String CLIENT_ALIAS = "client-ai";
45-
private static final char[] PASSWORD = "root".toCharArray();
4645

4746
private X509Certificate[] clientCertificateChain;
4847
private X509Certificate clientCertificate;
4948
private KeyPair clientKeyPair;
5049

51-
IoTDBKeyStoreLoaderClient load(Path baseDir) throws Exception {
50+
IoTDBKeyStoreLoaderClient load(final Path baseDir, final char[] password) throws Exception {
5251
final KeyStore keyStore = KeyStore.getInstance("PKCS12");
5352

5453
final Path serverKeyStore = baseDir.resolve("example-client.pfx");
5554

5655
System.out.println("Loading KeyStore at " + serverKeyStore);
5756

5857
if (!Files.exists(serverKeyStore)) {
59-
keyStore.load(null, PASSWORD);
58+
keyStore.load(null, password);
6059

6160
final KeyPair keyPair = SelfSignedCertificateGenerator.generateRsaKeyPair(2048);
6261

@@ -84,17 +83,17 @@ IoTDBKeyStoreLoaderClient load(Path baseDir) throws Exception {
8483
final X509Certificate certificate = builder.build();
8584

8685
keyStore.setKeyEntry(
87-
CLIENT_ALIAS, keyPair.getPrivate(), PASSWORD, new X509Certificate[] {certificate});
86+
CLIENT_ALIAS, keyPair.getPrivate(), password, new X509Certificate[] {certificate});
8887
try (OutputStream out = Files.newOutputStream(serverKeyStore)) {
89-
keyStore.store(out, PASSWORD);
88+
keyStore.store(out, password);
9089
}
9190
} else {
9291
try (InputStream in = Files.newInputStream(serverKeyStore)) {
93-
keyStore.load(in, PASSWORD);
92+
keyStore.load(in, password);
9493
}
9594
}
9695

97-
final Key clientPrivateKey = keyStore.getKey(CLIENT_ALIAS, PASSWORD);
96+
final Key clientPrivateKey = keyStore.getKey(CLIENT_ALIAS, password);
9897
if (clientPrivateKey instanceof PrivateKey) {
9998
clientCertificate = (X509Certificate) keyStore.getCertificate(CLIENT_ALIAS);
10099

0 commit comments

Comments
 (0)