Search in sources :

Example 61 with Name

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

the class AbstractRecord method writePrivilegeDef.

/**
     * {@inheritDoc}
     */
public void writePrivilegeDef(PrivilegeDefinition privilegeDefinition) throws JournalException {
    try {
        Map<String, String> nsMapping = new HashMap<String, String>();
        String uri = privilegeDefinition.getName().getNamespaceURI();
        nsMapping.put(nsResolver.getPrefix(uri), uri);
        for (Name n : privilegeDefinition.getDeclaredAggregateNames()) {
            nsMapping.put(nsResolver.getPrefix(n.getNamespaceURI()), n.getNamespaceURI());
        }
        StringWriter sw = new StringWriter();
        PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter("text/xml");
        writer.writeDefinitions(sw, new PrivilegeDefinition[] { privilegeDefinition }, nsMapping);
        sw.close();
        writeString(sw.toString());
    } catch (IOException e) {
        String msg = "I/O error while writing privilege definition.";
        throw new JournalException(msg, e);
    } catch (NamespaceException e) {
        String msg = "NamespaceException error while writing privilege definition.";
        throw new JournalException(msg, e);
    }
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) NamespaceException(javax.jcr.NamespaceException) PrivilegeDefinitionWriter(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter) IOException(java.io.IOException) Name(org.apache.jackrabbit.spi.Name)

Example 62 with Name

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

the class AbstractRecord method readPathElement.

/**
     * {@inheritDoc}
     */
