diff --git a/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java b/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java index 9f8c06fc3e5..1e4780c8108 100644 --- a/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java +++ b/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java @@ -69,7 +69,8 @@ public class ShieldPlugin extends Plugin { private final Settings settings; private final boolean enabled; private final boolean clientMode; - private final ShieldLicenseState shieldLicenseState = new ShieldLicenseState(); + private ShieldLicenseState shieldLicenseState; + public ShieldPlugin(Settings settings) { this.settings = settings; @@ -99,6 +100,10 @@ public class ShieldPlugin extends Plugin { new ShieldTransportModule(settings), new SSLModule(settings)); } else { + // we can't load that at construction time since the license plugin might not have been loaded at that point + // which might not be the case during Plugin class instantiation. Once nodeModules are pulled + // everything should have been loaded + shieldLicenseState = new ShieldLicenseState(); return Arrays.asList( new ShieldModule(settings), new LicenseModule(settings, shieldLicenseState), @@ -155,7 +160,10 @@ public class ShieldPlugin extends Plugin { if (enabled == false) { return; } - module.setSearcherWrapper((indexService) -> new ShieldIndexSearcherWrapper(indexService.getIndexSettings(), indexService.queryParserService(), indexService.mapperService(), indexService.bitsetFilterCache(), shieldLicenseState)); + assert shieldLicenseState != null; + module.setSearcherWrapper((indexService) -> new ShieldIndexSearcherWrapper(indexService.getIndexSettings(), + indexService.queryParserService(), indexService.mapperService(), + indexService.bitsetFilterCache(), shieldLicenseState)); if (clientMode == false) { module.registerQueryCache(ShieldPlugin.OPT_OUT_QUERY_CACHE, OptOutQueryCache::new); }