@CheckForNull private static String getPrincipalName(@Nonnull Tree tree) { PropertyState principalName = tree.getProperty(UserConstants.REP_PRINCIPAL_NAME); if (principalName != null) { return principalName.getValue(STRING); } else { String msg = "Authorizable without principal name " + UserUtil.getAuthorizableId(tree); log.warn(msg); return null; } }
@Nullable private static String getPrincipalName(@NotNull Tree tree) { PropertyState principalName = tree.getProperty(UserConstants.REP_PRINCIPAL_NAME); if (principalName != null) { return principalName.getValue(STRING); } else { String msg = "Authorizable without principal name " + UserUtil.getAuthorizableId(tree); log.warn(msg); return null; } }
@Nullable private static String getPrincipalName(@NotNull Tree tree) { PropertyState principalName = tree.getProperty(UserConstants.REP_PRINCIPAL_NAME); if (principalName != null) { return principalName.getValue(STRING); } else { String msg = "Authorizable without principal name " + UserUtil.getAuthorizableId(tree); log.warn(msg); return null; } }
@Nullable public Authorizable getAuthorizable(@Nullable Tree tree) throws RepositoryException { if (tree == null || !tree.exists()) { return null; } return getAuthorizable(UserUtil.getAuthorizableId(tree), tree); }
@Nullable public Authorizable getAuthorizable(@Nullable Tree tree) throws RepositoryException { if (tree == null || !tree.exists()) { return null; } return getAuthorizable(UserUtil.getAuthorizableId(tree), tree); }
@Override public Authorizable getAuthorizable(String id) throws RepositoryException { Authorizable authorizable = null; Tree tree = (Strings.isNullOrEmpty(id)) ? null : userProvider.getAuthorizable(id); if (tree != null) { authorizable = getAuthorizable(UserUtil.getAuthorizableId(tree), tree); } return authorizable; }
@Override public Authorizable getAuthorizable(String id) throws RepositoryException { Authorizable authorizable = null; Tree tree = (Strings.isNullOrEmpty(id)) ? null : userProvider.getAuthorizable(id); if (tree != null) { authorizable = getAuthorizable(UserUtil.getAuthorizableId(tree), tree); } return authorizable; }
@Nullable private Principal createPrincipal(@Nullable Tree authorizableTree) { if (authorizableTree != null) { AuthorizableType type = UserUtil.getType(authorizableTree); if (AuthorizableType.GROUP == type) { return createGroupPrincipal(authorizableTree); } else if (AuthorizableType.USER == type) { return createUserPrincipal(UserUtil.getAuthorizableId(authorizableTree, type), authorizableTree); } } return null; }
@Nullable private Principal createPrincipal(@Nullable Tree authorizableTree) { if (authorizableTree != null) { AuthorizableType type = UserUtil.getType(authorizableTree); if (AuthorizableType.GROUP == type) { return createGroupPrincipal(authorizableTree); } else if (AuthorizableType.USER == type) { return createUserPrincipal(UserUtil.getAuthorizableId(authorizableTree, type), authorizableTree); } } return null; }
private boolean isAdminUser(@Nonnull Tree userTree) { if (userTree.exists() && isUser(userTree)) { String id = UserUtil.getAuthorizableId(userTree); return UserUtil.getAdminId(provider.getConfig()).equals(id); } else { return false; } }
private boolean isAdminUser(@NotNull Tree userTree) { if (userTree.exists() && isUser(userTree)) { String id = UserUtil.getAuthorizableId(userTree); return UserUtil.getAdminId(provider.getConfig()).equals(id); } else { return false; } }
private boolean isAdminUser(@NotNull Tree userTree) { if (userTree.exists() && isUser(userTree)) { String id = UserUtil.getAuthorizableId(userTree); return UserUtil.getAdminId(provider.getConfig()).equals(id); } else { return false; } }
@Test public void testGetAuthorizableIdWithTypeFallback() { Map<AuthorizableType, String[]> test = ImmutableMap.<AuthorizableType,String[]>builder(). put(AuthorizableType.USER, new String[]{UserConstants.NT_REP_USER, UserConstants.NT_REP_SYSTEM_USER}). put(AuthorizableType.AUTHORIZABLE, new String[]{UserConstants.NT_REP_USER, UserConstants.NT_REP_SYSTEM_USER, UserConstants.NT_REP_GROUP}). put(AuthorizableType.GROUP, new String[]{UserConstants.NT_REP_GROUP}).build(); for (AuthorizableType type : test.keySet()) { for (String ntName : test.get(type)) { assertEquals("nodeName", UserUtil.getAuthorizableId(createTree(ntName, null, "nodeName"), type)); } } }
@Test public void testGetAuthorizableIdWithType() { Map<AuthorizableType, String[]> test = ImmutableMap.<AuthorizableType,String[]>builder(). put(AuthorizableType.USER, new String[] {UserConstants.NT_REP_USER, UserConstants.NT_REP_SYSTEM_USER}). put(AuthorizableType.AUTHORIZABLE, new String[] {UserConstants.NT_REP_USER, UserConstants.NT_REP_SYSTEM_USER, UserConstants.NT_REP_GROUP}). put(AuthorizableType.GROUP, new String[] {UserConstants.NT_REP_GROUP}).build(); for (AuthorizableType type : test.keySet()) { for (String ntName : test.get(type)) { assertEquals("id", UserUtil.getAuthorizableId(createTree(ntName, "id"), type)); } } }
@Test(expected=IllegalArgumentException.class) public void testGetAuthorizableIdTypeNotUser() { UserUtil.getAuthorizableId(createTree(JcrConstants.NT_UNSTRUCTURED, "id"), AuthorizableType.USER); }
@Test public void testGetAuthorizableIdFallback() { List<String> test = ImmutableList.of(UserConstants.NT_REP_GROUP, UserConstants.NT_REP_SYSTEM_USER, UserConstants.NT_REP_USER); for (String ntName : test) { assertEquals("nName", UserUtil.getAuthorizableId(createTree(ntName, null, "nName"))); } }
@Test public void testGetAuthorizableIdNoAuthorizableType() { List<String> test = ImmutableList.of(UserConstants.NT_REP_AUTHORIZABLE, JcrConstants.NT_UNSTRUCTURED); for (String ntName : test) { assertNull(UserUtil.getAuthorizableId(createTree(ntName, "id"))); } }
@Test public void testGetAuthorizableId() { List<String> test = ImmutableList.of(UserConstants.NT_REP_GROUP, UserConstants.NT_REP_SYSTEM_USER, UserConstants.NT_REP_USER); for (String ntName : test) { assertEquals("id", UserUtil.getAuthorizableId(createTree(ntName, "id"))); } }
@Test public void testGetAuthorizableId() throws Exception { UserProvider up = createUserProvider(); String userID = "Amanda"; Tree user = up.createUser(userID, null); assertEquals(userID, UserUtil.getAuthorizableId(user)); String groupID = "visitors"; Tree group = up.createGroup(groupID, null); assertEquals(groupID, UserUtil.getAuthorizableId(group)); }
@Test public void testCreateUserRFC7613Disabled() throws Exception { String userHalfWidth = "Amalia"; String userFullWidth = "\uff21\uff4d\uff41\uff4c\uff49\uff41"; UserProvider userProvider = createUserProvider(); Tree userTreeHalfWidth = userProvider.createUser(userHalfWidth, null); Tree userTreeFullWidth = userProvider.createUser(userFullWidth, null); root.commit(); assertEquals(userHalfWidth, UserUtil.getAuthorizableId(userTreeHalfWidth)); assertEquals(userFullWidth, UserUtil.getAuthorizableId(userTreeFullWidth)); }