public Path readPathElement() throws JournalException {
    try {
        Name name = resolver.getQName(readString());
        int index = readInt();
        if (index != 0) {
            return PathFactoryImpl.getInstance().create(name, index);
        } else {
            return PathFactoryImpl.getInstance().create(name);
        }
    } catch (NameException e) {
        String msg = "Unknown prefix error while reading path element.";
        throw new JournalException(msg, e);
    } catch (NamespaceException e) {
        String msg = "Illegal name error while reading path element.";
        throw new JournalException(msg, e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NamespaceException(javax.jcr.NamespaceException) Name(org.apache.jackrabbit.spi.Name)

Example 63 with Name

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

the class PropertyId method valueOf.

/**
     * Returns a property identifier instance holding the value of the
     * specified string. The string must be in the format returned by the
     * {@link #toString() toString()} method of this class.
     *
     * @param s a <code>String</code> containing the <code>PropertyId</code>
     *          representation to be parsed.
     * @return the <code>PropertyId</code> represented by the argument
     * @throws IllegalArgumentException if the specified string can not be parsed
     *                                  as a <code>PropertyId</code>.
     * @see #toString()
     */
public static PropertyId valueOf(String s) throws IllegalArgumentException {
    if (s == null) {
        throw new IllegalArgumentException("invalid PropertyId literal");
    }
    int i = s.indexOf('/');
    if (i == -1) {
        throw new IllegalArgumentException("invalid PropertyId literal");
    }
    String uuid = s.substring(0, i);
    Name name = NameFactoryImpl.getInstance().create(s.substring(i + 1));
    return new PropertyId(NodeId.valueOf(uuid), name);
}
Also used : Name(org.apache.jackrabbit.spi.Name)

Example 64 with Name

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

the class UserImporter method handlePropInfo.

// -----------------------------------------< ProtectedPropertyImporter >---
/**
     * @see ProtectedPropertyImporter#handlePropInfo(org.apache.jackrabbit.core.NodeImpl, org.apache.jackrabbit.core.xml.PropInfo, org.apache.jackrabbit.spi.QPropertyDefinition)
     */
public boolean handlePropInfo(NodeImpl parent, PropInfo protectedPropInfo, QPropertyDefinition def) throws RepositoryException {
    if (!initialized) {
        throw new IllegalStateException("Not initialized");
    }
    /* importer can only handle protected properties below user/group
           nodes that are properly stored underneath the configured users/groups
           hierarchies (see {@link UserManagerImpl#getAuthorizable(NodeImpl)}.
           this prevents from importing user/group nodes somewhere in the
           content hierarchy which isn't possible when creating user/groups
           using the corresponding API calls  {@link UserManager#createUser} or
           {@link UserManager#createGroup} respectively. */
    Authorizable a = userManager.getAuthorizable(parent);
    if (a == null) {
        log.warn("Cannot handle protected PropInfo " + protectedPropInfo + ". Node " + parent + " doesn't represent a valid Authorizable.");
        return false;
    }
    // assert that user manager is isn't in auto-save mode
    if (userManager.isAutoSave()) {
        userManager.autoSave(false);
    }
    try {
        Name propName = protectedPropInfo.getName();
        if (UserConstants.P_PRINCIPAL_NAME.equals(propName)) {
            // protected rep:principalName property defined by rep:Authorizable.
            if (def.isMultiple() || !UserConstants.NT_REP_AUTHORIZABLE.equals(def.getDeclaringNodeType())) {
                // some other unexpected property definition -> cannot handle
                log.warn("Unexpected definition for property rep:principalName");
                return false;
            }
            Value v = protectedPropInfo.getValues(PropertyType.STRING, resolver)[0];
            String princName = v.getString();
            userManager.setPrincipal(parent, new PrincipalImpl(princName));
            /*
                Execute authorizable actions for a NEW group as this is the
                same place in the userManager#createGroup that the actions
                are called.
                In case of a NEW user the actions are executed if the password
                has been imported before.
                */
            if (parent.isNew()) {
                if (a.isGroup()) {
                    userManager.onCreate((Group) a);
                } else if (currentPw.containsKey(a.getID())) {
                    userManager.onCreate((User) a, currentPw.remove(a.getID()));
                }
            }
            return true;
        } else if (UserConstants.P_PASSWORD.equals(propName)) {
            if (a.isGroup()) {
                log.warn("Expected parent node of type rep:User.");
                return false;
            }
            // minimal validation of the passed definition
            if (def.isMultiple() || !UserConstants.NT_REP_USER.equals(def.getDeclaringNodeType())) {
                // some other unexpected property definition -> cannot handle
                log.warn("Unexpected definition for property rep:password");
                return false;
            }
            Value v = protectedPropInfo.getValues(PropertyType.STRING, resolver)[0];
            String pw = v.getString();
            userManager.setPassword(parent, pw, false);
            /*
                 Execute authorizable actions for a NEW user at this point after
                 having set the password if the principal name has already been
                 processed, otherwise postpone it.
                 */
            if (parent.isNew()) {
                if (parent.hasProperty(UserConstants.P_PRINCIPAL_NAME)) {
                    userManager.onCreate((User) a, pw);
                } else {
                    // principal name not yet available -> remember the pw
                    currentPw.clear();
                    currentPw.put(a.getID(), pw);
                }
            }
            return true;
        } else if (UserConstants.P_IMPERSONATORS.equals(propName)) {
            if (a.isGroup()) {
                // unexpected parent type -> cannot handle
                log.warn("Expected parent node of type rep:User.");
                return false;
            }
            // minimal validation of the passed definition
            if (!def.isMultiple() || !UserConstants.MIX_REP_IMPERSONATABLE.equals(def.getDeclaringNodeType())) {
                // some other unexpected property definition -> cannot handle
                log.warn("Unexpected definition for property rep:impersonators");
                return false;
            }
            // since impersonators may be imported later on, postpone processing
            // to the end.
            // see -> process References
            Value[] vs = protectedPropInfo.getValues(PropertyType.STRING, resolver);
            referenceTracker.processedReference(new Impersonators(a.getID(), vs));
            return true;
        } else if (UserConstants.P_DISABLED.equals(propName)) {
            if (a.isGroup()) {
                log.warn("Expected parent node of type rep:User.");
                return false;
            }
            // minimal validation of the passed definition
            if (def.isMultiple() || !UserConstants.NT_REP_USER.equals(def.getDeclaringNodeType())) {
                // some other unexpected property definition -> cannot handle
                log.warn("Unexpected definition for property rep:disabled");
                return false;
            }
            Value v = protectedPropInfo.getValues(PropertyType.STRING, resolver)[0];
            ((User) a).disable(v.getString());
            return true;
        } else if (UserConstants.P_MEMBERS.equals(propName)) {
            if (!a.isGroup()) {
                // unexpected parent type -> cannot handle
                log.warn("Expected parent node of type rep:Group.");
                return false;
            }
            // minimal validation of the passed definition
            if (!def.isMultiple() || !UserConstants.NT_REP_GROUP.equals(def.getDeclaringNodeType())) {
                // some other unexpected property definition -> cannot handle
                log.warn("Unexpected definition for property rep:members");
                return false;
            }
            // since group-members are references to user/groups that potentially
            // are to be imported later on -> postpone processing to the end.
            // see -> process References
            Membership membership = new Membership(a.getID());
            for (Value v : protectedPropInfo.getValues(PropertyType.WEAKREFERENCE, resolver)) {
                membership.addMember(new NodeId(v.getString()));
            }
            referenceTracker.processedReference(membership);
            return true;
        }
        return false;
    } finally {
        // the original state.
        if (resetAutoSave) {
            userManager.autoSave(true);
        }
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Value(javax.jcr.Value) NodeId(org.apache.jackrabbit.core.id.NodeId) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) PrincipalImpl(org.apache.jackrabbit.core.security.principal.PrincipalImpl) Name(org.apache.jackrabbit.spi.Name)

Example 65 with Name

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

the class InternalFrozenNodeImpl method checkin.

/**
     * Checks-in a <code>src</code> node. It creates a new child node of
     * <code>parent</code> with the given <code>name</code> and adds the
     * source nodes properties according to their OPV value to the
     * list of frozen properties. It creates frozen child nodes for each child
     * node of <code>src</code> according to its OPV value.
     *
     * @param parent destination parent
     * @param name new node name
     * @param src source node state
     * @param forceCopy if <code>true</code> the OPV is ignored and a COPY is performed
     * @return the nde node state
     * @throws RepositoryException if an error occurs
     * @throws ItemStateException if an error during reading the items occurs
     */
private static NodeStateEx checkin(NodeStateEx parent, Name name, NodeStateEx src, boolean forceCopy) throws RepositoryException, ItemStateException {
    // create new node
    NodeStateEx node = parent.addNode(name, NameConstants.NT_FROZENNODE, null, true);
    // initialize the internal properties
    node.setPropertyValue(NameConstants.JCR_FROZENUUID, InternalValue.create(src.getNodeId().toString()));
    node.setPropertyValue(NameConstants.JCR_FROZENPRIMARYTYPE, InternalValue.create(src.getState().getNodeTypeName()));
    if (src.hasProperty(NameConstants.JCR_MIXINTYPES)) {
        node.setPropertyValues(NameConstants.JCR_FROZENMIXINTYPES, PropertyType.NAME, src.getPropertyValues(NameConstants.JCR_MIXINTYPES));
    }
    // add the properties
    for (PropertyState prop : src.getProperties()) {
        int opv;
        if (forceCopy) {
            opv = OnParentVersionAction.COPY;
        } else {
            opv = src.getDefinition(prop).getOnParentVersion();
        }
        Name propName = prop.getName();
        if (opv == OnParentVersionAction.ABORT) {
            parent.reload();
            throw new VersionException("Checkin aborted due to OPV abort in " + propName);
        } else if (opv == OnParentVersionAction.VERSION || opv == OnParentVersionAction.COPY) {
            // ignore frozen properties
            if (!propName.equals(NameConstants.JCR_PRIMARYTYPE) && !propName.equals(NameConstants.JCR_MIXINTYPES) && !propName.equals(NameConstants.JCR_UUID) && // JCR-3635: should never occur in normal content...
            !propName.equals(NameConstants.JCR_FROZENPRIMARYTYPE) && !propName.equals(NameConstants.JCR_FROZENMIXINTYPES) && !propName.equals(NameConstants.JCR_FROZENUUID)) {
                node.copyFrom(prop);
            }
        }
    }
    // add the frozen children and histories
    boolean isFull = src.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE);
    for (NodeStateEx child : src.getChildNodes()) {
        int opv;
        if (forceCopy) {
            opv = OnParentVersionAction.COPY;
        } else {
            opv = child.getDefinition().getOnParentVersion();
        }
        if (opv == OnParentVersionAction.ABORT) {
            throw new VersionException("Checkin aborted due to OPV in " + child);
        } else if (opv == OnParentVersionAction.VERSION) {
            if (isFull && child.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE)) {
                // create frozen versionable child
                NodeId histId = child.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
                NodeStateEx newChild = node.addNode(child.getName(), NameConstants.NT_VERSIONEDCHILD, null, false);
                newChild.setPropertyValue(NameConstants.JCR_CHILDVERSIONHISTORY, InternalValue.create(histId));
            } else {
                // else copy
                checkin(node, child.getName(), child, true);
            }
        } else if (opv == OnParentVersionAction.COPY) {
            checkin(node, child.getName(), child, true);
        }
    }
    return node;
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Name(org.apache.jackrabbit.spi.Name) VersionException(javax.jcr.version.VersionException)

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