@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; }
@Test public void testImportGroup() throws Exception { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"g\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + " <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Group</sv:value></sv:property>" + " <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>b2f5ff47-4366-31b6-a533-d8dc3614845d</sv:value></sv:property>" + " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>g</sv:value></sv:property>" + "</sv:node>"; Node target = getTargetNode(); doImport(getTargetPath(), xml); assertTrue(target.isModified()); Session s = getImportSession(); assertTrue(s.hasPendingChanges()); Authorizable newGroup = getUserManager().getAuthorizable("g"); assertNotNull(newGroup); assertTrue(newGroup.isGroup()); assertEquals("g", newGroup.getPrincipal().getName()); assertEquals("g", newGroup.getID()); Node n = s.getNode(newGroup.getPath()); assertTrue(n.isNew()); assertTrue(n.getParent().isSame(target)); assertEquals("g", n.getName()); assertEquals("g", n.getProperty(UserConstants.REP_PRINCIPAL_NAME).getString()); // saving changes of the import -> must succeed. add mandatory // props should have been created. s.save(); }
@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; } }
@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()); }
@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 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; } });
public void testCreateUser() throws NotExecutableException { try { Principal p = getTestPrincipal(); User u = uMgr.createUser(p.getName(), buildPassword(p)); save(uSession); fail("A non-UserAdmin should not be allowed to create a new User."); // clean-up: let superuser remove the user created by fault. userMgr.getAuthorizable(u.getID()).remove(); } catch (AuthorizableExistsException e) { // should never get here. fail(e.getMessage()); } catch (RepositoryException e) { // success } }
@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(); } }