Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.hivemq.edge.adapters.opcua.config;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
Expand All @@ -30,9 +31,9 @@
import java.util.Map;

@JsonDeserialize(using = Auth.AuthDeserializer.class)
public record Auth(@JsonProperty("basic") @ModuleConfigField(title = "Basic Authentication",
description = "Username / password based authentication") @Nullable BasicAuth basicAuth,
@JsonProperty("x509") @ModuleConfigField(title = "X509 Authentication",
public record Auth(@JsonProperty("basic") @JsonInclude(JsonInclude.Include.NON_NULL) @ModuleConfigField(title = "Basic Authentication",
description = "Username / password based authentication") @Nullable BasicAuth basicAuth,
@JsonProperty("x509") @JsonInclude(JsonInclude.Include.NON_NULL) @ModuleConfigField(title = "X509 Authentication",
description = "Authentication based on certificate / private key") @Nullable X509Auth x509Auth) {

@JsonCreator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
*/
public enum MsgSecurityMode {

@JsonProperty("None")
@JsonProperty("NONE")
NONE(MessageSecurityMode.None),

@JsonProperty("Sign")
@JsonProperty("SIGN")
SIGN(MessageSecurityMode.Sign),

@JsonProperty("SignAndEncrypt")
@JsonProperty("SIGN_AND_ENCRYPT")
SIGN_AND_ENCRYPT(MessageSecurityMode.SignAndEncrypt);

private final @NotNull MessageSecurityMode miloMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ public record Security(@JsonProperty("policy") @ModuleConfigField(title = "OPC U
@JsonProperty("messageSecurityMode")
@JsonInclude(JsonInclude.Include.NON_NULL)
@ModuleConfigField(title = "Message Security Mode",
description = "Message security mode (None, Sign, SignAndEncrypt). If not specified, defaults based on the select OPC UA Security Policy: None→None, others→SignAndEncrypt.",
required = false) @Nullable MsgSecurityMode messageSecurityMode) {
description = "Message security mode (None, Sign, SignAndEncrypt). If not specified, defaults based on the select OPC UA Security Policy: None→None, others→SignAndEncrypt.") @Nullable MsgSecurityMode messageSecurityMode) {

public Security(@JsonProperty("policy") final @Nullable SecPolicy policy,
@JsonProperty("messageSecurityMode") final @Nullable MsgSecurityMode messageSecurityMode) {
this.policy = Objects.requireNonNullElse(policy, Constants.DEFAULT_SECURITY_POLICY);
this.messageSecurityMode = messageSecurityMode;
this.messageSecurityMode = Objects.requireNonNullElse(messageSecurityMode, MsgSecurityMode.NONE);
}

// Backwards compatibility constructor
Expand All @@ -63,13 +62,13 @@ static class SecurityDeserializer extends JsonDeserializer<Security> {
final @NotNull DeserializationContext context) throws IOException {
final String text = parser.getText();
if (text != null && text.isEmpty()) {
return new Security(Constants.DEFAULT_SECURITY_POLICY, null);
return new Security(Constants.DEFAULT_SECURITY_POLICY, MsgSecurityMode.NONE);
}

try {
final Map<String, Object> map = parser.readValueAs(Map.class);
if (map == null || map.isEmpty()) {
return new Security(Constants.DEFAULT_SECURITY_POLICY, null);
return new Security(Constants.DEFAULT_SECURITY_POLICY, MsgSecurityMode.NONE);
}

final Object policyValue = map.get("policy");
Expand All @@ -85,12 +84,12 @@ static class SecurityDeserializer extends JsonDeserializer<Security> {
if (modeValue instanceof String) {
messageSecurityMode = MsgSecurityMode.fromString((String) modeValue);
} else {
messageSecurityMode = null;
messageSecurityMode = MsgSecurityMode.NONE;
}

return new Security(policy, messageSecurityMode);
} catch (final IOException e) {
return new Security(Constants.DEFAULT_SECURITY_POLICY, null);
return new Security(Constants.DEFAULT_SECURITY_POLICY, MsgSecurityMode.NONE);
}
}
}
Expand Down
Loading