You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by ld...@apache.org on 2024/02/12 17:25:18 UTC
(plc4x) 01/01: fix(plc4j): Stabilization of build after opcua security PR merges.
This is an automated email from the ASF dual-hosted git repository.
ldywicki pushed a commit to branch opcua-stability-fixes-0.12
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 271e1cbfb0b65e02cd07735e22ce58764502eb17
Author: Łukasz Dywicki <lu...@code-house.org>
AuthorDate: Mon Feb 12 18:25:05 2024 +0100
fix(plc4j): Stabilization of build after opcua security PR merges.
Signed-off-by: Łukasz Dywicki <lu...@code-house.org>
---
.../org/apache/plc4x/java/opcua/context/SecureChannel.java | 11 +++++------
.../java/opcua/context/SecureChannelTransactionManager.java | 4 ++--
.../apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java | 12 ++++++++++--
3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
index 3343727fe4..8c8b4ad56b 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
@@ -415,10 +415,7 @@ public class SecureChannel {
});
}
- public CompletableFuture<EndpointDescription> onDiscoverGetEndpointsRequest(
- OpenSecureChannelResponse openSecureChannelResponse) {
-// ChannelSecurityToken securityToken = (ChannelSecurityToken) openSecureChannelResponse.getSecurityToken();
-// securityHeader.set(new SecurityHeader(securityToken.getChannelId(), securityToken.getTokenId()));
+ public CompletableFuture<EndpointDescription> onDiscoverGetEndpointsRequest(OpenSecureChannelResponse openSecureChannelResponse) {
RequestHeader requestHeader = conversation.createRequestHeader();
GetEndpointsRequest endpointsRequest = new GetEndpointsRequest(
@@ -432,12 +429,13 @@ public class SecureChannel {
return conversation.submit(endpointsRequest, GetEndpointsResponse.class).thenApply(response -> {
List<ExtensionObjectDefinition> endpoints = response.getEndpoints();
+ MessageSecurityMode effectiveMode = this.configuration.getSecurityPolicy() == SecurityPolicy.NONE ? MessageSecurityMode.messageSecurityModeNone : this.configuration.getMessageSecurity().getMode();
for (ExtensionObjectDefinition endpoint : endpoints) {
EndpointDescription endpointDescription = (EndpointDescription) endpoint;
boolean urlMatch = endpointDescription.getEndpointUrl().getStringValue().equals(this.endpoint.getStringValue());
boolean policyMatch = endpointDescription.getSecurityPolicyUri().getStringValue().equals(this.configuration.getSecurityPolicy().getSecurityPolicyUri());
- boolean msgSecurityMatch = endpointDescription.getSecurityMode().equals(this.configuration.getMessageSecurity().getMode());
+ boolean msgSecurityMatch = endpointDescription.getSecurityMode().equals(effectiveMode);
LOGGER.debug("Validate OPC UA endpoint {} during discovery phase."
+ "Expected {}. Endpoint policy {} looking for {}. Message security {}, looking for {}", endpointDescription.getEndpointUrl().getStringValue(), this.endpoint.getStringValue(),
@@ -450,7 +448,8 @@ public class SecureChannel {
}
}
- throw new IllegalArgumentException("Could not find endpoint matching client configuration");
+ throw new IllegalArgumentException("Could not find endpoint matching client configuration. Tested " + endpoints.size() + " endpoints. "
+ + "None matched " + this.endpoint.getStringValue() + " " + this.configuration.getSecurityPolicy().getSecurityPolicyUri() + " " + this.configuration.getMessageSecurity().getMode());
});
}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannelTransactionManager.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannelTransactionManager.java
index 0690519f22..6a74fd17ec 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannelTransactionManager.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannelTransactionManager.java
@@ -73,11 +73,11 @@ public class SecureChannelTransactionManager {
* @return the next sequential request handle
*/
public int getRequestHandle() {
- int transactionId = requestHandleGenerator.getAndIncrement();
+ int requestHandle = requestHandleGenerator.getAndIncrement();
if (requestHandleGenerator.get() == SecureChannelTransactionManager.DEFAULT_MAX_REQUEST_ID) {
requestHandleGenerator.set(0);
}
- return transactionId;
+ return requestHandle;
}
}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
index f3286daaff..95c8b3ba65 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
@@ -94,7 +94,7 @@ public class OpcuaProtocolLogic extends Plc4xProtocolBase<OpcuaAPU> implements H
@Override
public void close(ConversationContext<OpcuaAPU> context) {
- //Nothing
+ tm.shutdown();
}
@Override
@@ -106,7 +106,15 @@ public class OpcuaProtocolLogic extends Plc4xProtocolBase<OpcuaAPU> implements H
subscriber.getValue().stopSubscriber();
}
- channel.onDisconnect();
+ RequestTransaction tx = tm.startRequest();
+ tx.submit(() -> {
+ try {
+ channel.onDisconnect();
+ tx.endRequest();
+ } catch (Exception e) {
+ tx.failRequest(e);
+ }
+ });
}
@Override