use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits in project jackrabbit-oak by apache.
the class CompositeProviderFullScopeTest method testHasPrivileges.
@Test
public void testHasPrivileges() throws Exception {
PrivilegeBitsProvider pbp = new PrivilegeBitsProvider(readOnlyRoot);
PrivilegeBits readNodes = pbp.getBits(REP_READ_NODES);
for (String path : defPrivileges.keySet()) {
Set<String> defaultPrivs = defPrivileges.get(path);
PrivilegeBits defaultBits = pbp.getBits(defaultPrivs);
Tree tree = readOnlyRoot.getTree(path);
if (defaultPrivs.isEmpty()) {
assertFalse(path, cppTestUser.hasPrivileges(tree, REP_READ_NODES));
} else if (defaultBits.includes(readNodes)) {
assertTrue(path, cppTestUser.hasPrivileges(tree, REP_READ_NODES));
if (!readNodes.equals(defaultBits)) {
assertFalse(path, cppTestUser.hasPrivileges(tree, defaultPrivs.toArray(new String[defaultPrivs.size()])));
}
} else {
assertFalse(path, cppTestUser.hasPrivileges(tree, REP_READ_NODES));
assertFalse(path, cppTestUser.hasPrivileges(tree, defaultPrivs.toArray(new String[defaultPrivs.size()])));
}
}
}
use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits in project jackrabbit-oak by apache.
the class CompositeProviderScopeTest method testGetPrivilegesAdmin.
@Test
public void testGetPrivilegesAdmin() throws Exception {
for (String path : NODE_PATHS) {
Tree tree = readOnlyRoot.getTree(path);
Set<String> privNames = cppAdminUser.getPrivileges(tree);
if (testProvider.isSupported(path)) {
PrivilegeBits expected = pbp.getBits(JCR_ALL).modifiable().diff(denied).unmodifiable();
assertEquals(expected, pbp.getBits(privNames));
} else {
assertEquals(path, ImmutableSet.of(JCR_ALL), privNames);
}
}
}
use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits in project jackrabbit-oak by apache.
the class CompositeProviderScopeTest method testGetPrivilegesOnRepoAdmin.
@Test
public void testGetPrivilegesOnRepoAdmin() throws Exception {
PrivilegeBits expected = pbp.getBits(JCR_ALL).modifiable().diff(pbp.getBits(JCR_NAMESPACE_MANAGEMENT)).unmodifiable();
assertEquals(expected, pbp.getBits(cppAdminUser.getPrivileges(null)));
}
use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits in project jackrabbit-oak by apache.
the class JcrAllTest method testAllAggregation.
@Test
public void testAllAggregation() throws Exception {
PrivilegeBits all = bitsProvider.getBits(JCR_ALL);
PrivilegeManager pMgr = getSecurityProvider().getConfiguration(PrivilegeConfiguration.class).getPrivilegeManager(root, NamePathMapper.DEFAULT);
Iterable<Privilege> declaredAggr = Arrays.asList(pMgr.getPrivilege(JCR_ALL).getDeclaredAggregatePrivileges());
String[] allAggregates = Iterables.toArray(Iterables.transform(declaredAggr, new Function<Privilege, String>() {
@Override
public String apply(@Nullable Privilege privilege) {
return checkNotNull(privilege).getName();
}
}), String.class);
PrivilegeBits all2 = bitsProvider.getBits(allAggregates);
assertEquals(all, all2);
assertEquals(Collections.singleton(JCR_ALL), bitsProvider.getPrivilegeNames(all2));
PrivilegeBits bits = PrivilegeBits.getInstance();
for (String name : allAggregates) {
bits.add(bitsProvider.getBits(name));
}
assertEquals(all, bits.unmodifiable());
}
use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits in project jackrabbit-oak by apache.
the class PrivilegeBitsProviderTest method testUnknownAggregation.
@Test
public void testUnknownAggregation() throws RepositoryException {
PrivilegeBits bits = bitsProvider.getBits(REP_WRITE, JCR_LIFECYCLE_MANAGEMENT);
Set<String> names = bitsProvider.getPrivilegeNames(bits);
assertEquals(2, names.size());
}
Aggregations