Skip to content

Commit

Permalink
Initialize empty document subset bit set cache used for DLS
Browse files Browse the repository at this point in the history
This commit initializes `DocumentSubsetBitsetCache` even if DLS
is disabled, previously it would throw null pointer when querying
usage stats. It is okay to initialize empty `DocumentSubsetBitsetCache`
so it does not fail when accessing usage stats.

Closes elastic#45147
  • Loading branch information
Yogesh Gaikwad committed Aug 31, 2019
1 parent 42c7449 commit ac01c9b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,6 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
securityContext.set(new SecurityContext(settings, threadPool.getThreadContext()));
components.add(securityContext.get());

if (XPackSettings.DLS_FLS_ENABLED.get(settings)) {
dlsBitsetCache.set(new DocumentSubsetBitsetCache(settings));
}

// audit trail service construction
final List<AuditTrail> auditTrails = XPackSettings.AUDIT_ENABLED.get(settings)
? Collections.singletonList(new LoggingAuditTrail(settings, clusterService, threadPool))
Expand Down Expand Up @@ -408,6 +404,7 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
final NativePrivilegeStore privilegeStore = new NativePrivilegeStore(settings, client, securityIndex.get());
components.add(privilegeStore);

dlsBitsetCache.set(new DocumentSubsetBitsetCache(settings));
final FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(settings);
final FileRolesStore fileRolesStore = new FileRolesStore(settings, env, resourceWatcherService, getLicenseState());
final NativeRolesStore nativeRolesStore = new NativeRolesStore(settings, client, getLicenseState(), securityIndex.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ public CompositeRolesStore(Settings settings, FileRolesStore fileRolesStore, Nat
ReservedRolesStore reservedRolesStore, NativePrivilegeStore privilegeStore,
List<BiConsumer<Set<String>, ActionListener<RoleRetrievalResult>>> rolesProviders,
ThreadContext threadContext, XPackLicenseState licenseState, FieldPermissionsCache fieldPermissionsCache,
ApiKeyService apiKeyService, @Nullable DocumentSubsetBitsetCache dlsBitsetCache,
ApiKeyService apiKeyService, DocumentSubsetBitsetCache dlsBitsetCache,
Consumer<Collection<RoleDescriptor>> effectiveRoleDescriptorsConsumer) {
this.fileRolesStore = fileRolesStore;
this.dlsBitsetCache = dlsBitsetCache;
this.fileRolesStore = Objects.requireNonNull(fileRolesStore);
this.dlsBitsetCache = Objects.requireNonNull(dlsBitsetCache);
fileRolesStore.addListener(this::invalidate);
this.nativeRolesStore = nativeRolesStore;
this.privilegeStore = privilegeStore;
this.licenseState = licenseState;
this.fieldPermissionsCache = fieldPermissionsCache;
this.apiKeyService = apiKeyService;
this.effectiveRoleDescriptorsConsumer = effectiveRoleDescriptorsConsumer;
this.nativeRolesStore = Objects.requireNonNull(nativeRolesStore);
this.privilegeStore = Objects.requireNonNull(privilegeStore);
this.licenseState = Objects.requireNonNull(licenseState);
this.fieldPermissionsCache = Objects.requireNonNull(fieldPermissionsCache);
this.apiKeyService = Objects.requireNonNull(apiKeyService);
this.effectiveRoleDescriptorsConsumer = Objects.requireNonNull(effectiveRoleDescriptorsConsumer);
CacheBuilder<RoleKey, Role> builder = CacheBuilder.builder();
final int cacheSize = CACHE_SIZE_SETTING.get(settings);
if (cacheSize >= 0) {
Expand Down
Loading

0 comments on commit ac01c9b

Please sign in to comment.