use of org.apache.jackrabbit.oak.plugins.tree.TreeLocation in project jackrabbit-oak by apache.
the class CugPermissionProviderTest method testSupportedPermissionsByLocation.
/**
* @see org.apache.jackrabbit.oak.spi.security.authorization.permission.AggregatedPermissionProvider#supportedPermissions(org.apache.jackrabbit.oak.plugins.tree.TreeLocation, long)
*/
@Test
public void testSupportedPermissionsByLocation() {
for (String path : PATH_INCUG_MAP.keySet()) {
boolean isInCug = PATH_INCUG_MAP.get(path);
TreeLocation location = TreeLocation.create(root, path);
if (isInCug) {
assertEquals(path, Permissions.READ, cugPermProvider.supportedPermissions(location, Permissions.READ));
assertEquals(path, Permissions.READ_NODE, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE));
assertEquals(path, Permissions.READ_PROPERTY, cugPermProvider.supportedPermissions(location, Permissions.READ_PROPERTY));
assertEquals(path, Permissions.READ, cugPermProvider.supportedPermissions(location, Permissions.ALL));
assertEquals(path, Permissions.READ_NODE, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE | Permissions.READ_ACCESS_CONTROL));
} else {
assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ));
assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE));
assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_PROPERTY));
assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.ALL));
assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE | Permissions.READ_ACCESS_CONTROL));
}
assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_ACCESS_CONTROL));
assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.MODIFY_ACCESS_CONTROL));
assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.ADD_NODE));
assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.WRITE));
assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(TreeLocation.create(root, "/path/to/no-existing/tree"), Permissions.READ));
}
}
use of org.apache.jackrabbit.oak.plugins.tree.TreeLocation in project jackrabbit-oak by apache.
the class CompositePermissionProvider method isGranted.
@Override
public boolean isGranted(@Nonnull String oakPath, @Nonnull String jcrActions) {
TreeLocation location = TreeLocation.create(immutableRoot, oakPath);
boolean isAcContent = ctx.definesLocation(location);
long permissions = Permissions.getPermissions(jcrActions, location, isAcContent);
PropertyState property = location.getProperty();
Tree tree = (property == null) ? location.getTree() : location.getParent().getTree();
if (tree != null) {
return isGranted(tree, property, permissions);
} else {
boolean isGranted = false;
long coveredPermissions = Permissions.NO_PERMISSION;
for (AggregatedPermissionProvider aggregatedPermissionProvider : pps) {
long supportedPermissions = aggregatedPermissionProvider.supportedPermissions(location, permissions);
if (doEvaluate(supportedPermissions)) {
isGranted = aggregatedPermissionProvider.isGranted(location, supportedPermissions);
coveredPermissions |= supportedPermissions;
if (!isGranted) {
break;
}
}
}
return isGranted && coveredPermissions == permissions;
}
}
use of org.apache.jackrabbit.oak.plugins.tree.TreeLocation in project jackrabbit-oak by apache.
the class AuthorizablePropertiesImpl method getNames.
//---------------------------------------------< AuthorizableProperties >---
@Nonnull
@Override
public Iterator<String> getNames(@Nonnull String relPath) throws RepositoryException {
String oakPath = getOakPath(relPath);
Tree tree = getTree();
TreeLocation location = getLocation(tree, oakPath);
Tree parent = location.getTree();
if (parent != null && Text.isDescendantOrEqual(tree.getPath(), parent.getPath())) {
List<String> l = new ArrayList<String>();
for (PropertyState property : parent.getProperties()) {
String propName = property.getName();
if (isAuthorizableProperty(tree, location.getChild(propName), false)) {
l.add(namePathMapper.getJcrName(propName));
}
}
return l.iterator();
} else {
throw new RepositoryException("Relative path " + relPath + " refers to non-existing tree or tree outside of scope of authorizable.");
}
}
use of org.apache.jackrabbit.oak.plugins.tree.TreeLocation in project jackrabbit-oak by apache.
the class AuthorizablePropertiesImpl method removeProperty.
/**
* @see org.apache.jackrabbit.api.security.user.Authorizable#removeProperty(String)
*/
@Override
public boolean removeProperty(@Nonnull String relPath) throws RepositoryException {
String oakPath = getOakPath(relPath);
Tree node = getTree();
TreeLocation propertyLocation = getLocation(node, oakPath);
if (propertyLocation.getProperty() != null) {
if (isAuthorizableProperty(node, propertyLocation, true)) {
return propertyLocation.remove();
} else {
throw new ConstraintViolationException("Property " + relPath + " isn't a modifiable authorizable property");
}
} else {
checkScope(node.getPath(), propertyLocation.getPath(), relPath);
}
// no such property or wasn't a property of this authorizable.
return false;
}
use of org.apache.jackrabbit.oak.plugins.tree.TreeLocation in project jackrabbit-oak by apache.
the class UserContextTest method testNonExistingTreeDefinesLocation.
@Test
public void testNonExistingTreeDefinesLocation() {
for (String ntName : NT_NAMES) {
Tree t = mockTree("anyName", ntName);
TreeLocation location = Mockito.mock(TreeLocation.class);
when(location.getTree()).thenReturn(t);
when(location.exists()).thenReturn(false);
when(location.getPath()).thenReturn("/somePath");
assertFalse(ctx.definesLocation(location));
}
}
Aggregations