Search in sources :

Example 31 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class NodeTypeRegistry method reregisterNodeType.

/**
     * Internal implementation of {@link #reregisterNodeType(QNodeTypeDefinition)}.
     *
     * @param ntd node type definition
     * @param external whether this invocation should be considered external
     * @return the new effective node type
     * @throws NoSuchNodeTypeException if <code>ntd</code> refers to an
     *                                 unknown node type
     * @throws InvalidNodeTypeDefException if the node type definition
     *                                     is invalid
     * @throws RepositoryException if another error occurs
     */
private EffectiveNodeType reregisterNodeType(QNodeTypeDefinition ntd, boolean external) throws NoSuchNodeTypeException, InvalidNodeTypeDefException, RepositoryException {
    EffectiveNodeType entNew;
    synchronized (this) {
        Name name = ntd.getName();
        if (!registeredNTDefs.containsKey(name)) {
            throw new NoSuchNodeTypeException(name.toString());
        }
        if (builtInNTDefs.contains(name)) {
            throw new RepositoryException(name.toString() + ": can't reregister built-in node type.");
        }
        /**
             * validate new node type definition
             */
        ntd = checkNtBaseSubtyping(ntd, registeredNTDefs);
        validateNodeTypeDef(ntd, entCache, registeredNTDefs, nsReg, false);
        /**
             * build diff of current and new definition and determine type of change
             */
        QNodeTypeDefinition ntdOld = registeredNTDefs.get(name);
        NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntdOld, ntd);
        if (!diff.isModified()) {
            // the definition has not been modified, there's nothing to do here...
            return getEffectiveNodeType(name);
        }
        // make sure existing content would not conflict
        // with new node type definition
        checkForConflictingContent(ntd, diff);
        /**
             * re-register node type definition and update caches &
             * notify listeners on re-registration
             */
        internalUnregister(name);
        // remove old node type definition from store
        customNTDefs.remove(name);
        entNew = internalRegister(ntd);
        // add new node type definition to store
        customNTDefs.add(ntd);
        // persist node type definitions
        persistCustomNodeTypeDefs(customNTDefs);
        // notify listeners
        notifyReRegistered(name);
    }
    // inform cluster if this is not an external invocation
    if (!external && eventChannel != null) {
        eventChannel.reregistered(ntd);
    }
    return entNew;
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException) NodeTypeDefDiff(org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefDiff)

Example 32 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class EffectiveNodeType method getApplicableChildNodeDef.

/**
     * Returns the applicable child node definition for a child node with the
     * specified name and node type. If there are multiple applicable definitions
     * named definitions will take precedence over residual definitions.
     *
     * @param name
     * @param nodeTypeName
     * @param ntReg
     * @return
     * @throws NoSuchNodeTypeException
     * @throws ConstraintViolationException if no applicable child node definition
     *                                      could be found
     */
public QNodeDefinition getApplicableChildNodeDef(Name name, Name nodeTypeName, NodeTypeRegistry ntReg) throws NoSuchNodeTypeException, ConstraintViolationException {
    EffectiveNodeType entTarget;
    if (nodeTypeName != null) {
        entTarget = ntReg.getEffectiveNodeType(nodeTypeName);
    } else {
        entTarget = null;
    }
    // try named node definitions first
    QItemDefinition[] defs = getNamedItemDefs(name);
    for (QItemDefinition def : defs) {
        if (def.definesNode()) {
            QNodeDefinition nd = (QNodeDefinition) def;
            Name[] types = nd.getRequiredPrimaryTypes();
            // node definition with that name exists
            if (entTarget != null && types != null) {
                // check 'required primary types' constraint
                if (entTarget.includesNodeTypes(types)) {
                    // found named node definition
                    return nd;
                }
            } else if (nd.getDefaultPrimaryType() != null) {
                // found node definition with default node type
                return nd;
            }
        }
    }
    // no item with that name defined;
    // try residual node definitions
    QNodeDefinition[] nda = getUnnamedNodeDefs();
    for (QNodeDefinition nd : nda) {
        if (entTarget != null && nd.getRequiredPrimaryTypes() != null) {
            // check 'required primary types' constraint
            if (!entTarget.includesNodeTypes(nd.getRequiredPrimaryTypes())) {
                continue;
            }
            // found residual node definition
            return nd;
        } else {
            // it must be determined from the default node type;
            if (nd.getDefaultPrimaryType() != null) {
                // found residual node definition with default node type
                return nd;
            }
        }
    }
    // no applicable definition found
    throw new ConstraintViolationException("no matching child node definition found for " + name);
}
Also used : ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) Name(org.apache.jackrabbit.spi.Name)

