Skip to content

Commit

Permalink
OAK-11395 : extracted out Set methods from CollectionUtils (#1988)
Browse files Browse the repository at this point in the history
Co-authored-by: Rishabh Kumar <diam@adobe.com>
  • Loading branch information
rishabhdaim and Rishabh Kumar authored Jan 15, 2025
1 parent 1b38cfa commit 6f235a0
Show file tree
Hide file tree
Showing 198 changed files with 1,418 additions and 1,268 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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.collections.SetUtils;
import org.apache.jackrabbit.oak.plugins.tree.RootProvider;
import org.apache.jackrabbit.oak.plugins.tree.TreeProvider;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
Expand Down Expand Up @@ -111,8 +111,8 @@ public void propertyAdded(PropertyState after) throws CommitFailedException {
@Override
public void propertyChanged(PropertyState before, PropertyState after) throws CommitFailedException {
if (isDynamicGroup && isMemberProperty(before)) {
Set<String> refsBefore = CollectionUtils.toSet(before.getValue(Type.STRINGS));
Set<String> refsAfter = CollectionUtils.toSet(after.getValue(Type.STRINGS));
Set<String> refsBefore = SetUtils.toSet(before.getValue(Type.STRINGS));
Set<String> refsAfter = SetUtils.toSet(after.getValue(Type.STRINGS));
refsAfter.removeAll(refsBefore);
if (!refsAfter.isEmpty()) {
throw commitFailedException(getParentBefore());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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.commons.collections.SetUtils;
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;
Expand Down Expand Up @@ -199,7 +199,7 @@ private Map<String, Set<String>> getAutomembership(boolean memberIsGroup) {

private static void updateAutoMembershipMap(@NotNull Map<String, Set<String>> map, @NotNull String syncHandlerName,
@NotNull String idpName, @NotNull String[] membership) {
Set<String> userMembership = CollectionUtils.toSet(membership);
Set<String> userMembership = SetUtils.toSet(membership);
Set<String> previous = map.put(idpName, userMembership);
if (previous != null) {
String msg = previous.equals(userMembership) ? "Duplicate" : "Colliding";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +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.commons.collections.SetUtils;
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;
Expand Down Expand Up @@ -326,7 +326,7 @@ public boolean isMember(@NotNull Group group, @NotNull Authorizable authorizable
return Collections.emptyIterator();
}

Set<Value> valueSet = CollectionUtils.toSet(vs);
Set<Value> valueSet = SetUtils.toSet(vs);
Iterator<Group> declared = Iterators.filter(Iterators.transform(valueSet.iterator(), value -> {
try {
String groupPrincipalName = value.getString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ProtectionConfig;
import org.jetbrains.annotations.NotNull;
import org.osgi.service.component.annotations.Activate;
Expand Down Expand Up @@ -58,8 +58,8 @@ public class ProtectionConfigImpl implements ProtectionConfig {

@Activate
protected void activate(Map<String, Object> properties) {
propertyNames = CollectionUtils.toSet(PropertiesUtil.toStringArray(properties.get("propertyNames"), new String[0]));
nodeNames = CollectionUtils.toSet(PropertiesUtil.toStringArray(properties.get("nodeNames"), new String[0]));
propertyNames = SetUtils.toSet(PropertiesUtil.toStringArray(properties.get("propertyNames"), new String[0]));
nodeNames = SetUtils.toSet(PropertiesUtil.toStringArray(properties.get("nodeNames"), new String[0]));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
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.SetUtils;
import org.apache.jackrabbit.oak.commons.jdkcompat.Java23Subject;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
import org.apache.jackrabbit.oak.spi.security.authentication.SystemSubject;
import org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncConfig;
Expand Down Expand Up @@ -86,7 +86,7 @@ public void before() throws Exception {
super.before();

getTestUser();
ids = CollectionUtils.toSet(getAllAuthorizableIds(getUserManager(root)));
ids = SetUtils.toSet(getAllAuthorizableIds(getUserManager(root)));

idp = createIDP();
syncConfig = createSyncConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
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.ExternalLoginTestBase;
Expand Down Expand Up @@ -244,7 +244,7 @@ public void testListIdentitiesAfterSync() throws Exception {
sync(USER_ID, false);

// membership-nesting is 1 => expect only 'USER_ID' plus the declared group-membership
Set<String> expected = CollectionUtils.toSet(USER_ID);
Set<String> expected = SetUtils.toSet(USER_ID);
for (ExternalIdentityRef extRef : idp.getUser(USER_ID).getDeclaredGroups()) {
expected.add(extRef.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.plugins.tree.TreeUtil;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity;
Expand Down Expand Up @@ -244,7 +244,7 @@ public void testSyncExternalUserDepth1() throws Exception {
PropertyState extPrincipalNames = tree.getProperty(REP_EXTERNAL_PRINCIPAL_NAMES);
assertNotNull(extPrincipalNames);

Set<String> pNames = CollectionUtils.toSet(extPrincipalNames.getValue(Type.STRINGS));
Set<String> pNames = SetUtils.toSet(extPrincipalNames.getValue(Type.STRINGS));
for (ExternalIdentityRef ref : externalUser.getDeclaredGroups()) {
assertTrue(pNames.remove(idp.getIdentity(ref).getPrincipalName()));
}
Expand All @@ -262,7 +262,7 @@ public void testSyncExternalUserDepthInfinite() throws Exception {
PropertyState extPrincipalNames = tree.getProperty(REP_EXTERNAL_PRINCIPAL_NAMES);
assertNotNull(extPrincipalNames);

Set<String> pNames = CollectionUtils.toSet(extPrincipalNames.getValue(Type.STRINGS));
Set<String> pNames = SetUtils.toSet(extPrincipalNames.getValue(Type.STRINGS));
Set<String> expected = new HashSet<>();
collectGroupPrincipals(expected, externalUser.getDeclaredGroups(), Long.MAX_VALUE);

Expand Down Expand Up @@ -352,7 +352,7 @@ private void assertIgnored(@NotNull ExternalUser externalUser, @NotNull External
assertNotNull(extPrincipalNames);

// the resulting rep:externalPrincipalNames must NOT contain the name of the colliding principal
Set<String> pNames = CollectionUtils.toSet(extPrincipalNames.getValue(Type.STRINGS));
Set<String> pNames = SetUtils.toSet(extPrincipalNames.getValue(Type.STRINGS));
assertFalse(pNames + " must not contain " + externalGroup.getPrincipalName(), pNames.contains(externalGroup.getPrincipalName()));
}

Expand All @@ -375,7 +375,7 @@ public void testSyncExternalUserGroupConflictWithUser() throws Exception {
assertNotNull(extPrincipalNames);

// the resulting rep:externalPrincipalNames must NOT contain the name of the colliding principal
Set<String> pNames = CollectionUtils.toSet(extPrincipalNames.getValue(Type.STRINGS));
Set<String> pNames = SetUtils.toSet(extPrincipalNames.getValue(Type.STRINGS));
assertFalse(pNames + " must not contain " + externalGroup.getPrincipalName(), pNames.contains(externalGroup.getPrincipalName()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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.commons.collections.SetUtils;
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.ExternalIdentityProvider;
Expand Down Expand Up @@ -117,7 +117,7 @@ private void assertSynched(@NotNull ExternalUser externalUser, @NotNull External
assertNotNull(extPrincipalNames);

// the resulting rep:externalPrincipalNames must contain the name of the principal
Set<String> pNames = CollectionUtils.toSet(extPrincipalNames.getValue(Type.STRINGS));
Set<String> pNames = SetUtils.toSet(extPrincipalNames.getValue(Type.STRINGS));
assertTrue(pNames + " must contain " + externalGroup.getPrincipalName(), pNames.contains(externalGroup.getPrincipalName()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.spi.security.authentication.external.basic.AutoMembershipConfig;
import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -97,7 +97,7 @@ public void testGetPrincipalsMultipleGroups() throws Exception {

Collection<Principal> principals = getAutoMembership(IDP_VALID_AM, authorizable, false);
assertFalse(principals.isEmpty());
Set<Principal> expected = CollectionUtils.toSet(automembershipGroup1.getPrincipal(), automembershipGroup2.getPrincipal());
Set<Principal> expected = SetUtils.toSet(automembershipGroup1.getPrincipal(), automembershipGroup2.getPrincipal());
assertEquals(expected, principals);

// change behavior of automembership-config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +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.commons.collections.SetUtils;
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;
Expand Down Expand Up @@ -107,7 +107,7 @@ private AutoMembershipProvider createAutoMembershipProvider(@NotNull Root root,
}

private static void assertMatchingEntries(@NotNull Iterator<Authorizable> it, @NotNull String... expectedIds) {
Set<String> ids = CollectionUtils.toSet(Iterators.transform(it, authorizable -> {
Set<String> ids = SetUtils.toSet(Iterators.transform(it, authorizable -> {
try {
return authorizable.getID();
} catch (RepositoryException repositoryException) {
Expand Down Expand Up @@ -378,7 +378,7 @@ public void testGetMembershipSelf() throws Exception {
public void testGetMembershipExternalUser() throws Exception {
setExternalId(getTestUser().getID(), IDP_VALID_AM);

Set<Group> groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), false));
Set<Group> groups = SetUtils.toSet(provider.getMembership(getTestUser(), false));
assertEquals(2, groups.size());
assertTrue(groups.contains(automembershipGroup1));
assertTrue(groups.contains(automembershipGroup2));
Expand All @@ -388,7 +388,7 @@ public void testGetMembershipExternalUser() throws Exception {
public void testGetMembershipExternalUserInherited() throws Exception {
setExternalId(getTestUser().getID(), IDP_VALID_AM);

Set<Group> groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), true));
Set<Group> groups = SetUtils.toSet(provider.getMembership(getTestUser(), true));
assertEquals(2, groups.size());
assertTrue(groups.contains(automembershipGroup1));
}
Expand All @@ -399,12 +399,12 @@ public void testGetMembershipExternalUserNestedGroups() throws Exception {

Group baseGroup = getTestGroup(automembershipGroup1);

Set<Group> groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), false));
Set<Group> groups = SetUtils.toSet(provider.getMembership(getTestUser(), false));
assertEquals(2, groups.size());
assertTrue(groups.contains(automembershipGroup1));
assertTrue(groups.contains(automembershipGroup2));

groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), true));
groups = SetUtils.toSet(provider.getMembership(getTestUser(), true));
assertEquals(3, groups.size());
assertTrue(groups.contains(automembershipGroup1));
assertTrue(groups.contains(automembershipGroup2));
Expand All @@ -421,12 +421,12 @@ public void testGetMembershipExternalUserEveryoneGroupExists() throws Exception
automembershipGroup2.addMember(automembershipGroup1);
root.commit();

Set<Group> groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), false));
Set<Group> groups = SetUtils.toSet(provider.getMembership(getTestUser(), false));
assertEquals(2, groups.size());
assertTrue(groups.contains(automembershipGroup1));
assertTrue(groups.contains(automembershipGroup2));

groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), true));
groups = SetUtils.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));
Expand Down Expand Up @@ -512,7 +512,7 @@ public void testGetMembershipAutogroupGroupMemberOfFails() throws Exception {
setExternalId(getTestUser().getID(), IDP_VALID_AM);

AutoMembershipProvider amp = createAutoMembershipProvider(root, um);
Set<Group> membership = CollectionUtils.toSet(amp.getMembership(getTestUser(), true));
Set<Group> membership = SetUtils.toSet(amp.getMembership(getTestUser(), true));
assertEquals(2, membership.size());
}

Expand Down
Loading

0 comments on commit 6f235a0

Please sign in to comment.