Skip to content
Merged
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
12 changes: 6 additions & 6 deletions src/main/java/org/opensearch/security/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ public class User implements Serializable, Writeable, CustomAttributesAware {
/**
* roles == backend_roles
*/
private final Set<String> roles = new HashSet<String>();
private final Set<String> securityRoles = new HashSet<String>();
private final Set<String> roles = Collections.synchronizedSet(new HashSet<String>());
private final Set<String> securityRoles = Collections.synchronizedSet(new HashSet<String>());
private String requestedTenant;
private Map<String, String> attributes = new HashMap<>();
private Map<String, String> attributes = Collections.synchronizedMap(new HashMap<>());
private boolean isInjected = false;

public User(final StreamInput in) throws IOException {
super();
name = in.readString();
roles.addAll(in.readList(StreamInput::readString));
requestedTenant = in.readString();
attributes = in.readMap(StreamInput::readString, StreamInput::readString);
attributes = Collections.synchronizedMap(in.readMap(StreamInput::readString, StreamInput::readString));
securityRoles.addAll(in.readList(StreamInput::readString));
}

Expand Down Expand Up @@ -250,7 +250,7 @@ public void writeTo(StreamOutput out) throws IOException {
*/
public synchronized final Map<String, String> getCustomAttributesMap() {
if(attributes == null) {
attributes = new HashMap<>();
attributes = Collections.synchronizedMap(new HashMap<>());
}
return attributes;
}
Expand All @@ -262,6 +262,6 @@ public final void addSecurityRoles(final Collection<String> securityRoles) {
}

public final Set<String> getSecurityRoles() {
return this.securityRoles == null ? Collections.emptySet() : Collections.unmodifiableSet(this.securityRoles);
return this.securityRoles == null ? Collections.synchronizedSet(Collections.emptySet()) : Collections.unmodifiableSet(this.securityRoles);
}
}