Search in sources :

Example 6 with PropertyImpl

use of org.apache.jackrabbit.core.PropertyImpl in project jackrabbit by apache.

the class ImpersonationImpl method updateImpersonatorNames.

private void updateImpersonatorNames(Set<String> principalNames) throws RepositoryException {
    NodeImpl userNode = user.getNode();
    try {
        String[] pNames = principalNames.toArray(new String[principalNames.size()]);
        if (pNames.length == 0) {
            PropertyImpl prop = userNode.getProperty(P_IMPERSONATORS);
            userManager.removeProtectedItem(prop, userNode);
        } else {
            Value[] values = new Value[pNames.length];
            for (int i = 0; i < pNames.length; i++) {
                values[i] = new StringValue(pNames[i]);
            }
            userManager.setProtectedProperty(userNode, P_IMPERSONATORS, values);
        }
    } catch (RepositoryException e) {
        // revert pending changes
        userNode.refresh(false);
        throw e;
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl) RepositoryException(javax.jcr.RepositoryException) StringValue(org.apache.jackrabbit.value.StringValue)

Example 7 with PropertyImpl

use of org.apache.jackrabbit.core.PropertyImpl in project jackrabbit by apache.

the class RetentionRegistryImpl method onEvent.

//-------------------------------------------< SynchronousEventListener >---
/**
     * @param events Events reporting hold/retention policy changes.
     */
public void onEvent(EventIterator events) {
    while (events.hasNext()) {
        Event ev = events.nextEvent();
        try {
            Path evPath = session.getQPath(ev.getPath());
            Path nodePath = evPath.getAncestor(1);
            Name propName = evPath.getName();
            if (RetentionManagerImpl.REP_HOLD.equals(propName)) {
                // hold changes
                switch(ev.getType()) {
                    case Event.PROPERTY_ADDED:
                    case Event.PROPERTY_CHANGED:
                        // build the Hold objects from the rep:hold property
                        // and put them into the hold map.
                        PropertyImpl p = (PropertyImpl) session.getProperty(ev.getPath());
                        addHolds(nodePath, p);
                        break;
                    case Event.PROPERTY_REMOVED:
                        // all holds present on this node were remove
                        // -> remove the corresponding entry in the holdMap.
                        removeHolds(nodePath);
                        break;
                }
            } else if (RetentionManagerImpl.REP_RETENTION_POLICY.equals(propName)) {
                // retention policy changes
                switch(ev.getType()) {
                    case Event.PROPERTY_ADDED:
                    case Event.PROPERTY_CHANGED:
                        // build the RetentionPolicy objects from the rep:retentionPolicy property
                        // and put it into the retentionMap.
                        PropertyImpl p = (PropertyImpl) session.getProperty(ev.getPath());
                        addRetentionPolicy(nodePath, p);
                        break;
                    case Event.PROPERTY_REMOVED:
                        // retention policy present on this node was remove
                        // -> remove the corresponding entry in the retentionMap.
                        removeRetentionPolicy(nodePath);
                        break;
                }
            }
        // else: not interested in any other property -> ignore.
        } catch (RepositoryException e) {
            log.warn("Internal error while processing event. {}", e.getMessage());
        // ignore.
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) Event(javax.jcr.observation.Event) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 8 with PropertyImpl

use of org.apache.jackrabbit.core.PropertyImpl in project jackrabbit by apache.

the class RetentionRegistryImpl method readRetentionFile.

/**
     * Read the file system resource containing the node ids of those nodes
     * contain holds/retention policies and populate the 2 path maps.
     *
     * If an entry in the retention file doesn't have a corresponding entry
     * (either rep:hold property or rep:retentionPolicy property at the
     * node identified by the node id entry) or doesn't correspond to an existing
     * node, that entry will be ignored. Upon {@link #close()} of this
     * manager, the file will be updated to reflect the actual set of holds/
     * retentions present and effective in the content.
     *
     * @throws IOException
     * @throws FileSystemException
     */
private void readRetentionFile() throws IOException, FileSystemException {
    if (retentionFile.exists()) {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(retentionFile.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                NodeId nodeId = NodeId.valueOf(line);
                try {
                    NodeImpl node = (NodeImpl) session.getItemManager().getItem(nodeId);
                    Path nodePath = node.getPrimaryPath();
                    if (node.hasProperty(RetentionManagerImpl.REP_HOLD)) {
                        PropertyImpl prop = node.getProperty(RetentionManagerImpl.REP_HOLD);
                        addHolds(nodePath, prop);
                    }
                    if (node.hasProperty(RetentionManagerImpl.REP_RETENTION_POLICY)) {
                        PropertyImpl prop = node.getProperty(RetentionManagerImpl.REP_RETENTION_POLICY);
                        addRetentionPolicy(nodePath, prop);
                    }
                } catch (RepositoryException e) {
                    // node doesn't exist any more or hold/retention has been removed.
                    // ignore. upon close() the file will not contain the given nodeId
                    // any more.
                    log.warn("Unable to read retention policy / holds from node '" + nodeId + "': " + e.getMessage());
                }
            }
        } finally {
            IOUtils.closeQuietly(reader);
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) InputStreamReader(java.io.InputStreamReader) NodeImpl(org.apache.jackrabbit.core.NodeImpl) BufferedReader(java.io.BufferedReader) NodeId(org.apache.jackrabbit.core.id.NodeId) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl) RepositoryException(javax.jcr.RepositoryException)

Example 9 with PropertyImpl

use of org.apache.jackrabbit.core.PropertyImpl in project jackrabbit by apache.

the class AuthorizableImplTest method testGroupGetProperties.

public void testGroupGetProperties() throws RepositoryException, NotExecutableException {
    AuthorizableImpl group = (AuthorizableImpl) getTestGroup(superuser);
    NodeImpl n = group.getNode();
    for (PropertyIterator it = n.getProperties(); it.hasNext(); ) {
        PropertyImpl p = (PropertyImpl) it.nextProperty();
        if (p.getDefinition().isProtected()) {
            assertFalse(group.hasProperty(p.getName()));
            assertNull(group.getProperty(p.getName()));
        } else {
            // authorizable defined property
            assertTrue(group.hasProperty(p.getName()));
            assertNotNull(group.getProperty(p.getName()));
        }
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) PropertyIterator(javax.jcr.PropertyIterator) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl)

Example 10 with PropertyImpl

use of org.apache.jackrabbit.core.PropertyImpl in project jackrabbit by apache.

the class MembershipCache method isMemberOfNodeBaseMembershipGroup.

/**
     * traverses the group structure of a node-based group to check if the given authorizable is member of this group.
     *
     * @param authorizableNodeIdentifier Identifier of the authorizable node
     * @param groupId if of the group
     * @param nIds output set to update of group node ids that were found via the node memberships
     * @param node the node to traverse
     * @throws RepositoryException if an error occurs
     */
private void isMemberOfNodeBaseMembershipGroup(String authorizableNodeIdentifier, String groupId, Set<String> nIds, NodeImpl node) throws RepositoryException {
    PropertyIterator pIter = node.getProperties();
    while (pIter.hasNext()) {
        PropertyImpl p = (PropertyImpl) pIter.nextProperty();
        if (p.getType() == PropertyType.WEAKREFERENCE) {
            Value[] values = p.isMultiple() ? p.getValues() : new Value[] { p.getValue() };
            for (Value v : values) {
                if (v.getString().equals(authorizableNodeIdentifier)) {
                    nIds.add(groupId);
                    return;
                }
            }
        }
    }
    NodeIterator iter = node.getNodes();
    while (iter.hasNext()) {
        NodeImpl child = (NodeImpl) iter.nextNode();
        if (child.isNodeType(NT_REP_MEMBERS)) {
            isMemberOfNodeBaseMembershipGroup(authorizableNodeIdentifier, groupId, nIds, child);
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) NodeImpl(org.apache.jackrabbit.core.NodeImpl) PropertyIterator(javax.jcr.PropertyIterator) Value(javax.jcr.Value) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl)

Aggregations

PropertyImpl (org.apache.jackrabbit.core.PropertyImpl)11 NodeImpl (org.apache.jackrabbit.core.NodeImpl)9 RepositoryException (javax.jcr.RepositoryException)6 PropertyIterator (javax.jcr.PropertyIterator)5 Value (javax.jcr.Value)4 NodeIterator (javax.jcr.NodeIterator)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 Path (org.apache.jackrabbit.spi.Path)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 Session (javax.jcr.Session)1 Event (javax.jcr.observation.Event)1 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)1 Name (org.apache.jackrabbit.spi.Name)1 StringValue (org.apache.jackrabbit.value.StringValue)1