Permissions { public static String getString(long permissions) { if (PERMISSION_NAMES.containsKey(permissions)) { return PERMISSION_NAMES.get(permissions); } else { StringBuilder sb = new StringBuilder(); for (Map.Entry<Long, String> entry : PERMISSION_NAMES.entrySet()) { long key = entry.getKey(); if ((permissions & key) == key) { if (sb.length() != 0) { sb.append(','); } sb.append(entry.getValue()); } } return sb.toString(); } } 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 testGetStringAllPermission() { String str = Permissions.getString(Permissions.ALL); assertEquals(Permissions.PERMISSION_NAMES.get(Permissions.ALL), str); }
@Test public void testGetStringNoPermission() { String str = Permissions.getString(Permissions.NO_PERMISSION); assertTrue(str.isEmpty()); }
@Test public void testGetStringMultiple() { for (long permissions : TEST.keySet()) { Set<String> expected = new HashSet<>(); for (long p : TEST.get(permissions)) { expected.add(Permissions.PERMISSION_NAMES.get(p)); } assertEquals(expected, Sets.newHashSet(Splitter.on(',').split(Permissions.getString(permissions)))); } }
@Test public void testGetStringAggregates() { Map<Long, Set<Long>> test = ImmutableMap.<Long, Set<Long>>of( Permissions.READ|Permissions.READ_ACCESS_CONTROL, ImmutableSet.of(Permissions.READ, Permissions.READ_NODE, Permissions.READ_PROPERTY, Permissions.READ_ACCESS_CONTROL), Permissions.REMOVE|Permissions.SET_PROPERTY, ImmutableSet.of(Permissions.REMOVE_NODE, Permissions.ADD_PROPERTY, Permissions.MODIFY_PROPERTY, Permissions.REMOVE_PROPERTY, Permissions.SET_PROPERTY, Permissions.REMOVE), Permissions.WRITE|Permissions.SET_PROPERTY, ImmutableSet.of(Permissions.WRITE), Permissions.WRITE|Permissions.VERSION_MANAGEMENT, ImmutableSet.of(Permissions.WRITE, Permissions.VERSION_MANAGEMENT, Permissions.REMOVE_NODE, Permissions.ADD_PROPERTY, Permissions.MODIFY_PROPERTY, Permissions.ADD_NODE, Permissions.REMOVE_PROPERTY, Permissions.SET_PROPERTY, Permissions.REMOVE) ); for (long permissions : test.keySet()) { Set<String> expected = new HashSet<>(); for (long p : test.get(permissions)) { expected.add(Permissions.PERMISSION_NAMES.get(p)); } assertEquals(expected, Sets.newHashSet(Splitter.on(',').split(Permissions.getString(permissions)))); } }