Permissions { public static long getPermission(@Nullable String path, long defaultPermission) { long permission; if (NamespaceConstants.NAMESPACES_PATH.equals(path)) { permission = Permissions.NAMESPACE_MANAGEMENT; } else if (NodeTypeConstants.NODE_TYPES_PATH.equals(path)) { permission = Permissions.NODE_TYPE_DEFINITION_MANAGEMENT; } else if (VersionConstants.SYSTEM_PATHS.contains(path)) { permission = Permissions.VERSION_MANAGEMENT; } else if (PrivilegeConstants.PRIVILEGES_PATH.equals(path)) { permission = Permissions.PRIVILEGE_MANAGEMENT; } else { permission = defaultPermission; } return permission; } private  Permissions(); static Set<String> getNames(long permissions); static String getString(long permissions); static boolean isRepositoryPermission(long permission); static boolean isAggregate(long permission); static Iterable<Long> aggregates(final long permissions); static boolean includes(long permissions, long permissionsToTest); static boolean respectParentPermissions(long permissions); static long diff(long permissions, long otherPermissions); static long getPermissions(@NotNull String jcrActions,
                                      @NotNull TreeLocation location,
                                      boolean isAccessControlContent); static long getPermissions(@Nullable String permissionNames); static long getPermission(@Nullable String path, long defaultPermission); static final long NO_PERMISSION; static final long READ_NODE; static final long READ_PROPERTY; static final long ADD_PROPERTY; static final long MODIFY_PROPERTY; static final long REMOVE_PROPERTY; static final long ADD_NODE; static final long REMOVE_NODE; static final long READ_ACCESS_CONTROL; static final long MODIFY_ACCESS_CONTROL; static final long NODE_TYPE_MANAGEMENT; static final long VERSION_MANAGEMENT; static final long LOCK_MANAGEMENT; static final long LIFECYCLE_MANAGEMENT; static final long RETENTION_MANAGEMENT; static final long MODIFY_CHILD_NODE_COLLECTION; static final long NODE_TYPE_DEFINITION_MANAGEMENT; static final long NAMESPACE_MANAGEMENT; static final long WORKSPACE_MANAGEMENT; static final long PRIVILEGE_MANAGEMENT; static final long USER_MANAGEMENT; static final long INDEX_DEFINITION_MANAGEMENT; static final long READ; static final long REMOVE; static final long SET_PROPERTY; static final long WRITE; static final long ALL; static final Map<Long, String> PERMISSION_NAMES; }
@Test public void testGetPermissionsForReservedPaths() { Map<String, Long> mapping = ImmutableMap.of( NamespaceConstants.NAMESPACES_PATH, Permissions.NAMESPACE_MANAGEMENT, NodeTypeConstants.NODE_TYPES_PATH, Permissions.NODE_TYPE_DEFINITION_MANAGEMENT, PrivilegeConstants.PRIVILEGES_PATH, Permissions.PRIVILEGE_MANAGEMENT ); for (String path : mapping.keySet()) { for (long defaultPermission : Permissions.PERMISSION_NAMES.keySet()) { assertEquals(mapping.get(path).longValue(), Permissions.getPermission(path, defaultPermission)); } } }
@Test public void testGetPermissionsForVersionPaths() { for (String path : VersionConstants.SYSTEM_PATHS) { for (long defaultPermission : Permissions.PERMISSION_NAMES.keySet()) { assertEquals(Permissions.VERSION_MANAGEMENT, Permissions.getPermission(path, defaultPermission)); } } }
@Test public void testGetPermissionsForRegularPaths() { for (String path : ImmutableList.of("/", "/a/b/c", "/myfile/jcr:content")) { for (long defaultPermission : Permissions.PERMISSION_NAMES.keySet()) { assertEquals(defaultPermission, Permissions.getPermission(path, defaultPermission)); } } }