protected void processCreate()

in src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java [423:498]


    protected void processCreate(Session session, Authorizable authorizable,
            Map<String, RequestProperty> reqProperties,
            List<Modification> changes) throws RepositoryException {

        @NotNull
        String path = authorizable.getPath();
        for (RequestProperty prop : reqProperties.values()) {
            String propName = prop.getName();
            if (JcrConstants.JCR_PRIMARYTYPE.equals(propName) || JcrConstants.JCR_MIXINTYPES.equals(propName)) {
                String parentPath = prop.getParentPath();
                if (parentPath == null && JcrConstants.JCR_PRIMARYTYPE.equals(propName)) {
                    // don't allow changing the primaryType of the user/group root node
                    continue;
                }

                String tp = null;
                if (parentPath == null || "/".equals(parentPath)) {
                    tp = path;
                } else if (parentPath.startsWith("/")){
                    tp = Paths.get(path, parentPath.substring(1)).toString();
                }
                if (tp != null && (tp.equals(path) || Paths.get(tp).startsWith(path))) {
                    Node node = null;
                    if (session.nodeExists(tp)) {
                        node = session.getNode(tp);
                    } else {
                        Node tempNode = session.getNode(path);
                        // create any missing intermediate nodes
                        Iterator<Path> elements = Paths.get(parentPath).iterator();
                        while (elements.hasNext()) {
                            String segment = elements.next().toString();
                            String tempPath = Paths.get(tempNode.getPath(), segment).toString();
                            if (session.nodeExists(tempPath)) {
                                tempNode = session.getNode(tempPath);
                            } else {
                                String primaryType = getPrimaryType(reqProperties, tempPath);
                                if (primaryType != null) {
                                    tempNode = tempNode.addNode(segment, primaryType);
                                } else {
                                    tempNode = tempNode.addNode(segment);
                                }
                                changes.add(Modification.onCreated(tempNode.getPath()));
                            }
                        }
                        node = tempNode;
                    }

                    if (node != null) {
                        // only allow changing the primaryType of the ancestors, not the root
                        if (JcrConstants.JCR_PRIMARYTYPE.equals(propName)) {
                            if (tp.equals(path)) {
                                // don't allow changing the primaryType of the user home root
                                throw new AccessDeniedException("Access denied.");
                            } else {
                                final String nodeType = prop == null ? null : prop.getStringValues()[0];
                                if (nodeType != null && !node.isNodeType(nodeType)) {
                                    node.setPrimaryType(nodeType);
                                    changes.add(Modification.onModified(Paths.get(node.getPath(), propName).toString()));
                                }
                            }
                        } else if (JcrConstants.JCR_MIXINTYPES.equals(propName)) {
                            String[] mixins = (prop == null) || !prop.hasValues() ? null : prop.getStringValues();
                            if (mixins != null) {
                                for (final String mixin : mixins) {
                                    if (!node.isNodeType(mixin)) {
                                        node.addMixin(mixin);
                                        changes.add(Modification.onModified(Paths.get(node.getPath(), propName).toString()));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }