diff --git a/shield/src/main/java/org/elasticsearch/index/ProtectedServiceInstaller.java b/shield/src/main/java/org/elasticsearch/index/ProtectedServiceInstaller.java deleted file mode 100644 index 90805ccd2ff..00000000000 --- a/shield/src/main/java/org/elasticsearch/index/ProtectedServiceInstaller.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.index; - -import org.elasticsearch.shield.ShieldPlugin; -import org.elasticsearch.shield.authz.accesscontrol.OptOutQueryCache; -import org.elasticsearch.shield.authz.accesscontrol.ShieldIndexSearcherWrapper; - -/** - * This class installs package protected extension points on the {@link IndexModule} - */ -public class ProtectedServiceInstaller { - - public static void install(IndexModule module, boolean clientMode) { - module.indexSearcherWrapper = ShieldIndexSearcherWrapper.class; - if (clientMode == false) { - module.registerQueryCache(ShieldPlugin.OPT_OUT_QUERY_CACHE, OptOutQueryCache::new); - } - } - -} diff --git a/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java b/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java index 49eebf04d06..9f8c06fc3e5 100644 --- a/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java +++ b/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java @@ -29,12 +29,13 @@ import org.elasticsearch.shield.authc.Realms; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.authc.support.UsernamePasswordToken; import org.elasticsearch.shield.authz.AuthorizationModule; -import org.elasticsearch.index.ProtectedServiceInstaller; import org.elasticsearch.shield.authz.accesscontrol.OptOutQueryCache; +import org.elasticsearch.shield.authz.accesscontrol.ShieldIndexSearcherWrapper; import org.elasticsearch.shield.authz.store.FileRolesStore; import org.elasticsearch.shield.crypto.CryptoModule; import org.elasticsearch.shield.crypto.InternalCryptoService; import org.elasticsearch.shield.license.LicenseModule; +import org.elasticsearch.shield.license.ShieldLicenseState; import org.elasticsearch.shield.license.ShieldLicensee; import org.elasticsearch.shield.rest.ShieldRestModule; import org.elasticsearch.shield.rest.action.RestShieldInfoAction; @@ -68,6 +69,7 @@ public class ShieldPlugin extends Plugin { private final Settings settings; private final boolean enabled; private final boolean clientMode; + private final ShieldLicenseState shieldLicenseState = new ShieldLicenseState(); public ShieldPlugin(Settings settings) { this.settings = settings; @@ -99,7 +101,7 @@ public class ShieldPlugin extends Plugin { } else { return Arrays.asList( new ShieldModule(settings), - new LicenseModule(settings), + new LicenseModule(settings, shieldLicenseState), new CryptoModule(settings), new AuthenticationModule(settings), new AuthorizationModule(settings), @@ -153,7 +155,10 @@ public class ShieldPlugin extends Plugin { if (enabled == false) { return; } - ProtectedServiceInstaller.install(module, clientMode); + 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); + } } public void onModule(ActionModule module) { diff --git a/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java b/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java index fbafb404553..2139f457976 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java +++ b/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java @@ -12,11 +12,9 @@ import org.apache.lucene.util.*; import org.apache.lucene.util.BitSet; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.support.LoggerMessageFormat; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.cache.bitset.BitsetFilterCache; import org.elasticsearch.index.engine.EngineConfig; @@ -59,7 +57,6 @@ public final class ShieldIndexSearcherWrapper extends IndexSearcherWrapper { private final ShieldLicenseState shieldLicenseState; private final ESLogger logger; - @Inject public ShieldIndexSearcherWrapper(IndexSettings indexSettings, IndexQueryParserService parserService, MapperService mapperService, BitsetFilterCache bitsetFilterCache, ShieldLicenseState shieldLicenseState) { this.logger = Loggers.getLogger(getClass(), indexSettings.getSettings()); diff --git a/shield/src/main/java/org/elasticsearch/shield/license/LicenseModule.java b/shield/src/main/java/org/elasticsearch/shield/license/LicenseModule.java index 9c7d015adb8..5469072a02c 100644 --- a/shield/src/main/java/org/elasticsearch/shield/license/LicenseModule.java +++ b/shield/src/main/java/org/elasticsearch/shield/license/LicenseModule.java @@ -13,15 +13,18 @@ import org.elasticsearch.shield.support.AbstractShieldModule; */ public class LicenseModule extends AbstractShieldModule.Node { - public LicenseModule(Settings settings) { + private final ShieldLicenseState shieldLicenseState; + + public LicenseModule(Settings settings, ShieldLicenseState shieldLicenseState) { super(settings); verifyLicensePlugin(); + this.shieldLicenseState = shieldLicenseState; } @Override protected void configureNode() { bind(ShieldLicensee.class).asEagerSingleton(); - bind(ShieldLicenseState.class).asEagerSingleton(); + bind(ShieldLicenseState.class).toInstance(shieldLicenseState); } private void verifyLicensePlugin() {