Search in sources :

Example 26 with SessionImpl

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

the class LockManagerImpl method writeLockProperties.

/**
     * Add the lock related properties to the target node.
     *
     * @param node
     * @param lockOwner
     * @param isDeep
     */
protected void writeLockProperties(NodeImpl node, String lockOwner, boolean isDeep) throws RepositoryException {
    boolean success = false;
    SessionImpl editingSession = (SessionImpl) node.getSession();
    WorkspaceImpl wsp = (WorkspaceImpl) editingSession.getWorkspace();
    UpdatableItemStateManager stateMgr = wsp.getItemStateManager();
    try {
        acquireLockPropertiesLock();
        if (stateMgr.inEditMode()) {
            throw new RepositoryException("Unable to write lock properties.");
        }
        stateMgr.edit();
        try {
            // add properties to content
            NodeId nodeId = node.getNodeId();
            NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);
            PropertyState propState;
            if (!nodeState.hasPropertyName(NameConstants.JCR_LOCKOWNER)) {
                propState = stateMgr.createNew(NameConstants.JCR_LOCKOWNER, nodeId);
                propState.setType(PropertyType.STRING);
                propState.setMultiValued(false);
            } else {
                propState = (PropertyState) stateMgr.getItemState(new PropertyId(nodeId, NameConstants.JCR_LOCKOWNER));
            }
            propState.setValues(new InternalValue[] { InternalValue.create(lockOwner) });
            nodeState.addPropertyName(NameConstants.JCR_LOCKOWNER);
            stateMgr.store(nodeState);
            if (!nodeState.hasPropertyName(NameConstants.JCR_LOCKISDEEP)) {
                propState = stateMgr.createNew(NameConstants.JCR_LOCKISDEEP, nodeId);
                propState.setType(PropertyType.BOOLEAN);
                propState.setMultiValued(false);
            } else {
                propState = (PropertyState) stateMgr.getItemState(new PropertyId(nodeId, NameConstants.JCR_LOCKISDEEP));
            }
            propState.setValues(new InternalValue[] { InternalValue.create(isDeep) });
            nodeState.addPropertyName(NameConstants.JCR_LOCKISDEEP);
            stateMgr.store(nodeState);
            stateMgr.update();
            success = true;
        } catch (ItemStateException e) {
            throw new RepositoryException("Error while creating lock.", e);
        } finally {
            if (!success) {
                // failed to set lock meta-data content, cleanup
                stateMgr.cancel();
                try {
                    unlock(node);
                } catch (RepositoryException e) {
                    // cleanup failed
                    log.error("error while cleaning up after failed lock attempt", e);
                }
            }
        }
    } finally {
        releaseLockPropertiesLock();
    }
}
Also used : UpdatableItemStateManager(org.apache.jackrabbit.core.state.UpdatableItemStateManager) WorkspaceImpl(org.apache.jackrabbit.core.WorkspaceImpl) NodeState(org.apache.jackrabbit.core.state.NodeState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) PropertyState(org.apache.jackrabbit.core.state.PropertyState) PropertyId(org.apache.jackrabbit.core.id.PropertyId) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 27 with SessionImpl

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

the class LockManagerImpl method holdsLock.

/**
     * {@inheritDoc}
     */
public boolean holdsLock(NodeImpl node) throws RepositoryException {
    acquire();
    try {
        SessionImpl session = (SessionImpl) node.getSession();
        PathMap.Element<LockInfo> element = lockMap.map(getPath(session, node.getId()), true);
        if (element == null) {
            return false;
        }
        return element.get() != null;
    } catch (ItemNotFoundException e) {
        return false;
    } finally {
        release();
    }
}
Also used : SessionImpl(org.apache.jackrabbit.core.SessionImpl) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 28 with SessionImpl

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

the class PrivilegeManagerImpl method registerPrivilege.

/**
     * Register a new custom privilege with the specified characteristics.
     * <p>
     * The current implementation has the following limitations and constraints:
     *
     * <ul>
     * <li>the name may not be in use by another privilege</li>
     * <li>the namespace URI must be a valid, registered namespace excluding
     * those namespaces marked as being reserved</li>
     * <li>an aggregate custom privilege is valid if all declared aggregate
     * names can be resolved to registered privileges and if there exists
     * no registered privilege with the same aggregated privileges.</li>
     * </ul>
     * <p>
     * <strong>Please note</strong><br>
     * Custom privilege(s) will not be enforced for any kind of repository
     * operations. Those are exclusively covered by the built-in privileges.
     * This also implies that the {@link Permission}s are not affected by
     * custom privileges.
     * <p>
     * Applications making use of the custom privilege(s) are in charge of
     * asserting whether the privileges are granted/denied according to their
     * application specific needs.
     *
     * @param privilegeName The name of the new custom privilege.
     * @param isAbstract Boolean flag indicating if the privilege is abstract.
     * @param declaredAggregateNames An array of privilege names referring to
     * registered privileges being aggregated by this new custom privilege.
     * In case of a non aggregate privilege an empty array should be passed.
     * @return the new privilege.
     * @throws AccessDeniedException If the session this manager has been created
     * lacks rep:privilegeManagement privilege.
     * @throws RepositoryException If the privilege could not be registered due
     * to constraint violations or if persisting the custom privilege fails.
     * @see PrivilegeManager#registerPrivilege(String, boolean, String[])
     */
