UserUtil implements UserConstants { @Nullable public static String getAuthorizableRootPath(@NotNull ConfigurationParameters parameters, @Nullable AuthorizableType type) { String path = null; if (type != null) { switch (type) { case USER: path = parameters.getConfigValue(UserConstants.PARAM_USER_PATH, UserConstants.DEFAULT_USER_PATH); break; case GROUP: path = parameters.getConfigValue(UserConstants.PARAM_GROUP_PATH, UserConstants.DEFAULT_GROUP_PATH); break; default: path = parameters.getConfigValue(UserConstants.PARAM_USER_PATH, UserConstants.DEFAULT_USER_PATH); String groupRoot = parameters.getConfigValue(UserConstants.PARAM_GROUP_PATH, UserConstants.DEFAULT_GROUP_PATH); while (!Text.isDescendantOrEqual(path, groupRoot)) { path = Text.getRelativeParent(path, 1); } } } return path; } private  UserUtil(); static boolean isAdmin(@NotNull ConfigurationParameters parameters, @NotNull String userId); @NotNull static String getAdminId(@NotNull ConfigurationParameters parameters); @NotNull static String getAnonymousId(@NotNull ConfigurationParameters parameters); static boolean isType(@Nullable Tree authorizableTree, @NotNull AuthorizableType type); @Nullable static AuthorizableType getType(@NotNull Tree authorizableNode); @Nullable static AuthorizableType getType(@Nullable String primaryTypeName); static boolean isSystemUser(@Nullable Tree authorizableTree); @Nullable static String getAuthorizableRootPath(@NotNull ConfigurationParameters parameters,
                                                 @Nullable AuthorizableType type); @Nullable static String getAuthorizableId(@NotNull Tree authorizableTree); @NotNull static String getAuthorizableId(@NotNull Tree authorizableTree, @NotNull AuthorizableType type); @Nullable static T castAuthorizable(@Nullable Authorizable authorizable, Class<T> authorizableClass); static int getImportBehavior(@NotNull ConfigurationParameters config);  }
@Test public void testGetAuthorizableRootPathDefault() { assertEquals(UserConstants.DEFAULT_GROUP_PATH, UserUtil.getAuthorizableRootPath(ConfigurationParameters.EMPTY, AuthorizableType.GROUP)); assertEquals(UserConstants.DEFAULT_USER_PATH, UserUtil.getAuthorizableRootPath(ConfigurationParameters.EMPTY, AuthorizableType.USER)); assertEquals("/rep:security/rep:authorizables", UserUtil.getAuthorizableRootPath(ConfigurationParameters.EMPTY, AuthorizableType.AUTHORIZABLE)); }
@Test public void testGetAuthorizableRootPath() { ConfigurationParameters config = ConfigurationParameters.of( UserConstants.PARAM_GROUP_PATH, "/groups", UserConstants.PARAM_USER_PATH, "/users"); assertEquals("/groups", UserUtil.getAuthorizableRootPath(config, AuthorizableType.GROUP)); assertEquals("/users", UserUtil.getAuthorizableRootPath(config, AuthorizableType.USER)); assertEquals("/", UserUtil.getAuthorizableRootPath(config, AuthorizableType.AUTHORIZABLE)); }
@Test public void testGetAuthorizableRootPathNullType() { assertNull(UserUtil.getAuthorizableRootPath(ConfigurationParameters.EMPTY, null)); }