@Override public void propertyDeleted(PropertyState before) throws CommitFailedException { throw new CommitFailedException(type, code, message); }
@Override public void onConstraintViolation(String path, List<String> nodeTypeNames, int code, String message ) { String fullPath = path + '[' + nodeTypeNames.toString() + ']'; log.warn(new CommitFailedException(CONSTRAINT, code, fullPath + ": " + message).getMessage()); } };
/** * Wraps the given {@link CommitFailedException} instance using the * appropriate {@link javax.jcr.RepositoryException} subclass based on the * {@link CommitFailedException#getType() type} of the given exception. * * @return matching repository exception */ public RepositoryException asRepositoryException() { return asRepositoryException(this.getMessage()); }
@Test public void testInvalidPrivilege() throws Exception { NodeUtil acl = createAcl(); String privName = "invalidPrivilegeName"; createACE(acl, "invalid", NT_REP_GRANT_ACE, testPrincipal.getName(), privName); try { root.commit(); fail("Creating an ACE with invalid privilege should fail."); } catch (CommitFailedException e) { // success assertTrue(e.isAccessControlViolation()); assertThat(e.getMessage(), containsString("/testRoot/rep:policy")); } }
@Test public void testPropertyDeleted() throws Exception { try { PropertyState before = PropertyStates.createProperty(REP_AGGREGATES, ImmutableList.of(REP_READ_NODES, REP_READ_PROPERTIES), Type.NAMES); PrivilegeValidator validator = new PrivilegeValidator(root, root, getTreeProvider()); validator.propertyDeleted(before); fail("removing property from privilege store must fail."); } catch (CommitFailedException e) { // success assertTrue(e.isConstraintViolation()); assertEquals(46, e.getCode()); } }
@Test public void testMissingMixin() throws Exception { NodeUtil cug = node.addChild(REP_CUG_POLICY, NT_REP_CUG_POLICY); cug.setStrings(REP_PRINCIPAL_NAMES, EveryonePrincipal.NAME); try { root.commit(); fail(); } catch (CommitFailedException e) { assertTrue(e.isAccessControlViolation()); assertEquals(22, e.getCode()); } finally { root.refresh(); } }
private static void assertCyclicCommitFailed(RepositoryException e) { Throwable th = e.getCause(); if (th != null) { assertTrue(th instanceof CommitFailedException); assertEquals(31, ((CommitFailedException) th).getCode()); } }
@Override public String enableCopyOnWrite() { try { COWNodeStore.this.enableCopyOnWrite(); } catch (CommitFailedException e) { return "can't enable the copy on write: " + e.getMessage(); } return "success"; }
/** * Wraps the given {@link CommitFailedException} instance using the * appropriate {@link RepositoryException} subclass based on the * {@link CommitFailedException#getType() type} of the given exception. * * @param exception typed commit failure exception * @return matching repository exception */ private static RepositoryException newRepositoryException(CommitFailedException exception) { return exception.asRepositoryException(); }
private static void assertCyclicMembershipError(Exception e) { Throwable th = e.getCause(); if (th != null) { assertTrue(th instanceof CommitFailedException); CommitFailedException ce = (CommitFailedException) th; assertEquals(CommitFailedException.CONSTRAINT, ce.getType()); assertEquals(31, ce.getCode()); } }
@Test public void testWriteCug() throws Exception { ContentSession cs = createTestSession2(); Root r = cs.getLatestRoot(); try { // modify the existing cug Tree tree = r.getTree("/content/a/rep:cugPolicy"); tree.setProperty(REP_PRINCIPAL_NAMES, ImmutableList.of(EveryonePrincipal.NAME, testGroupPrincipal.getName()), Type.STRINGS); r.commit(); fail(); } catch (CommitFailedException e) { assertTrue(e.isAccessViolation()); } finally { r.refresh(); } }
@Test public void type() { ConflictException e = new ConflictException("conflict"); CommitFailedException cfe = e.asCommitFailedException(); assertEquals(CommitFailedException.MERGE, cfe.getType()); }
@Test public void testPolicyWithOutChildOrder() throws AccessDeniedException { NodeUtil testRoot = getTestRoot(); testRoot.setNames(JcrConstants.JCR_MIXINTYPES, MIX_REP_ACCESS_CONTROLLABLE); testRoot.addChild(REP_POLICY, NT_REP_ACL); try { root.commit(); fail("Policy node with child node ordering"); } catch (CommitFailedException e) { // success assertTrue(e.isAccessControlViolation()); assertThat(e.getMessage(), containsString("OakAccessControl0004")); // Order of children is not stable assertThat(e.getMessage(), containsString("/testRoot/rep:policy")); } }
@Test public void testPropertyChanged() throws Exception { try { PropertyState before = PropertyStates.createProperty(REP_AGGREGATES, ImmutableList.of(REP_READ_NODES, REP_READ_PROPERTIES), Type.NAMES); PropertyState after = PropertyStates.createProperty(REP_AGGREGATES, ImmutableList.of(REP_READ_NODES), Type.NAMES); PrivilegeValidator validator = new PrivilegeValidator(root, root, getTreeProvider()); validator.propertyChanged(before, after); fail("modifying property in privilege store must fail."); } catch (CommitFailedException e) { // success assertTrue(e.isConstraintViolation()); assertEquals(45, e.getCode()); } }
@Test public void testInvalidPrimaryType() throws Exception { NodeUtil cug = node.addChild(REP_CUG_POLICY, NodeTypeConstants.NT_OAK_UNSTRUCTURED); cug.setStrings(REP_PRINCIPAL_NAMES, EveryonePrincipal.NAME); try { root.commit(); fail(); } catch (CommitFailedException e) { assertTrue(e.isAccessControlViolation()); assertEquals(21, e.getCode()); } finally { root.refresh(); } }
@Test public void testManuallyModifyExpirationDate() throws Exception { TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap()); NodeUtil tokenTree = new NodeUtil(getTokenTree(info)); try { tokenTree.setDate(TOKEN_ATTRIBUTE_EXPIRY, new Date().getTime()); root.commit(); fail("The token expiry must not manually be changed"); } catch (CommitFailedException e) { assertEquals(63, e.getCode()); } }
@Override public String enableCopyOnWrite() { try { COWNodeStore.this.enableCopyOnWrite(); } catch (CommitFailedException e) { return "can't enable the copy on write: " + e.getMessage(); } return "success"; }
/** * Wraps the given {@link CommitFailedException} instance using the * appropriate {@link RepositoryException} subclass based on the * {@link CommitFailedException#getType() type} of the given exception. * * @param exception typed commit failure exception * @return matching repository exception */ private static RepositoryException newRepositoryException(CommitFailedException exception) { return exception.asRepositoryException(); }
@Test public void testWrite() throws Exception { List<String> readOnly = ImmutableList.of("/content", "/content/a/b/c"); for (String p : readOnly) { try { NodeUtil content = new NodeUtil(testRoot.getTree(p)); content.addChild("writeTest", NT_OAK_UNSTRUCTURED); testRoot.commit(); fail(); } catch (CommitFailedException e) { assertTrue(e.isAccessViolation()); } finally { testRoot.refresh(); } } }
@Test public void uniquePropertyCommit() throws Exception{ defnb.async("async", "nrt"); defnb.indexRule("nt:base").property("foo").propertyIndex().unique(); addIndex(indexPath, defnb); root.commit(); createPath("/a").setProperty("foo", "bar"); root.commit(); createPath("/b").setProperty("foo", "bar"); try { root.commit(); fail(); } catch (CommitFailedException e) { assertEquals(CONSTRAINT, e.getType()); } }