public Privilege registerPrivilege(String privilegeName, boolean isAbstract, String[] declaredAggregateNames) throws AccessDeniedException, RepositoryException {
    if (resolver instanceof SessionImpl) {
        SessionImpl sImpl = (SessionImpl) resolver;
        sImpl.getAccessManager().checkRepositoryPermission(Permission.PRIVILEGE_MNGMT);
    } else {
        // cannot evaluate
        throw new AccessDeniedException("Registering privileges is not allowed for the editing session.");
    }
    Name name = resolver.getQName(privilegeName);
    Set<Name> daNames;
    if (declaredAggregateNames == null || declaredAggregateNames.length == 0) {
        daNames = Collections.emptySet();
    } else {
        daNames = new HashSet<Name>(declaredAggregateNames.length);
        for (String declaredAggregateName : declaredAggregateNames) {
            daNames.add(resolver.getQName(declaredAggregateName));
        }
    }
    registry.registerDefinition(name, isAbstract, daNames);
    return getPrivilege(privilegeName);
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) Name(org.apache.jackrabbit.spi.Name)

Example 29 with SessionImpl

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

the class UserAccessControlProviderTest method testNoNodeForPrincipal.

/**
     * @see <a href="https://issues.apache.org/jira/browse/JCR-2630">JCR-2630</a>
     */
public void testNoNodeForPrincipal() throws RepositoryException {
    final Principal testPrincipal = getTestPrincipal();
    String path = "/home/users/t/" + testPrincipal.getName();
    while (s.nodeExists(path)) {
        path += "_";
    }
    final String principalPath = path;
    List<Set<Principal>> principalSets = new ArrayList<Set<Principal>>();
    principalSets.add(Collections.<Principal>singleton(testPrincipal));
    principalSets.add(Collections.<Principal>singleton(new ItemBasedPrincipal() {

        public String getPath() {
            return principalPath;
        }

        public String getName() {
            return testPrincipal.getName();
        }
    }));
    Path rootPath = ((SessionImpl) s).getQPath("/");
    for (Set<Principal> principals : principalSets) {
        CompiledPermissions cp = provider.compilePermissions(principals);
        assertFalse(cp.canReadAll());
        assertFalse(cp.grants(rootPath, Permission.READ));
        assertTrue(cp.getPrivilegeSet(rootPath).isEmpty());
        assertSame(CompiledPermissions.NO_PERMISSION, cp);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) SessionImpl(org.apache.jackrabbit.core.SessionImpl) CompiledPermissions(org.apache.jackrabbit.core.security.authorization.CompiledPermissions) Principal(java.security.Principal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)

Example 30 with SessionImpl

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

the class IndexNodeResolverTest method testFindNodesNonExactWithApostrophe.

public void testFindNodesNonExactWithApostrophe() throws NotExecutableException, RepositoryException {
    UserImpl currentUser = getCurrentUser();
    Value vs = superuser.getValueFactory().createValue("value ' with apostrophe");
    currentUser.setProperty(propertyName1, vs);
    save();
    Name propName = ((SessionImpl) superuser).getQName(propertyName1);
    try {
        NodeResolver nr = createNodeResolver(currentUser.getNode().getSession());
        NodeIterator result = nr.findNodes(propName, "value ' with apostrophe", UserConstants.NT_REP_USER, false);
        assertTrue("expected result", result.hasNext());
        assertEquals(currentUser.getNode().getPath(), result.nextNode().getPath());
        assertFalse("expected no more results", result.hasNext());
    } finally {
        currentUser.removeProperty(propertyName1);
        save();
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Value(javax.jcr.Value) SessionImpl(org.apache.jackrabbit.core.SessionImpl) Name(org.apache.jackrabbit.spi.Name)

Aggregations

SessionImpl (org.apache.jackrabbit.core.SessionImpl)63 RepositoryException (javax.jcr.RepositoryException)16 Node (javax.jcr.Node)12 Value (javax.jcr.Value)11 Name (org.apache.jackrabbit.spi.Name)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Session (javax.jcr.Session)9 NodeImpl (org.apache.jackrabbit.core.NodeImpl)8 NodeId (org.apache.jackrabbit.core.id.NodeId)8 Principal (java.security.Principal)7 DataStoreGarbageCollector (org.apache.jackrabbit.api.management.DataStoreGarbageCollector)7 NodeIterator (javax.jcr.NodeIterator)6 Privilege (javax.jcr.security.Privilege)6 UserManager (org.apache.jackrabbit.api.security.user.UserManager)6 Path (org.apache.jackrabbit.spi.Path)6 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)5 PathMap (org.apache.jackrabbit.spi.commons.name.PathMap)5 InvalidItemStateException (javax.jcr.InvalidItemStateException)4 LockException (javax.jcr.lock.LockException)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4