add shield integration to the ScriptServiceProxy
This change adds support for to put the watcher user in the context that is passed to the ScriptService when Shield is installed and watcher integration with Shield is enabled. Original commit: elastic/x-pack-elasticsearch@7e9983df0e
This commit is contained in:
parent
b4a81af254
commit
22d0ba4cf9
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.watcher.shield;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.HasContext;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -51,6 +52,13 @@ public class ShieldIntegration {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO this is a hack that needs to go away with proper fixes in core
|
||||
public void putUserInContext(HasContext context) {
|
||||
if (userHolder != null) {
|
||||
context.putInContext("_shield_user", ((WatcherUserHolder) userHolder).user);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean installed() {
|
||||
try {
|
||||
ShieldIntegration.class.getClassLoader().loadClass("org.elasticsearch.shield.ShieldPlugin");
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.init.proxy;
|
||||
|
||||
import org.elasticsearch.common.ContextAndHeaderHolder;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.script.*;
|
||||
import org.elasticsearch.watcher.shield.ShieldIntegration;
|
||||
import org.elasticsearch.watcher.support.Script;
|
||||
import org.elasticsearch.watcher.support.init.InitializingService;
|
||||
|
||||
|
@ -19,6 +21,7 @@ import java.util.Map;
|
|||
public class ScriptServiceProxy implements InitializingService.Initializable {
|
||||
|
||||
private ScriptService service;
|
||||
private ContextAndHeaderHolder contextAndHeaderHolder = new ContextAndHeaderHolder();
|
||||
|
||||
/**
|
||||
* Creates a proxy to the given script service (can be used for testing)
|
||||
|
@ -32,6 +35,10 @@ public class ScriptServiceProxy implements InitializingService.Initializable {
|
|||
@Override
|
||||
public void init(Injector injector) {
|
||||
this.service = injector.getInstance(ScriptService.class);
|
||||
ShieldIntegration shieldIntegration = injector.getInstance(ShieldIntegration.class);
|
||||
if (shieldIntegration != null) {
|
||||
shieldIntegration.putUserInContext(contextAndHeaderHolder);
|
||||
}
|
||||
}
|
||||
|
||||
public CompiledScript compile(Script script) {
|
||||
|
@ -39,7 +46,7 @@ public class ScriptServiceProxy implements InitializingService.Initializable {
|
|||
}
|
||||
|
||||
public CompiledScript compile(org.elasticsearch.script.Script script) {
|
||||
return service.compile(script, WatcherScriptContext.CTX);
|
||||
return service.compile(script, WatcherScriptContext.CTX, contextAndHeaderHolder);
|
||||
}
|
||||
|
||||
public ExecutableScript executable(CompiledScript compiledScript, Map<String, Object> vars) {
|
||||
|
@ -48,7 +55,7 @@ public class ScriptServiceProxy implements InitializingService.Initializable {
|
|||
|
||||
|
||||
public ExecutableScript executable(org.elasticsearch.script.Script script) {
|
||||
return service.executable(script, WatcherScriptContext.CTX);
|
||||
return service.executable(script, WatcherScriptContext.CTX, contextAndHeaderHolder);
|
||||
}
|
||||
|
||||
public static final ScriptContext.Plugin INSTANCE = new ScriptContext.Plugin("elasticsearch-watcher", "watch");
|
||||
|
|
Loading…
Reference in New Issue