@Nonnull @Override public Principal perform() throws RepositoryException { return delegate.getPrincipal(); } });
private static String getAuthorizableEmail(Authorizable authorizable) throws RepositoryException { if (authorizable.hasProperty(PN_USER_EMAIL)) { Value[] emailVal = authorizable.getProperty(PN_USER_EMAIL); return emailVal[0].getString(); } return null; }
@Override public void afterSuite() throws Exception { UserManager userMgr = ((JackrabbitSession) session).getUserManager(); Authorizable authorizable = userMgr.getAuthorizable(USER); if (authorizable != null) { authorizable.remove(); } authorizable = userMgr.getAuthorizable(GROUP); if (authorizable != null) { Node n = session.getNode(Text.getRelativeParent(authorizable.getPath(), 1)); n.remove(); } session.save(); }
private Iterator<Group> getGroupParents(final ActionResult actionResult, final Authorizable authorizable) throws RepositoryException { String id = authorizable.getID(); actionResult.setAuthorizable(id); Iterator<Group> groups = authorizable.memberOf(); if (!groups.hasNext()) { actionResult.logWarning(MessagingUtils.groupIsMemberOfNoGroups(id)); } return groups; }
@Nonnull @Override public Value[] perform() throws RepositoryException { return delegate.getProperty(relPath); } });
@Nonnull @Override public Boolean perform() throws RepositoryException { return delegate.hasProperty(relPath); } });
@Nonnull @Override public Iterator<Group> perform() throws RepositoryException { Iterator<Group> groups = delegate.memberOf(); return Iterators.transform(groups, new Function<Group, Group>() { @Nullable @Override public Group apply(@Nullable Group group) { return GroupDelegator.wrap(sessionDelegate, group); } }); } });
@CheckForNull private User getUser(@Nonnull Tree tokenTree) throws RepositoryException { String userPath = Text.getRelativeParent(tokenTree.getPath(), 2); Authorizable authorizable = userManager.getAuthorizableByPath(userPath); if (authorizable != null && !authorizable.isGroup() && !((User) authorizable).isDisabled()) { return (User) authorizable; } else { return null; } }
public void testRemoveOtherUser() throws RepositoryException, NotExecutableException { // let superuser create another user. Principal p = getTestPrincipal(); String user2ID = userMgr.createUser(p.getName(), buildPassword(p), p, "/any/intermediate/path").getID(); save(superuser); try { Authorizable a = uMgr.getAuthorizable(user2ID); a.remove(); save(uSession); fail("A non-administrator user should not be allowed to remove another user."); } catch (AccessDeniedException e) { // success } // let superuser do clean up. Authorizable user2 = userMgr.getAuthorizable(user2ID); if (user2 != null) { user2.remove(); save(superuser); } }
@Test public void testGetGroupMembershipExternalGroup() throws Exception { Authorizable group = getUserManager(root).getAuthorizable("secondGroup"); assertNotNull(group); Set<? extends Principal> principals = principalProvider.getMembershipPrincipals(group.getPrincipal()); assertTrue(principals.isEmpty()); // same if the principal is not marked as 'GroupPrincipal' and not tree-based-principal principals = principalProvider.getMembershipPrincipals(new PrincipalImpl(group.getPrincipal().getName())); assertTrue(principals.isEmpty()); }
@Test public void testAdminUser() throws Exception { Authorizable a = userMgr.getAuthorizable(UserUtil.getAdminId(config)); assertFalse(a.isGroup()); User admin = (User) a; assertTrue(admin.isAdmin()); assertTrue(admin.getPrincipal() instanceof AdminPrincipal); assertTrue(admin.getPrincipal() instanceof TreeBasedPrincipal); assertEquals(admin.getID(), admin.getPrincipal().getName()); }
public boolean evaluate(Authorizable authorizable) { try { String name = authorizable.getID(); Principal principal = authorizable.getPrincipal(); return name.startsWith("a") || principal != null && principal.getName().startsWith("a"); } catch (RepositoryException e) { fail(e.getMessage()); } return false; } });
@Test public void testFindUserInAllGroups() throws RepositoryException, NotExecutableException { User u = null; try { Principal p = getTestPrincipal(); String uid = createUserId(); u = userMgr.createUser(uid, "pw", p, null); superuser.save(); Iterator<Authorizable> it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, null, UserManager.SEARCH_TYPE_GROUP); while (it.hasNext()) { if (it.next().getPrincipal().getName().equals(p.getName())) { fail("Searching for Groups should never find a user"); } } } finally { if (u != null) { u.remove(); superuser.save(); } } }
@Test public void testAdminImpersonation() throws Exception { final String adminPrincipalName = userMgr.getAuthorizable(superuser.getUserID()).getPrincipal().getName(); Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() { public <T> void build(QueryBuilder<T> builder) { builder.setCondition(builder.impersonates(adminPrincipalName)); } }); Iterator<Authorizable> expected = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, null, UserManager.SEARCH_TYPE_USER); assertTrue(result.hasNext()); assertSameElements(expected, result); }
public void testGetUserAfterCreation() throws RepositoryException, NotExecutableException { Principal p = getTestPrincipal(); String uid = p.getName(); User user = createUser(uid, "pw"); createdUsers.add(user); assertFalse(user.isSystemUser()); assertFalse(user.isGroup()); assertFalse(user.isAdmin()); Authorizable authorizable = userMgr.getAuthorizable(user.getID()); assertNotNull(authorizable); assertFalse(authorizable.isGroup()); assertFalse(((User) authorizable).isAdmin()); assertFalse(((User) authorizable).isSystemUser()); authorizable = userMgr.getAuthorizable(p); assertNotNull(authorizable); assertFalse(authorizable.isGroup()); assertFalse(((User) authorizable).isAdmin()); assertFalse(((User) authorizable).isSystemUser()); } }
@Test public void testFindAuthorizable() throws Exception { user = createUser(uid); Iterator<Authorizable> iterator = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, user.getPrincipal().getName()); assertTrue(iterator.hasNext()); Authorizable authorizable = iterator.next(); assertNotNull(authorizable); assertFalse(authorizable.isGroup()); assertTrue(((User) authorizable).isSystemUser()); assertFalse(iterator.hasNext()); }
protected void afterSuite() throws Exception { Node root = admin.getRootNode(); if (root.hasNode(ROOT_NODE_NAME)) { root.getNode(ROOT_NODE_NAME).remove(); } if (userManager != null) { userManager.getAuthorizable(TEST_USER_ID).remove(); } admin.save(); } }