Example 33 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class PrivilegeRegistry method getBits.

/**
     * Best effort approach to calculate bits for built-in privileges. Throws
     * <code>UnsupportedOperationException</code> if the workaround fails.
     * 
     * @param privileges An array of privileges.
     * @return The privilege bits.
     * @throws AccessControlException If the specified array is null
     * or if it contains an unregistered privilege.
     * @see #getPrivileges(int)
     * @deprecated Use {@link PrivilegeManagerImpl#getBits(javax.jcr.security.Privilege...)} instead.
     */
public static int getBits(Privilege[] privileges) throws AccessControlException {
    if (privileges == null || privileges.length == 0) {
        throw new AccessControlException("Privilege array is empty or null.");
    }
    Map<String, String> lookup = new HashMap<String, String>(2);
    lookup.put(Name.NS_REP_PREFIX, Name.NS_REP_URI);
    lookup.put(Name.NS_JCR_PREFIX, Name.NS_JCR_URI);
    int bits = NO_PRIVILEGE;
    for (Privilege priv : privileges) {
        String prefix = Text.getNamespacePrefix(priv.getName());
        if (lookup.containsKey(prefix)) {
            Name n = NAME_FACTORY.create(lookup.get(prefix), Text.getLocalName(priv.getName()));
            if (PRIVILEGE_NAMES.containsKey(n)) {
                bits |= PRIVILEGE_NAMES.get(n);
            } else if (NameConstants.JCR_WRITE.equals(n)) {
                bits |= createJcrWriteDefinition().bits.longValue();
            } else if (REP_WRITE_NAME.equals(n)) {
                Definition jcrWrite = createJcrWriteDefinition();
                bits |= createRepWriteDefinition(jcrWrite).bits.longValue();
            } else if (NameConstants.JCR_ALL.equals(n)) {
                for (Name pn : PRIVILEGE_NAMES.keySet()) {
                    bits |= PRIVILEGE_NAMES.get(pn);
                }
            } else {
                throw new AccessControlException("Unknown privilege '" + priv.getName() + "'.");
            }
        } else {
            throw new AccessControlException("Unknown privilege '" + priv.getName() + "'.");
        }
    }
    return bits;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege) Name(org.apache.jackrabbit.spi.Name)

Example 34 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class PrivilegeRegistry method registerDefinition.

//-----------------------------------< methods used by PrivilegeManager >---
/**
     * Validates and registers a new custom privilege definition with the
     * specified characteristics. Upon successful registration the new custom
     * definition is persisted in the corresponding file system resource.<p/>
     *
     * <p>The validation includes the following steps:</p>
     *
     * <ul>
     * <li>assert uniqueness of the specified privilegeName</li>
     * <li>make sure the name doesn't use a reserved namespace</li>
     * <li>assert that all names referenced in the specified name set refer
     * to existing privilege definitions.</li>
     * </ul>
     *
     * @param privilegeName
     * @param isAbstract
     * @param declaredAggregateNames
     * @throws RepositoryException If the privilege could not be registered due
     * to constraint violations or if persisting the custom privilege fails.
     */
