diff --git a/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java b/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java index 5533578df2a..2c5ad5082df 100644 --- a/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java +++ b/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield; -import com.google.common.collect.ImmutableList; import org.elasticsearch.action.ActionModule; import org.elasticsearch.client.Client; import org.elasticsearch.client.support.Headers; @@ -117,26 +116,25 @@ public class ShieldPlugin extends Plugin { if (enabled && clientMode == false) { failIfShieldQueryCacheIsNotActive(settings, false); } - return ImmutableList.of(); + return Collections.emptyList(); } @Override public Collection shardModules(Settings settings) { if (enabled && clientMode == false) { failIfShieldQueryCacheIsNotActive(settings, false); - return ImmutableList.of(new AccessControlShardModule(settings)); + return Collections.singletonList(new AccessControlShardModule(settings)); } else { - return ImmutableList.of(); + return Collections.emptyList(); } } @Override public Collection> nodeServices() { - ImmutableList.Builder> builder = ImmutableList.builder(); if (enabled && clientMode == false) { - builder.add(LicenseService.class).add(InternalCryptoService.class).add(FileRolesStore.class).add(Realms.class).add(IPFilter.class); + return Arrays.>asList(LicenseService.class, InternalCryptoService.class, FileRolesStore.class, Realms.class, IPFilter.class); } - return builder.build(); + return Collections.emptyList(); } @Override diff --git a/shield/src/main/java/org/elasticsearch/shield/authc/AuthenticationModule.java b/shield/src/main/java/org/elasticsearch/shield/authc/AuthenticationModule.java index f2003aebdac..0484f309fac 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authc/AuthenticationModule.java +++ b/shield/src/main/java/org/elasticsearch/shield/authc/AuthenticationModule.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authc; -import com.google.common.collect.ImmutableList; import org.elasticsearch.common.inject.multibindings.MapBinder; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.shield.authc.activedirectory.ActiveDirectoryRealm; @@ -22,7 +21,7 @@ import java.util.Map.Entry; */ public class AuthenticationModule extends AbstractShieldModule.Node { - private static final List INTERNAL_REALM_TYPES = ImmutableList.of(ESUsersRealm.TYPE, ActiveDirectoryRealm.TYPE, LdapRealm.TYPE, PkiRealm.TYPE); + private static final List INTERNAL_REALM_TYPES = Arrays.asList(ESUsersRealm.TYPE, ActiveDirectoryRealm.TYPE, LdapRealm.TYPE, PkiRealm.TYPE); private final Map>>> customRealms = new HashMap<>(); diff --git a/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectoryGroupsResolver.java b/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectoryGroupsResolver.java index b3c5439e8f0..17f2721ebf0 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectoryGroupsResolver.java +++ b/shield/src/main/java/org/elasticsearch/shield/authc/activedirectory/ActiveDirectoryGroupsResolver.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authc.activedirectory; -import com.google.common.collect.ImmutableList; import com.google.common.primitives.Ints; import com.unboundid.ldap.sdk.*; import org.elasticsearch.common.Strings; @@ -47,11 +46,10 @@ public class ActiveDirectoryGroupsResolver implements GroupsResolver { throw Exceptions.authenticationError("failed to fetch AD groups for DN [{}]", e, userDn); } - ImmutableList.Builder groups = ImmutableList.builder(); + List groupList = new ArrayList<>(); for (SearchResultEntry entry : results.getSearchEntries()) { - groups.add(entry.getDN()); + groupList.add(entry.getDN()); } - List groupList = groups.build(); if (logger.isDebugEnabled()) { logger.debug("found these groups [{}] for userDN [{}]", groupList, userDn); } diff --git a/shield/src/main/java/org/elasticsearch/shield/authz/AuthorizationService.java b/shield/src/main/java/org/elasticsearch/shield/authz/AuthorizationService.java index 50bfcadfd4f..67f62421dca 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authz/AuthorizationService.java +++ b/shield/src/main/java/org/elasticsearch/shield/authz/AuthorizationService.java @@ -5,11 +5,12 @@ */ package org.elasticsearch.shield.authz; -import com.google.common.collect.ImmutableList; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.shield.User; import org.elasticsearch.transport.TransportRequest; +import java.util.List; + /** * */ @@ -21,7 +22,7 @@ public interface AuthorizationService { * @param user The user * @param action The action */ - ImmutableList authorizedIndicesAndAliases(User user, String action); + List authorizedIndicesAndAliases(User user, String action); /** * Verifies that the given user can execute the given request (and action). If the user doesn't diff --git a/shield/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java b/shield/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java index b4fcf247acd..98375705f50 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java +++ b/shield/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java @@ -7,7 +7,6 @@ package org.elasticsearch.shield.authz; import com.google.common.base.Predicate; import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.action.CompositeIndicesRequest; @@ -34,8 +33,7 @@ import org.elasticsearch.shield.authz.indicesresolver.IndicesAndAliasesResolver; import org.elasticsearch.shield.authz.store.RolesStore; import org.elasticsearch.transport.TransportRequest; -import java.util.Map; -import java.util.Set; +import java.util.*; import static org.elasticsearch.shield.support.Exceptions.authorizationError; @@ -68,12 +66,12 @@ public class InternalAuthorizationService extends AbstractComponent implements A } @Override - public ImmutableList authorizedIndicesAndAliases(User user, String action) { + public List authorizedIndicesAndAliases(User user, String action) { String[] roles = user.roles(); if (roles.length == 0) { - return ImmutableList.of(); + return Collections.emptyList(); } - ImmutableList.Builder> predicates = ImmutableList.builder(); + List> predicates = new ArrayList<>(); for (String role : roles) { Permission.Global.Role global = rolesStore.role(role); if (global != null) { @@ -81,8 +79,8 @@ public class InternalAuthorizationService extends AbstractComponent implements A } } - ImmutableList.Builder indicesAndAliases = ImmutableList.builder(); - Predicate predicate = Predicates.or(predicates.build()); + List indicesAndAliases = new ArrayList<>(); + Predicate predicate = Predicates.or(predicates); MetaData metaData = clusterService.state().metaData(); // TODO: can this be done smarter? I think there are usually more indices/aliases in the cluster then indices defined a roles? for (Map.Entry entry : metaData.getAliasAndIndexLookup().entrySet()) { @@ -91,7 +89,7 @@ public class InternalAuthorizationService extends AbstractComponent implements A indicesAndAliases.add(aliasOrIndex); } } - return indicesAndAliases.build(); + return Collections.unmodifiableList(indicesAndAliases); } @Override diff --git a/shield/src/main/java/org/elasticsearch/shield/authz/Permission.java b/shield/src/main/java/org/elasticsearch/shield/authz/Permission.java index 517d7c33fc6..1a5ee65261a 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authz/Permission.java +++ b/shield/src/main/java/org/elasticsearch/shield/authz/Permission.java @@ -9,7 +9,10 @@ import com.google.common.base.Predicate; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; -import com.google.common.collect.*; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterators; +import com.google.common.collect.UnmodifiableIterator; import org.elasticsearch.cluster.metadata.AliasOrIndex; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; @@ -118,7 +121,7 @@ public interface Permission { private final String name; private Cluster.Core cluster = Cluster.Core.NONE; - private ImmutableList.Builder groups = ImmutableList.builder(); + private List groups = new ArrayList<>(); private Builder(String name) { this.name = name; @@ -140,8 +143,7 @@ public interface Permission { } public Role build() { - ImmutableList list = groups.build(); - Indices.Core indices = list.isEmpty() ? Indices.Core.NONE : new Indices.Core(list.toArray(new Indices.Group[list.size()])); + Indices.Core indices = groups.isEmpty() ? Indices.Core.NONE : new Indices.Core(groups.toArray(new Indices.Group[groups.size()])); return new Role(name, cluster, indices); } } @@ -149,7 +151,7 @@ public interface Permission { static class Compound extends Global { - public Compound(ImmutableList globals) { + public Compound(List globals) { super(new Cluster.Globals(globals), new Indices.Globals(globals)); } @@ -159,7 +161,7 @@ public interface Permission { public static class Builder { - private ImmutableList.Builder globals = ImmutableList.builder(); + private List globals = new ArrayList<>(); private Builder() { } @@ -170,7 +172,7 @@ public interface Permission { } public Compound build() { - return new Compound(globals.build()); + return new Compound(Collections.unmodifiableList(globals)); } } } @@ -218,9 +220,9 @@ public interface Permission { static class Globals implements Cluster { - private final ImmutableList globals; + private final List globals; - public Globals(ImmutableList globals) { + public Globals(List globals) { this.globals = globals; } @@ -275,13 +277,13 @@ public interface Permission { .build(new CacheLoader>() { @Override public Predicate load(String action) throws Exception { - ImmutableList.Builder indices = ImmutableList.builder(); + List indices = new ArrayList<>(); for (Group group : groups) { if (group.actionMatcher.apply(action)) { - indices.add(group.indices); + indices.addAll(Arrays.asList(group.indices)); } } - return new AutomatonPredicate(Automatons.patterns(indices.build())); + return new AutomatonPredicate(Automatons.patterns(Collections.unmodifiableList(indices))); } }); @@ -392,9 +394,9 @@ public interface Permission { public static class Globals implements Indices { - private final ImmutableList globals; + private final List globals; - public Globals(ImmutableList globals) { + public Globals(List globals) { this.globals = globals; } @@ -453,7 +455,7 @@ public interface Permission { private final Iterator globals; private Iterator current; - Iter(ImmutableList globals) { + Iter(List globals) { this.globals = globals.iterator(); advance(); } diff --git a/shield/src/main/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesAndAliasesResolver.java b/shield/src/main/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesAndAliasesResolver.java index e233bf9c729..4f75273f456 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesAndAliasesResolver.java +++ b/shield/src/main/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesAndAliasesResolver.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authz.indicesresolver; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; import org.elasticsearch.action.AliasesRequest; import org.elasticsearch.action.CompositeIndicesRequest; @@ -66,7 +65,7 @@ public class DefaultIndicesAndAliasesResolver implements IndicesAndAliasesResolv private Set resolveIndicesAndAliases(User user, String action, IndicesRequest indicesRequest, MetaData metaData) { if (indicesRequest.indicesOptions().expandWildcardsOpen() || indicesRequest.indicesOptions().expandWildcardsClosed()) { if (indicesRequest instanceof IndicesRequest.Replaceable) { - ImmutableList authorizedIndices = authzService.authorizedIndicesAndAliases(user, action); + List authorizedIndices = authzService.authorizedIndicesAndAliases(user, action); List indices = replaceWildcardsWithAuthorizedIndices(indicesRequest.indices(), indicesRequest.indicesOptions(), metaData, authorizedIndices); ((IndicesRequest.Replaceable) indicesRequest).indices(indices.toArray(new String[indices.size()])); } else { @@ -86,7 +85,7 @@ public class DefaultIndicesAndAliasesResolver implements IndicesAndAliasesResolv //AliasesRequest extends IndicesRequest.Replaceable, hence its indices have already been properly replaced. AliasesRequest aliasesRequest = (AliasesRequest) indicesRequest; if (aliasesRequest.expandAliasesWildcards()) { - ImmutableList authorizedIndices = authzService.authorizedIndicesAndAliases(user, action); + List authorizedIndices = authzService.authorizedIndicesAndAliases(user, action); List aliases = replaceWildcardsWithAuthorizedAliases(aliasesRequest.aliases(), loadAuthorizedAliases(authorizedIndices, metaData)); aliasesRequest.aliases(aliases.toArray(new String[aliases.size()])); } diff --git a/shield/src/main/java/org/elasticsearch/shield/license/LicenseService.java b/shield/src/main/java/org/elasticsearch/shield/license/LicenseService.java index d32f0ef41ee..b7506278440 100644 --- a/shield/src/main/java/org/elasticsearch/shield/license/LicenseService.java +++ b/shield/src/main/java/org/elasticsearch/shield/license/LicenseService.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.license; -import com.google.common.collect.ImmutableList; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; @@ -17,10 +16,7 @@ import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.core.LicensesClientService; import org.elasticsearch.shield.ShieldPlugin; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Locale; +import java.util.*; /** * @@ -46,7 +42,7 @@ public class LicenseService extends AbstractLifecycleComponent { super(settings); this.licensesClientService = licensesClientService; this.notifier = notifier; - this.expirationLoggers = ImmutableList.of( + this.expirationLoggers = Arrays.asList( new LicensesClientService.ExpirationCallback.Pre(days(7), days(30), days(1)) { @Override public void on(License license, LicensesClientService.ExpirationStatus status) { diff --git a/shield/src/main/java/org/elasticsearch/shield/support/Automatons.java b/shield/src/main/java/org/elasticsearch/shield/support/Automatons.java index 3eb5f9d1a81..6181b636d55 100644 --- a/shield/src/main/java/org/elasticsearch/shield/support/Automatons.java +++ b/shield/src/main/java/org/elasticsearch/shield/support/Automatons.java @@ -5,13 +5,13 @@ */ package org.elasticsearch.shield.support; -import com.google.common.collect.ImmutableList; import dk.brics.automaton.Automaton; import dk.brics.automaton.BasicAutomata; import dk.brics.automaton.BasicOperations; import dk.brics.automaton.RegExp; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -35,7 +35,7 @@ public final class Automatons { * Builds and returns an automaton that will represent the union of all the given patterns. */ public static Automaton patterns(String... patterns) { - return patterns(ImmutableList.copyOf(patterns)); + return patterns(Arrays.asList(patterns)); } /** diff --git a/shield/src/test/java/org/elasticsearch/shield/authc/InternalAuthenticationServiceTests.java b/shield/src/test/java/org/elasticsearch/shield/authc/InternalAuthenticationServiceTests.java index d8349a2df87..7885851bce4 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authc/InternalAuthenticationServiceTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authc/InternalAuthenticationServiceTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authc; -import com.google.common.collect.ImmutableList; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -27,6 +26,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -68,7 +68,7 @@ public class InternalAuthenticationServiceTests extends ESTestCase { realms = new Realms(Settings.EMPTY, new Environment(settings), Collections.emptyMap(), mock(ShieldSettingsFilter.class)) { @Override protected List initRealms() { - return ImmutableList.of(firstRealm, secondRealm); + return Arrays.asList(firstRealm, secondRealm); } }; realms.start(); diff --git a/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java b/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java index eb78e34cedf..995593c8fc8 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java @@ -6,7 +6,6 @@ package org.elasticsearch.shield.authc.esusers; import com.google.common.base.Charsets; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLoggerFactory; @@ -29,6 +28,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.nio.file.StandardOpenOption; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; @@ -68,7 +69,7 @@ public class FileUserPasswdStoreTests extends ESTestCase { Path file = createTempFile(); // writing in utf_16 should cause a parsing error as we try to read the file in utf_8 - Files.write(file, ImmutableList.of("aldlfkjldjdflkjd"), Charsets.UTF_16); + Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); Settings esusersSettings = Settings.builder() .put("files.users", file.toAbsolutePath()) @@ -146,7 +147,7 @@ public class FileUserPasswdStoreTests extends ESTestCase { watcherService.start(); // now replacing the content of the users file with something that cannot be read - Files.write(tmp, ImmutableList.of("aldlfkjldjdflkjd"), Charsets.UTF_16); + Files.write(tmp, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); if (!latch.await(5, TimeUnit.SECONDS)) { fail("Waited too long for the updated file to be picked up"); @@ -198,7 +199,7 @@ public class FileUserPasswdStoreTests extends ESTestCase { public void testParseFile_WhenCannotReadFile() throws Exception { Path file = createTempFile(); // writing in utf_16 should cause a parsing error as we try to read the file in utf_8 - Files.write(file, ImmutableList.of("aldlfkjldjdflkjd"), Charsets.UTF_16); + Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO); try { FileUserPasswdStore.parseFile(file, logger); @@ -211,7 +212,7 @@ public class FileUserPasswdStoreTests extends ESTestCase { @Test public void testParseFile_InvalidLineDoesNotResultInLoggerNPE() throws Exception { Path file = createTempFile(); - Files.write(file, ImmutableList.of("NotValidUsername=Password", "user:pass"), Charsets.UTF_8); + Files.write(file, Arrays.asList("NotValidUsername=Password", "user:pass"), Charsets.UTF_8); Map users = FileUserPasswdStore.parseFile(file, null); assertThat(users, notNullValue()); assertThat(users.keySet(), hasSize(1)); @@ -221,7 +222,7 @@ public class FileUserPasswdStoreTests extends ESTestCase { public void testParseFileLenient_WhenCannotReadFile() throws Exception { Path file = createTempFile(); // writing in utf_16 should cause a parsing error as we try to read the file in utf_8 - Files.write(file, ImmutableList.of("aldlfkjldjdflkjd"), Charsets.UTF_16); + Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO); Map users = FileUserPasswdStore.parseFileLenient(file, logger); assertThat(users, notNullValue()); diff --git a/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStoreTests.java b/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStoreTests.java index 8803f6664f0..e780683f63c 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStoreTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStoreTests.java @@ -6,7 +6,6 @@ package org.elasticsearch.shield.authc.esusers; import com.google.common.base.Charsets; -import com.google.common.collect.ImmutableList; import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLoggerFactory; @@ -27,10 +26,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.nio.file.StandardOpenOption; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -156,7 +152,7 @@ public class FileUserRolesStoreTests extends ESTestCase { watcherService.start(); // now replacing the content of the users file with something that cannot be read - Files.write(tmp, ImmutableList.of("aldlfkjldjdflkjd"), Charsets.UTF_16); + Files.write(tmp, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); if (!latch.await(5, TimeUnit.SECONDS)) { fail("Waited too long for the updated file to be picked up"); diff --git a/shield/src/test/java/org/elasticsearch/shield/authc/support/DnRoleMapperTests.java b/shield/src/test/java/org/elasticsearch/shield/authc/support/DnRoleMapperTests.java index e9809a88258..1acacbe114a 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authc/support/DnRoleMapperTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authc/support/DnRoleMapperTests.java @@ -6,7 +6,6 @@ package org.elasticsearch.shield.authc.support; import com.google.common.base.Charsets; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.unboundid.ldap.sdk.DN; import org.elasticsearch.common.settings.Settings; @@ -75,7 +74,7 @@ public class DnRoleMapperTests extends ESTestCase { public void testMapper_ConfiguredWithUnreadableFile() throws Exception { Path file = createTempFile(); // writing in utf_16 should cause a parsing error as we try to read the file in utf_8 - Files.write(file, ImmutableList.of("aldlfkjldjdflkjd"), Charsets.UTF_16); + Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool); DnRoleMapper mapper = createMapper(file, watcherService); @@ -99,7 +98,7 @@ public class DnRoleMapperTests extends ESTestCase { } }); - Set roles = mapper.resolveRoles("", ImmutableList.of("cn=shield,ou=marvel,o=superheros")); + Set roles = mapper.resolveRoles("", Collections.singletonList("cn=shield,ou=marvel,o=superheros")); assertThat(roles, notNullValue()); assertThat(roles.size(), is(1)); assertThat(roles, contains("shield")); @@ -116,7 +115,7 @@ public class DnRoleMapperTests extends ESTestCase { fail("Waited too long for the updated file to be picked up"); } - roles = mapper.resolveRoles("", ImmutableList.of("cn=fantastic_four,ou=marvel,o=superheros")); + roles = mapper.resolveRoles("", Collections.singletonList("cn=fantastic_four,ou=marvel,o=superheros")); assertThat(roles, notNullValue()); assertThat(roles.size(), is(1)); assertThat(roles, contains("fantastic_four")); @@ -139,7 +138,7 @@ public class DnRoleMapperTests extends ESTestCase { } }); - Set roles = mapper.resolveRoles("", ImmutableList.of("cn=shield,ou=marvel,o=superheros")); + Set roles = mapper.resolveRoles("", Collections.singletonList("cn=shield,ou=marvel,o=superheros")); assertThat(roles, notNullValue()); assertThat(roles.size(), is(1)); assertThat(roles, contains("shield")); @@ -147,7 +146,7 @@ public class DnRoleMapperTests extends ESTestCase { watcherService.start(); // now replacing the content of the users file with something that cannot be read - Files.write(file, ImmutableList.of("aldlfkjldjdflkjd"), Charsets.UTF_16); + Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); if (!latch.await(5, TimeUnit.SECONDS)) { fail("Waited too long for the updated file to be picked up"); @@ -211,7 +210,7 @@ public class DnRoleMapperTests extends ESTestCase { public void testParseFile_WhenCannotReadFile() throws Exception { Path file = createTempFile(); // writing in utf_16 should cause a parsing error as we try to read the file in utf_8 - Files.write(file, ImmutableList.of("aldlfkjldjdflkjd"), Charsets.UTF_16); + Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO); try { DnRoleMapper.parseFile(file, logger, "_type", "_name"); @@ -225,7 +224,7 @@ public class DnRoleMapperTests extends ESTestCase { public void testParseFileLenient_WhenCannotReadFile() throws Exception { Path file = createTempFile(); // writing in utf_16 should cause a parsing error as we try to read the file in utf_8 - Files.write(file, ImmutableList.of("aldlfkjldjdflkjd"), Charsets.UTF_16); + Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO); ImmutableMap> mappings = DnRoleMapper.parseFileLenient(file, logger, "_type", "_name"); assertThat(mappings, notNullValue()); diff --git a/shield/src/test/java/org/elasticsearch/shield/authz/InternalAuthorizationServiceTests.java b/shield/src/test/java/org/elasticsearch/shield/authz/InternalAuthorizationServiceTests.java index 02275ddc3b5..1d7d2115af4 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authz/InternalAuthorizationServiceTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authz/InternalAuthorizationServiceTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authz; -import com.google.common.collect.ImmutableList; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.alias.Alias; @@ -31,6 +30,8 @@ import org.elasticsearch.transport.TransportRequest; import org.junit.Before; import org.junit.Test; +import java.util.List; + import static org.elasticsearch.test.ShieldTestsUtils.assertAuthenticationException; import static org.elasticsearch.test.ShieldTestsUtils.assertAuthorizationException; import static org.hamcrest.Matchers.*; @@ -253,7 +254,7 @@ public class InternalAuthorizationServiceTests extends ESTestCase { public void testIndicesAliasesWithNoRolesUser() { User user = new User.Simple("test user"); - ImmutableList list = internalAuthorizationService.authorizedIndicesAndAliases(user, ""); + List list = internalAuthorizationService.authorizedIndicesAndAliases(user, ""); assertThat(list.isEmpty(), is(true)); } @@ -279,7 +280,7 @@ public class InternalAuthorizationServiceTests extends ESTestCase { .build(), true) .build()); - ImmutableList list = internalAuthorizationService.authorizedIndicesAndAliases(user, SearchAction.NAME); + List list = internalAuthorizationService.authorizedIndicesAndAliases(user, SearchAction.NAME); assertThat(list, containsInAnyOrder("a1", "a2", "aaaaaa", "b", "ab")); assertThat(list.contains("bbbbb"), is(false)); assertThat(list.contains("ba"), is(false)); diff --git a/shield/src/test/java/org/elasticsearch/shield/authz/PermissionTests.java b/shield/src/test/java/org/elasticsearch/shield/authz/PermissionTests.java index 749ea868587..e10264eda7f 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authz/PermissionTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authz/PermissionTests.java @@ -6,12 +6,13 @@ package org.elasticsearch.shield.authz; import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; import org.elasticsearch.action.get.GetAction; import org.elasticsearch.test.ESTestCase; import org.junit.Before; import org.junit.Test; +import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import static org.elasticsearch.shield.authz.Privilege.Index.*; @@ -51,7 +52,7 @@ public class PermissionTests extends ESTestCase { builder.set(Cluster.action("cluster:monitor/nodes/info")); Permission.Global.Role noIndicesPermission = builder.build(); - Permission.Indices.Globals indicesGlobals = new Permission.Indices.Globals(ImmutableList.of(noIndicesPermission, permission)); + Permission.Indices.Globals indicesGlobals = new Permission.Indices.Globals(Collections.unmodifiableList(Arrays.asList(noIndicesPermission, permission))); Iterator iterator = indicesGlobals.iterator(); assertThat(iterator.hasNext(), is(equalTo(true))); int count = 0; diff --git a/shield/src/test/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesResolverTests.java b/shield/src/test/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesResolverTests.java index 888ab54d491..3bde9f7d28a 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesResolverTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesResolverTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authz.indicesresolver; -import com.google.common.collect.ImmutableList; import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; @@ -33,6 +32,8 @@ import org.elasticsearch.test.ESTestCase; import org.junit.Before; import org.junit.Test; +import java.util.Arrays; +import java.util.Collections; import java.util.Set; import static org.hamcrest.Matchers.*; @@ -70,17 +71,17 @@ public class DefaultIndicesResolverTests extends ESTestCase { user = new User.Simple("user", "role"); String[] authorizedIndices = new String[]{"bar", "bar-closed", "foofoobar", "foofoo", "missing", "foofoo-closed"}; - when(authzService.authorizedIndicesAndAliases(user, SearchAction.NAME)).thenReturn(ImmutableList.copyOf(authorizedIndices)); - when(authzService.authorizedIndicesAndAliases(user, MultiSearchAction.NAME)).thenReturn(ImmutableList.copyOf(authorizedIndices)); - when(authzService.authorizedIndicesAndAliases(user, MultiGetAction.NAME)).thenReturn(ImmutableList.copyOf(authorizedIndices)); - when(authzService.authorizedIndicesAndAliases(user, IndicesAliasesAction.NAME)).thenReturn(ImmutableList.copyOf(authorizedIndices)); - when(authzService.authorizedIndicesAndAliases(user, GetAliasesAction.NAME)).thenReturn(ImmutableList.copyOf(authorizedIndices)); - when(authzService.authorizedIndicesAndAliases(user, DeleteIndexAction.NAME)).thenReturn(ImmutableList.copyOf(authorizedIndices)); + when(authzService.authorizedIndicesAndAliases(user, SearchAction.NAME)).thenReturn(Collections.unmodifiableList(Arrays.asList(authorizedIndices))); + when(authzService.authorizedIndicesAndAliases(user, MultiSearchAction.NAME)).thenReturn(Collections.unmodifiableList(Arrays.asList(authorizedIndices))); + when(authzService.authorizedIndicesAndAliases(user, MultiGetAction.NAME)).thenReturn(Collections.unmodifiableList(Arrays.asList(authorizedIndices))); + when(authzService.authorizedIndicesAndAliases(user, IndicesAliasesAction.NAME)).thenReturn(Collections.unmodifiableList(Arrays.asList(authorizedIndices))); + when(authzService.authorizedIndicesAndAliases(user, GetAliasesAction.NAME)).thenReturn(Collections.unmodifiableList(Arrays.asList(authorizedIndices))); + when(authzService.authorizedIndicesAndAliases(user, DeleteIndexAction.NAME)).thenReturn(Collections.unmodifiableList(Arrays.asList(authorizedIndices))); userNoIndices = new User.Simple("test", "test"); - when(authzService.authorizedIndicesAndAliases(userNoIndices, IndicesAliasesAction.NAME)).thenReturn(ImmutableList.of()); - when(authzService.authorizedIndicesAndAliases(userNoIndices, GetAliasesAction.NAME)).thenReturn(ImmutableList.of()); - when(authzService.authorizedIndicesAndAliases(userNoIndices, SearchAction.NAME)).thenReturn(ImmutableList.of()); - when(authzService.authorizedIndicesAndAliases(userNoIndices, MultiSearchAction.NAME)).thenReturn(ImmutableList.of()); + when(authzService.authorizedIndicesAndAliases(userNoIndices, IndicesAliasesAction.NAME)).thenReturn(Collections.emptyList()); + when(authzService.authorizedIndicesAndAliases(userNoIndices, GetAliasesAction.NAME)).thenReturn(Collections.emptyList()); + when(authzService.authorizedIndicesAndAliases(userNoIndices, SearchAction.NAME)).thenReturn(Collections.emptyList()); + when(authzService.authorizedIndicesAndAliases(userNoIndices, MultiSearchAction.NAME)).thenReturn(Collections.emptyList()); defaultIndicesResolver = new DefaultIndicesAndAliasesResolver(authzService); } diff --git a/shield/src/test/java/org/elasticsearch/shield/authz/store/FileRolesStoreTests.java b/shield/src/test/java/org/elasticsearch/shield/authz/store/FileRolesStoreTests.java index 71e56f3d0f1..81d73ee877d 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authz/store/FileRolesStoreTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authz/store/FileRolesStoreTests.java @@ -6,7 +6,6 @@ package org.elasticsearch.shield.authz.store; import com.google.common.base.Charsets; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; @@ -195,7 +194,7 @@ public class FileRolesStoreTests extends ESTestCase { @Test public void testThatEmptyFileDoesNotResultInLoop() throws Exception { Path file = createTempFile(); - Files.write(file, ImmutableList.of("#"), Charsets.UTF_8); + Files.write(file, Collections.singletonList("#"), Charsets.UTF_8); Map roles = FileRolesStore.parseFile(file, Collections.emptySet(), logger); assertThat(roles.keySet(), is(empty())); }