From f2abfb35f9cabd9663a1fc911ba972c743edb874 Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 21 Nov 2014 10:45:10 +0100 Subject: [PATCH] Work around circular dependency in core There is a circular dependency in core 1.4.0 that cause plugins to fail depending on their constructors injection. We have ClusterService in InternalAuthorizationService that triggers this problem, solved for now replacing the dependency with a Provider. The original bug is already fixed in core: https://github.com/elasticsearch/elasticsearch/pull/8415 . The problem manifested when enablieng a tribe node having shield installed on that node at the same time. Closes elastic/elasticsearch#363 Original commit: elastic/x-pack-elasticsearch@ac339ef247c408dbd8f0da47ff9a96490ff640c3 --- .../authz/InternalAuthorizationService.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java b/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java index 5c05f06b87c..df5e0a1676b 100644 --- a/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java +++ b/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.shield.authz; +import org.elasticsearch.Version; import org.elasticsearch.action.CompositeIndicesRequest; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.cluster.ClusterService; @@ -14,6 +15,7 @@ import org.elasticsearch.common.base.Predicates; import org.elasticsearch.common.collect.ImmutableList; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.Provider; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.shield.User; import org.elasticsearch.shield.audit.AuditTrail; @@ -31,16 +33,21 @@ import java.util.Set; */ public class InternalAuthorizationService extends AbstractComponent implements AuthorizationService { - private final ClusterService clusterService; + private final Provider clusterServiceProvider; private final RolesStore rolesStore; private final AuditTrail auditTrail; private final IndicesResolver[] indicesResolvers; + static { + //see https://github.com/elasticsearch/elasticsearch/pull/8415 + assert Version.CURRENT.onOrBefore(Version.V_1_4_0) : "replace the Provider with ClusterService"; + } + @Inject - public InternalAuthorizationService(Settings settings, RolesStore rolesStore, ClusterService clusterService, AuditTrail auditTrail) { + public InternalAuthorizationService(Settings settings, RolesStore rolesStore, Provider clusterServiceProvider, AuditTrail auditTrail) { super(settings); this.rolesStore = rolesStore; - this.clusterService = clusterService; + this.clusterServiceProvider = clusterServiceProvider; this.auditTrail = auditTrail; this.indicesResolvers = new IndicesResolver[] { new DefaultIndicesResolver(this) @@ -63,7 +70,7 @@ public class InternalAuthorizationService extends AbstractComponent implements A ImmutableList.Builder indicesAndAliases = ImmutableList.builder(); Predicate predicate = Predicates.or(predicates.build()); - MetaData metaData = clusterService.state().metaData(); + MetaData metaData = clusterServiceProvider.get().state().metaData(); for (String index : metaData.concreteAllIndices()) { if (predicate.apply(index)) { indicesAndAliases.add(index); @@ -176,7 +183,7 @@ public class InternalAuthorizationService extends AbstractComponent implements A } private Set resolveIndices(User user, String action, TransportRequest request) { - MetaData metaData = clusterService.state().metaData(); + MetaData metaData = clusterServiceProvider.get().state().metaData(); // some APIs are indices requests that are not actually associated with indices. For example, // search scroll request, is categorized under the indices context, but doesn't hold indices names