From 79afd834b9b946fa7b5ad5541b689c8b7404e7b5 Mon Sep 17 00:00:00 2001 From: Stephen Crawford Date: Thu, 16 Nov 2023 13:27:06 -0500 Subject: [PATCH] backport #1970 Signed-off-by: Stephen Crawford --- src/main/java/org/opensearch/security/user/User.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/opensearch/security/user/User.java b/src/main/java/org/opensearch/security/user/User.java index f7f7b93709..0150b64e9a 100644 --- a/src/main/java/org/opensearch/security/user/User.java +++ b/src/main/java/org/opensearch/security/user/User.java @@ -66,10 +66,10 @@ public class User implements Serializable, Writeable, CustomAttributesAware { /** * roles == backend_roles */ - private final Set roles = new HashSet(); - private final Set openDistroSecurityRoles = new HashSet(); + private final Set roles = Collections.synchronizedSet(new HashSet()); + private final Set openDistroSecurityRoles = Collections.synchronizedSet(new HashSet()); private String requestedTenant; - private Map attributes = new HashMap<>(); + private Map attributes = Collections.synchronizedMap(new HashMap<>()); private boolean isInjected = false; public User(final StreamInput in) throws IOException { @@ -77,7 +77,7 @@ public User(final StreamInput in) throws IOException { name = in.readString(); roles.addAll(in.readList(StreamInput::readString)); requestedTenant = in.readString(); - attributes = in.readMap(StreamInput::readString, StreamInput::readString); + attributes = attributes = Collections.synchronizedMap(in.readMap(StreamInput::readString, StreamInput::readString)); openDistroSecurityRoles.addAll(in.readList(StreamInput::readString)); } @@ -254,7 +254,7 @@ public void writeTo(StreamOutput out) throws IOException { */ public synchronized final Map getCustomAttributesMap() { if(attributes == null) { - attributes = new HashMap<>(); + attributes = Collections.synchronizedMap(new HashMap<>()); } return attributes; } @@ -266,6 +266,6 @@ public final void addSecurityRoles(final Collection securityRoles) { } public final Set getSecurityRoles() { - return this.openDistroSecurityRoles == null ? Collections.emptySet() : Collections.unmodifiableSet(this.openDistroSecurityRoles); + return this.openDistroSecurityRoles == null ? Collections.synchronizedSet(Collections.emptySet()) : Collections.unmodifiableSet(this.openDistroSecurityRoles); } }