Skip to content

Commit

Permalink
Sec index state listener
Browse files Browse the repository at this point in the history
  • Loading branch information
n1v0lg committed Nov 2, 2023
1 parent 523ada6 commit 8e06688
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,8 @@ Collection<Object> createComponents(

reservedRoleMappingAction.set(new ReservedRoleMappingAction(nativeRoleMappingStore));
systemIndices.getMainIndexManager().onStateRecovered(state -> reservedRoleMappingAction.get().securityIndexRecovered());
// How do we wait for role mappings to be available instead of only the security index?
systemIndices.getMainIndexManager().onStateRecovered(state -> nativeRoleMappingStore.loadCache());

cacheInvalidatorRegistry.validate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,6 @@ protected void loadMappings(ActionListener<List<ExpressionRoleMapping>> listener
new ContextPreservingActionListener<>(supplier, ActionListener.wrap((Collection<ExpressionRoleMapping> mappings) -> {
final List<ExpressionRoleMapping> mappingList = mappings.stream().filter(Objects::nonNull).toList();
logger.debug("successfully loaded [{}] role-mapping(s) from [{}]", mappingList.size(), securityIndex.aliasName());
// TODO hack hack hack
if (cache != null) {
cache.invalidateAll();
for (var mapping : mappingList) {
cache.put(mapping.getName(), mapping);
}
}
listener.onResponse(mappingList);
}, ex -> {
logger.error(
Expand All @@ -165,6 +158,17 @@ protected void loadMappings(ActionListener<List<ExpressionRoleMapping>> listener
}
}

public void loadCache() {
if (cache != null) {
loadMappings(ActionListener.wrap(roleMappings -> {
cache.invalidateAll();
for (var roleMapping : roleMappings) {
cache.put(roleMapping.getName(), roleMapping);
}
}, logger::error));
}
}

protected static ExpressionRoleMapping buildMapping(String id, BytesReference source) {
try (
InputStream stream = source.streamInput();
Expand Down Expand Up @@ -370,7 +374,7 @@ public void onSecurityIndexStateChange(SecurityIndexManager.State previousState,
refreshRealms(ActionListener.noop(), null);
// TODO is this what we want?
if (cache != null) {
// re-load cache, yikes...
// reload cache, yikes...
getMappings(ActionListener.noop());
}
}
Expand Down

0 comments on commit 8e06688

Please sign in to comment.