Merge pull request elastic/elasticsearch#876 from s1monw/catchup/pull/14303

Use official public API to register query cache and index searcher wrapper

Original commit: elastic/x-pack-elasticsearch@00cd2ea3e5
This commit is contained in:
Simon Willnauer 2015-10-27 14:51:37 +01:00
commit b6038ae97f
4 changed files with 13 additions and 32 deletions

View File

@ -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);
}
}
}

View File

@ -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.<Module>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) {

View File

@ -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());

View File

@ -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() {