From b78262046e724998dd84ede254312e2fe84b2841 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Thu, 7 Aug 2014 14:06:14 +0200 Subject: [PATCH] Packaging: Fix broken paths, adapt to elasticsearch packaging * Add config and bin directory to assembly * Add main method to ESUsersTool so it starts * Fix bin/esusers to actually start * Fix ESUsersTool to write files in config/shield by default as each plugin has its own directory after installation * Changed bin/ and config/ directory to reflect path after installation in ES Original commit: elastic/x-pack-elasticsearch@7d4165e389dbe5d9d60067ccb47d98d2c1c0dd07 --- src/main/assemblies/plugin.xml | 4 ++-- .../shield/authc/esusers/FileUserPasswdStore.java | 4 +++- .../shield/authc/esusers/FileUserRolesStore.java | 4 +++- .../elasticsearch/shield/authc/esusers/tool/ESUsersTool.java | 4 ++++ .../java/org/elasticsearch/shield/plugin/SecurityPlugin.java | 4 +++- .../org/elasticsearch/shield/plugin/ShieldPluginTests.java | 2 +- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/assemblies/plugin.xml b/src/main/assemblies/plugin.xml index 552e09b4b9d..67d54d1523f 100644 --- a/src/main/assemblies/plugin.xml +++ b/src/main/assemblies/plugin.xml @@ -8,11 +8,11 @@ false - bin + bin/shield bin - config + config/shield config diff --git a/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStore.java b/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStore.java index ac419871eb6..81d04845518 100644 --- a/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStore.java +++ b/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStore.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.shield.authc.support.Hasher; import org.elasticsearch.shield.authc.support.UserPasswdStore; +import org.elasticsearch.shield.plugin.SecurityPlugin; import org.elasticsearch.watcher.FileChangesListener; import org.elasticsearch.watcher.FileWatcher; import org.elasticsearch.watcher.ResourceWatcherService; @@ -74,7 +75,8 @@ public class FileUserPasswdStore extends AbstractComponent implements UserPasswd public static Path resolveFile(Settings settings, Environment env) { String location = settings.get("shield.authc.esusers.files.users"); if (location == null) { - return env.configFile().toPath().resolve(".users"); + File shieldDirectory = new File(env.configFile(), SecurityPlugin.NAME); + return shieldDirectory.toPath().resolve(".users"); } return Paths.get(location); } diff --git a/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStore.java b/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStore.java index dcb2a40b8bf..79d503050f1 100644 --- a/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStore.java +++ b/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStore.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.shield.authc.support.UserRolesStore; +import org.elasticsearch.shield.plugin.SecurityPlugin; import org.elasticsearch.watcher.FileChangesListener; import org.elasticsearch.watcher.FileWatcher; import org.elasticsearch.watcher.ResourceWatcherService; @@ -67,7 +68,8 @@ public class FileUserRolesStore extends AbstractComponent implements UserRolesSt public static Path resolveFile(Settings settings, Environment env) { String location = settings.get("shield.authc.esusers.files.users_roles"); if (location == null) { - return env.configFile().toPath().resolve(".users_roles"); + File shieldDirectory = new File(env.configFile(), SecurityPlugin.NAME); + return shieldDirectory.toPath().resolve(".users_roles"); } return Paths.get(location); } diff --git a/src/main/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersTool.java b/src/main/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersTool.java index a001a85c736..6cc857a07d7 100644 --- a/src/main/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersTool.java +++ b/src/main/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersTool.java @@ -34,6 +34,10 @@ public class ESUsersTool extends CliTool { .cmds(Useradd.CMD, Userdel.CMD, Passwd.CMD) .build(); + public static void main(String[] args) { + new ESUsersTool().execute(args); + } + public ESUsersTool() { super(CONFIG); } diff --git a/src/main/java/org/elasticsearch/shield/plugin/SecurityPlugin.java b/src/main/java/org/elasticsearch/shield/plugin/SecurityPlugin.java index 0d0c54856b0..f09cff24aaa 100644 --- a/src/main/java/org/elasticsearch/shield/plugin/SecurityPlugin.java +++ b/src/main/java/org/elasticsearch/shield/plugin/SecurityPlugin.java @@ -17,9 +17,11 @@ import java.util.Collection; */ public class SecurityPlugin extends AbstractPlugin { + public static final String NAME = "shield"; + @Override public String name() { - return "shield"; + return NAME; } @Override diff --git a/src/test/java/org/elasticsearch/shield/plugin/ShieldPluginTests.java b/src/test/java/org/elasticsearch/shield/plugin/ShieldPluginTests.java index 9ea41e04f60..4f9b480007e 100644 --- a/src/test/java/org/elasticsearch/shield/plugin/ShieldPluginTests.java +++ b/src/test/java/org/elasticsearch/shield/plugin/ShieldPluginTests.java @@ -41,7 +41,7 @@ public class ShieldPluginTests extends ElasticsearchIntegrationTest { logger.info("--> Checking nodes info"); for (NodeInfo nodeInfo : nodeInfos.getNodes()) { assertThat(nodeInfo.getPlugins().getInfos(), hasSize(1)); - assertThat(nodeInfo.getPlugins().getInfos().get(0).getName(), is("shield")); + assertThat(nodeInfo.getPlugins().getInfos().get(0).getName(), is(SecurityPlugin.NAME)); } }