PermissionUtil implements PermissionConstants { public static boolean isAdminOrSystem(@NotNull Set<Principal> principals, @NotNull ConfigurationParameters config) { if (principals.contains(SystemPrincipal.INSTANCE)) { return true; } else { Set<String> adminNames = config.getConfigValue(PARAM_ADMINISTRATIVE_PRINCIPALS, Collections.EMPTY_SET); for (Principal principal : principals) { if (principal instanceof AdminPrincipal || adminNames.contains(principal.getName())) { return true; } } return false; } } private  PermissionUtil(); @Nullable static String getParentPathOrNull(@NotNull final String path); @NotNull static String getEntryName(@Nullable String accessControlledPath); static boolean checkACLPath(@NotNull NodeBuilder node, @NotNull String path); static boolean checkACLPath(@NotNull Tree node, @NotNull String path); @NotNull static Tree getPermissionsRoot(@NotNull Root root, @NotNull String permissionRootName); @NotNull static Tree getPrincipalRoot(@NotNull Tree permissionsTree, @NotNull String principalName); static boolean isAdminOrSystem(@NotNull Set<Principal> principals, @NotNull ConfigurationParameters config); @Nullable static String getPath(@Nullable Tree parentBefore, @Nullable Tree parentAfter); @Nullable static Tree getReadOnlyTreeOrNull(@Nullable Tree tree, @NotNull Root readOnlyRoot); @NotNull static Tree getReadOnlyTree(@NotNull Tree tree, @NotNull Root readOnlyRoot);  }
@Test public void testIsAdminOrSystem() { ConfigurationParameters params = ConfigurationParameters.of(PARAM_ADMINISTRATIVE_PRINCIPALS, ImmutableSet.of("administrative")); Set<Principal> principals = ImmutableSet.of(new PrincipalImpl("name"), new PrincipalImpl("administrative")); assertTrue(PermissionUtil.isAdminOrSystem(principals, params)); assertFalse(PermissionUtil.isAdminOrSystem(principals, ConfigurationParameters.EMPTY)); }
@Test public void testIsAdminOrSystemForAdminPrincipal() { assertTrue(PermissionUtil.isAdminOrSystem(ImmutableSet.of(mock(AdminPrincipal.class)), ConfigurationParameters.EMPTY)); assertTrue(PermissionUtil.isAdminOrSystem(ImmutableSet.of(new PrincipalImpl("name"), mock(AdminPrincipal.class)), ConfigurationParameters.EMPTY)); }
@Test public void testIsAdminOrSystemForSystemPrincial() { assertTrue(PermissionUtil.isAdminOrSystem(ImmutableSet.of(SystemPrincipal.INSTANCE), ConfigurationParameters.EMPTY)); assertTrue(PermissionUtil.isAdminOrSystem(ImmutableSet.of(new PrincipalImpl("name"), SystemPrincipal.INSTANCE), ConfigurationParameters.EMPTY)); }