Skip to content

Commit

Permalink
fix(plc4j): Adjust endpoint selection logic.
Browse files Browse the repository at this point in the history
Signed-off-by: Łukasz Dywicki <[email protected]>
  • Loading branch information
splatch committed Oct 18, 2024
1 parent a6e364a commit 7a4ef4a
Showing 1 changed file with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,10 @@ public CompletableFuture<EndpointDescription> onDiscoverGetEndpointsRequest() {
);

return conversation.submit(endpointsRequest, GetEndpointsResponse.class).thenApply(response -> {
List<ExtensionObjectDefinition> endpoints = response.getEndpoints();
Entry<EndpointDescription, UserTokenPolicy> entry = selectEndpoint(response.getEndpoints(), this.endpoints, this.configuration.getSecurityPolicy(), this.configuration.getMessageSecurity());

if (entry == null) {
Set<String> endpointUris = endpoints.stream()
.filter(EndpointDescription.class::isInstance)
.map(EndpointDescription.class::cast)
Set<String> endpointUris = response.getEndpoints().stream()
.map(EndpointDescription::getEndpointUrl)
.map(PascalString::getStringValue)
.collect(Collectors.toSet());
Expand Down Expand Up @@ -499,18 +496,13 @@ private static ReadBufferByteBased toBuffer(Supplier<Payload> supplier) {
* @param messageSecurity Message security needed by client.
* @return Endpoint matching given.
*/
private Entry<EndpointDescription, UserTokenPolicy> selectEndpoint(List<ExtensionObjectDefinition> extensionObjects, Collection<String> contactPoints,
private Entry<EndpointDescription, UserTokenPolicy> selectEndpoint(List<EndpointDescription> extensionObjects, Collection<String> contactPoints,
SecurityPolicy securityPolicy, MessageSecurity messageSecurity) throws PlcRuntimeException {
// Get a list of the endpoints which match ours.
MessageSecurityMode effectiveMessageSecurity = SecurityPolicy.NONE == securityPolicy ? MessageSecurityMode.messageSecurityModeNone : messageSecurity.getMode();
List<Entry<EndpointDescription, UserTokenPolicy>> serverEndpoints = new ArrayList<>();

for (ExtensionObjectDefinition extensionObject : extensionObjects) {
if (!(extensionObject instanceof EndpointDescription)) {
continue;
}

EndpointDescription endpointDescription = (EndpointDescription) extensionObject;
for (EndpointDescription endpointDescription : extensionObjects) {
if (isMatchingEndpoint(endpointDescription, contactPoints)) {
boolean policyMatch = endpointDescription.getSecurityPolicyUri().getStringValue().equals(securityPolicy.getSecurityPolicyUri());
boolean msgSecurityMatch = endpointDescription.getSecurityMode().equals(effectiveMessageSecurity);
Expand All @@ -519,12 +511,9 @@ private Entry<EndpointDescription, UserTokenPolicy> selectEndpoint(List<Extensio
continue;
}

for (ExtensionObjectDefinition objectDefinition : endpointDescription.getUserIdentityTokens()) {
if (objectDefinition instanceof UserTokenPolicy) {
UserTokenPolicy userTokenPolicy = (UserTokenPolicy) objectDefinition;
if (isUserTokenPolicyCompatible(userTokenPolicy, this.username)) {
serverEndpoints.add(entry(endpointDescription, userTokenPolicy));
}
for (UserTokenPolicy userTokenPolicy : endpointDescription.getUserIdentityTokens()) {
if (isUserTokenPolicyCompatible(userTokenPolicy, this.username)) {
serverEndpoints.add(entry(endpointDescription, userTokenPolicy));
}
}
}
Expand Down

0 comments on commit 7a4ef4a

Please sign in to comment.