Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11317 : removed usage of ImmutableSet from guava #1914

Merged
merged 4 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -203,9 +205,7 @@ public Authorizable setAutoMembershipConfig(@NotNull AutoMembershipConfig autoMe
*/
@NotNull
public Set<String> getAutoMembership(@NotNull org.apache.jackrabbit.api.security.user.Authorizable authorizable) {
return ImmutableSet.<String>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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -220,7 +219,7 @@ private Map<Principal, Group> 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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 = ImmutableSet.copyOf(membership);
Set<String> userMembership = CollectionUtils.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 @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -326,7 +326,7 @@ public boolean isMember(@NotNull Group group, @NotNull Authorizable authorizable
return Collections.emptyIterator();
}

Set<Value> valueSet = ImmutableSet.copyOf(vs);
Set<Value> valueSet = CollectionUtils.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 @@ -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;
Expand Down Expand Up @@ -58,8 +58,8 @@ public class ProtectionConfigImpl implements ProtectionConfig {

@Activate
protected void activate(Map<String, Object> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> expected = ImmutableSet.<String>builder()
.addAll(globalGroupIds)
.addAll(configGroupIds).build();
Set<String> expected = new HashSet<>();
expected.addAll(globalGroupIds);
expected.addAll(configGroupIds);
assertEquals(expected, dscA.getAutoMembership(user));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,7 +116,7 @@ public void testGetPrincipalsMultipleGroups() throws Exception {
public void testGetPrincipalsMixed() throws Exception {
Collection<Principal> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
*/
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;
import org.apache.jackrabbit.api.security.user.User;
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;
Expand Down Expand Up @@ -107,14 +107,14 @@ private AutoMembershipProvider createAutoMembershipProvider(@NotNull Root root,
}

private static void assertMatchingEntries(@NotNull Iterator<Authorizable> it, @NotNull String... expectedIds) {
Set<String> ids = ImmutableSet.copyOf(Iterators.transform(it, authorizable -> {
Set<String> 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
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 = ImmutableSet.copyOf(provider.getMembership(getTestUser(), false));
Set<Group> groups = CollectionUtils.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 = ImmutableSet.copyOf(provider.getMembership(getTestUser(), true));
Set<Group> groups = CollectionUtils.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 = ImmutableSet.copyOf(provider.getMembership(getTestUser(), false));
Set<Group> 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));
Expand All @@ -421,12 +421,12 @@ public void testGetMembershipExternalUserEveryoneGroupExists() throws Exception
automembershipGroup2.addMember(automembershipGroup1);
root.commit();

Set<Group> groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), false));
Set<Group> 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));
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 = ImmutableSet.copyOf(amp.getMembership(getTestUser(), true));
Set<Group> membership = CollectionUtils.toSet(amp.getMembership(getTestUser(), true));
assertEquals(2, membership.size());
}

Expand Down
Loading
Loading