Skip to content

Commit

Permalink
OAK-11311: Remove usage of Guava ImmutableList - oak-exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
reschke committed Dec 19, 2024
1 parent 1c5d4f1 commit 0083a8f
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.exercise.security.authorization.models.readonly;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy;
import org.apache.jackrabbit.commons.iterator.AccessControlPolicyIteratorAdapter;
import org.apache.jackrabbit.oak.api.PropertyState;
Expand Down Expand Up @@ -344,25 +343,25 @@ public RepositoryInitializer getRepositoryInitializer() {
@NotNull
@Override
public List<? extends CommitHook> getCommitHooks(@NotNull String workspaceName) {
return ImmutableList.of();
return List.of();
}

@NotNull
@Override
public List<? extends ValidatorProvider> getValidators(@NotNull String workspaceName, @NotNull Set<Principal> principals, @NotNull MoveTracker moveTracker) {
return ImmutableList.of();
return List.of();
}

@NotNull
@Override
public List<ThreeWayConflictHandler> getConflictHandlers() {
return ImmutableList.of();
return List.of();
}

@NotNull
@Override
public List<ProtectedItemImporter> getProtectedItemImporters() {
return ImmutableList.of();
return List.of();
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.jackrabbit.oak.exercise.security.authorization.models.simplifiedroles;

import java.util.List;

import javax.jcr.AccessDeniedException;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
Expand All @@ -27,7 +29,6 @@
import javax.jcr.security.Privilege;
import javax.jcr.version.VersionException;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.commons.iterator.AccessControlPolicyIteratorAdapter;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
Expand Down Expand Up @@ -86,7 +87,7 @@ public AccessControlPolicy[] getEffectivePolicies(String absPath) throws PathNot
@Override
public AccessControlPolicyIterator getApplicablePolicies(String absPath) throws PathNotFoundException, AccessDeniedException, RepositoryException {
// EXERCISE
return new AccessControlPolicyIteratorAdapter(ImmutableList.of());
return new AccessControlPolicyIteratorAdapter(List.of());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.exercise.security.authorization.models.simplifiedroles;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Tree;
Expand Down Expand Up @@ -168,7 +167,7 @@ public RepositoryInitializer getRepositoryInitializer() {
@NotNull
@Override
public List<? extends ValidatorProvider> getValidators(@NotNull String workspaceName, @NotNull Set<Principal> principals, @NotNull MoveTracker moveTracker) {
return ImmutableList.of(new ValidatorProvider() {
return List.of(new ValidatorProvider() {
@Override
protected Validator getRootValidator(NodeState before, NodeState after, CommitInfo info) {
// EXERCISE: write a validator that meets the following requirements:
Expand All @@ -188,7 +187,7 @@ protected Validator getRootValidator(NodeState before, NodeState after, CommitIn
@Override
public List<ProtectedItemImporter> getProtectedItemImporters() {
// EXERCISE
return ImmutableList.of();
return List.of();
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import javax.jcr.security.AccessControlPolicy;
import javax.jcr.security.Privilege;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.api.JackrabbitSession;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager;
Expand Down Expand Up @@ -270,7 +269,7 @@ public void testSessionGetEffectivePoliciesWithoutPrivilege() throws Exception {
testSession = getTestSession();
AccessControlManager testAcMgr = testSession.getAccessControlManager();

List<String> paths = ImmutableList.of(testRoot, NodeTypeConstants.NODE_TYPES_PATH);
List<String> paths = List.of(testRoot, NodeTypeConstants.NODE_TYPES_PATH);
for (String path : paths) {
// EXERCISE : complete or fix the test case
AccessControlPolicy[] effectivePolicies = testAcMgr.getEffectivePolicies(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.jackrabbit.oak.exercise.security.authorization.accesscontrol;

import java.security.Principal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.jcr.RepositoryException;
Expand All @@ -27,7 +28,6 @@
import javax.jcr.security.AccessControlManager;
import javax.jcr.security.Privilege;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.api.JackrabbitSession;
import org.apache.jackrabbit.api.JackrabbitWorkspace;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry;
Expand Down Expand Up @@ -186,15 +186,16 @@ public void testUpdateAndComplementary() throws Exception {

public void testAddEntryWithInvalidPrincipals() throws Exception {
// EXERCISE: explain for each principal in the list why using it for an ACE fails
List<Principal> invalidPrincipals = ImmutableList.of(
List<Principal> invalidPrincipals = Arrays.asList(
new InvalidTestPrincipal("unknown"),
null,
new PrincipalImpl(""), new Principal() {
@Override
public String getName() {
return "unknown";
}
});
new PrincipalImpl(""),
new Principal() {
@Override
public String getName() {
return "unknown";
}
});

for (Principal principal : invalidPrincipals) {
try {
Expand Down Expand Up @@ -227,7 +228,7 @@ public void testAddEntryWithInvalidPrivilege() throws Exception {
Privilege customPriv = ((JackrabbitWorkspace) superuser.getWorkspace()).getPrivilegeManager().registerPrivilege(privilegeName, true, new String[0]);

// EXERCISE : walks through this test and explain why adding those ACEs fails.
List<Privilege[]> invalidPrivileges = ImmutableList.of(
List<Privilege[]> invalidPrivileges = Arrays.asList(
new Privilege[0],
null,
new Privilege[] {customPriv}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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;
Expand Down Expand Up @@ -203,8 +202,7 @@ public void before() throws Exception {

root.commit();

trees = ImmutableList.<Tree>builder().add(root.getTree("/")).add(testTree).add(aTree).add(aaTree).add(bTree).add(bbTree).add(cTree).add(ccTree).build();

trees = List.of(root.getTree("/"), testTree, aTree, aaTree, bTree, bbTree, cTree, ccTree);
}

private PermissionProvider getPermissionProvider(@NotNull Set<Principal> principals) {
Expand Down Expand Up @@ -269,7 +267,7 @@ public void testGuestAccess() throws Exception {

@Test
public void testWriteAccess() throws Exception {
List<Set<Principal>> editors = ImmutableList.<Set<Principal>>of(
List<Set<Principal>> editors = List.of(
ImmutableSet.<Principal>of(new Editor("ida")),
ImmutableSet.<Principal>of(EveryonePrincipal.getInstance(), new Editor("amanda")),
ImmutableSet.<Principal>of(getTestUser().getPrincipal(),new Editor("susi")),
Expand Down Expand Up @@ -309,7 +307,7 @@ public void testWriteAccess() throws Exception {

@Test
public void testReadAccess() throws Exception {
List<Set<Principal>> readers = ImmutableList.<Set<Principal>>of(
List<Set<Principal>> readers = List.of(
ImmutableSet.<Principal>of(new Reader("ida")),
ImmutableSet.<Principal>of(EveryonePrincipal.getInstance(), new Reader("fairuz")),
ImmutableSet.<Principal>of(getTestUser().getPrincipal(),new Editor("juni")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
*/
package org.apache.jackrabbit.oak.exercise.security.privilege;

import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import javax.jcr.RepositoryException;
import javax.jcr.security.AccessControlManager;
import javax.jcr.security.AccessControlPolicy;
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;
Expand Down Expand Up @@ -135,7 +134,7 @@ public void testAggregation() throws RepositoryException {
);

Iterable<Privilege> aggregated = Iterables.<Privilege>filter(
ImmutableList.<Privilege>copyOf(privilegeManager.getRegisteredPrivileges()),
Arrays.asList(privilegeManager.getRegisteredPrivileges()),
input -> input != null && input.isAggregate());

for (Privilege aggrPrivilege : aggregated) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import javax.jcr.Node;
import javax.jcr.RepositoryException;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.api.JackrabbitSession;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
Expand Down Expand Up @@ -149,7 +148,7 @@ public void testUserNodeType() throws RepositoryException {
String expectedNodeTypeName = null; // EXERCISE
assertEquals(expectedNodeTypeName, node.getPrimaryNodeType().getName());

List<String> mixinTypes = ImmutableList.of(); // EXERCISE : fill the list
List<String> mixinTypes = List.of(); // EXERCISE : fill the list
for (String mixin : mixinTypes) {
assertTrue(node.isNodeType(mixin));
}
Expand All @@ -174,7 +173,7 @@ public void testGroupNodeType() throws RepositoryException {
String expectedNodeTypeName = null; // EXERCISE
assertEquals(expectedNodeTypeName, node.getPrimaryNodeType().getName());

List<String> mixinTypes = ImmutableList.of(); // EXERCISE : fill the list
List<String> mixinTypes = List.of(); // EXERCISE : fill the list
for (String mixin : mixinTypes) {
assertTrue(node.isNodeType(mixin));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import javax.jcr.RepositoryException;
import javax.jcr.Value;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.api.JackrabbitSession;
import org.apache.jackrabbit.api.security.user.Authorizable;
Expand Down Expand Up @@ -125,7 +124,7 @@ public void testArbitraryProperties() throws RepositoryException {
Node node = getAuthorizableNode(testUser);

// EXERCISE: build the list of existing user properties rel paths
List<String> userPropertiesPath = ImmutableList.of();
List<String> userPropertiesPath = List.of();
for (String relPath : userPropertiesPath) {
assertTrue(testUser.hasProperty(relPath));
}
Expand All @@ -139,13 +138,13 @@ public void testArbitraryProperties() throws RepositoryException {
assertArrayEquals(petsExpected, node.getProperty(expectedRelPath).getValues());

// EXERCISE: build a list of protected JCR properties that cannot be accessed using the Authorizable interface
List<String> protectedJcrPropertyNames = ImmutableList.of();
List<String> protectedJcrPropertyNames = List.of();
for (String relPath : protectedJcrPropertyNames) {
assertFalse(testUser.hasProperty(relPath));
}

// EXERCISE: build a list of protected properties defined by the authorizable or user node type definitions that cannot be accessed using the Authorizable interface
List<String> protectedAuthorizablePropertyNames = ImmutableList.of();
List<String> protectedAuthorizablePropertyNames = List.of();
for (String relPath : protectedAuthorizablePropertyNames) {
assertFalse(testUser.hasProperty(relPath));
}
Expand Down

0 comments on commit 0083a8f

Please sign in to comment.