@Nonnull private PrivilegeBits getPrivilegeBits(@Nullable Tree tree) { EntryPredicate pred = (tree == null) ? new EntryPredicate() : new EntryPredicate(tree, null, false); Iterator<PermissionEntry> entries = getEntryIterator(pred); PrivilegeBits allowBits = PrivilegeBits.getInstance(); PrivilegeBits denyBits = PrivilegeBits.getInstance(); while (entries.hasNext()) { PermissionEntry entry = entries.next(); if (entry.isAllow) { allowBits.addDifference(entry.privilegeBits, denyBits); } else { denyBits.addDifference(entry.privilegeBits, allowBits); } } // special handling for paths that are always readable if (tree != null && readPolicy.isReadableTree(tree, false)) { allowBits.add(bitsProvider.getBits(PrivilegeConstants.JCR_READ)); } return allowBits; }
@NotNull private PrivilegeBits getPrivilegeBits(@Nullable Tree tree) { EntryPredicate pred = (tree == null) ? new EntryPredicate() : new EntryPredicate(tree, null, false); Iterator<PermissionEntry> entries = getEntryIterator(pred); PrivilegeBits allowBits = PrivilegeBits.getInstance(); PrivilegeBits denyBits = PrivilegeBits.getInstance(); while (entries.hasNext()) { PermissionEntry entry = entries.next(); if (entry.isAllow) { allowBits.addDifference(entry.privilegeBits, denyBits); } else { denyBits.addDifference(entry.privilegeBits, allowBits); } } // special handling for paths that are always readable if (tree != null && readPolicy.isReadableTree(tree, false)) { allowBits.add(bitsProvider.getBits(PrivilegeConstants.JCR_READ)); } return allowBits; }
@NotNull private PrivilegeBits getPrivilegeBits(@Nullable Tree tree) { EntryPredicate pred = (tree == null) ? new EntryPredicate() : new EntryPredicate(tree, null, false); Iterator<PermissionEntry> entries = getEntryIterator(pred); PrivilegeBits allowBits = PrivilegeBits.getInstance(); PrivilegeBits denyBits = PrivilegeBits.getInstance(); while (entries.hasNext()) { PermissionEntry entry = entries.next(); if (entry.isAllow) { allowBits.addDifference(entry.privilegeBits, denyBits); } else { denyBits.addDifference(entry.privilegeBits, allowBits); } } // special handling for paths that are always readable if (tree != null && readPolicy.isReadableTree(tree, false)) { allowBits.add(bitsProvider.getBits(PrivilegeConstants.JCR_READ)); } return allowBits; }
if (matchesParent) { if (entry.isAllow) { parentAllowBits.addDifference(entry.privilegeBits, parentDenyBits); } else { parentDenyBits.addDifference(entry.privilegeBits, parentAllowBits); allowBits.addDifference(entry.privilegeBits, denyBits); denyBits.addDifference(entry.privilegeBits, allowBits);
if (matchesParent) { if (entry.isAllow) { parentAllowBits.addDifference(entry.privilegeBits, parentDenyBits); } else { parentDenyBits.addDifference(entry.privilegeBits, parentAllowBits); allowBits.addDifference(entry.privilegeBits, denyBits); denyBits.addDifference(entry.privilegeBits, allowBits);
if (matchesParent) { if (entry.isAllow) { parentAllowBits.addDifference(entry.privilegeBits, parentDenyBits); } else { parentDenyBits.addDifference(entry.privilegeBits, parentAllowBits); allowBits.addDifference(entry.privilegeBits, denyBits); denyBits.addDifference(entry.privilegeBits, allowBits);
PrivilegeBits.EMPTY.addDifference(PrivilegeBits.EMPTY, PrivilegeBits.EMPTY); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { PrivilegeBits nxt = pb.nextBits(); try { pb.addDifference(nxt, mod); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { pb.addDifference(nxt, READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { tmp.addDifference(nxt, READ_NODES_PRIVILEGE_BITS); mod.add(nxt); tmp = PrivilegeBits.getInstance(nxt); PrivilegeBits mod2 = PrivilegeBits.getInstance(mod); tmp.addDifference(mod2, READ_NODES_PRIVILEGE_BITS); tmp.addDifference(READ_NODES_PRIVILEGE_BITS, mod2); tmp.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS); tmp.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS);
assertNotSame(pb, pb.unmodifiable()); pb.add(READ_NODES_PRIVILEGE_BITS); pb.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS); pb.diff(READ_NODES_PRIVILEGE_BITS); assertNotSame(pb, pb.unmodifiable()); pb.add(READ_NODES_PRIVILEGE_BITS); pb.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS); pb.diff(READ_NODES_PRIVILEGE_BITS); assertNotSame(pb, pb.unmodifiable()); pb.add(READ_NODES_PRIVILEGE_BITS); pb.addDifference(READ_NODES_PRIVILEGE_BITS, PrivilegeBits.EMPTY); pb.diff(READ_NODES_PRIVILEGE_BITS); pb.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) {
@Test public void testGetInstanceFromMvPropertyState() { PropertyState property = PropertyStates.createProperty("name", ImmutableSet.of(Long.MAX_VALUE, Long.MIN_VALUE / 2), Type.LONGS); PrivilegeBits pb = PrivilegeBits.getInstance(property); assertEquivalent(pb, PrivilegeBits.getInstance(property)); assertSame(pb, pb.unmodifiable()); assertEquivalent(pb, PrivilegeBits.getInstance(pb)); assertEquivalent(PrivilegeBits.getInstance(pb), pb); assertNotSame(pb, PrivilegeBits.getInstance(pb)); try { pb.add(READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { // success } try { pb.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { // success } try { pb.diff(READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { // success } }
@Test public void testGetInstanceFromPropertyState() { for (long l : LONGS) { PropertyState property = createPropertyState(l); PrivilegeBits pb = PrivilegeBits.getInstance(property); assertEquivalent(pb, PrivilegeBits.getInstance(property)); assertSame(pb, pb.unmodifiable()); assertEquivalent(pb, PrivilegeBits.getInstance(pb)); assertEquivalent(PrivilegeBits.getInstance(pb), pb); assertNotSame(pb, PrivilegeBits.getInstance(pb)); try { pb.add(READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { // success } try { pb.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { // success } try { pb.diff(READ_NODES_PRIVILEGE_BITS); fail("UnsupportedOperation expected"); } catch (UnsupportedOperationException e) { // success } } }