void registerDefinition(Name privilegeName, boolean isAbstract, Set<Name> declaredAggregateNames) throws RepositoryException {
    PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, isAbstract, declaredAggregateNames);
    Map<Name, PrivilegeDefinition> stubs = Collections.singletonMap(privilegeName, def);
    registerCustomDefinitions(stubs);
    // inform clustering about the new privilege.
    if (eventChannel != null) {
        eventChannel.registeredPrivileges(stubs.values());
    }
}
Also used : PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) Name(org.apache.jackrabbit.spi.Name)

Example 35 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class ACLEditor method setPolicy.

/**
     * @see AccessControlEditor#setPolicy(String,AccessControlPolicy)
     */
public void setPolicy(String nodePath, AccessControlPolicy policy) throws RepositoryException {
    checkProtectsNode(nodePath);
    checkValidPolicy(nodePath, policy);
    NodeImpl aclNode = getAclNode(nodePath);
    if (aclNode != null) {
        // remove all existing aces
        for (NodeIterator aceNodes = aclNode.getNodes(); aceNodes.hasNext(); ) {
            NodeImpl aceNode = (NodeImpl) aceNodes.nextNode();
            removeItem(aceNode);
        }
    } else {
        // create the acl node
        aclNode = (nodePath == null) ? createRepoAclNode() : createAclNode(nodePath);
    }
    AccessControlEntry[] entries = ((ACLTemplate) policy).getAccessControlEntries();
    for (AccessControlEntry entry : entries) {
        AccessControlEntryImpl ace = (AccessControlEntryImpl) entry;
        Name nodeName = getUniqueNodeName(aclNode, ace.isAllow() ? "allow" : "deny");
        Name ntName = (ace.isAllow()) ? NT_REP_GRANT_ACE : NT_REP_DENY_ACE;
        ValueFactory vf = session.getValueFactory();
        // create the ACE node
        NodeImpl aceNode = addNode(aclNode, nodeName, ntName);
        // write the rep:principalName property
        String principalName = ace.getPrincipal().getName();
        setProperty(aceNode, P_PRINCIPAL_NAME, vf.createValue(principalName));
        // ... and the rep:privileges property
        Privilege[] pvlgs = ace.getPrivileges();
        Value[] names = getPrivilegeNames(pvlgs, vf);
        setProperty(aceNode, P_PRIVILEGES, names);
        // store the restrictions:
        Set<Name> restrNames = ace.getRestrictions().keySet();
        for (Name restrName : restrNames) {
            Value value = ace.getRestriction(restrName);
            setProperty(aceNode, restrName, value);
        }
    }
    // mark the parent modified.
    markModified(((NodeImpl) aclNode.getParent()));
}
Also used : NodeIterator(javax.jcr.NodeIterator) AccessControlEntryImpl(org.apache.jackrabbit.core.security.authorization.AccessControlEntryImpl) NodeImpl(org.apache.jackrabbit.core.NodeImpl) AccessControlEntry(javax.jcr.security.AccessControlEntry) ValueFactory(javax.jcr.ValueFactory) Name(org.apache.jackrabbit.spi.Name) Value(javax.jcr.Value) Privilege(javax.jcr.security.Privilege)

Aggregations

Name (org.apache.jackrabbit.spi.Name)382 RepositoryException (javax.jcr.RepositoryException)101 ArrayList (java.util.ArrayList)57 QValue (org.apache.jackrabbit.spi.QValue)42 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)39 HashSet (java.util.HashSet)38 Path (org.apache.jackrabbit.spi.Path)38 NodeId (org.apache.jackrabbit.core.id.NodeId)37 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)33 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)32 NodeId (org.apache.jackrabbit.spi.NodeId)32 PropertyId (org.apache.jackrabbit.core.id.PropertyId)29 HashMap (java.util.HashMap)28 NamespaceException (javax.jcr.NamespaceException)28 NodeState (org.apache.jackrabbit.core.state.NodeState)28 Value (javax.jcr.Value)25 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)25 InternalValue (org.apache.jackrabbit.core.value.InternalValue)23 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)22 PropertyState (org.apache.jackrabbit.core.state.PropertyState)22