diff --git a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/basic/DefaultSyncConfig.java b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/basic/DefaultSyncConfig.java index 73eee24a7b5..581ae7cab97 100644 --- a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/basic/DefaultSyncConfig.java +++ b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/basic/DefaultSyncConfig.java @@ -19,9 +19,11 @@ import java.util.Collections; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.jetbrains.annotations.NotNull; /** @@ -203,9 +205,7 @@ public Authorizable setAutoMembershipConfig(@NotNull AutoMembershipConfig autoMe */ @NotNull public Set getAutoMembership(@NotNull org.apache.jackrabbit.api.security.user.Authorizable authorizable) { - return ImmutableSet.builder(). - addAll(autoMembershipConfig.getAutoMembership(authorizable)). - addAll(getAutoMembership()).build(); + return Stream.concat(autoMembershipConfig.getAutoMembership(authorizable).stream().filter(Objects::nonNull), getAutoMembership().stream().filter(Objects::nonNull)).collect(Collectors.toUnmodifiableSet()); } /** diff --git a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipPrincipals.java b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipPrincipals.java index 4e82e98a875..8e91be9f427 100644 --- a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipPrincipals.java +++ b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipPrincipals.java @@ -19,7 +19,6 @@ import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.UserManager; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.oak.spi.security.authentication.external.basic.AutoMembershipConfig; import org.apache.jackrabbit.oak.spi.security.principal.GroupPrincipals; @@ -220,7 +219,7 @@ private Map collectGlobalAutoMembershipPrincipals(@NotNull Str } } // only cache the principal instance but not the group (tree might become disconnected) - principalMap.put(idpName, ImmutableSet.copyOf(map.keySet())); + principalMap.put(idpName, Set.copyOf(map.keySet())); } else { // resolve Group objects from cached principals principalMap.get(idpName).forEach(groupPrincipal -> { diff --git a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalAuthorizableActionProvider.java b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalAuthorizableActionProvider.java index b20a86ac1ce..6c7fb590579 100644 --- a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalAuthorizableActionProvider.java +++ b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalAuthorizableActionProvider.java @@ -16,11 +16,11 @@ */ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.commons.PropertiesUtil; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.spi.security.SecurityProvider; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef; @@ -199,7 +199,7 @@ private Map> getAutomembership(boolean memberIsGroup) { private static void updateAutoMembershipMap(@NotNull Map> map, @NotNull String syncHandlerName, @NotNull String idpName, @NotNull String[] membership) { - Set userMembership = ImmutableSet.copyOf(membership); + Set userMembership = CollectionUtils.toSet(membership); Set previous = map.put(idpName, userMembership); if (previous != null) { String msg = previous.equals(userMembership) ? "Duplicate" : "Colliding"; diff --git a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProvider.java b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProvider.java index f37af55f81e..dc14aae5087 100644 --- a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProvider.java +++ b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProvider.java @@ -45,7 +45,6 @@ import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.jackrabbit.commons.iterator.AbstractLazyIterator; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.oak.api.PropertyState; @@ -56,6 +55,7 @@ import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.memory.PropertyValues; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef; @@ -326,7 +326,7 @@ public boolean isMember(@NotNull Group group, @NotNull Authorizable authorizable return Collections.emptyIterator(); } - Set valueSet = ImmutableSet.copyOf(vs); + Set valueSet = CollectionUtils.toSet(vs); Iterator declared = Iterators.filter(Iterators.transform(valueSet.iterator(), value -> { try { String groupPrincipalName = value.getString(); diff --git a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ProtectionConfigImpl.java b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ProtectionConfigImpl.java index afc52c42d4f..68d5864abc6 100644 --- a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ProtectionConfigImpl.java +++ b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ProtectionConfigImpl.java @@ -16,10 +16,10 @@ */ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PropertiesUtil; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.ProtectionConfig; import org.jetbrains.annotations.NotNull; import org.osgi.service.component.annotations.Activate; @@ -58,8 +58,8 @@ public class ProtectionConfigImpl implements ProtectionConfig { @Activate protected void activate(Map properties) { - propertyNames = ImmutableSet.copyOf(PropertiesUtil.toStringArray(properties.get("propertyNames"), new String[0])); - nodeNames = ImmutableSet.copyOf(PropertiesUtil.toStringArray(properties.get("nodeNames"), new String[0])); + propertyNames = CollectionUtils.toSet(PropertiesUtil.toStringArray(properties.get("propertyNames"), new String[0])); + nodeNames = CollectionUtils.toSet(PropertiesUtil.toStringArray(properties.get("nodeNames"), new String[0])); } @Override diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/TestIdentityProvider.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/TestIdentityProvider.java index ebbb8d17b0c..c2a8cbbb660 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/TestIdentityProvider.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/TestIdentityProvider.java @@ -31,7 +31,6 @@ import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.jetbrains.annotations.NotNull; public class TestIdentityProvider implements ExternalIdentityProvider { @@ -238,7 +237,7 @@ public TestIdentity withGroups(@NotNull String ... grps) { @NotNull public TestIdentity withGroups(@NotNull ExternalIdentityRef... groups) { - this.groups.addAll(ImmutableSet.copyOf(groups)); + this.groups.addAll(Set.of(groups)); return this; } } diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/basic/DefaultSyncConfigTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/basic/DefaultSyncConfigTest.java index 2cc06dd4afc..6f4e295d284 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/basic/DefaultSyncConfigTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/basic/DefaultSyncConfigTest.java @@ -17,10 +17,10 @@ package org.apache.jackrabbit.oak.spi.security.authentication.external.basic; import java.util.Collections; +import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.User; import org.jetbrains.annotations.NotNull; @@ -158,9 +158,9 @@ public void testAutoMembership() { // only global ids for getAutoMembership(Authorizable) as no specific config for 'gr' assertEquals(globalGroupIds, dscA.getAutoMembership(gr)); // for 'user' the combine set of global and conditional config is returned - Set expected = ImmutableSet.builder() - .addAll(globalGroupIds) - .addAll(configGroupIds).build(); + Set expected = new HashSet<>(); + expected.addAll(globalGroupIds); + expected.addAll(configGroupIds); assertEquals(expected, dscA.getAutoMembership(user)); } } diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/SyncMBeanImplTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/SyncMBeanImplTest.java index 29c35dc4761..3eda03bb4c9 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/SyncMBeanImplTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/SyncMBeanImplTest.java @@ -24,7 +24,6 @@ import javax.jcr.RepositoryException; import javax.jcr.ValueFactory; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.User; @@ -637,7 +636,7 @@ public void testListOrphanedUsers() throws Exception { result = syncMBean.listOrphanedUsers(); assertEquals(2, result.length); - assertEquals(Set.of("thirdUser", "g"), ImmutableSet.copyOf(result)); + assertEquals(Set.of("thirdUser", "g"), Set.of(result)); } @Test @@ -669,7 +668,7 @@ public void testListOrphanedUsersThrowingHandler() throws Exception { result = createThrowingSyncMBean(true).listOrphanedUsers(); assertEquals(2, result.length); - assertEquals(Set.of("thirdUser", "g"), ImmutableSet.copyOf(result)); + assertEquals(Set.of("thirdUser", "g"), Set.of(result)); } @Test diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipPrincipalsTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipPrincipalsTest.java index 965a6b90d87..571cccdb2ed 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipPrincipalsTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipPrincipalsTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.user.Authorizable; @@ -117,7 +116,7 @@ public void testGetPrincipalsMultipleGroups() throws Exception { public void testGetPrincipalsMixed() throws Exception { Collection principals = getAutoMembership(IDP_MIXED_AM, authorizable, false); assertFalse(principals.isEmpty()); - assertEquals(Set.of(automembershipGroup1.getPrincipal()), ImmutableSet.copyOf(principals)); + assertEquals(Set.of(automembershipGroup1.getPrincipal()), Set.copyOf(principals)); verifyNoInteractions(authorizable, amConfig); } diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipProviderTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipProviderTest.java index a07bab29442..060e04976f5 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipProviderTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipProviderTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; @@ -24,6 +23,7 @@ import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.jackrabbit.oak.api.QueryEngine; import org.apache.jackrabbit.oak.api.Root; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef; import org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncConfig; import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal; @@ -107,14 +107,14 @@ private AutoMembershipProvider createAutoMembershipProvider(@NotNull Root root, } private static void assertMatchingEntries(@NotNull Iterator it, @NotNull String... expectedIds) { - Set ids = ImmutableSet.copyOf(Iterators.transform(it, authorizable -> { + Set ids = CollectionUtils.toSet(Iterators.transform(it, authorizable -> { try { return authorizable.getID(); } catch (RepositoryException repositoryException) { return ""; } })); - assertEquals(ImmutableSet.copyOf(expectedIds), ids); + assertEquals(Set.of(expectedIds), ids); } @Test @@ -378,7 +378,7 @@ public void testGetMembershipSelf() throws Exception { public void testGetMembershipExternalUser() throws Exception { setExternalId(getTestUser().getID(), IDP_VALID_AM); - Set groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), false)); + Set groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), false)); assertEquals(2, groups.size()); assertTrue(groups.contains(automembershipGroup1)); assertTrue(groups.contains(automembershipGroup2)); @@ -388,7 +388,7 @@ public void testGetMembershipExternalUser() throws Exception { public void testGetMembershipExternalUserInherited() throws Exception { setExternalId(getTestUser().getID(), IDP_VALID_AM); - Set groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), true)); + Set groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), true)); assertEquals(2, groups.size()); assertTrue(groups.contains(automembershipGroup1)); } @@ -399,12 +399,12 @@ public void testGetMembershipExternalUserNestedGroups() throws Exception { Group baseGroup = getTestGroup(automembershipGroup1); - Set groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), false)); + Set groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), false)); assertEquals(2, groups.size()); assertTrue(groups.contains(automembershipGroup1)); assertTrue(groups.contains(automembershipGroup2)); - groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), true)); + groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), true)); assertEquals(3, groups.size()); assertTrue(groups.contains(automembershipGroup1)); assertTrue(groups.contains(automembershipGroup2)); @@ -421,12 +421,12 @@ public void testGetMembershipExternalUserEveryoneGroupExists() throws Exception automembershipGroup2.addMember(automembershipGroup1); root.commit(); - Set groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), false)); + Set groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), false)); assertEquals(2, groups.size()); assertTrue(groups.contains(automembershipGroup1)); assertTrue(groups.contains(automembershipGroup2)); - groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), true)); + groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), true)); assertEquals(2, groups.size()); // all duplicates must be properly filtered and everyone must be omitted assertTrue(groups.contains(automembershipGroup1)); assertTrue(groups.contains(automembershipGroup2)); @@ -512,7 +512,7 @@ public void testGetMembershipAutogroupGroupMemberOfFails() throws Exception { setExternalId(getTestUser().getID(), IDP_VALID_AM); AutoMembershipProvider amp = createAutoMembershipProvider(root, um); - Set membership = ImmutableSet.copyOf(amp.getMembership(getTestUser(), true)); + Set membership = CollectionUtils.toSet(amp.getMembership(getTestUser(), true)); assertEquals(2, membership.size()); } diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderTest.java index 3fa32144a98..0df66b4beb1 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal; import org.apache.jackrabbit.api.security.principal.PrincipalManager; @@ -29,6 +28,7 @@ import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.tree.TreeAware; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup; @@ -90,13 +90,13 @@ void sync(@NotNull ExternalUser externalUser) throws Exception { @NotNull Set getExpectedGroupPrincipals(@NotNull String userId) throws Exception { if (syncConfig.user().getMembershipNestingDepth() == 1) { - return ImmutableSet.copyOf(idp.getUser(userId).getDeclaredGroups()).stream().map(externalIdentityRef -> { + return CollectionUtils.toSet(idp.getUser(userId).getDeclaredGroups()).stream().map(externalIdentityRef -> { try { return new PrincipalImpl(idp.getIdentity(externalIdentityRef).getPrincipalName()); } catch (ExternalIdentityException e) { throw new RuntimeException(e); } - }).collect(Collectors.toSet()); + }).collect(Collectors.toUnmodifiableSet()); } else { Set set = new HashSet<>(); collectExpectedPrincipals(set, idp.getUser(userId).getDeclaredGroups(), syncConfig.user().getMembershipNestingDepth()); @@ -213,7 +213,7 @@ public void testGetPrincipalDynamicGroup() throws Exception { @Test public void testGetPrincipalInheritedGroups() throws Exception { - ImmutableSet declared = ImmutableSet.copyOf(idp.getUser(USER_ID).getDeclaredGroups()); + Set declared = Collections.unmodifiableSet(CollectionUtils.toSet(idp.getUser(USER_ID).getDeclaredGroups())); for (ExternalIdentityRef ref : declared) { for (ExternalIdentityRef inheritedGroupRef : idp.getIdentity(ref).getDeclaredGroups()) { @@ -491,24 +491,20 @@ public void testFindPrincipalsByHintTypeNotGroup() { @Test public void testFindPrincipalsByHintTypeGroup() { Set expected = buildExpectedPrincipals("a"); - Set res = ImmutableSet - .copyOf(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_GROUP)); + Set res = CollectionUtils.toSet(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_GROUP)); assertEquals(expected, res); - Set res2 = ImmutableSet - .copyOf(principalProvider.findPrincipals("a", false, PrincipalManager.SEARCH_TYPE_GROUP, 0, -1)); + Set res2 = CollectionUtils.toSet(principalProvider.findPrincipals("a", false, PrincipalManager.SEARCH_TYPE_GROUP, 0, -1)); assertEquals(expected, res2); } @Test public void testFindPrincipalsByHintTypeAll() { Set expected = buildExpectedPrincipals("a"); - Set res = ImmutableSet - .copyOf(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_ALL)); + Set res = CollectionUtils.toSet(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_ALL)); assertEquals(expected, res); - Set res2 = ImmutableSet - .copyOf(principalProvider.findPrincipals("a", false, PrincipalManager.SEARCH_TYPE_ALL, 0, -1)); + Set res2 = CollectionUtils.toSet(principalProvider.findPrincipals("a", false, PrincipalManager.SEARCH_TYPE_ALL, 0, -1)); assertEquals(expected, res2); } @@ -518,11 +514,9 @@ public void testFindPrincipalsContainingUnderscore() throws Exception { sync(externalUser); Set expected = buildExpectedPrincipals("_gr_u_"); - Set res = ImmutableSet - .copyOf(principalProvider.findPrincipals("_", PrincipalManager.SEARCH_TYPE_ALL)); + Set res = CollectionUtils.toSet(principalProvider.findPrincipals("_", PrincipalManager.SEARCH_TYPE_ALL)); assertEquals(expected, res); - Set res2 = ImmutableSet - .copyOf(principalProvider.findPrincipals("_", false, PrincipalManager.SEARCH_TYPE_ALL, 0, -1)); + Set res2 = CollectionUtils.toSet(principalProvider.findPrincipals("_", false, PrincipalManager.SEARCH_TYPE_ALL, 0, -1)); assertEquals(expected, res2); } @@ -532,10 +526,9 @@ public void testFindPrincipalsContainingPercentSign() throws Exception { sync(externalUser); Set expected = buildExpectedPrincipals("g%r%"); - Set res = ImmutableSet.copyOf(principalProvider.findPrincipals("%", PrincipalManager.SEARCH_TYPE_ALL)); + Set res = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals("%", PrincipalManager.SEARCH_TYPE_ALL))); assertEquals(expected, res); - Set res2 = ImmutableSet - .copyOf(principalProvider.findPrincipals("%", false, PrincipalManager.SEARCH_TYPE_ALL, 0, -1)); + Set res2 = CollectionUtils.toSet(principalProvider.findPrincipals("%", false, PrincipalManager.SEARCH_TYPE_ALL, 0, -1)); assertEquals(expected, res2); } @@ -547,16 +540,16 @@ public void testFindPrincipalsByTypeNotGroup() { @Test public void testFindPrincipalsByTypeGroup() throws Exception { - Set res = ImmutableSet.copyOf(principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_GROUP)); + Set res = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_GROUP))); assertEquals(getExpectedAllSearchResult(USER_ID), res); - Set res2 = ImmutableSet.copyOf(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, -1)); + Set res2 = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, -1))); assertEquals(getExpectedAllSearchResult(USER_ID), res2); } @Test public void testFindPrincipalsByTypeAll() throws Exception { - Set res = ImmutableSet.copyOf(principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_ALL)); + Set res = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_ALL))); assertEquals(getExpectedAllSearchResult(USER_ID), res); } @@ -576,10 +569,10 @@ public void testFindPrincipalsFiltersDuplicates() throws Exception { } Iterator res = principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_ALL); - assertEquals(expected, ImmutableSet.copyOf(res)); + assertEquals(expected, Collections.unmodifiableSet(CollectionUtils.toSet(res))); Iterator res2 = principalProvider.findPrincipals("a", false, PrincipalManager.SEARCH_TYPE_ALL, 0, -1); - assertEquals(expected, ImmutableSet.copyOf(res2)); + assertEquals(expected, Collections.unmodifiableSet(CollectionUtils.toSet(res2))); } @Test @@ -604,7 +597,7 @@ public void testFindPrincipalsWithOffset() throws Exception { long offset = 2; long expectedSize = (all.size() <= offset) ? 0 : all.size()-offset; - Set result = ImmutableSet.copyOf(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, offset, -1)); + Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, offset, -1))); assertEquals(expectedSize, result.size()); } @@ -612,7 +605,7 @@ public void testFindPrincipalsWithOffset() throws Exception { public void testFindPrincipalsWithOffsetEqualsResultSize() throws Exception { Set all = getExpectedAllSearchResult(USER_ID); - Set result = ImmutableSet.copyOf(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, all.size(), -1)); + Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, all.size(), -1))); assertTrue(result.isEmpty()); } @@ -620,13 +613,13 @@ public void testFindPrincipalsWithOffsetEqualsResultSize() throws Exception { public void testFindPrincipalsWithOffsetExceedsResultSize() throws Exception { Set all = getExpectedAllSearchResult(USER_ID); - Set result = ImmutableSet.copyOf(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, all.size()+1, -1)); + Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, all.size()+1, -1))); assertTrue(result.isEmpty()); } @Test public void testFindPrincipalsWithLimit() { - Set result = ImmutableSet.copyOf(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, 1)); + Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, 1))); int expectedSize = (hasDynamicGroups()) ? 0 : 1; assertEquals(expectedSize, result.size()); } @@ -635,13 +628,13 @@ public void testFindPrincipalsWithLimit() { public void testFindPrincipalsWithLimitExceedsResultSize() throws Exception { Set all = getExpectedAllSearchResult(USER_ID); - Set result = ImmutableSet.copyOf(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, all.size()+1)); + Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, all.size()+1))); assertEquals(all, result); } @Test public void testFindPrincipalsWithZeroLimit() { - Set result = ImmutableSet.copyOf(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, 0)); + Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, 0, 0))); assertTrue(result.isEmpty()); } @@ -651,7 +644,7 @@ public void testFindPrincipalsWithOffsetAndLimit() throws Exception { long offset = all.size()-1; long limit = all.size(); - Set result = ImmutableSet.copyOf(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, offset, limit)); + Set result = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals(null, false, PrincipalManager.SEARCH_TYPE_GROUP, offset, limit))); int expectedSize = (hasDynamicGroups()) ? 0 : 1; assertEquals(expectedSize, result.size()); } diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderWithCacheTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderWithCacheTest.java index c2388b1b13c..c58d4264457 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderWithCacheTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProviderWithCacheTest.java @@ -33,22 +33,18 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import javax.jcr.RepositoryException; -import org.apache.jackrabbit.api.security.principal.GroupPrincipal; -import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef; import org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncConfig; -import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal; import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl; import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration; import org.apache.jackrabbit.oak.spi.security.user.cache.CacheConstants; @@ -124,7 +120,7 @@ protected ConfigurationParameters getSecurityConfigParameters() { @NotNull Set getExternalGroupPrincipals(@NotNull String userId) throws Exception { if (syncConfig.user().getMembershipNestingDepth() == 1) { - return ImmutableSet.copyOf(idp.getUser(userId).getDeclaredGroups()).stream().map(externalIdentityRef -> { + return CollectionUtils.toSet(idp.getUser(userId).getDeclaredGroups()).stream().map(externalIdentityRef -> { try { return new PrincipalImpl(idp.getIdentity(externalIdentityRef).getPrincipalName()); } catch (ExternalIdentityException e) { diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderAutoMembershipTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderAutoMembershipTest.java index 9f4c37d3bbb..7d68a2ceb49 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderAutoMembershipTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderAutoMembershipTest.java @@ -17,9 +17,7 @@ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; -import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal; import org.apache.jackrabbit.api.security.principal.PrincipalManager; @@ -41,6 +39,7 @@ import java.security.Principal; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -158,10 +157,10 @@ protected DefaultSyncConfig createSyncConfig() { @Override @NotNull Set getExpectedGroupPrincipals(@NotNull String userId) throws Exception { - ImmutableSet.Builder builder = ImmutableSet.builder() - .addAll(super.getExpectedGroupPrincipals(userId)) - .add(userAutoMembershipGroup.getPrincipal()) - .add(groupAutoMembershipGroup.getPrincipal()); + Set builder = new HashSet<>(); + builder.addAll(super.getExpectedGroupPrincipals(userId)); + builder.add(userAutoMembershipGroup.getPrincipal()); + builder.add(groupAutoMembershipGroup.getPrincipal()); if (nestedAutomembership) { builder.add(baseGroup.getPrincipal()); } @@ -171,7 +170,7 @@ Set getExpectedGroupPrincipals(@NotNull String userId) throws Excepti builder.add(baseGroup2.getPrincipal()); } } - return builder.build(); + return Set.copyOf(builder); } @Override diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderDeepNestingTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderDeepNestingTest.java index 5839699882c..2f0ba7809c0 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderDeepNestingTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/PrincipalProviderDeepNestingTest.java @@ -17,12 +17,12 @@ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; import java.security.Principal; +import java.util.Collections; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; - import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.principal.PrincipalManager; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser; @@ -86,7 +86,7 @@ public void testGetPrincipalInheritedGroups() throws Exception { @Test public void testFindPrincipalsByHintTypeGroup() { Set expected = Set.of(new PrincipalImpl("a"), new PrincipalImpl("aa"), new PrincipalImpl("aaa")); - Set res = ImmutableSet.copyOf(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_GROUP)); + Set res = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_GROUP))); assertEquals(expected, res); } @@ -98,7 +98,7 @@ public void testFindPrincipalsByHintTypeAll() { new PrincipalImpl("a"), new PrincipalImpl("aa"), new PrincipalImpl("aaa")); - Set res = ImmutableSet.copyOf(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_ALL)); + Set res = Collections.unmodifiableSet(CollectionUtils.toSet(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_ALL))); assertEquals(expected, res); } diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncConfigTrackerTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncConfigTrackerTest.java index a93b91e8559..a9369d79653 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncConfigTrackerTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncConfigTrackerTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.ObjectArrays; import org.apache.jackrabbit.oak.spi.security.authentication.external.SyncHandler; import org.apache.jackrabbit.oak.spi.security.authentication.external.basic.AutoMembershipAware; @@ -142,8 +141,8 @@ public void testGetAutoMembership() { Map automembership = tracker.getAutoMembership(); assertEquals(1, automembership.size()); - Set expected = ImmutableSet.copyOf(ObjectArrays.concat(uam, gam, String.class)); - assertEquals(expected, ImmutableSet.copyOf(automembership.get("idp"))); + Set expected = Set.of(ObjectArrays.concat(uam, gam, String.class)); + assertEquals(expected, Set.of(automembership.get("idp"))); } @Test @@ -202,8 +201,8 @@ public void testGetAutoMembershipMultipleHandlersAndIdps() { Map automembership = tracker.getAutoMembership(); assertEquals(2, automembership.size()); - Set expected = ImmutableSet.copyOf(ObjectArrays.concat(uam, gam, String.class)); - assertEquals(expected, ImmutableSet.copyOf(automembership.get("idp"))); + Set expected = Set.of(ObjectArrays.concat(uam, gam, String.class)); + assertEquals(expected, Set.of(automembership.get("idp"))); assertArrayEquals(uam, automembership.get("idp2")); } diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java index 6cdbb380662..3f1bd3b6112 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTrackerTest.java @@ -16,14 +16,15 @@ */ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.impl.SyncHandlerMapping; import org.junit.Before; import org.junit.Test; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; +import java.util.Collections; import java.util.Set; import static org.apache.jackrabbit.oak.spi.security.authentication.external.impl.SyncHandlerMapping.PARAM_IDP_NAME; @@ -72,23 +73,23 @@ public void testAddingServiceWithProperties() { when(ref.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP"); tracker.addingService(ref); - assertEquals(Set.of("testIDP"), ImmutableSet.copyOf(tracker.getIdpNames("testSH"))); + assertEquals(Set.of("testIDP"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH")))); ServiceReference ref2 = mock(ServiceReference.class); when(ref2.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("testSH-2"); when(ref2.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP-2"); tracker.addingService(ref2); - assertEquals(Set.of("testIDP"), ImmutableSet.copyOf(tracker.getIdpNames("testSH"))); - assertEquals(Set.of("testIDP-2"), ImmutableSet.copyOf(tracker.getIdpNames("testSH-2"))); + assertEquals(Set.of("testIDP"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH")))); + assertEquals(Set.of("testIDP-2"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH-2")))); ServiceReference ref3 = mock(ServiceReference.class); when(ref3.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("testSH"); when(ref3.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP-3"); tracker.addingService(ref3); - assertEquals(Set.of("testIDP", "testIDP-3"), ImmutableSet.copyOf(tracker.getIdpNames("testSH"))); - assertEquals(Set.of("testIDP-2"), ImmutableSet.copyOf(tracker.getIdpNames("testSH-2"))); + assertEquals(Set.of("testIDP", "testIDP-3"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH")))); + assertEquals(Set.of("testIDP-2"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH-2")))); } @Test @@ -121,13 +122,13 @@ public void testModifiedServiceWithProperties() { when(ref.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("testSH"); when(ref.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP-2"); tracker.modifiedService(ref, service); - assertEquals(Set.of("testIDP-2"), ImmutableSet.copyOf(tracker.getIdpNames("testSH"))); + assertEquals(Set.of("testIDP-2"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH")))); when(ref.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("testSH-3"); when(ref.getProperty(PARAM_IDP_NAME)).thenReturn("testIDP-3"); tracker.modifiedService(ref, service); assertTrue(Iterables.isEmpty(tracker.getIdpNames("testSH"))); - assertEquals(Set.of("testIDP-3"), ImmutableSet.copyOf(tracker.getIdpNames("testSH-3"))); + assertEquals(Set.of("testIDP-3"), Collections.unmodifiableSet(CollectionUtils.toSet(tracker.getIdpNames("testSH-3")))); } @Test diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SystemPrincipalConfigTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SystemPrincipalConfigTest.java index 34e19cf9546..0efea39c5a8 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SystemPrincipalConfigTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SystemPrincipalConfigTest.java @@ -16,9 +16,7 @@ */ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; -import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.oak.spi.commit.MoveTracker; import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider; @@ -61,7 +59,7 @@ public class SystemPrincipalConfigTest extends AbstractExternalAuthTest { private SystemPrincipalConfig systemPrincipalConfig; public SystemPrincipalConfigTest(String[] systemUserNames, String name) { - this.systemUserNames = (systemUserNames == null) ? null : ImmutableSet.copyOf(systemUserNames); + this.systemUserNames = (systemUserNames == null) ? null : Set.of(systemUserNames); } @Parameterized.Parameters(name = "name={1}") diff --git a/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java b/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java index 749de755083..39a2ebc2e87 100644 --- a/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java +++ b/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java @@ -17,10 +17,10 @@ package org.apache.jackrabbit.oak.security.authentication.ldap.impl; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.directory.api.util.Strings; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException; @@ -64,7 +64,7 @@ public void testListUsers() throws Exception { Iterator ids = Iterators.transform(users, externalUser -> externalUser.getId()); Set expectedIds = Set.of(TEST_USER0_UID, TEST_USER1_UID, TEST_USER5_UID, "hnelson", "thardy", "tquist", "fchristi", "wbush", "cbuckley", "jhallett", "mchrysta", "wbligh", "jfryer"); - assertEquals(expectedIds, ImmutableSet.copyOf(ids)); + assertEquals(expectedIds, CollectionUtils.toSet(ids)); } @Test @@ -74,7 +74,7 @@ public void testListUsersWithExtraFilter() throws Exception { Iterator ids = Iterators.transform(users, externalUser -> externalUser.getId()); Set expectedIds = Set.of(TEST_USER0_UID, TEST_USER1_UID, TEST_USER5_UID, "hnelson", "thardy", "tquist", "fchristi", "wbush", "cbuckley", "jhallett", "mchrysta", "wbligh", "jfryer"); - assertEquals(expectedIds, ImmutableSet.copyOf(ids)); + assertEquals(expectedIds, CollectionUtils.toSet(ids)); } /** @@ -202,8 +202,8 @@ public void testGetDeclaredMembers() throws Exception { Iterable memberrefs = gr.getDeclaredMembers(); Iterable memberIds = Iterables.transform(memberrefs, externalIdentityRef -> externalIdentityRef.getId()); - Set expected = ImmutableSet.copyOf(TEST_GROUP1_MEMBERS); - assertEquals(expected, ImmutableSet.copyOf(memberIds)); + Set expected = Set.of(TEST_GROUP1_MEMBERS); + assertEquals(expected, CollectionUtils.toSet(memberIds)); } @Test @@ -238,7 +238,7 @@ public void testGetDeclaredGroupMissingIdAttribute() throws Exception { ExternalUser user = idp.getUser(TEST_USER1_UID); Iterable groupRefs = user.getDeclaredGroups(); Iterable groupIds = Iterables.transform(groupRefs, externalIdentityRef -> externalIdentityRef.getId()); - assertEquals(ImmutableSet.copyOf(TEST_USER1_GROUPS), ImmutableSet.copyOf(groupIds)); + assertEquals(Set.of(TEST_USER1_GROUPS), CollectionUtils.toSet(groupIds)); } @Test @@ -297,7 +297,7 @@ public void testListGroups() throws Exception { Iterator ids = Iterators.transform(groups, externalGroup -> externalGroup.getId()); Set expectedIds = Set.of(TEST_GROUP1_NAME, TEST_GROUP2_NAME, TEST_GROUP3_NAME, "Administrators"); - assertEquals(expectedIds, ImmutableSet.copyOf(ids)); + assertEquals(expectedIds, CollectionUtils.toSet(ids)); } @Test @@ -308,6 +308,6 @@ public void testListGroupsWithEmptyExtraFilter() throws Exception { Iterator ids = Iterators.transform(groups, externalGroup -> externalGroup.getId()); Set expectedIds = Set.of(TEST_GROUP1_NAME, TEST_GROUP2_NAME, TEST_GROUP3_NAME, "Administrators"); - assertEquals(expectedIds, ImmutableSet.copyOf(ids)); + assertEquals(expectedIds, CollectionUtils.toSet(ids)); } } diff --git a/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManager.java b/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManager.java index 0fd6220e027..3c4886446cf 100644 --- a/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManager.java +++ b/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManager.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.cug.impl; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy; @@ -374,7 +373,7 @@ private Set collectEffectiveCandidates(@NotNull Root r, @NotNull Iterabl Tree cug = CugUtil.getCug(t); PropertyState pNames = (cug == null) ? null : cug.getProperty(REP_PRINCIPAL_NAMES); if (pNames != null) { - if (!Collections.disjoint(ImmutableSet.copyOf(principalNames), ImmutableSet.copyOf(pNames.getValue(Type.STRINGS)))) { + if (!Collections.disjoint(CollectionUtils.toSet(principalNames), CollectionUtils.toSet(pNames.getValue(Type.STRINGS)))) { candidates.add(path); } Iterables.addAll(eval, nestedCugPaths(cug)); diff --git a/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugExcludeImpl.java b/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugExcludeImpl.java index d92d3bb4f94..1aaeada34eb 100644 --- a/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugExcludeImpl.java +++ b/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugExcludeImpl.java @@ -19,8 +19,11 @@ import java.security.Principal; import java.util.Collections; import java.util.Map; +import java.util.Objects; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; +import java.util.stream.Collectors; +import java.util.stream.Stream; + import org.apache.jackrabbit.oak.commons.PropertiesUtil; import org.apache.jackrabbit.oak.spi.security.authorization.cug.CugExclude; import org.jetbrains.annotations.NotNull; @@ -80,6 +83,6 @@ protected void modified(Map properties) { } private void setPrincipalNames(@NotNull Map properties) { - this.principalNames = ImmutableSet.copyOf(PropertiesUtil.toStringArray(properties.get("principalNames"), new String[0])); + this.principalNames = Stream.of(PropertiesUtil.toStringArray(properties.get("principalNames"), new String[0])).filter(Objects::nonNull).collect(Collectors.toUnmodifiableSet()); } } diff --git a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/AbstractCugTest.java b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/AbstractCugTest.java index a80cfa3b7db..00045c0596e 100644 --- a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/AbstractCugTest.java +++ b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/AbstractCugTest.java @@ -17,6 +17,7 @@ package org.apache.jackrabbit.oak.spi.security.authorization.cug.impl; import java.security.Principal; +import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -28,7 +29,6 @@ import javax.jcr.security.AccessControlPolicy; import javax.jcr.security.AccessControlPolicyIterator; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.User; @@ -40,6 +40,7 @@ import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.conditions.Validate; import org.apache.jackrabbit.oak.plugins.tree.RootProvider; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; @@ -149,7 +150,7 @@ protected ConfigurationParameters getSecurityConfigParameters() { } CugPermissionProvider createCugPermissionProvider(@NotNull Set supportedPaths, @NotNull Principal... principals) { - return new CugPermissionProvider(root, root.getContentSession().getWorkspaceName(), ImmutableSet.copyOf(principals), supportedPaths, getConfig(AuthorizationConfiguration.class).getContext(), getRootProvider(), getTreeProvider()); + return new CugPermissionProvider(root, root.getContentSession().getWorkspaceName(), Set.of(principals), supportedPaths, getConfig(AuthorizationConfiguration.class).getContext(), getRootProvider(), getTreeProvider()); } void createTrees(@NotNull Tree tree, @NotNull String... names) throws AccessDeniedException { @@ -269,7 +270,7 @@ static void assertNestedCugs(@NotNull Root root, @NotNull RootProvider rootProvi assertFalse(tree.hasProperty(HIDDEN_NESTED_CUGS)); } else { assertTrue(tree.hasProperty(HIDDEN_NESTED_CUGS)); - assertEquals(ImmutableSet.copyOf(expectedNestedPaths), ImmutableSet.copyOf(tree.getProperty(HIDDEN_NESTED_CUGS).getValue(Type.PATHS))); + assertEquals(Set.of(expectedNestedPaths), Collections.unmodifiableSet(CollectionUtils.toSet(tree.getProperty(HIDDEN_NESTED_CUGS).getValue(Type.PATHS)))); assertTrue(tree.hasProperty(HIDDEN_TOP_CUG_CNT)); assertEquals(Long.valueOf(expectedNestedPaths.length), tree.getProperty(HIDDEN_TOP_CUG_CNT).getValue(Type.LONG)); @@ -282,7 +283,7 @@ static void assertNestedCugs(@NotNull Root root, @NotNull RootProvider rootProvi assertFalse(tree.hasProperty(HIDDEN_NESTED_CUGS)); } else { assertTrue(tree.hasProperty(HIDDEN_NESTED_CUGS)); - assertEquals(ImmutableSet.copyOf(expectedNestedPaths), ImmutableSet.copyOf(tree.getProperty(HIDDEN_NESTED_CUGS).getValue(Type.PATHS))); + assertEquals(Set.of(expectedNestedPaths), Collections.unmodifiableSet(CollectionUtils.toSet(tree.getProperty(HIDDEN_NESTED_CUGS).getValue(Type.PATHS)))); } } diff --git a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManagerTest.java b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManagerTest.java index 34e1598281a..cdc445031c7 100644 --- a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManagerTest.java +++ b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManagerTest.java @@ -31,7 +31,6 @@ import javax.jcr.security.Privilege; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.JcrConstants; @@ -74,7 +73,7 @@ public class CugAccessControlManagerTest extends AbstractCugTest { public void before() throws Exception { super.before(); - cugAccessControlManager = new CugAccessControlManager(root, NamePathMapper.DEFAULT, getSecurityProvider(), ImmutableSet.copyOf(SUPPORTED_PATHS), getExclude(), getRootProvider()); + cugAccessControlManager = new CugAccessControlManager(root, NamePathMapper.DEFAULT, getSecurityProvider(), Set.of(SUPPORTED_PATHS), getExclude(), getRootProvider()); } private CugPolicy createCug(@NotNull String path) { @@ -238,7 +237,7 @@ public void testGetEffectivePoliciesNotEnabled() throws Exception { ConfigurationParameters config = ConfigurationParameters.of(AuthorizationConfiguration.NAME, ConfigurationParameters.of( CugConstants.PARAM_CUG_SUPPORTED_PATHS, SUPPORTED_PATHS, CugConstants.PARAM_CUG_ENABLED, false)); - CugAccessControlManager acMgr = new CugAccessControlManager(root, NamePathMapper.DEFAULT, CugSecurityProvider.newTestSecurityProvider(config), ImmutableSet.copyOf(SUPPORTED_PATHS), getExclude(), getRootProvider()); + CugAccessControlManager acMgr = new CugAccessControlManager(root, NamePathMapper.DEFAULT, CugSecurityProvider.newTestSecurityProvider(config), Set.of(SUPPORTED_PATHS), getExclude(), getRootProvider()); AccessControlPolicy[] policies = acMgr.getEffectivePolicies(SUPPORTED_PATH); assertEquals(0, policies.length); @@ -254,7 +253,7 @@ public void testGetEffectivePoliciesNoReadAcPermission() throws Exception { // test-user only has read-access on /content (no read-ac permission) try (ContentSession cs = createTestSession()) { Root r = cs.getLatestRoot(); - CugAccessControlManager m = new CugAccessControlManager(r, NamePathMapper.DEFAULT, getSecurityProvider(), ImmutableSet.copyOf(SUPPORTED_PATHS), getExclude(), getRootProvider()); + CugAccessControlManager m = new CugAccessControlManager(r, NamePathMapper.DEFAULT, getSecurityProvider(), Set.of(SUPPORTED_PATHS), getExclude(), getRootProvider()); AccessControlPolicy[] effective = m.getEffectivePolicies("/content"); assertEquals(0, effective.length); } @@ -266,7 +265,7 @@ public void testGetEffectivePoliciesNoReadPermission() throws Exception { // test-user only has read-access on /content (no read-ac permission) try (ContentSession cs = createTestSession()) { Root r = cs.getLatestRoot(); - CugAccessControlManager m = new CugAccessControlManager(r, NamePathMapper.DEFAULT, getSecurityProvider(), ImmutableSet.copyOf(SUPPORTED_PATHS), getExclude(), getRootProvider()); + CugAccessControlManager m = new CugAccessControlManager(r, NamePathMapper.DEFAULT, getSecurityProvider(), Set.of(SUPPORTED_PATHS), getExclude(), getRootProvider()); m.getEffectivePolicies("/content2"); } } @@ -278,7 +277,7 @@ public void testGetEffectivePoliciesLimitedReadAcPermission() throws Exception { // test-user2 only has read-ac permission on /content but not on /content2 try (ContentSession cs = createTestSession2()) { Root r = cs.getLatestRoot(); - CugAccessControlManager m = new CugAccessControlManager(r, NamePathMapper.DEFAULT, getSecurityProvider(), ImmutableSet.copyOf(SUPPORTED_PATHS), getExclude(), getRootProvider()); + CugAccessControlManager m = new CugAccessControlManager(r, NamePathMapper.DEFAULT, getSecurityProvider(), Set.of(SUPPORTED_PATHS), getExclude(), getRootProvider()); AccessControlPolicy[] effective = m.getEffectivePolicies("/content/a/b/c"); // [/content/a, /content/a/b/c] assertEquals(2, effective.length); @@ -586,7 +585,7 @@ public void testGetEffectivePrincipalDistributed() throws Exception { AccessControlPolicy[] testgroupEffective = cugAccessControlManager.getEffectivePolicies(Set.of(getTestGroupPrincipal())); assertEquals(2, testgroupEffective.length); - assertTrue(Sets.intersection(ImmutableSet.copyOf(everyoneEffective), ImmutableSet.copyOf(testgroupEffective)).isEmpty()); + assertTrue(Sets.intersection(Set.of(everyoneEffective), Set.of(testgroupEffective)).isEmpty()); } @Test @@ -596,7 +595,7 @@ public void testGetEffectivePrincipalNoReadAcPermission() throws Exception { try (ContentSession cs = createTestSession()) { Root r = cs.getLatestRoot(); CugAccessControlManager m = new CugAccessControlManager(r, NamePathMapper.DEFAULT, getSecurityProvider(), - ImmutableSet.copyOf(SUPPORTED_PATHS), getExclude(), getRootProvider()); + Set.of(SUPPORTED_PATHS), getExclude(), getRootProvider()); AccessControlPolicy[] effective = m.getEffectivePolicies(Set.of(getTestGroupPrincipal(), EveryonePrincipal.getInstance())); assertEquals(0, effective.length); } @@ -610,7 +609,7 @@ public void testGetEffectivePrincipalLimitedReadAcPermission() throws Exception try (ContentSession cs = createTestSession2()) { Root r = cs.getLatestRoot(); CugAccessControlManager m = new CugAccessControlManager(r, NamePathMapper.DEFAULT, getSecurityProvider(), - ImmutableSet.copyOf(SUPPORTED_PATHS), getExclude(), getRootProvider()); + Set.of(SUPPORTED_PATHS), getExclude(), getRootProvider()); AccessControlPolicy[] effective = m.getEffectivePolicies(Set.of(getTestGroupPrincipal(), EveryonePrincipal.getInstance())); // [/content/a, /content/a/b/c, /content/aa/bb] but not: /content2 assertEquals(3, effective.length); @@ -643,7 +642,7 @@ public void testGetEffectiveByPrincipalNotEnabled() throws Exception { ConfigurationParameters config = ConfigurationParameters.of(AuthorizationConfiguration.NAME, ConfigurationParameters.of( CugConstants.PARAM_CUG_SUPPORTED_PATHS, SUPPORTED_PATHS, CugConstants.PARAM_CUG_ENABLED, false)); - CugAccessControlManager acMgr = new CugAccessControlManager(root, NamePathMapper.DEFAULT, CugSecurityProvider.newTestSecurityProvider(config), ImmutableSet.copyOf(SUPPORTED_PATHS), getExclude(), getRootProvider()); + CugAccessControlManager acMgr = new CugAccessControlManager(root, NamePathMapper.DEFAULT, CugSecurityProvider.newTestSecurityProvider(config), Set.of(SUPPORTED_PATHS), getExclude(), getRootProvider()); assertEquals(0, acMgr.getEffectivePolicies(Set.of(getTestGroupPrincipal(), EveryonePrincipal.getInstance())).length); } @@ -677,7 +676,7 @@ public void testGetEffectivePrincipalsPathsDisabled() throws Exception { ConfigurationParameters config = ConfigurationParameters.of(AuthorizationConfiguration.NAME, ConfigurationParameters.of( CugConstants.PARAM_CUG_SUPPORTED_PATHS, SUPPORTED_PATHS, CugConstants.PARAM_CUG_ENABLED, false)); - CugAccessControlManager acMgr = new CugAccessControlManager(root, NamePathMapper.DEFAULT, CugSecurityProvider.newTestSecurityProvider(config), ImmutableSet.copyOf(SUPPORTED_PATHS), getExclude(), getRootProvider()); + CugAccessControlManager acMgr = new CugAccessControlManager(root, NamePathMapper.DEFAULT, CugSecurityProvider.newTestSecurityProvider(config), Set.of(SUPPORTED_PATHS), getExclude(), getRootProvider()); Iterator effective = acMgr.getEffectivePolicies(principalSet, "/content/a"); assertFalse(effective.hasNext()); @@ -730,7 +729,7 @@ public void testGetEffectivePrincipalsPathsMissingPermission() throws Exception // test-user only has read-access on /content (no read-ac permission) try (ContentSession cs = createTestSession()) { Root r = cs.getLatestRoot(); - CugAccessControlManager m = new CugAccessControlManager(r, NamePathMapper.DEFAULT, getSecurityProvider(), ImmutableSet.copyOf(SUPPORTED_PATHS), getExclude(), getRootProvider()); + CugAccessControlManager m = new CugAccessControlManager(r, NamePathMapper.DEFAULT, getSecurityProvider(), Set.of(SUPPORTED_PATHS), getExclude(), getRootProvider()); Iterator effective = m.getEffectivePolicies(Set.of(getTestGroupPrincipal()), "/content/a"); assertFalse(effective.hasNext()); } diff --git a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugConfigurationTest.java b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugConfigurationTest.java index e5aab423ae1..8f92428a209 100644 --- a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugConfigurationTest.java +++ b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugConfigurationTest.java @@ -24,7 +24,6 @@ import javax.jcr.security.AccessControlManager; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.security.authorization.composite.CompositeAuthorizationConfiguration; @@ -220,7 +219,7 @@ public void testModified() { } private static void assertSupportedPaths(@NotNull CugConfiguration configuration, @NotNull String... paths) { - Set expected = ImmutableSet.copyOf(paths); + Set expected = Set.of(paths); assertEquals(expected, configuration.getParameters().getConfigValue(CugConstants.PARAM_CUG_SUPPORTED_PATHS, Set.of())); } diff --git a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugEvaluationTest.java b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugEvaluationTest.java index 4aea777e4d0..e9c7b205214 100644 --- a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugEvaluationTest.java +++ b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugEvaluationTest.java @@ -23,7 +23,6 @@ import javax.jcr.security.AccessControlManager; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.ContentSession; @@ -100,7 +99,7 @@ private PermissionProvider createPermissionProvider(ContentSession cs) { } private PermissionProvider createPermissionProvider(Principal... principals) { - return getSecurityProvider().getConfiguration(AuthorizationConfiguration.class).getPermissionProvider(root, adminSession.getWorkspaceName(), ImmutableSet.copyOf(principals)); + return getSecurityProvider().getConfiguration(AuthorizationConfiguration.class).getPermissionProvider(root, adminSession.getWorkspaceName(), Set.of(principals)); } @Test diff --git a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugImportBaseTest.java b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugImportBaseTest.java index 0c217d95387..510843007e0 100644 --- a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugImportBaseTest.java +++ b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugImportBaseTest.java @@ -31,12 +31,12 @@ import javax.jcr.nodetype.ConstraintViolationException; import javax.jcr.security.AccessControlException; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.JackrabbitRepository; import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.oak.api.CommitFailedException; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.jcr.Jcr; import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants; import org.apache.jackrabbit.oak.query.QueryEngineSettings; @@ -191,7 +191,7 @@ private void doImport(Session importSession, String parentPath, String xml) thro static void assertPrincipalNames(@NotNull Set expectedPrincipalNames, @NotNull Value[] principalNames) { assertEquals(expectedPrincipalNames.size(), principalNames.length); - Set result = ImmutableSet.copyOf(Iterables.transform(ImmutableSet.copyOf(principalNames), principalName -> { + Set result = CollectionUtils.toSet(Iterables.transform(Set.of(principalNames), principalName -> { try { return principalName.getString(); } catch (RepositoryException e) { diff --git a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugTreePermissionTest.java b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugTreePermissionTest.java index 96afce352dc..f830bbdc0aa 100644 --- a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugTreePermissionTest.java +++ b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugTreePermissionTest.java @@ -17,7 +17,8 @@ package org.apache.jackrabbit.oak.spi.security.authorization.cug.impl; import java.security.Principal; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; +import java.util.Set; + import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; @@ -56,7 +57,7 @@ private CugTreePermission getCugTreePermission(@NotNull Principal... principals) } private CugTreePermission getCugTreePermission(@NotNull String path, @NotNull Principal... principals) { - CugPermissionProvider pp = createCugPermissionProvider(ImmutableSet.copyOf(SUPPORTED_PATHS), principals); + CugPermissionProvider pp = createCugPermissionProvider(Set.of(SUPPORTED_PATHS), principals); TreePermission targetTp = getTreePermission(root, path, pp); assertTrue(targetTp instanceof CugTreePermission); return (CugTreePermission) targetTp; diff --git a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/MoveRenameTest.java b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/MoveRenameTest.java index d197a18991d..86fca43095d 100644 --- a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/MoveRenameTest.java +++ b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/MoveRenameTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.cug.impl; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal; import org.jetbrains.annotations.NotNull; @@ -29,6 +28,7 @@ import javax.jcr.security.AccessControlManager; import javax.jcr.security.AccessControlPolicy; import java.security.Principal; +import java.util.Set; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -68,7 +68,7 @@ public void before() throws Exception { } private void assertCugPrivileges(@NotNull Principal principal, boolean isGranted, String... paths) { - CugPermissionProvider pp = createCugPermissionProvider(ImmutableSet.copyOf(SUPPORTED_PATHS), principal); + CugPermissionProvider pp = createCugPermissionProvider(Set.of(SUPPORTED_PATHS), principal); for (String path : paths) { assertEquals(isGranted, pp.isGranted(path, Session.ACTION_READ)); } diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractEntryTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractEntryTest.java index c7daf722bde..b8979808fd4 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractEntryTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractEntryTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.security.authorization.restriction.RestrictionProviderImpl; @@ -37,6 +36,7 @@ import javax.jcr.security.AccessControlException; import javax.jcr.security.Privilege; import java.security.Principal; +import java.util.Set; import static org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants.NT_OAK_UNSTRUCTURED; import static org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants.REP_GLOB; @@ -129,7 +129,7 @@ public void testEquals() throws Exception { private final class TestEntry extends AbstractEntry { TestEntry(@Nullable String oakPath, @NotNull Principal principal, @NotNull PrivilegeBits privilegeBits, @NotNull Restriction... restrictions) throws AccessControlException { - super(oakPath, principal, privilegeBits, ImmutableSet.copyOf(restrictions), AbstractEntryTest.this.getNamePathMapper()); + super(oakPath, principal, privilegeBits, Set.of(restrictions), AbstractEntryTest.this.getNamePathMapper()); } TestEntry(@NotNull AbstractEntry base) throws AccessControlException { diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractPrincipalBasedTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractPrincipalBasedTest.java index b928786709c..931e4a4292e 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractPrincipalBasedTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractPrincipalBasedTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.ObjectArrays; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; @@ -28,6 +27,7 @@ import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.impl.LocalNameMapper; import org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; @@ -49,16 +49,14 @@ import javax.jcr.security.AccessControlPolicy; import javax.jcr.security.Privilege; import java.security.Principal; -import java.util.Collections; import java.util.Map; +import java.util.Set; import java.util.UUID; import static java.util.Objects.requireNonNull; import static org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants.NT_OAK_UNSTRUCTURED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public abstract class AbstractPrincipalBasedTest extends AbstractSecurityTest { @@ -114,7 +112,7 @@ protected SecurityProvider initSecurityProvider() { @Override @NotNull protected Privilege[] privilegesFromNames(@NotNull String... privilegeNames) throws RepositoryException { - Iterable pn = Iterables.transform(ImmutableSet.copyOf(privilegeNames), privName -> getNamePathMapper().getJcrName(privName)); + Iterable pn = Iterables.transform(CollectionUtils.toLinkedSet(privilegeNames), privName -> getNamePathMapper().getJcrName(privName)); return super.privilegesFromNames(pn); } @@ -185,7 +183,7 @@ boolean addDefaultEntry(@Nullable String path, @NotNull Principal principal, @Nu @NotNull PrincipalBasedPermissionProvider createPermissionProvider(@NotNull Root root, @NotNull Principal... principals) { - PermissionProvider pp = principalBasedAuthorizationConfiguration.getPermissionProvider(root, root.getContentSession().getWorkspaceName(), ImmutableSet.copyOf(principals)); + PermissionProvider pp = principalBasedAuthorizationConfiguration.getPermissionProvider(root, root.getContentSession().getWorkspaceName(), Set.of(principals)); if (pp instanceof PrincipalBasedPermissionProvider) { return (PrincipalBasedPermissionProvider) pp; } else { diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/EffectivePolicyTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/EffectivePolicyTest.java index 32f94958dd4..edb50a398ba 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/EffectivePolicyTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/EffectivePolicyTest.java @@ -16,13 +16,13 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry; import org.apache.jackrabbit.api.security.authorization.PrincipalAccessControlList; import org.apache.jackrabbit.api.security.principal.PrincipalManager; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl; import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants; import org.apache.jackrabbit.util.Text; @@ -138,7 +138,7 @@ public void testEffectivePolicyByPath() throws Exception { // filter expected entries: only entries that take effect at the target path should be taken into consideration ImmutablePrincipalPolicy byPrincipal = (ImmutablePrincipalPolicy) acMgr.getEffectivePolicies(Set.of(effectivePolicy.getPrincipal()))[0]; - Set expected = ImmutableSet.copyOf(Iterables.filter(byPrincipal.getEntries(), entry -> { + Set expected = CollectionUtils.toSet(Iterables.filter(byPrincipal.getEntries(), entry -> { String effectivePath = ((PrincipalAccessControlList.Entry) entry).getEffectivePath(); return effectivePath != null && Text.isDescendantOrEqual(effectivePath, path); })); diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PolicyValidatorLimitedUserTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PolicyValidatorLimitedUserTest.java index 257e67b2c8a..bcdced199da 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PolicyValidatorLimitedUserTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PolicyValidatorLimitedUserTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.ContentSession; @@ -94,7 +93,7 @@ private Tree createPolicyEntryTree(@NotNull Root r, @NotNull String effectiveOak policy.setProperty(REP_PRINCIPAL_NAME, getTestSystemUser().getPrincipal().getName()); Tree entry = TreeUtil.addChild(policy, "entry", NT_REP_PRINCIPAL_ENTRY); entry.setProperty(REP_EFFECTIVE_PATH, effectiveOakPath, Type.PATH); - entry.setProperty(REP_PRIVILEGES, ImmutableSet.copyOf(privNames), Type.NAMES); + entry.setProperty(REP_PRIVILEGES, Set.of(privNames), Type.NAMES); return entry; } diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAccessControlManagerTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAccessControlManagerTest.java index f00ce03e00f..c5a54cbf0f3 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAccessControlManagerTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAccessControlManagerTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy; import org.apache.jackrabbit.api.security.authorization.PrincipalAccessControlList; @@ -49,7 +48,6 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import static org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl.Constants.MIX_REP_PRINCIPAL_BASED_MIXIN; import static org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl.Constants.REP_PRINCIPAL_POLICY; @@ -520,7 +518,7 @@ public void testGetPrivilegesByPrincipals() throws Exception { } private void assertPrivileges(@NotNull Privilege[] privs, @NotNull String... expectedOakPrivNames) throws Exception { - assertEquals(ImmutableSet.copyOf(privilegesFromNames(expectedOakPrivNames)), ImmutableSet.copyOf(privs)); + assertEquals(Set.of(privilegesFromNames(expectedOakPrivNames)), Set.of(privs)); } @Test diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsAccessControlTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsAccessControlTest.java index 80e1caf9aa7..e3f84bed9c1 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsAccessControlTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsAccessControlTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.JcrConstants; @@ -204,7 +203,7 @@ public void testGetEffectivePoliciesLimitedAccess2() throws Exception { // test-session can read-ac at readable path but cannot access principal-based policy try (ContentSession cs = Java23Subject.doAsPrivileged(getTestSubject(), (PrivilegedExceptionAction) () -> getContentRepository().login(null, null), null)) { PrincipalBasedAccessControlManager testAcMgr = new PrincipalBasedAccessControlManager(getMgrProvider(cs.getLatestRoot()), getFilterProvider()); - Set effective = ImmutableSet.copyOf(testAcMgr.getEffectivePolicies(path)); + Set effective = Set.of(testAcMgr.getEffectivePolicies(path)); assertEquals(1, effective.size()); assertTrue(effective.contains(ReadPolicy.INSTANCE)); diff --git a/oak-benchmarks/src/main/java/org/apache/jackrabbit/oak/benchmark/authorization/AbstractHasItemGetItemTest.java b/oak-benchmarks/src/main/java/org/apache/jackrabbit/oak/benchmark/authorization/AbstractHasItemGetItemTest.java index 2e5a219e7b7..0f189f3979a 100644 --- a/oak-benchmarks/src/main/java/org/apache/jackrabbit/oak/benchmark/authorization/AbstractHasItemGetItemTest.java +++ b/oak-benchmarks/src/main/java/org/apache/jackrabbit/oak/benchmark/authorization/AbstractHasItemGetItemTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.benchmark.authorization; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager; import org.apache.jackrabbit.api.security.user.Group; @@ -86,7 +85,7 @@ protected void beforeSuite() throws Exception { createForEachPrincipal(principal, acMgr, allPrivileges); adminSession.save(); - nodeSet = ImmutableSet.copyOf(nodePaths); + nodeSet = Set.copyOf(nodePaths); } private void createForEachPrincipal(@NotNull Principal pGrantedRead, @NotNull JackrabbitAccessControlManager acMgr, @NotNull List allPrivileges) throws RepositoryException { diff --git a/oak-blob-cloud-azure/src/test/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/AzureBlobStoreBackendTest.java b/oak-blob-cloud-azure/src/test/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/AzureBlobStoreBackendTest.java index 41acca88007..788ca33e9e2 100644 --- a/oak-blob-cloud-azure/src/test/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/AzureBlobStoreBackendTest.java +++ b/oak-blob-cloud-azure/src/test/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/AzureBlobStoreBackendTest.java @@ -24,7 +24,6 @@ import com.microsoft.azure.storage.blob.SharedAccessBlobPolicy; import org.apache.jackrabbit.core.data.DataRecord; import org.apache.jackrabbit.core.data.DataStoreException; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.jetbrains.annotations.NotNull; import org.junit.After; import org.junit.ClassRule; @@ -38,6 +37,8 @@ import java.util.EnumSet; import java.util.Properties; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import java.util.stream.StreamSupport; import static com.microsoft.azure.storage.blob.SharedAccessBlobPermissions.ADD; @@ -99,7 +100,8 @@ public void initWithSharedAccessSignature_readWrite() throws Exception { azureBlobStoreBackend.init(); assertWriteAccessGranted(azureBlobStoreBackend, "file"); - assertReadAccessGranted(azureBlobStoreBackend, concat(BLOBS, "file")); + assertReadAccessGranted(azureBlobStoreBackend, + concat(BLOBS, "file")); } @Test @@ -290,7 +292,7 @@ private static Instant yesterday() { } private static Set concat(Set set, String element) { - return ImmutableSet.builder().addAll(set).add(element).build(); + return Stream.concat(set.stream(), Stream.of(element)).collect(Collectors.toSet()); } private static String getConnectionString() { diff --git a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java index d888c5a7ba3..14e48337309 100644 --- a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java +++ b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java @@ -20,6 +20,7 @@ import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -119,7 +120,7 @@ public static List> partitionList(final List list, final int n) { * @param the type of the elements */ @NotNull - public static Set toSet(@NotNull final Iterable iterable) { + public static Set toSet(@NotNull final Iterable iterable) { Objects.requireNonNull(iterable); final Set result = new HashSet<>(); iterable.forEach(result::add); @@ -185,9 +186,23 @@ public static Set toSet(@NotNull final T... elements) { Objects.requireNonNull(elements); // make sure the set does not need to be resized given the initial content final Set result = new HashSet<>(ensureCapacity(elements.length)); - for (T element : elements) { - result.add(element); - } + result.addAll(Arrays.asList(elements)); + return result; + } + + /** + * Convert a vararg list of items to a set. The returning set is mutable and supports all optional operations. + * @param elements elements to convert + * @return the set + * @param the type of the elements + */ + @SafeVarargs + @NotNull + public static Set toLinkedSet(@NotNull final T... elements) { + Objects.requireNonNull(elements); + // make sure the set does not need to be resized given the initial content + final Set result = new LinkedHashSet<>(ensureCapacity(elements.length)); + result.addAll(Arrays.asList(elements)); return result; } diff --git a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/package-info.java b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/package-info.java index 11a3fa317b3..df06d85d18c 100644 --- a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/package-info.java +++ b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/package-info.java @@ -21,7 +21,7 @@ * Utilities for Java collections and streams. */ @Internal(since = "1.0.0") -@Version("1.2.0") +@Version("1.3.0") package org.apache.jackrabbit.oak.commons.collections; import org.apache.jackrabbit.oak.commons.annotations.Internal; import org.osgi.annotation.versioning.Version; diff --git a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java index 018a3fcc433..d03467948e3 100644 --- a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java +++ b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtilsTest.java @@ -188,6 +188,24 @@ public void nullArrayToSet() { CollectionUtils.toSet((String[])null); } + @Test + public void arrayToLinkedSet() { + final Set s = CollectionUtils.toLinkedSet(data); + Assert.assertEquals(s, CollectionUtils.toLinkedSet(data.toArray())); + } + + @Test + public void arrayContainingNullToLinkedSet() { + final Set expected = Collections.singleton(null); + final Set result = CollectionUtils.toLinkedSet((String)null); + Assert.assertEquals(expected, result); + } + + @Test(expected = NullPointerException.class) + public void nullArrayToLinkedSet() { + CollectionUtils.toLinkedSet((String[])null); + } + @Test public void iteratorToIIteratable() { Iterator iterator = List.of("a", "b", "c").iterator(); diff --git a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/mount/MountInfo.java b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/mount/MountInfo.java index 15a31227fce..2757c56a244 100644 --- a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/mount/MountInfo.java +++ b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/mount/MountInfo.java @@ -28,7 +28,6 @@ import java.util.TreeSet; import java.util.function.Function; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import static java.util.Objects.requireNonNull; @@ -65,7 +64,7 @@ public MountInfo(String name, boolean readOnly, List pathsSupportingFrag this.readOnly = readOnly; this.pathFragmentName = "oak:mount-" + name; this.includedPaths = cleanCopy(includedPaths); - this.pathsSupportingFragments = ImmutableSet.copyOf(pathsSupportingFragments); + this.pathsSupportingFragments = CollectionUtils.toSet(pathsSupportingFragments); } @Override diff --git a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/observation/ChangeSet.java b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/observation/ChangeSet.java index 3193836945b..2bb9d85891e 100644 --- a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/observation/ChangeSet.java +++ b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/observation/ChangeSet.java @@ -21,8 +21,6 @@ import java.util.HashSet; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; - import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.commons.json.JsopBuilder; import org.apache.jackrabbit.oak.commons.json.JsopReader; @@ -74,11 +72,11 @@ public final class ChangeSet { ChangeSet(int maxPathDepth, Set parentPaths, Set parentNodeNames, Set parentNodeTypes, Set propertyNames, Set allNodeTypes) { this.maxPathDepth = maxPathDepth; - this.parentPaths = parentPaths == null ? null : ImmutableSet.copyOf(parentPaths); - this.parentNodeNames = parentNodeNames == null ? null : ImmutableSet.copyOf(parentNodeNames); - this.parentNodeTypes = parentNodeTypes == null ? null : ImmutableSet.copyOf(parentNodeTypes); - this.propertyNames = propertyNames == null ? null : ImmutableSet.copyOf(propertyNames); - this.allNodeTypes = allNodeTypes == null ? null : ImmutableSet.copyOf(allNodeTypes); + this.parentPaths = parentPaths == null ? null : Set.copyOf(parentPaths); + this.parentNodeNames = parentNodeNames == null ? null : Set.copyOf(parentNodeNames); + this.parentNodeTypes = parentNodeTypes == null ? null : Set.copyOf(parentNodeTypes); + this.propertyNames = propertyNames == null ? null : Set.copyOf(propertyNames); + this.allNodeTypes = allNodeTypes == null ? null : Set.copyOf(allNodeTypes); boolean hitsMaxPathDepth = false; if (parentPaths != null) { diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/NodeStateCopier.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/NodeStateCopier.java index bb12e558896..be4c2ce2b9e 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/NodeStateCopier.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/NodeStateCopier.java @@ -41,7 +41,6 @@ import java.util.stream.StreamSupport; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.ImmutableSet.copyOf; import static java.util.Collections.emptySet; /** @@ -402,7 +401,7 @@ private Builder() {} @NotNull public Builder include(@NotNull Set paths) { if (!requireNonNull(paths).isEmpty()) { - this.includePaths = copyOf(paths); + this.includePaths = Set.copyOf(paths); } return this; } @@ -416,7 +415,7 @@ public Builder include(@NotNull Set paths) { */ @NotNull public Builder include(@NotNull String... paths) { - return include(copyOf(requireNonNull(paths))); + return include(Set.of(requireNonNull(paths))); } /** @@ -442,7 +441,7 @@ public Builder preserve(@NotNull boolean preserveOnTarget) { @NotNull public Builder exclude(@NotNull Set paths) { if (!requireNonNull(paths).isEmpty()) { - this.excludePaths = copyOf(paths); + this.excludePaths = Set.copyOf(paths); } return this; } @@ -456,7 +455,7 @@ public Builder exclude(@NotNull Set paths) { */ @NotNull public Builder exclude(@NotNull String... paths) { - return exclude(copyOf(requireNonNull(paths))); + return exclude(Set.of(requireNonNull(paths))); } /** @@ -469,7 +468,7 @@ public Builder exclude(@NotNull String... paths) { @NotNull public Builder supportFragment(@NotNull Set paths) { if (!requireNonNull(paths).isEmpty()) { - this.fragmentPaths = copyOf(paths); + this.fragmentPaths = Set.copyOf(paths); } return this; } @@ -483,7 +482,7 @@ public Builder supportFragment(@NotNull Set paths) { */ @NotNull public Builder supportFragment(@NotNull String... paths) { - return supportFragment(copyOf(requireNonNull(paths))); + return supportFragment(Set.of(requireNonNull(paths))); } /** @@ -496,7 +495,7 @@ public Builder supportFragment(@NotNull String... paths) { @NotNull public Builder excludeFragments(@NotNull Set fragments) { if (!requireNonNull(fragments).isEmpty()) { - this.excludeFragments = copyOf(fragments); + this.excludeFragments = Set.copyOf(fragments); } return this; } @@ -510,7 +509,7 @@ public Builder excludeFragments(@NotNull Set fragments) { */ @NotNull public Builder excludeFragments(@NotNull String... fragments) { - return exclude(copyOf(requireNonNull(fragments))); + return exclude(Set.of(requireNonNull(fragments))); } /** @@ -523,7 +522,7 @@ public Builder excludeFragments(@NotNull String... fragments) { @NotNull public Builder merge(@NotNull Set paths) { if (!requireNonNull(paths).isEmpty()) { - this.mergePaths = copyOf(paths); + this.mergePaths = Set.copyOf(paths); } return this; } @@ -537,7 +536,7 @@ public Builder merge(@NotNull Set paths) { */ @NotNull public Builder merge(@NotNull String... paths) { - return merge(copyOf(requireNonNull(paths))); + return merge(Set.of(requireNonNull(paths))); } @NotNull diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenConfigurationImpl.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenConfigurationImpl.java index 77ffd3eeb18..5498e17af55 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenConfigurationImpl.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenConfigurationImpl.java @@ -17,8 +17,8 @@ package org.apache.jackrabbit.oak.security.authentication.token; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.Root; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.commit.MoveTracker; import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider; import org.apache.jackrabbit.oak.spi.security.ConfigurationBase; @@ -176,7 +176,7 @@ private CredentialsSupport newCredentialsSupport() { } else if (size == 1) { return credentialsSupport.values().iterator().next(); } else { - return CompositeCredentialsSupport.newInstance(() -> ImmutableSet.copyOf(credentialsSupport.values())); + return CompositeCredentialsSupport.newInstance(() -> CollectionUtils.toLinkedSet(credentialsSupport.values())); } } } diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeAccessControlManager.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeAccessControlManager.java index 0c68a5e0477..edabe40266e 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeAccessControlManager.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeAccessControlManager.java @@ -18,6 +18,7 @@ import java.security.Principal; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -31,12 +32,12 @@ import javax.jcr.security.Privilege; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager; import org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy; import org.apache.jackrabbit.commons.iterator.AccessControlPolicyIteratorAdapter; import org.apache.jackrabbit.oak.api.Root; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.spi.security.SecurityProvider; import org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AbstractAccessControlManager; @@ -71,12 +72,11 @@ public CompositeAccessControlManager(@NotNull Root root, @NotNull @Override public Privilege[] getSupportedPrivileges(String absPath) throws RepositoryException { - ImmutableSet.Builder privs = ImmutableSet.builder(); + Set privs = new HashSet<>(); for (AccessControlManager acMgr : acMgrs) { - privs.add(acMgr.getSupportedPrivileges(absPath)); + privs.addAll(CollectionUtils.toSet(acMgr.getSupportedPrivileges(absPath))); } - Set s = privs.build(); - return s.toArray(new Privilege[0]); + return privs.toArray(new Privilege[0]); } @Override diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/CurrentPattern.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/CurrentPattern.java index 73341ac0f07..790da2b61d1 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/CurrentPattern.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/CurrentPattern.java @@ -16,11 +16,11 @@ */ package org.apache.jackrabbit.oak.security.authorization.restriction; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.index.IndexConstants; import org.apache.jackrabbit.oak.spi.namespace.NamespaceConstants; import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants; @@ -68,7 +68,7 @@ class CurrentPattern implements RestrictionPattern { * is used for a single node below jcr:system only, while the property name is used in every access control entry. * Therefore these two names are omitted from the list. */ - private static final Set NODE_NAMES = ImmutableSet.builder().add( + private static final Set NODE_NAMES = Set.of( JcrConstants.JCR_CHILDNODEDEFINITION, JcrConstants.JCR_CONTENT, JcrConstants.JCR_FROZENNODE, @@ -92,14 +92,14 @@ class CurrentPattern implements RestrictionPattern { UserConstants.REP_MEMBERS_LIST, IndexConstants.INDEX_DEFINITIONS_NAME, "rep:cugPolicy", - "rep:principalPolicy").build(); + "rep:principalPolicy"); private final String treePath; private final Set propertyNames; CurrentPattern(@NotNull String treePath, @NotNull Iterable propertyNames) { this.treePath = treePath; - this.propertyNames = ImmutableSet.copyOf(propertyNames); + this.propertyNames = CollectionUtils.toSet(propertyNames); } @Override diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/ItemNamePattern.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/ItemNamePattern.java index 723227c9b27..15fd1388cc8 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/ItemNamePattern.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/ItemNamePattern.java @@ -17,10 +17,10 @@ package org.apache.jackrabbit.oak.security.authorization.restriction; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,7 +37,7 @@ class ItemNamePattern implements RestrictionPattern { private final Set names; ItemNamePattern(Iterable names) { - this.names = ImmutableSet.copyOf(names); + this.names = CollectionUtils.toLinkedSet(names); } @Override diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/NodeTypePattern.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/NodeTypePattern.java index 8e7062f7a26..2e72b3a2888 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/NodeTypePattern.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/NodeTypePattern.java @@ -17,9 +17,9 @@ package org.apache.jackrabbit.oak.security.authorization.restriction; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; import org.jetbrains.annotations.NotNull; @@ -41,7 +41,7 @@ class NodeTypePattern implements RestrictionPattern { private final Set nodeTypeNames; NodeTypePattern(@NotNull Iterable nodeTypeNames) { - this.nodeTypeNames = ImmutableSet.copyOf(nodeTypeNames); + this.nodeTypeNames = CollectionUtils.toLinkedSet(nodeTypeNames); } @Override diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/PrefixPattern.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/PrefixPattern.java index be031e90152..012b53255c6 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/PrefixPattern.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/restriction/PrefixPattern.java @@ -17,10 +17,10 @@ package org.apache.jackrabbit.oak.security.authorization.restriction; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern; import org.apache.jackrabbit.util.Text; import org.jetbrains.annotations.NotNull; @@ -45,7 +45,7 @@ class PrefixPattern implements RestrictionPattern { private final Set prefixes; PrefixPattern(@NotNull Iterable prefixes) { - this.prefixes = ImmutableSet.copyOf(prefixes); + this.prefixes = CollectionUtils.toSet(prefixes); } @Override diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/RepMembersConflictHandler.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/RepMembersConflictHandler.java index cf0e5fecaf5..97fa82bb058 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/RepMembersConflictHandler.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/RepMembersConflictHandler.java @@ -24,6 +24,7 @@ import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder; import org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler; import org.apache.jackrabbit.oak.spi.security.user.UserConstants; @@ -31,7 +32,6 @@ import org.apache.jackrabbit.oak.spi.state.NodeState; import org.jetbrains.annotations.NotNull; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Sets; /** @@ -81,7 +81,7 @@ public Resolution changeDeletedProperty(@NotNull NodeBuilder parent, @NotNull Pr public Resolution changeChangedProperty(@NotNull NodeBuilder parent, @NotNull PropertyState ours, @NotNull PropertyState theirs, @NotNull PropertyState base) { if (isRepMembersProperty(theirs)) { - Set baseMembers = ImmutableSet.copyOf(base.getValue(Type.STRINGS)); + Set baseMembers = CollectionUtils.toSet(base.getValue(Type.STRINGS)); mergeChange(parent, ours, theirs, baseMembers); return Resolution.MERGED; } else { @@ -157,8 +157,8 @@ private static void mergeChange(@NotNull NodeBuilder parent, @NotNull PropertySt PropertyBuilder merged = PropertyBuilder.array(Type.WEAKREFERENCE); merged.setName(UserConstants.REP_MEMBERS); - Set theirMembers = ImmutableSet.copyOf(theirs.getValue(Type.STRINGS)); - Set ourMembers = ImmutableSet.copyOf(ours.getValue(Type.STRINGS)); + Set theirMembers = CollectionUtils.toSet(theirs.getValue(Type.STRINGS)); + Set ourMembers = CollectionUtils.toSet(ours.getValue(Type.STRINGS)); // merge ours and theirs to a de-duplicated set Set combined = new LinkedHashSet<>(Sets.intersection(ourMembers, theirMembers)); diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexInfoServiceImplTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexInfoServiceImplTest.java index 559af789eee..448da5c7e6d 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexInfoServiceImplTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexInfoServiceImplTest.java @@ -20,18 +20,15 @@ package org.apache.jackrabbit.oak.plugins.index; import java.util.Map; -import java.util.Properties; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider; import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore; import org.apache.jackrabbit.oak.spi.commit.CommitInfo; import org.apache.jackrabbit.oak.spi.commit.EmptyHook; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.apache.jackrabbit.oak.spi.state.NodeState; -import org.junit.After; -import org.junit.Before; import org.junit.Test; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -52,7 +49,7 @@ public void names() throws Exception{ AsyncIndexUpdate async2 = new AsyncIndexUpdate("foo-async", store, provider); async2.run(); - Set names = ImmutableSet.copyOf(service.getAsyncLanes()); + Set names = CollectionUtils.toSet(service.getAsyncLanes()); assertThat(names, containsInAnyOrder("async", "foo-async")); service.bindStatsMBeans(async.getIndexStats()); @@ -64,7 +61,7 @@ public void info() throws Exception{ AsyncIndexUpdate async = new AsyncIndexUpdate("foo-async", store, provider); async.run(); - Set names = ImmutableSet.copyOf(service.getAsyncLanes()); + Set names = CollectionUtils.toSet(service.getAsyncLanes()); assertThat(names, containsInAnyOrder("foo-async")); service.bindStatsMBeans(async.getIndexStats()); diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java index 715b2a2a2a0..4ccea8d9fe3 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexUpdateTest.java @@ -98,8 +98,6 @@ import org.junit.Test; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.guava.common.collect.Maps; import ch.qos.logback.classic.Level; @@ -211,10 +209,10 @@ public void testAsyncDouble() throws Exception { PropertyIndexLookup lookup = new PropertyIndexLookup(root); assertEquals(Set.of("testRoot"), find(lookup, "foo", "abc")); - assertEquals(ImmutableSet. of(), find(lookup, "foo", "def")); - assertEquals(ImmutableSet. of(), find(lookup, "foo", "ghi")); + assertEquals(Set. of(), find(lookup, "foo", "def")); + assertEquals(Set. of(), find(lookup, "foo", "ghi")); - assertEquals(ImmutableSet. of(), find(lookup, "bar", "abc")); + assertEquals(Set. of(), find(lookup, "bar", "abc")); assertEquals(Set.of("testRoot"), find(lookup, "bar", "def")); assertEquals(Set.of("testSecond"), find(lookup, "bar", "ghi")); @@ -268,7 +266,7 @@ public void testAsyncDoubleSubtree() throws Exception { .getChildNode("newchild").getChildNode("other")); assertEquals(Set.of("testChild"), find(lookupChild, "foo", "xyz")); - assertEquals(ImmutableSet. of(), + assertEquals(Set. of(), find(lookupChild, "foo", "abc")); } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/Jackrabbit2ConfigurationTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/Jackrabbit2ConfigurationTest.java index 38ab5410d73..345232b8646 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/Jackrabbit2ConfigurationTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/Jackrabbit2ConfigurationTest.java @@ -24,7 +24,6 @@ import javax.security.auth.login.Configuration; import javax.security.auth.login.LoginException; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.authentication.token.TokenCredentials; import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.oak.AbstractSecurityTest; @@ -244,7 +243,7 @@ public void testTokenCreationWithAttributes() throws Exception { cs = login(sc); AuthInfo ai = cs.getAuthInfo(); - Set attrNames = ImmutableSet.copyOf(ai.getAttributeNames()); + Set attrNames = Set.of(ai.getAttributeNames()); assertTrue(attrNames.contains("attr")); assertFalse(attrNames.contains(".token")); assertFalse(attrNames.contains(".token.mandatory")); @@ -268,7 +267,7 @@ public void testTokenCreationWithImpersonationAttributes() throws Exception { cs = login(ic); AuthInfo ai = cs.getAuthInfo(); - Set attrNames = ImmutableSet.copyOf(ai.getAttributeNames()); + Set attrNames = Set.of(ai.getAttributeNames()); assertTrue(attrNames.contains("attr")); assertFalse(attrNames.contains(".token")); assertFalse(attrNames.contains(".token.mandatory")); diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImplTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImplTest.java index 504f891cbff..076ef15f63e 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImplTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/user/LoginModuleImplTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.security.authentication.user; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.api.security.user.UserManager; @@ -72,6 +71,8 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.apache.jackrabbit.oak.spi.security.authentication.AbstractLoginModule.SHARED_KEY_CREDENTIALS; import static org.apache.jackrabbit.oak.spi.security.authentication.AbstractLoginModule.SHARED_KEY_PRE_AUTH_LOGIN; @@ -376,7 +377,7 @@ public void testLoginPreAuthenticated() throws Exception { assertTrue(lm.commit()); // verify subject has been updated with test-user principals - Set expected = new ImmutableSet.Builder().add(foreignPrincipal).addAll(principals).build(); + Set expected = Stream.concat(Stream.of(foreignPrincipal), principals.stream()).collect(Collectors.toSet()); assertEquals(expected, subject.getPrincipals()); // no other public credentials than the AuthInfo assertEquals(1, subject.getPublicCredentials().size()); diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ACLTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ACLTest.java index 877e05ee0a3..2bf3ceea6a3 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ACLTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ACLTest.java @@ -35,7 +35,6 @@ import javax.jcr.security.Privilege; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; @@ -587,7 +586,7 @@ public void testAllowWriteDenyRemoveGroupEntries() throws Exception { Privilege[] expected = privilegesFromNames(JCR_ADD_CHILD_NODES, JCR_REMOVE_NODE, JCR_MODIFY_PROPERTIES, JCR_NODE_TYPE_MANAGEMENT); assertEquals(expected.length, allows.size()); - assertEquals(ImmutableSet.copyOf(expected), allows); + assertEquals(Set.of(expected), allows); assertEquals(1, denies.size()); assertArrayEquals(privilegesFromNames(JCR_REMOVE_CHILD_NODES), denies.toArray(new Privilege[0])); diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlImporterBaseTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlImporterBaseTest.java index e390978ed5c..02dfc26fdcd 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlImporterBaseTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlImporterBaseTest.java @@ -17,8 +17,6 @@ package org.apache.jackrabbit.oak.security.authorization.accesscontrol; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; @@ -27,6 +25,7 @@ import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; @@ -455,7 +454,7 @@ public void testImportSimple() throws Exception { assertEquals(principalName, TreeUtil.getString(aceTree, REP_PRINCIPAL_NAME)); assertEquals( Set.of(PrivilegeConstants.JCR_READ, PrivilegeConstants.JCR_ADD_CHILD_NODES), - ImmutableSet.copyOf(TreeUtil.getNames(aceTree, REP_PRIVILEGES))); + CollectionUtils.toSet(TreeUtil.getNames(aceTree, REP_PRIVILEGES))); assertFalse(aceTree.hasChild(REP_RESTRICTIONS)); } @@ -504,7 +503,7 @@ private static void assertImport(@NotNull Tree aclTree, @NotNull String principa assertEquals(principalName, TreeUtil.getString(aceTree, REP_PRINCIPAL_NAME)); assertEquals( Set.of(PrivilegeConstants.JCR_READ, PrivilegeConstants.JCR_ADD_CHILD_NODES), - ImmutableSet.copyOf(TreeUtil.getNames(aceTree, REP_PRIVILEGES))); + CollectionUtils.toSet(TreeUtil.getNames(aceTree, REP_PRIVILEGES))); assertTrue(aceTree.hasChild(REP_RESTRICTIONS)); diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImplTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImplTest.java index 1de18efa535..3d4a7e05b3f 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImplTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImplTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.security.authorization.accesscontrol; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry; @@ -615,8 +614,8 @@ public void testGetPrivilegesForPrincipals() throws Exception { assertArrayEquals(new Privilege[0], acMgr.getPrivileges(null, testPrincipals)); assertArrayEquals(new Privilege[0], acMgr.getPrivileges("/", testPrincipals)); assertEquals( - ImmutableSet.copyOf(testPrivileges), - ImmutableSet.copyOf(acMgr.getPrivileges(testPath, testPrincipals))); + Set.of(testPrivileges), + Set.of(acMgr.getPrivileges(testPath, testPrincipals))); } //--------------------------------------< getApplicablePolicies(String) >--- @@ -1372,7 +1371,7 @@ public void testSetPolicyWithExistingMixins() throws Exception { root.commit(); assertEquals(Set.of(JcrConstants.MIX_LOCKABLE, MIX_REP_ACCESS_CONTROLLABLE), - ImmutableSet.copyOf(TreeUtil.getNames(root.getTree(testPath), JcrConstants.JCR_MIXINTYPES))); + CollectionUtils.toSet(TreeUtil.getNames(root.getTree(testPath), JcrConstants.JCR_MIXINTYPES))); } //--------------------------< removePolicy(String, AccessControlPolicy) >--- diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerLimitedPermissionsTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerLimitedPermissionsTest.java index 4513f5be4c0..55c3ea3d92f 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerLimitedPermissionsTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerLimitedPermissionsTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.security.authorization.accesscontrol; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; import org.apache.jackrabbit.api.security.principal.PrincipalManager; @@ -319,10 +318,10 @@ public void testGetPrivileges() throws Exception { assertArrayEquals(new Privilege[0], testAcMgr.getPrivileges(null, testPrincipals)); Privilege[] privs = testAcMgr.getPrivileges(testPath); - assertEquals(ImmutableSet.copyOf(testPrivileges), ImmutableSet.copyOf(privs)); + assertEquals(Set.of(testPrivileges), Set.of(privs)); privs = testAcMgr.getPrivileges(testPath, testPrincipals); - assertEquals(ImmutableSet.copyOf(testPrivileges), ImmutableSet.copyOf(privs)); + assertEquals(Set.of(testPrivileges), Set.of(privs)); // but for 'admin' the test-session doesn't have sufficient privileges try { diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/EntryTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/EntryTest.java index bddd70eed59..e5bbeddb924 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/EntryTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/EntryTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.security.authorization.accesscontrol; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry; import org.apache.jackrabbit.api.security.authorization.PrivilegeCollection; import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils; @@ -166,7 +165,7 @@ public void testGetPrivileges() throws RepositoryException { Privilege[] expected = AccessControlUtils.privilegesFromNames(acMgr, PrivilegeConstants.JCR_ADD_CHILD_NODES, PrivilegeConstants.JCR_REMOVE_CHILD_NODES); - assertEquals(ImmutableSet.copyOf(expected), ImmutableSet.copyOf(privs)); + assertEquals(Set.of(expected), Set.of(privs)); } @Test @@ -389,8 +388,8 @@ public void testGetRestrictionsNone() throws Exception { @Test public void testGetPrivilegeCollection() throws Exception { PrivilegeCollection pc = createEntry(Privilege.JCR_READ, Privilege.JCR_WRITE).getPrivilegeCollection(); - Set expected = ImmutableSet.copyOf(AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ, Privilege.JCR_WRITE)); - assertEquals(expected, ImmutableSet.copyOf(pc.getPrivileges())); + Set expected = Set.of(AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ, Privilege.JCR_WRITE)); + assertEquals(expected, Set.of(pc.getPrivileges())); assertEquals(pc, createEntry(JCR_READ, JCR_WRITE).getPrivilegeCollection()); assertEquals(pc, createEntry(JCR_READ, PrivilegeConstants.JCR_ADD_CHILD_NODES, PrivilegeConstants.JCR_MODIFY_PROPERTIES, diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/AbstractCompositeProviderTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/AbstractCompositeProviderTest.java index b19cd3bbeb3..d3a49d87312 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/AbstractCompositeProviderTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/AbstractCompositeProviderTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.security.authorization.composite; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; @@ -250,7 +249,7 @@ List getAggregatedProviders(@NotNull String worksp } CompositePermissionProvider createPermissionProvider(Principal... principals) { - return createPermissionProvider(ImmutableSet.copyOf(principals)); + return createPermissionProvider(Set.of(principals)); } CompositePermissionProvider createPermissionProvider(Set principals) { @@ -261,7 +260,7 @@ CompositePermissionProvider createPermissionProvider(Set principals) } CompositePermissionProvider createPermissionProviderOR(Principal... principals) { - return createPermissionProviderOR(ImmutableSet.copyOf(principals)); + return createPermissionProviderOR(Set.of(principals)); } CompositePermissionProvider createPermissionProviderOR(Set principals) { diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeAccessControlManagerTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeAccessControlManagerTest.java index ae9cab531ae..3b90bdb869b 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeAccessControlManagerTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/composite/CompositeAccessControlManagerTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.security.authorization.composite; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; @@ -106,8 +105,8 @@ private CompositeAccessControlManager createComposite(@NotNull AggregationFilter @Test public void testGetSupportedPrivileges() throws Exception { - Set expected = ImmutableSet.copyOf(getPrivilegeManager(root).getRegisteredPrivileges()); - Set result = ImmutableSet.copyOf(acMgr.getSupportedPrivileges("/")); + Set expected = Set.of(getPrivilegeManager(root).getRegisteredPrivileges()); + Set result = Set.of(acMgr.getSupportedPrivileges("/")); assertEquals(expected, result); result = CollectionUtils.toSet(acMgr.getSupportedPrivileges(TEST_PATH)); @@ -124,7 +123,7 @@ public void testGetApplicablePolicies() throws Exception { } } - Set applicable = ImmutableSet.copyOf(acMgr.getApplicablePolicies(TEST_PATH)); + Set applicable = CollectionUtils.toSet(acMgr.getApplicablePolicies(TEST_PATH)); assertEquals(2, applicable.size()); assertTrue(applicable.contains(TestPolicy.INSTANCE)); } @@ -164,7 +163,7 @@ public void testGetPolicies() throws Exception { acMgr.setPolicy(TEST_PATH, plc); len++; - Set policySet = ImmutableSet.copyOf(acMgr.getPolicies(TEST_PATH)); + Set policySet = Set.of(acMgr.getPolicies(TEST_PATH)); assertEquals(len, policySet.size()); assertTrue(policySet.contains(TestPolicy.INSTANCE)); assertTrue(policySet.contains(plc)); diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/RepoLevelPolicyTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/RepoLevelPolicyTest.java index e866b4c3a91..d16be3a76a4 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/RepoLevelPolicyTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/RepoLevelPolicyTest.java @@ -22,7 +22,6 @@ import javax.jcr.security.AccessControlManager; import javax.jcr.security.Privilege; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal; import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants; @@ -119,9 +118,9 @@ public void testHasPrivilege() throws Exception { public void testGetPrivileges() throws Exception { setupPermission(null, getTestUser().getPrincipal(), true, JCR_READ_ACCESS_CONTROL, JCR_NAMESPACE_MANAGEMENT); - Set expected = ImmutableSet.copyOf(privilegesFromNames(JCR_READ_ACCESS_CONTROL, JCR_NAMESPACE_MANAGEMENT)); + Set expected = Set.of(privilegesFromNames(JCR_READ_ACCESS_CONTROL, JCR_NAMESPACE_MANAGEMENT)); AccessControlManager testAcMgr = getAccessControlManager(getTestRoot()); - assertEquals(expected, ImmutableSet.copyOf(testAcMgr.getPrivileges(null))); + assertEquals(expected, Set.of(testAcMgr.getPrivileges(null))); } } \ No newline at end of file diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionHookTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionHookTest.java index 2fc474635a6..1f575b3284d 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionHookTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionHookTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.security.authorization.permission; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; @@ -456,7 +455,7 @@ public void testDynamicJcrAll() throws Exception { // verify that the permission provider still exposes the correct privilege // (jcr:all) for the given childPath irrespective of the dynamic nature of // the privilege bits in the persisted permission entry. - Set principalSet = ImmutableSet.of(EveryonePrincipal.getInstance()); + Set principalSet = Set.of(EveryonePrincipal.getInstance()); PermissionProvider permissionProvider = getConfig(AuthorizationConfiguration.class).getPermissionProvider(root, root.getContentSession().getWorkspaceName(), principalSet); Tree childTree = root.getTree(childPath); assertTrue(permissionProvider.hasPrivileges(childTree, PrivilegeConstants.JCR_ALL)); @@ -798,7 +797,7 @@ public void testInvalidPolicyNodeBecomesTypeRepACL() throws Exception { assertEquals(2, principalPermissionStore.getChildrenCount(10)); Iterable paths = Iterables.transform(principalPermissionStore.getChildren(), tree -> tree.getProperty(REP_ACCESS_CONTROLLED_PATH).getValue(Type.STRING)); - assertEquals(Set.of(testPath, t.getPath()), ImmutableSet.copyOf(paths)); + assertEquals(Set.of(testPath, t.getPath()), CollectionUtils.toSet(paths)); } @Test diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/AbstractRestrictionProviderTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/AbstractRestrictionProviderTest.java index 7601461a0b1..7558c2e14b8 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/AbstractRestrictionProviderTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/AbstractRestrictionProviderTest.java @@ -23,7 +23,6 @@ import javax.jcr.ValueFactory; import javax.jcr.security.AccessControlException; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.AbstractSecurityTest; import org.apache.jackrabbit.oak.api.PropertyState; @@ -94,7 +93,7 @@ private Tree getAceTree(Restriction... restrictions) throws Exception { Tree tmp = TreeUtil.addChild(rootNode, "testRoot", JcrConstants.NT_UNSTRUCTURED); Tree policy = TreeUtil.addChild(tmp, REP_POLICY, NT_REP_ACL); Tree ace = TreeUtil.addChild(policy, "ace0", NT_REP_GRANT_ACE); - restrictionProvider.writeRestrictions(tmp.getPath(), ace, ImmutableSet.copyOf(restrictions)); + restrictionProvider.writeRestrictions(tmp.getPath(), ace, Set.of(restrictions)); return ace; } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/CompositeRestrictionProviderTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/CompositeRestrictionProviderTest.java index d685423124b..1ad0fa9ae45 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/CompositeRestrictionProviderTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/CompositeRestrictionProviderTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.security.authorization.restriction; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.AbstractSecurityTest; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; @@ -27,7 +26,6 @@ import org.apache.jackrabbit.oak.spi.security.authorization.restriction.CompositePattern; import org.apache.jackrabbit.oak.spi.security.authorization.restriction.CompositeRestrictionProvider; import org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction; -import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition; import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinitionImpl; import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionImpl; import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider; @@ -126,7 +124,7 @@ public void testWriteUnsupportedRestrictions() throws Exception { Tree aceNode = TreeUtil.addChild(root.getTree("/"), "test", NT_REP_GRANT_ACE); Restriction invalid = new RestrictionImpl(PropertyStates.createProperty("invalid", vf.createValue(true)), false); try { - provider.writeRestrictions("/test", aceNode, ImmutableSet.of(invalid)); + provider.writeRestrictions("/test", aceNode, Set.of(invalid)); fail("AccessControlException expected"); } catch (AccessControlException e) { // success diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java index 2e5ad92e9f3..54cba9ac032 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java @@ -23,10 +23,7 @@ import java.util.List; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; - import org.apache.jackrabbit.guava.common.collect.Iterators; -import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.principal.PrincipalManager; import org.apache.jackrabbit.api.security.user.Authorizable; @@ -79,7 +76,7 @@ public void testEveryoneMembers() throws Exception { root.commit(); Principal ep = principalProvider.getPrincipal(EveryonePrincipal.NAME); - Set everyoneMembers = ImmutableSet.copyOf(Collections.list(((GroupPrincipal) ep).members())); + Set everyoneMembers = Set.copyOf(Collections.list(((GroupPrincipal) ep).members())); Iterator all = principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_ALL); while (all.hasNext()) { diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeBitsProviderTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeBitsProviderTest.java index d9f6800a7d7..e320c591924 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeBitsProviderTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeBitsProviderTest.java @@ -20,9 +20,9 @@ import java.util.Set; import javax.jcr.RepositoryException; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; import org.apache.jackrabbit.oak.AbstractSecurityTest; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits; import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBitsProvider; import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants; @@ -106,12 +106,12 @@ public void testGetAggregatedNamesUnknown() throws Exception { @Test public void testGetAggregatedNamesJcrAll() throws Exception { - assertEquals(NON_AGGREGATE_PRIVILEGES, ImmutableSet.copyOf(bitsProvider.getAggregatedPrivilegeNames(JCR_ALL))); + assertEquals(NON_AGGREGATE_PRIVILEGES, CollectionUtils.toSet(bitsProvider.getAggregatedPrivilegeNames(JCR_ALL))); } @Test public void testGetAggregatedNamesIncludingJcrAll() throws Exception { - assertEquals(NON_AGGREGATE_PRIVILEGES, ImmutableSet.copyOf(bitsProvider.getAggregatedPrivilegeNames(JCR_READ, JCR_WRITE, JCR_ALL))); + assertEquals(NON_AGGREGATE_PRIVILEGES, CollectionUtils.toSet(bitsProvider.getAggregatedPrivilegeNames(JCR_READ, JCR_WRITE, JCR_ALL))); } @Test @@ -119,12 +119,12 @@ public void getAggregatedNamesWithCustom() throws Exception { PrivilegeManager pMgr = getPrivilegeManager(root); pMgr.registerPrivilege("test1", true, null); - assertEquals(Set.of("test1"), ImmutableSet.copyOf(bitsProvider.getAggregatedPrivilegeNames("test1"))); + assertEquals(Set.of("test1"), CollectionUtils.toSet(bitsProvider.getAggregatedPrivilegeNames("test1"))); Set expected = new HashSet<>(NON_AGGREGATE_PRIVILEGES); expected.add("test1"); - assertEquals(expected, ImmutableSet.copyOf(bitsProvider.getAggregatedPrivilegeNames(JCR_ALL))); - assertEquals(expected, ImmutableSet.copyOf(bitsProvider.getAggregatedPrivilegeNames(JCR_ALL))); + assertEquals(expected, CollectionUtils.toSet(bitsProvider.getAggregatedPrivilegeNames(JCR_ALL))); + assertEquals(expected, CollectionUtils.toSet(bitsProvider.getAggregatedPrivilegeNames(JCR_ALL))); } } \ No newline at end of file diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeConfigurationImplTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeConfigurationImplTest.java index 2a64b88e0cd..92eb28ff05e 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeConfigurationImplTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeConfigurationImplTest.java @@ -16,10 +16,9 @@ */ package org.apache.jackrabbit.oak.security.privilege; -import java.security.Principal; import java.util.List; +import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.namepath.NamePathMapper; @@ -72,7 +71,7 @@ public void testGetCommitHooks() { @Test public void testGetValidators() { - List l = configuration.getValidators("wspName", ImmutableSet.of(), new MoveTracker()); + List l = configuration.getValidators("wspName", Set.of(), new MoveTracker()); assertEquals(1, l.size()); assertTrue(l.get(0) instanceof PrivilegeValidatorProvider); } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeImplTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeImplTest.java index ddae8eba7b9..4b6f2babb27 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeImplTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeImplTest.java @@ -20,7 +20,6 @@ import javax.jcr.security.Privilege; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; import org.apache.jackrabbit.oak.AbstractSecurityTest; @@ -67,7 +66,7 @@ private static void assertAggregation(@NotNull Privilege[] aggr, @NotNull String assertEquals(expectedNames.length, aggr.length); Set expected = CollectionUtils.toSet(expectedNames); - Set result = CollectionUtils.toSet(Iterables.transform(ImmutableSet.copyOf(aggr), Privilege::getName)); + Set result = CollectionUtils.toSet(Iterables.transform(Set.of(aggr), Privilege::getName)); assertEquals(expected, result); } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeManagerImplTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeManagerImplTest.java index 689b5f38c41..4fd5a8a982c 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeManagerImplTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeManagerImplTest.java @@ -23,11 +23,11 @@ import javax.jcr.security.AccessControlException; import javax.jcr.security.Privilege; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; import org.apache.jackrabbit.oak.AbstractSecurityTest; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.impl.GlobalNameMapper; import org.apache.jackrabbit.oak.namepath.impl.LocalNameMapper; import org.apache.jackrabbit.oak.namepath.NamePathMapper; @@ -217,7 +217,7 @@ protected Root getWriteRoot() { Iterable aggr = TreeUtil.getStrings(privTree, PrivilegeConstants.REP_AGGREGATES); assertNotNull(aggr); - assertEquals(Set.of("jcr:read", "jcr:write"), ImmutableSet.copyOf(aggr)); + assertEquals(Set.of("jcr:read", "jcr:write"), CollectionUtils.toSet(aggr)); } } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidatorTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidatorTest.java index d3b4a621724..fcb7eadaa5c 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidatorTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidatorTest.java @@ -17,8 +17,9 @@ package org.apache.jackrabbit.oak.security.privilege; import java.util.Collections; +import java.util.Set; + import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.AbstractSecurityTest; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; @@ -78,7 +79,7 @@ public void after() throws Exception { private Tree createPrivilegeTree(@NotNull String privName, @NotNull String... aggr) { Tree privTree = privilegesTree.addChild(privName); privTree.setProperty(JCR_PRIMARYTYPE, NT_REP_PRIVILEGE, Type.NAME); - privTree.setProperty(REP_AGGREGATES, ImmutableSet.copyOf(aggr), Type.NAMES); + privTree.setProperty(REP_AGGREGATES, Set.of(aggr), Type.NAMES); return privTree; } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/AddMembersByIdIgnoreTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/AddMembersByIdIgnoreTest.java index fcce1a541c1..6bc4f44e5e8 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/AddMembersByIdIgnoreTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/AddMembersByIdIgnoreTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.security.user; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration; import org.apache.jackrabbit.oak.spi.xml.ImportBehavior; @@ -41,7 +40,7 @@ protected ConfigurationParameters getSecurityConfigParameters() { @Test public void testNonExistingMember() throws Exception { Set failed = addNonExistingMember(); - assertEquals(ImmutableSet.copyOf(NON_EXISTING_IDS), failed); + assertEquals(Set.of(NON_EXISTING_IDS), failed); } @Test diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImplTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImplTest.java index 071ee17fd0e..664659b8a03 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImplTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImplTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.security.user; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; import org.apache.jackrabbit.api.security.user.Authorizable; @@ -27,6 +26,7 @@ import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; import org.apache.jackrabbit.oak.plugins.value.jcr.PartialValueFactory; @@ -156,7 +156,7 @@ public void testGetNamesCurrent2() throws Exception { Iterator names = properties.getNames("."); Set expected = Set.of("prop", "mvProp"); - assertEquals(expected, ImmutableSet.copyOf(names)); + assertEquals(expected, CollectionUtils.toSet(names)); } @Test(expected = RepositoryException.class) @@ -169,7 +169,7 @@ public void testGetNamesRelPath() throws Exception { Iterator names = properties.getNames("relPath"); Set expected = Set.of("prop", "mvProp"); - assertEquals(expected, ImmutableSet.copyOf(names)); + assertEquals(expected, CollectionUtils.toSet(names)); } //--------------------------------------------------------< getProperty >--- diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/EveryoneGroupTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/EveryoneGroupTest.java index 1950e881950..99b3e9752cd 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/EveryoneGroupTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/EveryoneGroupTest.java @@ -20,12 +20,12 @@ import java.util.Iterator; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.jackrabbit.oak.AbstractSecurityTest; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal; import org.junit.Test; @@ -104,7 +104,7 @@ public void testIsDeclaredMember() throws Exception { @Test public void testGetMembers() throws Exception { - Set members = ImmutableSet.copyOf(everyoneGroup.getMembers()); + Set members = CollectionUtils.toSet(everyoneGroup.getMembers()); assertFalse(members.contains(everyoneGroup)); for (Authorizable a : authorizables) { @@ -114,7 +114,7 @@ public void testGetMembers() throws Exception { @Test public void testGetDeclaredMembers() throws Exception { - Set members = ImmutableSet.copyOf(everyoneGroup.getDeclaredMembers()); + Set members = CollectionUtils.toSet(everyoneGroup.getDeclaredMembers()); assertFalse(members.contains(everyoneGroup)); for (Authorizable a : authorizables) { @@ -176,7 +176,7 @@ public void testEveryoneDeclaredMemberOf() throws Exception { @Test public void testMemberOfIncludesEveryone() throws Exception { for (Authorizable a : authorizables) { - Set groups = ImmutableSet.copyOf(a.memberOf()); + Set groups = CollectionUtils.toSet(a.memberOf()); assertTrue(groups.contains(everyoneGroup)); } } @@ -184,7 +184,7 @@ public void testMemberOfIncludesEveryone() throws Exception { @Test public void testDeclaredMemberOfIncludesEveryone() throws Exception { for (Authorizable a : authorizables) { - Set groups = ImmutableSet.copyOf(a.declaredMemberOf()); + Set groups = CollectionUtils.toSet(a.declaredMemberOf()); assertTrue(groups.contains(everyoneGroup)); } } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/ImpersonationImplEmptyTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/ImpersonationImplEmptyTest.java index d8ee65e2dae..b87d8d41dd6 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/ImpersonationImplEmptyTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/ImpersonationImplEmptyTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.security.user; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.User; @@ -95,7 +94,7 @@ private Principal getAdminPrincipal() throws Exception { @NotNull static Subject createSubject(@NotNull Principal... principals) { - return new Subject(true, ImmutableSet.copyOf(principals), Set.of(), Set.of()); + return new Subject(true, Set.of(principals), Set.of(), Set.of()); } @Test diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/ImpersonationImplTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/ImpersonationImplTest.java index 2e69715c552..1b244b09d47 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/ImpersonationImplTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/ImpersonationImplTest.java @@ -25,7 +25,6 @@ import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.api.security.principal.PrincipalIterator; import org.apache.jackrabbit.api.security.user.Group; @@ -33,6 +32,7 @@ import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl; import org.apache.jackrabbit.oak.spi.security.user.UserConstants; import org.jetbrains.annotations.NotNull; @@ -172,7 +172,7 @@ public void testContentRepresentationAfterModification() throws Exception { assertNotNull(property); Set expected = Set.of(impersonator.getPrincipal().getName(), principal2.getName()); - assertEquals(expected, ImmutableSet.copyOf(property.getValue(Type.STRINGS))); + assertEquals(expected, CollectionUtils.toSet(property.getValue(Type.STRINGS))); impersonation.revokeImpersonation(impersonator.getPrincipal()); @@ -180,7 +180,7 @@ public void testContentRepresentationAfterModification() throws Exception { assertNotNull(property); expected = Set.of(principal2.getName()); - assertEquals(expected, ImmutableSet.copyOf(property.getValue(Type.STRINGS))); + assertEquals(expected, CollectionUtils.toSet(property.getValue(Type.STRINGS))); impersonation.revokeImpersonation(principal2); assertNull(tree.getProperty(UserConstants.REP_IMPERSONATORS)); diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/InheritedMembersIteratorTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/InheritedMembersIteratorTest.java index c34f8ee213f..2709dfde220 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/InheritedMembersIteratorTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/InheritedMembersIteratorTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.security.user; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.api.security.user.Authorizable; @@ -24,6 +23,7 @@ import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.jackrabbit.oak.AbstractSecurityTest; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.user.DynamicMembershipProvider; import org.jetbrains.annotations.NotNull; import org.junit.Before; @@ -134,7 +134,7 @@ public void testDynamicMembersFails() throws Exception { } private static @NotNull Set getMembersIds(@NotNull InheritedMembersIterator it) { - return ImmutableSet.copyOf(Iterators.transform(it, authorizable -> { + return CollectionUtils.toSet(Iterators.transform(it, authorizable -> { try { return authorizable.getID(); } catch (RepositoryException repositoryException) { diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RemoveMembersByIdBestEffortTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RemoveMembersByIdBestEffortTest.java index e0dfefd3cbe..f517e4e45c5 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RemoveMembersByIdBestEffortTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RemoveMembersByIdBestEffortTest.java @@ -18,7 +18,6 @@ import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration; import org.apache.jackrabbit.oak.spi.xml.ImportBehavior; @@ -42,7 +41,7 @@ protected ConfigurationParameters getSecurityConfigParameters() { @Test public void testNonExistingMember() throws Exception { Set failed = removeNonExistingMember(); - assertEquals(ImmutableSet.copyOf(NON_EXISTING_IDS), failed); + assertEquals(Set.of(NON_EXISTING_IDS), failed); } @Test diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RemoveMembersByIdIgnoreTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RemoveMembersByIdIgnoreTest.java index 0c5ef1b0d17..9eba0f3e7b8 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RemoveMembersByIdIgnoreTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RemoveMembersByIdIgnoreTest.java @@ -18,7 +18,6 @@ import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration; import org.apache.jackrabbit.oak.spi.xml.ImportBehavior; @@ -41,7 +40,7 @@ protected ConfigurationParameters getSecurityConfigParameters() { @Test public void testNonExistingMember() throws Exception { Set failed = removeNonExistingMember(); - assertEquals(ImmutableSet.copyOf(NON_EXISTING_IDS), failed); + assertEquals(Set.of(NON_EXISTING_IDS), failed); } @Test diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RepMembersConflictHandlerTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RepMembersConflictHandlerTest.java index ab75b267b73..f473a376e3c 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RepMembersConflictHandlerTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/RepMembersConflictHandlerTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.security.user; -import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.User; diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterImpersonationBestEffortTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterImpersonationBestEffortTest.java index 38e47e967e5..6e1b057e579 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterImpersonationBestEffortTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterImpersonationBestEffortTest.java @@ -16,9 +16,9 @@ */ package org.apache.jackrabbit.oak.security.user; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.xml.ImportBehavior; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -43,7 +43,7 @@ public void testUnknownImpersonators() throws Exception { PropertyState impersonators = userTree.getProperty(REP_IMPERSONATORS); assertNotNull(impersonators); - assertEquals(Set.of("impersonator1", "impersonator2"), ImmutableSet.copyOf(impersonators.getValue(Type.STRINGS))); + assertEquals(Set.of("impersonator1", "impersonator2"), CollectionUtils.toSet(impersonators.getValue(Type.STRINGS))); } @Test @@ -53,6 +53,6 @@ public void testMixedImpersonators() throws Exception { PropertyState impersonators = userTree.getProperty(REP_IMPERSONATORS); assertNotNull(impersonators); - assertEquals(Set.of("impersonator1", testUser.getPrincipal().getName()), ImmutableSet.copyOf(impersonators.getValue(Type.STRINGS))); + assertEquals(Set.of("impersonator1", testUser.getPrincipal().getName()), CollectionUtils.toSet(impersonators.getValue(Type.STRINGS))); } } \ No newline at end of file diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterImpersonationIgnoreTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterImpersonationIgnoreTest.java index f8bdae4c430..9a0ac481438 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterImpersonationIgnoreTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterImpersonationIgnoreTest.java @@ -17,13 +17,13 @@ package org.apache.jackrabbit.oak.security.user; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal; @@ -121,7 +121,7 @@ public void testReplaceExistingProperty2() throws Exception { PropertyState impersonators = userTree.getProperty(REP_IMPERSONATORS); assertNotNull(impersonators); - assertEquals(Set.of("impersonator1", testUser.getPrincipal().getName()), ImmutableSet.copyOf(impersonators.getValue(Type.STRINGS))); + assertEquals(Set.of("impersonator1", testUser.getPrincipal().getName()), CollectionUtils.toSet(impersonators.getValue(Type.STRINGS))); } @Test diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterMembershipIgnoreTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterMembershipIgnoreTest.java index d154b00c271..87c0e70ddf3 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterMembershipIgnoreTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserImporterMembershipIgnoreTest.java @@ -22,12 +22,12 @@ import javax.jcr.RepositoryException; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal; import org.junit.Test; @@ -136,7 +136,7 @@ public void testAddMemberToNonExistingMember() throws Exception { PropertyState members = groupTree.getProperty(REP_MEMBERS); assertNotNull(members); - assertEquals(Set.of(unknownContentId, knownMemberContentId), ImmutableSet.copyOf(members.getValue(Type.STRINGS))); + assertEquals(Set.of(unknownContentId, knownMemberContentId), CollectionUtils.toSet(members.getValue(Type.STRINGS))); } @Test @@ -151,7 +151,7 @@ public void testAddReplacesExistingMember() throws Exception { PropertyState members = groupTree.getProperty(REP_MEMBERS); assertNotNull(members); - assertEquals(Set.of(contentId), ImmutableSet.copyOf(members.getValue(Type.STRINGS))); + assertEquals(Set.of(contentId), CollectionUtils.toSet(members.getValue(Type.STRINGS))); } @Test diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserPrincipalProviderWithCacheTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserPrincipalProviderWithCacheTest.java index 9ffab3c9a14..9eab5f5b6d0 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserPrincipalProviderWithCacheTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserPrincipalProviderWithCacheTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.security.user; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.principal.PrincipalIterator; import org.apache.jackrabbit.api.security.principal.PrincipalManager; @@ -29,6 +28,7 @@ import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.jdkcompat.Java23Subject; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; import org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest; @@ -183,7 +183,7 @@ public void testPrincipalManagerGetGroupMembershipPopulatesCache() throws Except PrincipalManager principalManager = getPrincipalManager(systemRoot); PrincipalIterator principalIterator = principalManager.getGroupMembership(getTestUser().getPrincipal()); - assertPrincipals(ImmutableSet.copyOf(principalIterator), EveryonePrincipal.getInstance(), testGroup.getPrincipal()); + assertPrincipals(CollectionUtils.toSet(principalIterator), EveryonePrincipal.getInstance(), testGroup.getPrincipal()); root.refresh(); diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManagerTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManagerTest.java index 4af97d30882..a3c476adae7 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManagerTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManagerTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.security.user.query; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; @@ -28,6 +27,7 @@ import org.apache.jackrabbit.oak.api.ContentSession; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.query.QueryEngineSettings; import org.apache.jackrabbit.oak.security.internal.SecurityProviderBuilder; import org.apache.jackrabbit.oak.security.user.AbstractUserTest; @@ -53,6 +53,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Set; import static java.util.Objects.requireNonNull; import static org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_READ; @@ -144,7 +145,7 @@ private static void assertResultContainsAuthorizables(@NotNull Iterator getCredentialClasses() { - return ImmutableSet.of(MyCredentials.class); + return Set.of(MyCredentials.class); } @CheckForNull diff --git a/oak-doc/src/site/markdown/security/authentication/token/default.md b/oak-doc/src/site/markdown/security/authentication/token/default.md index 99965e10abc..f04ef4f9056 100644 --- a/oak-doc/src/site/markdown/security/authentication/token/default.md +++ b/oak-doc/src/site/markdown/security/authentication/token/default.md @@ -261,7 +261,7 @@ in order to enable a custom `CredentialsSupport`. @Nonnull @Override public Set getCredentialClasses() { - return ImmutableSet.of(MyCredentials.class); + return Set.of(MyCredentials.class); } @CheckForNull diff --git a/oak-doc/src/site/markdown/security/user/default.md b/oak-doc/src/site/markdown/security/user/default.md index 3bb9817370d..fe269004d6f 100644 --- a/oak-doc/src/site/markdown/security/user/default.md +++ b/oak-doc/src/site/markdown/security/user/default.md @@ -326,7 +326,7 @@ implementation. //------------------------------------------------< SCR Integration >--- @Activate private void activate(Map properties) { - ids = ImmutableSet.copyOf(PropertiesUtil.toStringArray(properties.get("ids"), new String[0])); + ids = CollectionUtils.toSet(PropertiesUtil.toStringArray(properties.get("ids"), new String[0])); } } diff --git a/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/Role.java b/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/Role.java index 8418d2b535d..028ae916773 100644 --- a/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/Role.java +++ b/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/Role.java @@ -16,8 +16,12 @@ */ package org.apache.jackrabbit.oak.exercise.security.authorization.models.simplifiedroles; +import java.util.Collections; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authorization.permission.Permissions; import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants; import org.jetbrains.annotations.NotNull; @@ -37,12 +41,12 @@ final class Role { private Role(long permissions, String... privilegeNames) { this.permissions = permissions; - this.privilegeNames = ImmutableSet.copyOf(privilegeNames); + this.privilegeNames = Collections.unmodifiableSet(CollectionUtils.toSet(privilegeNames)); } private Role(@NotNull Role base, long permissions, String... privilegeNames) { this.permissions = base.permissions|permissions; - this.privilegeNames = ImmutableSet.builder().addAll(base.privilegeNames).add(privilegeNames).build(); + this.privilegeNames = Collections.unmodifiableSet(Stream.concat(base.privilegeNames.stream(), Stream.of(privilegeNames)).collect(Collectors.toSet())); } boolean grants(long permissions) { diff --git a/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/ThreeRolesPermissionProvider.java b/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/ThreeRolesPermissionProvider.java index b62101bb2f1..dff973e224e 100644 --- a/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/ThreeRolesPermissionProvider.java +++ b/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/ThreeRolesPermissionProvider.java @@ -16,11 +16,11 @@ */ package org.apache.jackrabbit.oak.exercise.security.authorization.models.simplifiedroles; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.tree.ReadOnly; import org.apache.jackrabbit.oak.plugins.tree.RootProvider; import org.apache.jackrabbit.oak.plugins.tree.TreeLocation; @@ -61,7 +61,7 @@ class ThreeRolesPermissionProvider implements AggregatedPermissionProvider, Thre @NotNull String supportedPath, @NotNull Context ctx, @NotNull RootProvider rootProvider) { this.root = root; - this.principalNames = ImmutableSet.copyOf(Iterables.transform(principals, Principal::getName)); + this.principalNames = CollectionUtils.toSet(Iterables.transform(principals, Principal::getName)); this.supportedPath = supportedPath; this.ctx = ctx; this.rootProvider = rootProvider; @@ -166,7 +166,7 @@ public Set getPrivileges(@Nullable Tree tree) { @Override public boolean hasPrivileges(@Nullable Tree tree, @NotNull String... privilegeNames) { - return getPrivileges(tree).containsAll(ImmutableSet.copyOf(privilegeNames)); + return getPrivileges(tree).containsAll(CollectionUtils.toSet(privilegeNames)); } @NotNull diff --git a/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/principal/CustomPrincipalProvider.java b/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/principal/CustomPrincipalProvider.java index 87c024906e4..32ef340a0b0 100644 --- a/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/principal/CustomPrincipalProvider.java +++ b/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/principal/CustomPrincipalProvider.java @@ -20,7 +20,6 @@ import java.util.Collections; import java.util.Iterator; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,7 +35,7 @@ class CustomPrincipalProvider implements PrincipalProvider { private final Set knownPrincipalNames; CustomPrincipalProvider(String[] knownPrincipalNames) { - this.knownPrincipalNames = ImmutableSet.copyOf(knownPrincipalNames); + this.knownPrincipalNames = Set.of(knownPrincipalNames); } @Nullable diff --git a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L5_CustomPermissionEvaluationTest.java b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L5_CustomPermissionEvaluationTest.java index 35c9d8076ac..656aef48e05 100644 --- a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L5_CustomPermissionEvaluationTest.java +++ b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L5_CustomPermissionEvaluationTest.java @@ -19,12 +19,13 @@ import java.security.Principal; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.jcr.GuestCredentials; import javax.jcr.Session; import javax.jcr.security.Privilege; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; @@ -270,10 +271,10 @@ public void testGuestAccess() throws Exception { @Test public void testWriteAccess() throws Exception { List> editors = ImmutableList.>of( - ImmutableSet.of(new Editor("ida")), - ImmutableSet.of(EveryonePrincipal.getInstance(), new Editor("amanda")), - ImmutableSet.of(getTestUser().getPrincipal(),new Editor("susi")), - ImmutableSet.builder().addAll(getGuestPrincipals()).add(new Editor("naima")).build() + Set.of(new Editor("ida")), + Set.of(EveryonePrincipal.getInstance(), new Editor("amanda")), + Set.of(getTestUser().getPrincipal(),new Editor("susi")), + Stream.concat(getGuestPrincipals().stream(), Stream.of(new Editor("naima"))).collect(Collectors.toUnmodifiableSet()) ); for (Set principals : editors) { @@ -310,10 +311,10 @@ public void testWriteAccess() throws Exception { @Test public void testReadAccess() throws Exception { List> readers = ImmutableList.>of( - ImmutableSet.of(new Reader("ida")), - ImmutableSet.of(EveryonePrincipal.getInstance(), new Reader("fairuz")), - ImmutableSet.of(getTestUser().getPrincipal(),new Editor("juni")), - ImmutableSet.builder().addAll(getGuestPrincipals()).add(new Editor("ale")).build() + Set.of(new Reader("ida")), + Set.of(EveryonePrincipal.getInstance(), new Reader("fairuz")), + Set.of(getTestUser().getPrincipal(),new Editor("juni")), + Stream.concat(getGuestPrincipals().stream(), Stream.of(new Editor("ale"))).collect(Collectors.toUnmodifiableSet()) ); PrivilegeManager privilegeManager = getPrivilegeManager(root); diff --git a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/principalbased/AbstractPrincipalBasedTest.java b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/principalbased/AbstractPrincipalBasedTest.java index 0c6ed8a58ce..5276820ba9f 100644 --- a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/principalbased/AbstractPrincipalBasedTest.java +++ b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/principalbased/AbstractPrincipalBasedTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.exercise.security.authorization.principalbased; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager; import org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy; @@ -160,14 +159,14 @@ PrincipalBasedAuthorizationConfiguration getPrincipalBasedAuthorizationConfigura @Nullable static PrincipalAccessControlList getApplicablePrincipalAccessControlList(@NotNull JackrabbitAccessControlManager acMgr, @NotNull Principal principal) throws Exception { - Set applicable = ImmutableSet.copyOf(acMgr.getApplicablePolicies(principal)); + Set applicable = Set.of(acMgr.getApplicablePolicies(principal)); PrincipalAccessControlList acl = (PrincipalAccessControlList) Iterables.find(applicable, accessControlPolicy -> accessControlPolicy instanceof PrincipalAccessControlList, null); return acl; } @NotNull ContentSession getTestSession(@NotNull Principal... principals) throws Exception { - Subject subject = new Subject(true, ImmutableSet.copyOf(principals), Set.of(), Set.of()); + Subject subject = new Subject(true, Set.of(principals), Set.of(), Set.of()); return Java23Subject.doAsPrivileged(subject, (PrivilegedExceptionAction) () -> getContentRepository().login(null, null), null); } } \ No newline at end of file diff --git a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L3_BuiltInPrivilegesTest.java b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L3_BuiltInPrivilegesTest.java index 8e68990fe6f..ffedf62fa52 100644 --- a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L3_BuiltInPrivilegesTest.java +++ b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L3_BuiltInPrivilegesTest.java @@ -24,8 +24,6 @@ import javax.jcr.security.Privilege; import org.apache.jackrabbit.guava.common.collect.ImmutableList; - -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; @@ -140,7 +138,7 @@ public void testAggregation() throws RepositoryException { for (Privilege aggrPrivilege : aggregated) { Set expected = expectedResults.get(aggrPrivilege.getName()); - assertEquals(expected, ImmutableSet.copyOf(aggrPrivilege.getDeclaredAggregatePrivileges())); + assertEquals(expected, Set.of(aggrPrivilege.getDeclaredAggregatePrivileges())); } } diff --git a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L7_PrivilegeDiscoveryTest.java b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L7_PrivilegeDiscoveryTest.java index 68776e651be..a26a37a1a24 100644 --- a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L7_PrivilegeDiscoveryTest.java +++ b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L7_PrivilegeDiscoveryTest.java @@ -26,7 +26,6 @@ import javax.jcr.security.AccessControlManager; import javax.jcr.security.Privilege; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager; import org.apache.jackrabbit.api.security.user.Authorizable; @@ -240,15 +239,15 @@ public void testGetPrivileges() throws Exception { Set expected = null; // EXERCISE Privilege[] testRootPrivs = acMgr.getPrivileges(testRoot); - assertEquals(expected, ImmutableSet.copyOf(testRootPrivs)); + assertEquals(expected, Set.of(testRootPrivs)); expected = null; // EXERCISE Privilege[] privs = acMgr.getPrivileges(testPath); - assertEquals(expected, ImmutableSet.copyOf(privs)); + assertEquals(expected, Set.of(privs)); expected = null; // EXERCISE Privilege[] childPrivs = acMgr.getPrivileges(childPath); - assertEquals(expected, ImmutableSet.copyOf(childPrivs)); + assertEquals(expected, Set.of(childPrivs)); } public void testGetPrivilegesForPrincipals() throws Exception { @@ -264,7 +263,7 @@ public void testGetPrivilegesForPrincipals() throws Exception { for (String path : expected.keySet()) { Set expectedPrivs = expected.get(path); Privilege[] privs = acMgr.getPrivileges(path, principals); - assertEquals(expectedPrivs, ImmutableSet.copyOf(privs)); + assertEquals(expectedPrivs, Set.of(privs)); } // 2. EXERCISE: expected privileges for the 'gPrincipal' only @@ -277,7 +276,7 @@ public void testGetPrivilegesForPrincipals() throws Exception { for (String path : expected.keySet()) { Set expectedPrivs = expected.get(path); Privilege[] privs = acMgr.getPrivileges(path, principals); - assertEquals(expectedPrivs, ImmutableSet.copyOf(privs)); + assertEquals(expectedPrivs, Set.of(privs)); } // 3. EXERCISE: expected privileges for the 'uPrincipal' and 'gPrincipal' @@ -290,7 +289,7 @@ public void testGetPrivilegesForPrincipals() throws Exception { for (String path : expected.keySet()) { Set expectedPrivs = expected.get(path); Privilege[] privs = acMgr.getPrivileges(path, principals); - assertEquals(expectedPrivs, ImmutableSet.copyOf(privs)); + assertEquals(expectedPrivs, Set.of(privs)); } // 4. EXERCISE: expected privileges for the 'uPrincipal', 'gPrincipal' + everyone @@ -303,7 +302,7 @@ public void testGetPrivilegesForPrincipals() throws Exception { for (String path : expected.keySet()) { Set expectedPrivs = expected.get(path); Privilege[] privs = acMgr.getPrivileges(path, principals); - assertEquals(expectedPrivs, ImmutableSet.copyOf(privs)); + assertEquals(expectedPrivs, Set.of(privs)); } } @@ -314,7 +313,7 @@ public void testGetPrivilegesForPrincipalsUserSession() throws Exception { Privilege[] privs = acMgr.getPrivileges(testPath, Set.of(gPrincipal)); Set expectedPrivs = null; - assertEquals(expectedPrivs, ImmutableSet.copyOf(privs)); + assertEquals(expectedPrivs, Set.of(privs)); } public void testHasPermissionVsHasPrivilege() throws Exception { diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/JackrabbitAccessControlManagerTest.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/JackrabbitAccessControlManagerTest.java index d1005470b78..f617c752a67 100644 --- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/JackrabbitAccessControlManagerTest.java +++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/JackrabbitAccessControlManagerTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.jcr.security.authorization; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager; import org.apache.jackrabbit.api.security.authorization.PrivilegeCollection; import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal; @@ -95,8 +94,8 @@ public void testPrivilegeCollectionFromNames() throws Exception { PrivilegeCollection pc = jrAcMgr.privilegeCollectionFromNames(Privilege.JCR_READ, Privilege.JCR_WRITE); assertFalse(pc instanceof PrivilegeCollection.Default); - Set expected = ImmutableSet.copyOf(privilegesFromNames(new String[] {Privilege.JCR_READ, Privilege.JCR_WRITE})); - assertEquals(expected, ImmutableSet.copyOf(pc.getPrivileges())); + Set expected = Set.of(privilegesFromNames(new String[] {Privilege.JCR_READ, Privilege.JCR_WRITE})); + assertEquals(expected, Set.of(pc.getPrivileges())); } public void testPrivilegeCollectionFromInvalidNames() throws Exception { diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/privilege/PrivilegeRegistrationTest.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/privilege/PrivilegeRegistrationTest.java index 0a08f937831..77957a8bad5 100644 --- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/privilege/PrivilegeRegistrationTest.java +++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/privilege/PrivilegeRegistrationTest.java @@ -34,7 +34,6 @@ import javax.jcr.security.AccessControlException; import javax.jcr.security.Privilege; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils; @@ -431,7 +430,7 @@ public void testJcrAllWithCustomPrivileges() throws Exception { JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) session.getAccessControlManager(); Privilege[] allPrivileges = AccessControlUtils.privilegesFromNames(session, Privilege.JCR_ALL); - Set principalSet = ImmutableSet.of(EveryonePrincipal.getInstance()); + Set principalSet = Set.of(EveryonePrincipal.getInstance()); assertTrue(acMgr.hasPrivileges(testPath, principalSet, allPrivileges)); diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithActionsBestEffortTest.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithActionsBestEffortTest.java index 4cf4b565fef..cb1d1c7e26e 100755 --- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithActionsBestEffortTest.java +++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithActionsBestEffortTest.java @@ -16,11 +16,11 @@ */ package org.apache.jackrabbit.oak.jcr.security.user; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.oak.api.Root; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.SecurityProvider; @@ -140,16 +140,16 @@ public void onMemberAdded(@NotNull Group group, @NotNull Authorizable member, @N @Override public void onMembersAdded(@NotNull Group group, @NotNull Iterable memberIds, @NotNull Iterable failedIds, @NotNull Root root, @NotNull NamePathMapper namePathMapper) throws RepositoryException { this.group = group; - this.memberIds.addAll(ImmutableSet.copyOf(memberIds)); - this.failedIds.addAll(ImmutableSet.copyOf(failedIds)); + this.memberIds.addAll(CollectionUtils.toSet(memberIds)); + this.failedIds.addAll(CollectionUtils.toSet(failedIds)); onMembersAddedCalled = true; } @Override public void onMembersAddedContentId(@NotNull Group group, @NotNull Iterable memberContentIds, @NotNull Iterable failedIds, @NotNull Root root, @NotNull NamePathMapper namePathMapper) throws RepositoryException { this.group = group; - this.memberContentIds.addAll(ImmutableSet.copyOf(memberContentIds)); - this.failedIds.addAll(ImmutableSet.copyOf(failedIds)); + this.memberContentIds.addAll(CollectionUtils.toSet(memberContentIds)); + this.failedIds.addAll(CollectionUtils.toSet(failedIds)); onMembersAddedContentIdCalled = true; } } diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithActionsTest.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithActionsTest.java index ad541f344cf..5ee9f91f243 100644 --- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithActionsTest.java +++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupImportWithActionsTest.java @@ -16,11 +16,11 @@ */ package org.apache.jackrabbit.oak.jcr.security.user; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.oak.api.Root; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.SecurityProvider; @@ -132,7 +132,7 @@ private class TestGroupAction extends AbstractGroupAction { @Override public void onMembersAdded(@NotNull Group group, @NotNull Iterable memberIds, @NotNull Iterable failedIds, @NotNull Root root, @NotNull NamePathMapper namePathMapper) throws RepositoryException { this.group = group; - this.memberIds.addAll(ImmutableSet.copyOf(memberIds)); + this.memberIds.addAll(CollectionUtils.toSet(memberIds)); onMembersAddedCalled = true; } diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/CopyOnReadDirectory.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/CopyOnReadDirectory.java index ce29ff52c95..7b4689cda01 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/CopyOnReadDirectory.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/CopyOnReadDirectory.java @@ -33,8 +33,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.commons.PerfLogger; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FilterDirectory; @@ -332,7 +332,7 @@ private void removeDeletedFiles() throws IOException { Set filesToBeDeleted = // Files present locally - ImmutableSet.copyOf(local.listAll()).stream() + CollectionUtils.toSet(local.listAll()).stream() // but not in my view .filter(name -> !remoteFiles.contains(name)) // and also older than a safe timestamp (deleteBeforeTS) diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/OakDirectory.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/OakDirectory.java index dbde40b651f..d862c5eb314 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/OakDirectory.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/directory/OakDirectory.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.Blob; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; @@ -131,7 +130,7 @@ public OakDirectory(NodeBuilder builder, String dataNodeName, LuceneIndexDefinit this.definition = definition; this.readOnly = readOnly; this.fileNames.addAll(getListing()); - this.fileNamesAtStart = ImmutableSet.copyOf(this.fileNames); + this.fileNamesAtStart = Set.copyOf(this.fileNames); this.indexName = definition.getIndexName(); this.blobFactory = blobFactory; this.blobDeletionCallback = blobDeletionCallback; @@ -341,7 +340,7 @@ private Set getListing(){ if (fileNames == null){ fileNames = directoryBuilder.getChildNodeNames(); } - Set result = ImmutableSet.copyOf(fileNames); + Set result = CollectionUtils.toSet(fileNames); PERF_LOGGER.end(start, 100, "Directory listing performed. Total {} files", result.size()); return result; } diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/UniquenessConstraintValidator.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/UniquenessConstraintValidator.java index eb746986830..d26e7963b7c 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/UniquenessConstraintValidator.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/UniquenessConstraintValidator.java @@ -24,13 +24,13 @@ import java.util.Set; import org.apache.jackrabbit.guava.common.collect.HashMultimap; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Multimap; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.spi.state.NodeStateUtils; @@ -68,7 +68,7 @@ public void validate() throws CommitFailedException { String propertyRelativePath = e.getKey(); String value = e.getValue(); Iterable indexedPaths = getIndexedPaths(propertyRelativePath, value); - Set allPaths = ImmutableSet.copyOf(indexedPaths); + Set allPaths = CollectionUtils.toSet(indexedPaths); //If more than one match found then filter out stale paths if (allPaths.size() > 1) { diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/PathElementComparator.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/PathElementComparator.java index 3b2d5ff9988..971e090ce52 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/PathElementComparator.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/PathElementComparator.java @@ -24,7 +24,7 @@ import java.util.Iterator; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; public class PathElementComparator implements Comparator> { private final Set preferred; @@ -34,7 +34,7 @@ public PathElementComparator() { } public PathElementComparator(Iterable preferredPathElements) { - this.preferred = ImmutableSet.copyOf(preferredPathElements); + this.preferred = CollectionUtils.toSet(preferredPathElements); } @Override diff --git a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java index 17246e02980..b1ba9e8f7ae 100644 --- a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java +++ b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/IndexDefinition.java @@ -20,7 +20,6 @@ package org.apache.jackrabbit.oak.plugins.index.search; import org.apache.jackrabbit.JcrConstants; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.primitives.Ints; import org.apache.jackrabbit.oak.api.IllegalRepositoryStateException; @@ -29,6 +28,7 @@ import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.index.IndexConstants; import org.apache.jackrabbit.oak.plugins.index.search.util.ConfigUtil; @@ -1723,7 +1723,7 @@ private NodeState getTikaConfigNode() { private static Set getMultiProperty(NodeState definition, String propName) { PropertyState pse = definition.getProperty(propName); - return pse != null ? ImmutableSet.copyOf(pse.getValue(Type.STRINGS)) : Set.of(); + return pse != null ? CollectionUtils.toSet(pse.getValue(Type.STRINGS)) : Set.of(); } private static Set toLowerCase(Set values) { diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParameters.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParameters.java index 63406d872eb..a7a36f35b17 100644 --- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParameters.java +++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParameters.java @@ -27,8 +27,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.commons.PropertiesUtil; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -306,13 +306,13 @@ private static Set convertToSet(@NotNull Object configProperty, @NotNull Clas if (configProperty instanceof Set) { return (Set) configProperty; } else if (configProperty instanceof Collection) { - return ImmutableSet.copyOf((Collection) configProperty); + return Collections.unmodifiableSet(CollectionUtils.toSet((Collection) configProperty)); } else if (configProperty.getClass().isArray()) { - return ImmutableSet.copyOf((Object[]) configProperty); + return Collections.unmodifiableSet(CollectionUtils.toSet((Object[]) configProperty)); } else { String[] arr = PropertiesUtil.toStringArray(configProperty); if (arr != null) { - return ImmutableSet.copyOf(arr); + return Collections.unmodifiableSet(CollectionUtils.toSet(arr)); } else { String str = configProperty.toString(); log.warn("Unsupported target type {} for value {}", clazz.getName(), str); diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/AbstractLoginModule.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/AbstractLoginModule.java index 8c49550772b..1f5fef3ec7e 100644 --- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/AbstractLoginModule.java +++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/AbstractLoginModule.java @@ -24,6 +24,8 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.jcr.Credentials; import javax.jcr.NoSuchWorkspaceException; import javax.security.auth.DestroyFailedException; @@ -36,7 +38,6 @@ import javax.security.auth.spi.LoginModule; import org.apache.jackrabbit.guava.common.base.Stopwatch; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.jackrabbit.oak.api.AuthInfo; import org.apache.jackrabbit.oak.api.ContentRepository; @@ -212,9 +213,7 @@ public void initialize(Subject subject, CallbackHandler callbackHandler, Map creds = ImmutableSet.builder() - .addAll(subject.getPublicCredentials(Credentials.class)) - .addAll(subject.getPublicCredentials(AuthInfo.class)).build(); + Set creds = Stream.concat(subject.getPublicCredentials(Credentials.class).stream(), subject.getPublicCredentials(AuthInfo.class).stream()).collect(Collectors.toSet()); if (!subject.getPrincipals().isEmpty() && !creds.isEmpty()) { // clear subject if not readonly if (!subject.isReadOnly()) { diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImpl.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImpl.java index 19ad19ecc98..c7c83f45931 100644 --- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImpl.java +++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImpl.java @@ -25,8 +25,8 @@ import javax.jcr.SimpleCredentials; import javax.security.auth.Subject; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.AuthInfo; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,7 +48,7 @@ public AuthInfoImpl(@Nullable String userID, @Nullable Map attributes @Nullable Iterable principals) { this.userID = userID; this.attributes = (attributes == null) ? Collections.emptyMap() : attributes; - this.principals = (principals == null) ? Collections.emptySet() : ImmutableSet.copyOf(principals); + this.principals = (principals == null) ? Collections.emptySet() : Set.copyOf(CollectionUtils.toSet(principals)); } public static AuthInfo createFromSubject(@NotNull Subject subject) { diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/credentials/SimpleCredentialsSupport.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/credentials/SimpleCredentialsSupport.java index 47011218563..f287795bdaf 100644 --- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/credentials/SimpleCredentialsSupport.java +++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/credentials/SimpleCredentialsSupport.java @@ -23,7 +23,6 @@ import javax.jcr.Credentials; import javax.jcr.SimpleCredentials; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Maps; import org.jetbrains.annotations.NotNull; @@ -47,7 +46,7 @@ public static CredentialsSupport getInstance() { @Override @NotNull public Set getCredentialClasses() { - return ImmutableSet.of(SimpleCredentials.class); + return Set.of(SimpleCredentials.class); } @Override @@ -65,8 +64,7 @@ public String getUserId(@NotNull Credentials credentials) { public Map getAttributes(@NotNull Credentials credentials) { if (credentials instanceof SimpleCredentials) { final SimpleCredentials sc = (SimpleCredentials) credentials; - return Maps.asMap(ImmutableSet.copyOf(sc.getAttributeNames()), - input -> sc.getAttribute(input)); + return Maps.asMap(Set.of(sc.getAttributeNames()), sc::getAttribute); } else { return Collections.emptyMap(); } diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/ACE.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/ACE.java index c590a7b0f2b..b72c37ce713 100644 --- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/ACE.java +++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/ACE.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry; import org.apache.jackrabbit.api.security.authorization.PrivilegeCollection; import org.apache.jackrabbit.oak.namepath.NamePathMapper; @@ -76,7 +75,7 @@ public ACE(@Nullable Principal principal, @Nullable PrivilegeBits privilegeBits, this.principal = principal; this.privilegeBits = privilegeBits; this.isAllow = isAllow; - this.restrictions = (restrictions == null) ? Collections.emptySet() : ImmutableSet.copyOf(restrictions); + this.restrictions = (restrictions == null) ? Collections.emptySet() : Collections.unmodifiableSet(restrictions); this.namePathMapper = namePathMapper; this.valueFactory = new PartialValueFactory(namePathMapper); } diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java index b811eb00bf9..4b29d9ed9f9 100644 --- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java +++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java @@ -31,10 +31,10 @@ import javax.jcr.security.AccessControlException; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; import org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; @@ -70,7 +70,7 @@ public Set getSupportedRestrictions(@Nullable String oakP if (isUnsupportedPath(oakPath)) { return Collections.emptySet(); } else { - return ImmutableSet.copyOf(supported.values()); + return CollectionUtils.toLinkedSet(supported.values()); } } diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/ImmutablePrivilegeDefinition.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/ImmutablePrivilegeDefinition.java index 6cf1199e132..6878a868803 100644 --- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/ImmutablePrivilegeDefinition.java +++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/ImmutablePrivilegeDefinition.java @@ -16,11 +16,11 @@ */ package org.apache.jackrabbit.oak.spi.security.privilege; +import java.util.Collections; import java.util.Objects; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; - +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,11 +37,7 @@ public final class ImmutablePrivilegeDefinition implements PrivilegeDefinition { public ImmutablePrivilegeDefinition(@NotNull String name, boolean isAbstract, @Nullable Iterable declaredAggregateNames) { this.name = name; this.isAbstract = isAbstract; - ImmutableSet.Builder builder = ImmutableSet.builder(); - if (declaredAggregateNames != null) { - builder.addAll(declaredAggregateNames); - } - this.declaredAggregateNames = builder.build(); + this.declaredAggregateNames = declaredAggregateNames != null ? Collections.unmodifiableSet(CollectionUtils.toSet(declaredAggregateNames)) : Set.of(); hashcode = Objects.hash(this.name, this.isAbstract, this.declaredAggregateNames); } diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java index 80d672506f7..346b9d314cc 100644 --- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java +++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProvider.java @@ -28,7 +28,6 @@ import javax.jcr.security.Privilege; import org.apache.jackrabbit.guava.common.collect.FluentIterable; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Root; @@ -202,7 +201,7 @@ public Set getPrivilegeNames(@Nullable PrivilegeBits privilegeBits) { privilegeNames = bitsToNames.get(pb); } else { privilegeNames = collectPrivilegeNames(privilegesTree, pb); - bitsToNames.put(pb, ImmutableSet.copyOf(privilegeNames)); + bitsToNames.put(pb, Set.copyOf(privilegeNames)); } return privilegeNames; } @@ -251,7 +250,7 @@ public Iterable getAggregatedPrivilegeNames(@NotNull String... privilege return extractAggregatedPrivileges(Collections.singleton(privName)); } } else { - Set pNames = ImmutableSet.copyOf(privilegeNames); + Set pNames = Set.of(privilegeNames); if (NON_AGGREGATE_PRIVILEGES.containsAll(pNames)) { return pNames; } else { @@ -267,15 +266,14 @@ private Iterable extractAggregatedPrivileges(@NotNull Iterable p @NotNull private Set resolveBuiltInAggregation(@NotNull String privilegeName) { - ImmutableSet.Builder builder = ImmutableSet.builder(); + Set set = new HashSet<>(); for (String name : AGGREGATE_PRIVILEGES.get(privilegeName)) { if (!AGGREGATE_PRIVILEGES.containsKey(name)) { - builder.add(name); + set.add(name); } else { - builder.addAll(resolveBuiltInAggregation(name)); + set.addAll(resolveBuiltInAggregation(name)); } } - Set set = builder.build(); aggregation.put(privilegeName, set); return set; } @@ -294,19 +292,18 @@ public Iterable apply(@Nullable String privName) { } else if (AGGREGATE_PRIVILEGES.containsKey(privName)) { return resolveBuiltInAggregation(privName); } else { - ImmutableSet.Builder builder = ImmutableSet.builder(); - fillAggregation(getPrivilegesTree().getChild(privName), builder); + Set aggregates = new HashSet<>(); + fillAggregation(getPrivilegesTree().getChild(privName), aggregates); - Set aggregates = builder.build(); if (!JCR_ALL.equals(privName) && !aggregates.isEmpty()) { aggregation.put(privName, aggregates); } - return aggregates; + return Set.copyOf(aggregates); } } } - private void fillAggregation(@NotNull Tree privTree, @NotNull ImmutableSet.Builder builder) { + private void fillAggregation(@NotNull Tree privTree, @NotNull Set set) { if (!privTree.exists()) { return; } @@ -314,17 +311,17 @@ private void fillAggregation(@NotNull Tree privTree, @NotNull ImmutableSet.Build if (aggregates != null) { for (String name : aggregates.getValue(Type.NAMES)) { if (NON_AGGREGATE_PRIVILEGES.contains(name)) { - builder.add(name); + set.add(name); } else if (aggregation.containsKey(name)) { - builder.addAll(aggregation.get(name)); + set.addAll(aggregation.get(name)); } else if (AGGREGATE_PRIVILEGES.containsKey(name)) { - builder.addAll(resolveBuiltInAggregation(name)); + set.addAll(resolveBuiltInAggregation(name)); } else { - fillAggregation(privTree.getParent().getChild(name), builder); + fillAggregation(privTree.getParent().getChild(name), set); } } } else { - builder.add(privTree.getName()); + set.add(privTree.getName()); } } } diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java index 32e66e7cf0e..20e0a06213d 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/CompositeConfigurationTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.spi.security; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.plugins.tree.RootProvider; import org.apache.jackrabbit.oak.plugins.tree.TreeProvider; @@ -372,7 +371,7 @@ public ConfigurationParameters getParameters() { }; addConfiguration(withParams); - assertEquals(ImmutableSet.copyOf(params.keySet()), ImmutableSet.copyOf(compositeConfiguration.getParameters().keySet())); + assertEquals(Set.copyOf(params.keySet()), Set.copyOf(compositeConfiguration.getParameters().keySet())); ConfigurationParameters params2 = ConfigurationParameters.of("a", "valueA2", "c", "valueC"); SecurityConfiguration withParams2 = new SecurityConfiguration.Default() { @@ -386,7 +385,7 @@ public ConfigurationParameters getParameters() { ConfigurationParameters compositeParams = compositeConfiguration.getParameters(); assertEquals(3, compositeParams.size()); - assertEquals(ImmutableSet.copyOf(ConfigurationParameters.of(params, params2).keySet()), ImmutableSet.copyOf(compositeParams.keySet())); + assertEquals(Set.copyOf(ConfigurationParameters.of(params, params2).keySet()), Set.copyOf(compositeParams.keySet())); assertEquals("valueA2", compositeParams.getConfigValue("a", "def")); } diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParametersTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParametersTest.java index 32cfc1bf0a7..49bc7757e9b 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParametersTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/ConfigurationParametersTest.java @@ -27,9 +27,8 @@ import java.util.Properties; import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; -import org.apache.jackrabbit.guava.common.collect.Sets; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -92,8 +91,8 @@ public void testCreationFromProperties() { properties.put("a", "b"); ConfigurationParameters cp = ConfigurationParameters.of(properties); - assertEquals(ImmutableSet.copyOf(properties.keySet()), ImmutableSet.copyOf(cp.keySet())); - assertEquals(ImmutableSet.copyOf(properties.values()), ImmutableSet.copyOf(cp.values())); + assertEquals(Set.copyOf(properties.keySet()), Set.copyOf(cp.keySet())); + assertEquals(Set.copyOf(properties.values()), Set.copyOf(cp.values())); } @@ -110,8 +109,8 @@ public void testCreationFromDictionary() { dict.put("a", "b"); ConfigurationParameters cp = ConfigurationParameters.of(dict); - assertEquals(ImmutableSet.copyOf(Iterators.forEnumeration(dict.keys())), ImmutableSet.copyOf(cp.keySet())); - assertEquals(ImmutableSet.copyOf(Iterators.forEnumeration(dict.elements())), ImmutableSet.copyOf(cp.values())); + assertEquals(Collections.unmodifiableSet(CollectionUtils.toSet(Iterators.forEnumeration(dict.keys()))), Set.copyOf(cp.keySet())); + assertEquals(Collections.unmodifiableSet(CollectionUtils.toSet(Iterators.forEnumeration(dict.elements()))), Set.copyOf(cp.values())); } @@ -322,10 +321,10 @@ public void testImpossibleConversion() { @Test public void testConversionToSet() { String[] stringArray = new String[] {"a", "b"}; - Set stringSet = ImmutableSet.copyOf(stringArray); + Set stringSet = Set.of(stringArray); TestObject[] testObjectArray = new TestObject[] {new TestObject("a"), new TestObject("b")}; - Set testObjectSet = ImmutableSet.copyOf(testObjectArray); + Set testObjectSet = Set.of(testObjectArray); // map of config value (key) and expected result set. Map> configValues = new HashMap<>(); @@ -464,10 +463,10 @@ public void testInvalidConversionToBoolean() { @Test public void testConversionToStringArray() { String[] stringArray = new String[] {"a", "b"}; - Set stringSet = ImmutableSet.copyOf(stringArray); + Set stringSet = Collections.unmodifiableSet(CollectionUtils.toSet(stringArray)); TestObject[] testObjectArray = new TestObject[] {new TestObject("a"), new TestObject("b")}; - Set testObjectSet = ImmutableSet.copyOf(testObjectArray); + Set testObjectSet = Collections.unmodifiableSet(CollectionUtils.toSet(testObjectArray)); String[] defaultStrings = new String[]{"abc", "def", "ghi"}; diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AbstractLoginModuleTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AbstractLoginModuleTest.java index 98646e9ebd4..f8677cd2400 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AbstractLoginModuleTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AbstractLoginModuleTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authentication; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.api.security.authentication.token.TokenCredentials; import org.apache.jackrabbit.api.security.principal.PrincipalManager; import org.apache.jackrabbit.api.security.user.UserManager; @@ -63,6 +62,8 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.apache.jackrabbit.oak.spi.security.authentication.AbstractLoginModule.SHARED_KEY_CREDENTIALS; import static org.junit.Assert.assertEquals; @@ -146,7 +147,7 @@ public void testLogout() throws Exception { @Test public void testLogoutSuccessClearsSubject() throws Exception { - Subject subject = new Subject(false, ImmutableSet.of(new PrincipalImpl("pName")), Set.of(new TestCredentials()), Set.of()); + Subject subject = new Subject(false, Set.of(new PrincipalImpl("pName")), Set.of(new TestCredentials()), Set.of()); AbstractLoginModule loginModule = initLoginModule(subject); assertTrue(loginModule.logout()); @@ -157,7 +158,7 @@ public void testLogoutSuccessClearsSubject() throws Exception { @Test public void testLogoutSuccessReadOnlySubject() throws Exception { - Subject subject = new Subject(true, ImmutableSet.of(new PrincipalImpl("pName")), Set.of(new TestCredentials()), Set.of()); + Subject subject = new Subject(true, Set.of(new PrincipalImpl("pName")), Set.of(new TestCredentials()), Set.of()); AbstractLoginModule loginModule = initLoginModule(subject); assertTrue(loginModule.logout()); @@ -168,14 +169,14 @@ public void testLogoutSuccessReadOnlySubject() throws Exception { @Test public void testLogoutSubjectWithoutCredentials() throws Exception { - Subject subject = new Subject(false, ImmutableSet.of(new PrincipalImpl("pName")), Set.of("stringNotCredentials"), Set.of()); + Subject subject = new Subject(false, Set.of(new PrincipalImpl("pName")), Set.of("stringNotCredentials"), Set.of()); AbstractLoginModule loginModule = initLoginModule(subject); loginModule.logout(); assertFalse(subject.getPublicCredentials().isEmpty()); assertFalse(subject.getPrincipals().isEmpty()); - subject = new Subject(false, ImmutableSet.of(new PrincipalImpl("pName")), Set.of(), Set.of()); + subject = new Subject(false, Set.of(new PrincipalImpl("pName")), Set.of(), Set.of()); loginModule = initLoginModule(subject); loginModule.logout(); @@ -208,7 +209,7 @@ public void testLogoutCPSuccess() throws LoginException { String userId = TestPrincipalProvider.getIDFromPrincipal(p); Set principals = pp.getPrincipals(userId); - Set all = ImmutableSet.builder().add(p).add(foreignPrincipal).addAll(principals).build(); + Set all = Stream.concat(Stream.of(p, foreignPrincipal), principals.stream()).collect(Collectors.toUnmodifiableSet()); AuthInfo authInfo = new AuthInfoImpl(userId, null, all); @@ -242,7 +243,7 @@ public void testLogoutCPDestroyable() throws Exception { Credentials foreign2 = new TokenCredentials("token"); Subject subject = new Subject(true, - ImmutableSet.of(new PrincipalImpl("pName")), + Set.of(new PrincipalImpl("pName")), Set.of(creds, foreign1, foreign2), Set.of()); AbstractLoginModule loginModule = initLoginModule(subject); diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplTest.java index 4d3fce193e5..a8fb7711fd5 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/AuthInfoImplTest.java @@ -25,7 +25,6 @@ import javax.jcr.SimpleCredentials; import javax.security.auth.Subject; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.AuthInfo; import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl; @@ -41,7 +40,7 @@ public class AuthInfoImplTest { private static final String USER_ID = "userId"; private static final Map ATTRIBUTES = Map.of("attr", "value"); - private static final Set PRINCIPALS = ImmutableSet.of(new PrincipalImpl("principalName")); + private static final Set PRINCIPALS = Set.of(new PrincipalImpl("principalName")); private final AuthInfoImpl authInfo = new AuthInfoImpl(USER_ID, ATTRIBUTES, PRINCIPALS); diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/OpenAuthorizationConfigurationTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/OpenAuthorizationConfigurationTest.java index 741b24a75c3..bf43d7cc670 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/OpenAuthorizationConfigurationTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/OpenAuthorizationConfigurationTest.java @@ -16,9 +16,8 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization; -import java.security.Principal; +import java.util.Set; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.spi.security.authorization.permission.OpenPermissionProvider; @@ -43,6 +42,6 @@ public void testGetRestrictionProvider() { @Test public void testGetPermissionProvider() { - assertSame(OpenPermissionProvider.getInstance(), config.getPermissionProvider(Mockito.mock(Root.class), "default", ImmutableSet.of())); + assertSame(OpenPermissionProvider.getInstance(), config.getPermissionProvider(Mockito.mock(Root.class), "default", Set.of())); } } \ No newline at end of file diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/AbstractAccessControlTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/AbstractAccessControlTest.java index 2f4793bcc3e..5fb9bbdc4a0 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/AbstractAccessControlTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/AbstractAccessControlTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction; @@ -62,7 +61,7 @@ ACE createEntry(boolean isAllow, String... privilegeName) ACE createEntry(Principal principal, PrivilegeBits privilegeBits, boolean isAllow, Restriction... restrictions) throws RepositoryException { - return new TestACE(principal, privilegeBits, isAllow, ImmutableSet.copyOf(restrictions)); + return new TestACE(principal, privilegeBits, isAllow, Set.of(restrictions)); } private final class TestACE extends ACE { diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/PermissionsTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/PermissionsTest.java index da7bddc1fe1..063c78f9d9d 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/PermissionsTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/PermissionsTest.java @@ -25,7 +25,6 @@ import org.apache.jackrabbit.guava.common.base.Splitter; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.JackrabbitSession; @@ -231,7 +230,7 @@ public void testAggregates() { Permissions.SET_PROPERTY, Set.of(Permissions.ADD_PROPERTY, Permissions.MODIFY_PROPERTY, Permissions.REMOVE_PROPERTY), Permissions.WRITE, Set.of(Permissions.ADD_NODE, Permissions.REMOVE_NODE, Permissions.ADD_PROPERTY, Permissions.REMOVE_PROPERTY,Permissions.MODIFY_PROPERTY) ); - aggregation.forEach((key, value) -> assertEquals(value, ImmutableSet.copyOf(Permissions.aggregates(key)))); + aggregation.forEach((key, value) -> assertEquals(value, CollectionUtils.toSet(Permissions.aggregates(key)))); } @Test diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/CompositePrincipalProviderTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/CompositePrincipalProviderTest.java index 7c2205bf2e0..df88787fb7c 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/CompositePrincipalProviderTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/CompositePrincipalProviderTest.java @@ -28,12 +28,12 @@ import java.util.TreeSet; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal; import org.apache.jackrabbit.api.security.principal.PrincipalManager; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.junit.Test; @@ -60,7 +60,7 @@ private Iterable testPrincipals() { } private static void assertIterator(@NotNull Iterable expected, @NotNull Iterator result) { - assertEquals(ImmutableSet.copyOf(expected), ImmutableSet.copyOf(result)); + assertEquals(CollectionUtils.toSet(expected), CollectionUtils.toSet(result)); } @Test diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalManagerImplTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalManagerImplTest.java index 9bc41a56ff8..9012de45676 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalManagerImplTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalManagerImplTest.java @@ -20,12 +20,12 @@ import java.util.Collections; import java.util.Enumeration; import java.util.Iterator; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.principal.PrincipalIterator; import org.apache.jackrabbit.api.security.principal.PrincipalManager; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -54,7 +54,7 @@ private static boolean isGroup(Principal p) { } private static void assertIterator(@NotNull Iterator expected, @NotNull Iterator result) { - assertEquals(ImmutableSet.copyOf(expected), ImmutableSet.copyOf(result)); + assertEquals(CollectionUtils.toSet(expected), CollectionUtils.toSet(result)); } @Test diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/TestPrincipalProvider.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/TestPrincipalProvider.java index 1e4b97fab54..3decaf497b9 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/TestPrincipalProvider.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/principal/TestPrincipalProvider.java @@ -17,6 +17,8 @@ package org.apache.jackrabbit.oak.spi.security.principal; import java.security.Principal; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Enumeration; import java.util.HashSet; import java.util.Iterator; @@ -25,7 +27,6 @@ import java.util.Set; import java.util.function.Predicate; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.guava.common.collect.Maps; @@ -33,6 +34,7 @@ import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal; import org.apache.jackrabbit.api.security.principal.PrincipalManager; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,7 +56,7 @@ public TestPrincipalProvider(boolean exposesEveryone) { public TestPrincipalProvider(String... principalNames) { this.exposesEveryone = true; - this.principals = Maps.toMap(ImmutableSet.copyOf(principalNames), input -> new ItemBasedPrincipal() { + this.principals = Maps.toMap(CollectionUtils.toLinkedSet(Arrays.asList(principalNames)), input -> new ItemBasedPrincipal() { @NotNull @Override public String getPath() { @@ -173,7 +175,7 @@ private static final class TestGroup extends PrincipalImpl implements GroupPrinc public TestGroup(String name, Principal... members) { super(name); - Set mset = ImmutableSet.copyOf(members); + Set mset = Set.of(members); this.members = Iterators.asEnumeration(mset.iterator()); } diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java index 81526f2241d..048a25e0b74 100644 --- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java +++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/privilege/PrivilegeBitsProviderTest.java @@ -17,12 +17,12 @@ package org.apache.jackrabbit.oak.spi.security.privilege; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; import org.jetbrains.annotations.NotNull; @@ -392,20 +392,20 @@ public void testGetAggregatedPrivilegeNamesNonAggregates() { @Test public void testGetAggregatedPrivilegeNamesJcrRead() { - assertEquals(ImmutableSet.copyOf(AGGREGATE_PRIVILEGES.get(JCR_READ)), ImmutableSet.copyOf(bitsProvider.getAggregatedPrivilegeNames(JCR_READ))); + assertEquals(Set.of(AGGREGATE_PRIVILEGES.get(JCR_READ)), CollectionUtils.toSet(bitsProvider.getAggregatedPrivilegeNames(JCR_READ))); } @Test public void testGetAggregatedPrivilegeNamesJcrWrite() { // nested aggregated privileges in this case - Set result = ImmutableSet.copyOf(bitsProvider.getAggregatedPrivilegeNames(JCR_WRITE)); - assertNotEquals(ImmutableSet.copyOf(AGGREGATE_PRIVILEGES.get(JCR_WRITE)), result); + Set result = CollectionUtils.toSet(bitsProvider.getAggregatedPrivilegeNames(JCR_WRITE)); + assertNotEquals(Set.of(AGGREGATE_PRIVILEGES.get(JCR_WRITE)), result); String[] expected = new String[] { JCR_ADD_CHILD_NODES, JCR_REMOVE_CHILD_NODES, JCR_REMOVE_NODE, REP_ADD_PROPERTIES, REP_ALTER_PROPERTIES, REP_REMOVE_PROPERTIES }; - assertEquals(ImmutableSet.copyOf(expected), result); + assertEquals(Set.of(expected), result); } @Test @@ -416,35 +416,35 @@ public void testGetAggregatedPrivilegeNamesBuiltInTwice() { @Test public void testGetAggregatedPrivilegeNamesMultipleBuiltIn() { - Iterable expected = ImmutableSet.copyOf(Iterables.concat( + Iterable expected = CollectionUtils.toSet(Iterables.concat( bitsProvider.getAggregatedPrivilegeNames(JCR_READ), bitsProvider.getAggregatedPrivilegeNames(JCR_WRITE))); // create new to avoid reading from cache PrivilegeBitsProvider bp = new PrivilegeBitsProvider(root); Iterable result = bp.getAggregatedPrivilegeNames(JCR_READ, JCR_WRITE); - assertEquals(expected, ImmutableSet.copyOf(result)); + assertEquals(expected, CollectionUtils.toSet(result)); } @Test public void testGetAggregatedPrivilegeNamesMultipleBuiltIn2() { - Iterable expected = ImmutableSet.copyOf(Iterables.concat( + Iterable expected = CollectionUtils.toSet(Iterables.concat( bitsProvider.getAggregatedPrivilegeNames(JCR_READ), bitsProvider.getAggregatedPrivilegeNames(JCR_WRITE))); // read with same provider (i.e. reading from cache) Iterable result = bitsProvider.getAggregatedPrivilegeNames(JCR_READ, JCR_WRITE); - assertEquals(expected, ImmutableSet.copyOf(result)); + assertEquals(expected, CollectionUtils.toSet(result)); } @Test public void testGetAggregatedPrivilegeNamesMixedBuiltIn() { - Iterable expected = ImmutableSet.copyOf(Iterables.concat( + Iterable expected = CollectionUtils.toSet(Iterables.concat( Set.of(JCR_LOCK_MANAGEMENT), bitsProvider.getAggregatedPrivilegeNames(JCR_WRITE))); Iterable result = bitsProvider.getAggregatedPrivilegeNames(JCR_LOCK_MANAGEMENT, JCR_WRITE); - assertEquals(expected, ImmutableSet.copyOf(result)); + assertEquals(expected, CollectionUtils.toSet(result)); } @Test @@ -474,7 +474,7 @@ public void testGetAggregatedPrivilegeNames() { when(privTree.getChild(KNOWN_PRIV_NAME)).thenReturn(pTree); Iterable result = bitsProvider.getAggregatedPrivilegeNames(KNOWN_PRIV_NAME); - assertEquals(expected, ImmutableSet.copyOf(result)); + assertEquals(expected, CollectionUtils.toSet(result)); } @Test @@ -486,7 +486,7 @@ public void testGetAggregatedPrivilegeNamesNested() { Iterable result = bitsProvider.getAggregatedPrivilegeNames(KNOWN_PRIV_NAME); Set expected = Set.of(REP_READ_NODES, REP_READ_PROPERTIES, JCR_ADD_CHILD_NODES); - assertEquals(expected, ImmutableSet.copyOf(result)); + assertEquals(expected, CollectionUtils.toSet(result)); } @Test @@ -497,10 +497,10 @@ public void testGetAggregatedPrivilegeNamesNestedWithCache() { when(privTree.getChild(KNOWN_PRIV_NAME)).thenReturn(pTree); Iterable result = bitsProvider.getAggregatedPrivilegeNames(KNOWN_PRIV_NAME); - Set expected = ImmutableSet.copyOf(Iterables.concat( + Set expected = CollectionUtils.toSet(Iterables.concat( Set.of(JCR_ADD_CHILD_NODES), bitsProvider.getAggregatedPrivilegeNames(JCR_READ))); - assertEquals(expected, ImmutableSet.copyOf(result)); + assertEquals(expected, CollectionUtils.toSet(result)); } } diff --git a/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentStoreServiceTest.java b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentStoreServiceTest.java index a4531c3b5c3..8a9b35faed1 100644 --- a/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentStoreServiceTest.java +++ b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/AzureSegmentStoreServiceTest.java @@ -16,9 +16,10 @@ */ package org.apache.jackrabbit.oak.segment.azure; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import com.microsoft.azure.storage.StorageException; -import com.microsoft.azure.storage.blob.*; +import com.microsoft.azure.storage.blob.SharedAccessBlobPermissions; +import com.microsoft.azure.storage.blob.SharedAccessBlobPolicy; +import com.microsoft.azure.storage.blob.CloudBlobContainer; import java.io.IOException; import java.net.URISyntaxException; import java.time.Duration; @@ -27,6 +28,7 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.Set; +import java.util.stream.Stream; import java.util.stream.StreamSupport; import org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzuriteDockerRule; @@ -243,7 +245,7 @@ private static Instant yesterday() { } private static Set concat(Set blobs, String element) { - return ImmutableSet.builder().addAll(blobs).add(element).build(); + return Stream.concat(blobs.stream(), Stream.of(element)).collect(toSet()); } private static Configuration getConfigurationWithSharedAccessSignature(String sasToken) { diff --git a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java index b537728fea3..c6533bdb1c0 100644 --- a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java +++ b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.composite; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.Blob; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; @@ -294,7 +293,7 @@ public boolean release(String checkpoint) { } private String getPartialCheckpointName(MountedNodeStore nodeStore, String globalCheckpoint, Map globalCheckpointProperties, boolean resolveByName) { - Set validCheckpointNames = ImmutableSet.copyOf(nodeStore.getNodeStore().checkpoints()); + Set validCheckpointNames = CollectionUtils.toSet(nodeStore.getNodeStore().checkpoints()); String result = globalCheckpointProperties.get(CHECKPOINT_METADATA_MOUNT + nodeStore.getMount().getName()); if (result != null && validCheckpointNames.contains(result)) { return result; diff --git a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositionContext.java b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositionContext.java index f8a99669b5c..2c68e1a1fd6 100644 --- a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositionContext.java +++ b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositionContext.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.composite; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.api.Blob; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.spi.mount.Mount; @@ -36,6 +35,7 @@ import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; import java.util.stream.StreamSupport; import static java.util.Collections.singletonList; @@ -67,10 +67,7 @@ class CompositionContext { this.prefetchNodeStore = globalStore instanceof PrefetchNodeStore ? (PrefetchNodeStore) globalStore : PrefetchNodeStore.NOOP; this.nonDefaultStores = nonDefaultStores; - ImmutableSet.Builder b = ImmutableSet.builder(); - b.add(this.globalStore); - b.addAll(this.nonDefaultStores); - allStores = b.build(); + allStores = Stream.concat(Stream.of(this.globalStore), this.nonDefaultStores.stream()).collect(Collectors.toUnmodifiableSet()); this.nodeStoresByMount = allStores.stream().collect(Collectors.toMap(MountedNodeStore::getMount, Function.identity())); this.nodeStateMonitor = nodeStateMonitor; diff --git a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/checks/NodeTypeMountedNodeStoreChecker.java b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/checks/NodeTypeMountedNodeStoreChecker.java index 0ee31a4a483..a7a8c040620 100644 --- a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/checks/NodeTypeMountedNodeStoreChecker.java +++ b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/checks/NodeTypeMountedNodeStoreChecker.java @@ -20,6 +20,7 @@ import java.util.Set; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.ComponentPropertyType; import org.osgi.service.component.annotations.ConfigurationPolicy; @@ -37,8 +38,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; - @Component(configurationPolicy = ConfigurationPolicy.REQUIRE, service = {MountedNodeStoreChecker.class}) public class NodeTypeMountedNodeStoreChecker implements MountedNodeStoreChecker { @@ -81,13 +80,13 @@ public NodeTypeMountedNodeStoreChecker() { public NodeTypeMountedNodeStoreChecker(String invalidNodeType, String errorLabel, String... excludedNodeTypes) { this.invalidNodeType = invalidNodeType; this.errorLabel = errorLabel; - this.excludedNodeTypes = ImmutableSet.copyOf(excludedNodeTypes); + this.excludedNodeTypes = CollectionUtils.toSet(excludedNodeTypes); } protected void activate(ComponentContext ctx) { invalidNodeType = requireNonNull(PropertiesUtil.toString(ctx.getProperties().get(INVALID_NODE_TYPE), null), INVALID_NODE_TYPE); errorLabel = requireNonNull(PropertiesUtil.toString(ctx.getProperties().get(ERROR_LABEL), null), ERROR_LABEL); - excludedNodeTypes = ImmutableSet.copyOf(PropertiesUtil.toStringArray(ctx.getProperties().get(EXCLUDED_NODE_TYPES), new String[0])); + excludedNodeTypes = CollectionUtils.toSet(PropertiesUtil.toStringArray(ctx.getProperties().get(EXCLUDED_NODE_TYPES), new String[0])); } @Override diff --git a/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/it/BackwardCompatibleMountCompositeIT.java b/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/it/BackwardCompatibleMountCompositeIT.java index 9d501f89bc9..86255e79eba 100644 --- a/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/it/BackwardCompatibleMountCompositeIT.java +++ b/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/it/BackwardCompatibleMountCompositeIT.java @@ -18,11 +18,12 @@ */ package org.apache.jackrabbit.oak.composite.it; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Set; import javax.inject.Inject; + +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.junit.Test; @@ -67,7 +68,7 @@ public void compositeNodeStoreCreatedFromDeprecatedConfiguration() { NodeState root = store.getRoot(); Set expectedNodes = Set.of("content", "apps", "libs"); - Set actualNodes = ImmutableSet.copyOf(root.getChildNodeNames()); + Set actualNodes = CollectionUtils.toSet(root.getChildNodeNames()); assertTrue("Expected nodes " + expectedNodes + ", but was " + actualNodes, actualNodes.containsAll(expectedNodes)); assertTrue("'libs' path should be mounted", root.getChildNode("libs").getChildNode("libsMount").exists()); diff --git a/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/it/MultiMountCompositeIT.java b/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/it/MultiMountCompositeIT.java index e2d65446e13..947ffff8121 100644 --- a/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/it/MultiMountCompositeIT.java +++ b/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/it/MultiMountCompositeIT.java @@ -18,11 +18,12 @@ */ package org.apache.jackrabbit.oak.composite.it; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Set; import javax.inject.Inject; + +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.junit.Test; @@ -64,7 +65,7 @@ public void compositeNodeStoreWithMultipleReadOnlyMounts() { NodeState root = store.getRoot(); Set expectedNodes = Set.of("content", "apps", "libs"); - Set actualNodes = ImmutableSet.copyOf(root.getChildNodeNames()); + Set actualNodes = CollectionUtils.toSet(root.getChildNodeNames()); assertTrue("Expected nodes " + expectedNodes + ", but was " + actualNodes, actualNodes.containsAll(expectedNodes)); assertTrue("'apps' mount should be mounted", root.getChildNode("apps").getChildNode("appsMount").exists()); diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java index c27cbbb389c..6695ab1fcba 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoStatus.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.plugins.document.mongo; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import com.mongodb.BasicDBObject; import com.mongodb.ClientSessionOptions; import com.mongodb.MongoClient; @@ -38,6 +37,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -45,10 +45,7 @@ public class MongoStatus implements ServerMonitorListener { private static final Logger LOG = LoggerFactory.getLogger(MongoStatus.class); - private static final ImmutableSet SERVER_DETAIL_FIELD_NAMES - = ImmutableSet.builder() - .add("host", "process", "connections", "repl", "storageEngine", "mem") - .build(); + private static final Set SERVER_DETAIL_FIELD_NAMES = Set.of("host", "process", "connections", "repl", "storageEngine", "mem"); private final MongoClient client; diff --git a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java index 60adf281898..83e8c2c85f5 100755 --- a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java +++ b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositorySidegrade.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Calendar; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -26,7 +27,6 @@ import javax.jcr.RepositoryException; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.api.CommitFailedException; @@ -69,7 +69,6 @@ import org.slf4j.LoggerFactory; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.ImmutableSet.copyOf; import static org.apache.jackrabbit.guava.common.collect.Sets.union; import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM; @@ -217,7 +216,7 @@ public void setCustomCommitHooks(List customCommitHooks) { * @param includes Paths to be included in the copy. */ public void setIncludes(@NotNull String... includes) { - this.includePaths = copyOf(requireNonNull(includes)); + this.includePaths = Set.of(requireNonNull(includes)); } /** @@ -227,7 +226,7 @@ public void setIncludes(@NotNull String... includes) { * @param excludes Paths to be excluded from the copy. */ public void setExcludes(@NotNull String... excludes) { - this.excludePaths = copyOf(requireNonNull(excludes)); + this.excludePaths = Set.of(requireNonNull(excludes)); } /** @@ -237,7 +236,7 @@ public void setExcludes(@NotNull String... excludes) { * @param merges Paths to be merged during copy. */ public void setMerges(@NotNull String... merges) { - this.mergePaths = copyOf(requireNonNull(merges)); + this.mergePaths = Set.of(requireNonNull(merges)); } public void setFilterLongNames(boolean filterLongNames) { @@ -465,17 +464,16 @@ private boolean isCompleteMigration() { private void copyWorkspace(NodeState sourceRoot, NodeBuilder targetRoot) { final Set includes = calculateEffectiveIncludePaths(includePaths, sourceRoot); - ImmutableSet.Builder excludes = new ImmutableSet.Builder<>(); - excludes.addAll(excludePaths); + final Set excludes = new HashSet<>(excludePaths); if (!versionCopyConfiguration.isCopyAll()) { excludes.add("/jcr:system/jcr:versionStorage"); } excludes.add("/:async"); - final Set merges = union(copyOf(this.mergePaths), Set.of("/jcr:system")); + final Set merges = union(Set.copyOf(this.mergePaths), Set.of("/jcr:system")); NodeStateCopier.builder() .include(includes) - .exclude(excludes.build()) + .exclude(Set.copyOf(excludes)) .merge(merges) .copy(sourceRoot, targetRoot); diff --git a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java index 2457bc7df8d..cf579d980b4 100644 --- a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java +++ b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java @@ -17,8 +17,6 @@ package org.apache.jackrabbit.oak.upgrade; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.ImmutableSet.copyOf; - import static org.apache.jackrabbit.guava.common.collect.Sets.union; import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM; import static org.apache.jackrabbit.oak.plugins.migration.FilteringNodeState.ALL; @@ -323,7 +321,7 @@ public void setCustomCommitHooks(List customCommitHooks) { * @param includes Paths to be included in the copy. */ public void setIncludes(@NotNull String... includes) { - this.includePaths = copyOf(requireNonNull(includes)); + this.includePaths = Set.of(requireNonNull(includes)); } /** @@ -333,7 +331,7 @@ public void setIncludes(@NotNull String... includes) { * @param excludes Paths to be excluded from the copy. */ public void setExcludes(@NotNull String... excludes) { - this.excludePaths = copyOf(requireNonNull(excludes)); + this.excludePaths = Set.of(requireNonNull(excludes)); } /** @@ -343,7 +341,7 @@ public void setExcludes(@NotNull String... excludes) { * @param merges Paths to be merged during copy. */ public void setMerges(@NotNull String... merges) { - this.mergePaths = copyOf(requireNonNull(merges)); + this.mergePaths = Set.of(requireNonNull(merges)); } /** @@ -941,8 +939,8 @@ private PropertyDefinitionTemplate createPropertyDefinitionTemplate(ValueFactory private String copyWorkspace(NodeState sourceRoot, NodeBuilder targetRoot, String workspaceName) throws RepositoryException { final Set includes = calculateEffectiveIncludePaths(includePaths, sourceRoot); - final Set excludes = union(copyOf(this.excludePaths), Set.of("/jcr:system/jcr:versionStorage")); - final Set merges = union(copyOf(this.mergePaths), Set.of("/jcr:system")); + final Set excludes = union(Set.copyOf(this.excludePaths), Set.of("/jcr:system/jcr:versionStorage")); + final Set merges = union(Set.copyOf(this.mergePaths), Set.of("/jcr:system")); logger.info("Copying workspace {} [i: {}, e: {}, m: {}]", workspaceName, includes, excludes, merges); @@ -961,7 +959,7 @@ private String copyWorkspace(NodeState sourceRoot, NodeBuilder targetRoot, Strin static Set calculateEffectiveIncludePaths(Set includePaths, NodeState sourceRoot) { if (!includePaths.contains("/")) { - return copyOf(includePaths); + return Set.copyOf(includePaths); } // include child nodes from source individually to avoid deleting other initialized content