Skip to content

Commit 4c6c607

Browse files
committed
update PrivilegesEvaluator to subscribe to changes on setting for whether user attribute serialization is enabled
Signed-off-by: Mark Boyd <[email protected]>
1 parent 7645558 commit 4c6c607

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
8181
import org.opensearch.cluster.metadata.Metadata;
8282
import org.opensearch.cluster.service.ClusterService;
83+
import org.opensearch.common.settings.ClusterSettings;
8384
import org.opensearch.common.settings.Settings;
8485
import org.opensearch.common.util.concurrent.ThreadContext;
8586
import org.opensearch.core.common.Strings;
@@ -105,6 +106,7 @@
105106
import org.opensearch.security.securityconf.impl.v7.TenantV7;
106107
import org.opensearch.security.support.Base64Helper;
107108
import org.opensearch.security.support.ConfigConstants;
109+
import org.opensearch.security.support.SecuritySettings;
108110
import org.opensearch.security.support.WildcardMatcher;
109111
import org.opensearch.security.user.User;
110112
import org.opensearch.tasks.Task;
@@ -153,6 +155,7 @@ public class PrivilegesEvaluator {
153155
private PrivilegesInterceptor privilegesInterceptor;
154156

155157
private final boolean checkSnapshotRestoreWritePrivileges;
158+
private boolean isUserAttributeSerializationEnabled;
156159

157160
private final ClusterInfoHolder clusterInfoHolder;
158161
private final ConfigurationRepository configurationRepository;
@@ -204,6 +207,10 @@ public PrivilegesEvaluator(
204207
ConfigConstants.SECURITY_CHECK_SNAPSHOT_RESTORE_WRITE_PRIVILEGES,
205208
ConfigConstants.SECURITY_DEFAULT_CHECK_SNAPSHOT_RESTORE_WRITE_PRIVILEGES
206209
);
210+
this.isUserAttributeSerializationEnabled = settings.getAsBoolean(
211+
USER_ATTRIBUTE_SERIALIZATION_ENABLED,
212+
USER_ATTRIBUTE_SERIALIZATION_ENABLED_DEFAULT
213+
);
207214

208215
this.clusterInfoHolder = clusterInfoHolder;
209216
this.irr = irr;
@@ -236,6 +243,8 @@ public PrivilegesEvaluator(
236243
actionPrivileges.clusterStateMetadataDependentPrivileges().updateClusterStateMetadataAsync(clusterService, threadPool);
237244
}
238245
});
246+
247+
this.registerClusterSettingsChangeListener(clusterService.getClusterSettings());
239248
}
240249
}
241250

@@ -286,8 +295,17 @@ public boolean isInitialized() {
286295
return configModel != null && dcm != null && actionPrivileges.get() != null;
287296
}
288297

298+
public void registerClusterSettingsChangeListener(final ClusterSettings clusterSettings) {
299+
clusterSettings.addSettingsUpdateConsumer(
300+
SecuritySettings.USER_ATTRIBUTE_SERIALIZATION_ENABLED_SETTING,
301+
newIsUserAttributeSerializationEnabled -> {
302+
isUserAttributeSerializationEnabled = newIsUserAttributeSerializationEnabled;
303+
}
304+
);
305+
}
306+
289307
private boolean isUserAttributeSerializationEnabled() {
290-
return this.settings.getAsBoolean(USER_ATTRIBUTE_SERIALIZATION_ENABLED, USER_ATTRIBUTE_SERIALIZATION_ENABLED_DEFAULT);
308+
return isUserAttributeSerializationEnabled;
291309
}
292310

293311
private void setUserInfoInThreadContext(PrivilegesEvaluationContext context) {

0 commit comments

Comments
 (0)