private Tree getCache(@NotNull Authorizable authorizable) throws Exception { ContentSession cs = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() { @Override public ContentSession run() throws LoginException, NoSuchWorkspaceException { return login(null); } }); try { Root r = cs.getLatestRoot(); NodeUtil n = new NodeUtil(r.getTree(authorizable.getPath())); NodeUtil c = n.getOrAddChild(CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE); c.setLong(CacheConstants.REP_EXPIRATION, 1); r.commit(CacheValidatorProvider.asCommitAttributes()); } finally { cs.close(); } root.refresh(); return root.getTree(authorizable.getPath()).getChild(CacheConstants.REP_CACHE); }
@Test public void testChangeRegularRepUnstructuredPrimaryType() throws Exception { Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath()); NodeUtil n = new NodeUtil(userTree).getOrAddChild("test", NodeTypeConstants.NT_REP_UNSTRUCTURED); root.commit(); n.setName(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED); root.commit(); }
return getParent(); } else if (relativePath.indexOf('/') == -1) { return getOrAddChild(relativePath, primaryTypeName); } else { Tree t = TreeUtil.getTree(tree, relativePath);
@Test public void testNestedCache() throws Exception { NodeUtil cache = new NodeUtil(getCache(getTestUser())); try { NodeUtil c = cache.getOrAddChild(CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE); c.setLong(CacheConstants.REP_EXPIRATION, 223); root.commit(CacheValidatorProvider.asCommitAttributes()); fail("Creating nested cache must fail."); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); assertEquals(34, e.getCode()); } finally { root.refresh(); } }
@Test public void testGetTokenInfoFromInvalidLocation4() throws Exception { TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap()); Tree tokenTree = getTokenTree(info); assertNotNull(tokenProvider.getTokenInfo(info.getToken())); TokenInfo info2 = null; try { Tree adminTree = root.getTree(getUserManager(root).getAuthorizable(adminSession.getAuthInfo().getUserID()).getPath()); NodeUtil node = new NodeUtil(adminTree).getOrAddChild(TOKENS_NODE_NAME, JcrConstants.NT_UNSTRUCTURED); assertTrue(root.move(tokenTree.getPath(), node.getTree().getPath() + '/' + tokenTree.getName())); info2 = tokenProvider.getTokenInfo(info.getToken()); assertNotNull(info2); assertFalse(info2.matches(new TokenCredentials(info.getToken()))); } finally { root.refresh(); } }
@Test public void testCreateTokenAtInvalidLocationInsideUser2() throws Exception { TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap()); Tree tokenTree = getTokenTree(info); assertNotNull(tokenProvider.getTokenInfo(info.getToken())); Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath()); NodeUtil node = new NodeUtil(userTree).getOrAddChild(TOKENS_NODE_NAME, TOKENS_NT_NAME); try { node = node.addChild("invalid", JcrConstants.NT_UNSTRUCTURED); createTokenTree(info, node, TOKEN_NT_NAME); tokenTree.remove(); root.commit(CommitMarker.asCommitAttributes()); fail("Creating a new token '" + node.getTree().getPath() + "' must fail."); } catch (CommitFailedException e) { assertEquals(65, e.getCode()); } finally { node.getTree().remove(); root.commit(CommitMarker.asCommitAttributes()); } }
@Test public void testSingleTypeHistoryProperty() throws Exception { Tree userTree = root.getTree(getTestUser().getPath()); Tree pwdNode = new NodeUtil(userTree).getOrAddChild(REP_PWD, NT_REP_PASSWORD).getTree(); pwdNode.setProperty(REP_PWD_HISTORY, "singleValuedProperty"); assertFalse(pwdNode.getProperty(REP_PWD_HISTORY).isArray()); assertFalse(pwdNode.getProperty(REP_PWD_HISTORY).getType().isArray()); PasswordHistory history = new PasswordHistory(CONFIG); assertTrue(history.updatePasswordHistory(userTree, "anyOtherPassword")); assertTrue(pwdNode.getProperty(REP_PWD_HISTORY).isArray()); assertTrue(pwdNode.getProperty(REP_PWD_HISTORY).getType().isArray()); } }