use of org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider in project jackrabbit-oak by apache.
the class CompositeAuthorizationConfigurationTest method testMultipleGetPermissionProvider.
@Test
public void testMultipleGetPermissionProvider() {
CompositeAuthorizationConfiguration cc = getCompositeConfiguration(new OpenAuthorizationConfiguration(), new AuthorizationConfigurationImpl(getSecurityProvider()));
PermissionProvider pp = cc.getPermissionProvider(root, root.getContentSession().getWorkspaceName(), Collections.<Principal>emptySet());
assertFalse(pp instanceof CompositePermissionProvider);
}
use of org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider in project jackrabbit-oak by apache.
the class CompositeProviderCoverageTest method testGetTreePermissionInstance.
@Override
@Test
public void testGetTreePermissionInstance() throws Exception {
PermissionProvider pp = createPermissionProvider(EveryonePrincipal.getInstance());
TreePermission parentPermission = TreePermission.EMPTY;
for (String path : TP_PATHS) {
TreePermission tp = pp.getTreePermission(readOnlyRoot.getTree(path), parentPermission);
assertTrue(tp instanceof LimitedTreePermission);
parentPermission = tp;
}
}
use of org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider in project jackrabbit-oak by apache.
the class CompositeProviderNoScopeTest method testGetTreePermissionInstance.
@Override
@Test
public void testGetTreePermissionInstance() throws Exception {
PermissionProvider pp = createPermissionProvider();
TreePermission parentPermission = TreePermission.EMPTY;
for (String path : TP_PATHS) {
Tree t = readOnlyRoot.getTree(path);
TreePermission tp = pp.getTreePermission(t, parentPermission);
assertCompositeTreePermission(t.isRoot(), tp);
parentPermission = tp;
}
}
use of org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider in project jackrabbit-oak by apache.
the class PermissionHookTest method testDynamicJcrAll.
/**
* @see <a href="https://issues.apache.org/jira/browse/OAK-2015">OAK-2015</a>
*/
@Test
public void testDynamicJcrAll() throws Exception {
AccessControlManager acMgr = getAccessControlManager(root);
// grant 'everyone' jcr:all at the child path.
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, childPath);
acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privilegesFromNames(JCR_ALL));
acMgr.setPolicy(childPath, acl);
root.commit();
// verify that the permission store contains an entry for everyone at childPath
// and the privilegeBits for jcr:all are reflect with a placeholder value.
Tree allEntry = getEntry(EveryonePrincipal.getInstance(), childPath, 0);
assertTrue(allEntry.exists());
PropertyState ps = allEntry.getProperty(PermissionConstants.REP_PRIVILEGE_BITS);
assertEquals(1, ps.count());
assertEquals(PermissionStore.DYNAMIC_ALL_BITS, ps.getValue(Type.LONG, 0).longValue());
// verify that the permission provider still exposes the correct privilege
// (jcr:all) for the given childPath irrespective of the dynamic nature of
// the privilege bits in the persisted permission entry.
Set<Principal> principalSet = ImmutableSet.<Principal>of(EveryonePrincipal.getInstance());
PermissionProvider permissionProvider = getConfig(AuthorizationConfiguration.class).getPermissionProvider(root, root.getContentSession().getWorkspaceName(), principalSet);
Tree childTree = root.getTree(childPath);
assertTrue(permissionProvider.hasPrivileges(childTree, PrivilegeConstants.JCR_ALL));
assertTrue(permissionProvider.getPrivileges(childTree).contains(PrivilegeConstants.JCR_ALL));
// also verify the permission evaluation
long diff = Permissions.diff(Permissions.ALL, Permissions.REMOVE_NODE | Permissions.ADD_NODE);
assertFalse(permissionProvider.isGranted(childTree, null, Permissions.REMOVE_NODE));
assertFalse(permissionProvider.isGranted(childTree, null, Permissions.ADD_NODE));
assertTrue(permissionProvider.isGranted(childTree, null, diff));
// remove the ACE again
acl = AccessControlUtils.getAccessControlList(acMgr, childPath);
for (AccessControlEntry ace : acl.getAccessControlEntries()) {
if (EveryonePrincipal.NAME.equals(ace.getPrincipal().getName())) {
acl.removeAccessControlEntry(ace);
}
}
acMgr.setPolicy(childPath, acl);
root.commit();
// verify that the corresponding permission entry has been removed.
Tree everyoneRoot = getPrincipalRoot(EveryonePrincipal.getInstance());
Tree parent = everyoneRoot.getChild(PermissionUtil.getEntryName(childPath));
if (parent.exists()) {
assertFalse(parent.getChild("0").exists());
}
}
use of org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider in project jackrabbit-oak by apache.
the class PermissionProviderImplTest method testReadPath.
@Test
public void testReadPath() throws Exception {
ContentSession testSession = createTestSession();
try {
Root r = testSession.getLatestRoot();
PermissionProvider pp = createPermissionProvider(testSession);
Tree tree = r.getTree("/");
assertFalse(tree.exists());
assertFalse(pp.getTreePermission(tree, TreePermission.EMPTY).canRead());
for (String path : READ_PATHS) {
tree = r.getTree(path);
assertTrue(tree.exists());
assertTrue(pp.getTreePermission(tree, TreePermission.EMPTY).canRead());
}
} finally {
testSession.close();
}
}
Aggregations