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 0e146de2a64..8bd49ae52d6 100644 --- a/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStore.java +++ b/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStore.java @@ -117,7 +117,11 @@ public class FileUserPasswdStore extends AbstractComponent implements UserPasswd users.put(username, hash.toCharArray()); } - return users.build(); + ImmutableMap usersMap = users.build(); + if (logger != null && usersMap.isEmpty()){ + logger.warn("No users found in file [" + path.toAbsolutePath() + "]. Use bin/shield/esusers to add users and role mappings"); + } + return usersMap; } public static void writeFile(Map esUsers, Path path) { diff --git a/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java b/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java index 21a30418e8a..29dc163c68f 100644 --- a/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java +++ b/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java @@ -6,6 +6,8 @@ package org.elasticsearch.shield.authc.esusers; import com.carrotsearch.ant.tasks.junit4.dependencies.com.google.common.base.Charsets; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; @@ -29,6 +31,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.*; +import static org.mockito.Mockito.*; /** * @@ -116,4 +119,15 @@ public class FileUserPasswdStoreTests extends ElasticsearchTestCase { assertThat(users, notNullValue()); assertThat(users.keySet(), hasSize(1)); } + + @Test + public void testParseEmptyFile() throws Exception { + File empty = this.tempFolder.newFile(); + Path path = Paths.get(getClass().getResource("users").toURI()); + ESLogger log = ESLoggerFactory.getLogger("test"); + log = spy(log); + Map users = FileUserPasswdStore.parseFile(empty.toPath(), log); + + verify(log, times(1)).warn(contains("No users found")); + } }