Search in sources :

Example 31 with PropertyState

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

the class PermissionStoreImpl method createPermissionEntry.

@Nonnull
private PermissionEntry createPermissionEntry(@Nonnull String path, @Nonnull Tree entryTree) {
    PropertyState ps = entryTree.getProperty(REP_PRIVILEGE_BITS);
    PrivilegeBits bits = (isJcrAll(ps)) ? allBits : PrivilegeBits.getInstance(ps);
    boolean isAllow = TreeUtil.getBoolean(entryTree, REP_IS_ALLOW);
    return new PermissionEntry(path, isAllow, Integer.parseInt(entryTree.getName()), bits, restrictionProvider.getPattern(path, entryTree));
}
Also used : PrivilegeBits(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Nonnull(javax.annotation.Nonnull)

Example 32 with PropertyState

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

the class ImpersonationImpl method getImpersonatorNames.

@Nonnull
private Set<String> getImpersonatorNames(@Nonnull Tree userTree) {
    Set<String> princNames = new HashSet<String>();
    PropertyState impersonators = userTree.getProperty(REP_IMPERSONATORS);
    if (impersonators != null) {
        for (String v : impersonators.getValue(STRINGS)) {
            princNames.add(v);
        }
    }
    return princNames;
}
Also used : HashSet(java.util.HashSet) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Nonnull(javax.annotation.Nonnull)

Example 33 with PropertyState

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

the class MembershipWriter method addMembers.

/**
     * Adds a new member to the given {@code groupTree}.
     *
     * @param groupTree the group to add the member to
     * @param memberIds the ids of the new members as map of 'contentId':'memberId'
     * @return the set of member IDs that was not successfully processed.
     * @throws RepositoryException if an error occurs
     */
Set<String> addMembers(@Nonnull Tree groupTree, @Nonnull Map<String, String> memberIds) throws RepositoryException {
    // check all possible rep:members properties for the new member and also find the one with the least values
    Tree membersList = groupTree.getChild(UserConstants.REP_MEMBERS_LIST);
    Iterator<Tree> trees = Iterators.concat(Iterators.singletonIterator(groupTree), membersList.getChildren().iterator());
    Set<String> failed = new HashSet<String>(memberIds.size());
    int bestCount = membershipSizeThreshold;
    PropertyState bestProperty = null;
    Tree bestTree = null;
    // for the insertion of the new members.
    while (trees.hasNext() && !memberIds.isEmpty()) {
        Tree t = trees.next();
        PropertyState refs = t.getProperty(UserConstants.REP_MEMBERS);
        if (refs != null) {
            int numRefs = 0;
            for (String ref : refs.getValue(Type.WEAKREFERENCES)) {
                String id = memberIds.remove(ref);
                if (id != null) {
                    failed.add(id);
                    if (memberIds.isEmpty()) {
                        break;
                    }
                }
                numRefs++;
            }
            if (numRefs < bestCount) {
                bestCount = numRefs;
                bestProperty = refs;
                bestTree = t;
            }
        }
    }
    // with the best-matching property and create new member-ref-nodes as needed.
    if (!memberIds.isEmpty()) {
        PropertyBuilder<String> propertyBuilder;
        int propCnt;
        if (bestProperty == null) {
            // so there are no members at all or all are full
            if (!groupTree.hasProperty(UserConstants.REP_MEMBERS)) {
                bestTree = groupTree;
            } else {
                bestTree = createMemberRefTree(groupTree, membersList);
            }
            propertyBuilder = PropertyBuilder.array(Type.WEAKREFERENCE, UserConstants.REP_MEMBERS);
            propCnt = 0;
        } else {
            propertyBuilder = PropertyBuilder.copy(Type.WEAKREFERENCE, bestProperty);
            propCnt = bestCount;
        }
        // for simplicity this is achieved by introducing new tree(s)
        if ((propCnt + memberIds.size()) > membershipSizeThreshold) {
            while (!memberIds.isEmpty()) {
                Set<String> s = new HashSet<String>();
                Iterator<String> it = memberIds.keySet().iterator();
                while (propCnt < membershipSizeThreshold && it.hasNext()) {
                    s.add(it.next());
                    it.remove();
                    propCnt++;
                }
                propertyBuilder.addValues(s);
                bestTree.setProperty(propertyBuilder.getPropertyState());
                if (it.hasNext()) {
                    // continue filling the next (new) node + propertyBuilder pair
                    propCnt = 0;
                    bestTree = createMemberRefTree(groupTree, membersList);
                    propertyBuilder = PropertyBuilder.array(Type.WEAKREFERENCE, UserConstants.REP_MEMBERS);
                }
            }
        } else {
            propertyBuilder.addValues(memberIds.keySet());
            bestTree.setProperty(propertyBuilder.getPropertyState());
        }
    }
    return failed;
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) HashSet(java.util.HashSet) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 34 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 35 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)

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