diff --git a/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java b/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java index 095b971ccd1..2f5ac7334a2 100644 --- a/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java +++ b/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java @@ -18,6 +18,7 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.http.HttpServerModule; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexService; +import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestModule; import org.elasticsearch.shield.action.ShieldActionFilter; @@ -51,7 +52,6 @@ import org.elasticsearch.shield.transport.netty.ShieldNettyHttpServerTransport; import org.elasticsearch.shield.transport.netty.ShieldNettyTransport; import org.elasticsearch.transport.TransportModule; -import java.io.Closeable; import java.nio.file.Path; import java.util.*; import java.security.AccessController; @@ -179,13 +179,6 @@ public class ShieldPlugin extends Plugin { clusterDynamicSettingsModule.registerClusterDynamicSetting(IPFilter.IP_FILTER_ENABLED_HTTP_SETTING, Validator.EMPTY); } - @Override - public void onIndexService(IndexService indexService) { - if (enabled && clientMode == false) { - failIfShieldQueryCacheIsNotActive(indexService.getIndexSettings().getSettings(), false); - } - } - @Override public void onIndexModule(IndexModule module) { if (enabled == false) { @@ -199,6 +192,12 @@ public class ShieldPlugin extends Plugin { } if (clientMode == false) { module.registerQueryCache(ShieldPlugin.OPT_OUT_QUERY_CACHE, OptOutQueryCache::new); + module.addIndexEventListener(new IndexEventListener() { + @Override + public void afterIndexCreated(IndexService indexService) { + failIfShieldQueryCacheIsNotActive(indexService.getIndexSettings().getSettings(), false); + } + }); } }