Search in sources :

Example 96 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class AuthorizablePropertiesImpl method getAuthorizableProperty.

/**
     * Returns the valid authorizable property identified by the specified
     * property location or {@code null} if that property does not exist or
     * isn't a authorizable property because it is protected or outside of the
     * scope of the {@code authorizableTree}.
     *
     * @param authorizableTree The tree of the target authorizable.
     * @param propertyLocation Location to be tested.
     * @param verifyAncestor   If true the property is tested to be a descendant
     *                         of the node of this authorizable; otherwise it is expected that this
     *                         test has been executed by the caller.
     * @return a valid authorizable property or {@code null} if no such property
     *         exists or fi the property is protected or not defined by the rep:authorizable
     *         node type or one of it's sub-node types.
     * @throws RepositoryException If an error occurs.
     */
@CheckForNull
private PropertyState getAuthorizableProperty(@Nonnull Tree authorizableTree, @Nonnull TreeLocation propertyLocation, boolean verifyAncestor) throws RepositoryException {
    PropertyState property = propertyLocation.getProperty();
    if (property == null) {
        return null;
    }
    String authorizablePath = authorizableTree.getPath();
    if (verifyAncestor && !Text.isDescendant(authorizablePath, propertyLocation.getPath())) {
        log.debug("Attempt to access property outside of authorizable scope.");
        return null;
    }
    Tree parent = propertyLocation.getParent().getTree();
    if (parent == null) {
        log.debug("Unable to determine definition of authorizable property at " + propertyLocation.getPath());
        return null;
    }
    ReadOnlyNodeTypeManager nodeTypeManager = authorizable.getUserManager().getNodeTypeManager();
    PropertyDefinition def = nodeTypeManager.getDefinition(parent, property, true);
    if (def.isProtected() || (authorizablePath.equals(parent.getPath()) && !def.getDeclaringNodeType().isNodeType(UserConstants.NT_REP_AUTHORIZABLE))) {
        return null;
    }
    return property;
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) ReadOnlyNodeTypeManager(org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) CheckForNull(javax.annotation.CheckForNull)

Example 97 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class AuthorizablePropertiesImpl method setProperty.

/**
     * @see org.apache.jackrabbit.api.security.user.Authorizable#setProperty(String, javax.jcr.Value[])
     */
@Override
public void setProperty(@Nonnull String relPath, @Nullable Value[] values) throws RepositoryException {
    if (values == null) {
        removeProperty(relPath);
    } else {
        String oakPath = getOakPath(relPath);
        String name = Text.getName(oakPath);
        PropertyState propertyState = PropertyStates.createProperty(name, Arrays.asList(values));
        String intermediate = (oakPath.equals(name)) ? null : Text.getRelativeParent(oakPath, 1);
        Tree parent = getOrCreateTargetTree(intermediate);
        checkProtectedProperty(parent, propertyState);
        parent.setProperty(propertyState);
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 98 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState 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.");
    }
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) ArrayList(java.util.ArrayList) Tree(org.apache.jackrabbit.oak.api.Tree) RepositoryException(javax.jcr.RepositoryException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Nonnull(javax.annotation.Nonnull)

Example 99 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class AuthorizablePropertiesImpl method setProperty.

/**
     * @see org.apache.jackrabbit.api.security.user.Authorizable#setProperty(String, javax.jcr.Value)
     */
@Override
public void setProperty(@Nonnull String relPath, @Nullable Value value) throws RepositoryException {
    if (value == null) {
        removeProperty(relPath);
    } else {
        String oakPath = getOakPath(relPath);
        String name = Text.getName(oakPath);
        PropertyState propertyState = PropertyStates.createProperty(name, value);
        String intermediate = (oakPath.equals(name)) ? null : Text.getRelativeParent(oakPath, 1);
        Tree parent = getOrCreateTargetTree(intermediate);
        checkProtectedProperty(parent, propertyState);
        parent.setProperty(propertyState);
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 100 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class RestrictionProviderImpl method validateRestrictions.

@Override
public void validateRestrictions(String oakPath, @Nonnull Tree aceTree) throws AccessControlException {
    super.validateRestrictions(oakPath, aceTree);
    Tree restrictionsTree = getRestrictionsTree(aceTree);
    PropertyState glob = restrictionsTree.getProperty(REP_GLOB);
    if (glob != null) {
        GlobPattern.validate(glob.getValue(Type.STRING));
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Aggregations

PropertyState (org.apache.jackrabbit.oak.api.PropertyState)404 Test (org.junit.Test)189 Tree (org.apache.jackrabbit.oak.api.Tree)138 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)49 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)45 Nonnull (javax.annotation.Nonnull)31 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)29 RemoteTree (org.apache.jackrabbit.oak.remote.RemoteTree)28 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)28 Blob (org.apache.jackrabbit.oak.api.Blob)21 ArrayList (java.util.ArrayList)20 LongPropertyState (org.apache.jackrabbit.oak.plugins.memory.LongPropertyState)17 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)16 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)14 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)13 CheckForNull (javax.annotation.CheckForNull)12 RepositoryException (javax.jcr.RepositoryException)10 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)10 Map (java.util.Map)9 Value (javax.jcr.Value)9