Search in sources :

Example 11 with PropInfo

use of org.apache.jackrabbit.oak.spi.xml.PropInfo in project jackrabbit-oak by apache.

the class AccessControlImporterBaseTest method testUnknownRestriction.

@Test(expected = ValueFormatException.class)
public void testUnknownRestriction() throws Exception {
    init();
    importer.start(aclTree);
    importer.startChildInfo(aceInfo, ImmutableList.of(principalInfo, privInfo));
    PropInfo invalidRestrProp = new PropInfo("unknown", PropertyType.STRING, createTextValue("val"));
    importer.startChildInfo(restrInfo, ImmutableList.of(invalidRestrProp));
    importer.endChildInfo();
    importer.endChildInfo();
    importer.end(aclTree);
}
Also used : PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 12 with PropInfo

use of org.apache.jackrabbit.oak.spi.xml.PropInfo in project jackrabbit-oak by apache.

the class AccessControlImporterBaseTest method testImportWithRestrictions.

@Test
public void testImportWithRestrictions() throws Exception {
    // single value restriction
    PropInfo globInfo = new PropInfo(REP_GLOB, PropertyType.STRING, createTextValue("/*"));
    // mv restriction
    PropInfo ntNamesInfo = new PropInfo(REP_NT_NAMES, PropertyType.NAME, createTextValues(NodeTypeConstants.NT_OAK_RESOURCE, NodeTypeConstants.NT_OAK_RESOURCE));
    // mv restriction with singular value
    PropInfo itemNamesInfo = new PropInfo(REP_ITEM_NAMES, PropertyType.NAME, createTextValue("itemName"));
    init();
    importer.start(aclTree);
    importer.startChildInfo(aceInfo, ImmutableList.of(principalInfo, privInfo, globInfo, ntNamesInfo, itemNamesInfo));
    importer.endChildInfo();
    importer.end(aclTree);
    assertImport(aclTree, principalName);
}
Also used : PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 13 with PropInfo

use of org.apache.jackrabbit.oak.spi.xml.PropInfo in project jackrabbit-oak by apache.

the class AccessControlImporterIgnoreTest method testImportWithUnknownPrincipal.

@Test
public void testImportWithUnknownPrincipal() throws Exception {
    init();
    importer.start(aclTree);
    PropInfo privs = new PropInfo(REP_PRIVILEGES, PropertyType.NAME, createTextValues(PrivilegeConstants.JCR_READ));
    importer.startChildInfo(aceInfo, ImmutableList.of(unknownPrincipalInfo, privs));
    importer.endChildInfo();
    importer.end(aclTree);
    // ace with invalid principal is ignored with this behaviour => ace tree not imported
    assertFalse(aclTree.getChildren().iterator().hasNext());
}
Also used : PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) Test(org.junit.Test)

Example 14 with PropInfo

use of org.apache.jackrabbit.oak.spi.xml.PropInfo in project jackrabbit-oak by apache.

the class DocViewImportHandler method startElement.

//-------------------------------------------------------< ContentHandler >
/**
     * {@inheritDoc}
     * <p>
     * See also {@link org.apache.jackrabbit.commons.xml.Exporter#exportProperties(Node)}
     * regarding special handling of multi-valued properties on export.
     */
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    // process buffered character data
    processCharacters();
    try {
        NameInfo nameInfo = new NameInfo(qName);
        nameInfo = processName(nameInfo);
        // properties
        String id = null;
        String nodeTypeName = null;
        Iterable<String> mixinTypes = null;
        List<PropInfo> props = new ArrayList<PropInfo>(atts.getLength());
        for (int i = 0; i < atts.getLength(); i++) {
            if (atts.getURI(i).equals(NamespaceConstants.NAMESPACE_XMLNS)) {
                // see http://issues.apache.org/jira/browse/JCR-620#action_12448164
                continue;
            }
            NameInfo propNameInfo = processName(new NameInfo(atts.getQName(i)));
            String attrValue = atts.getValue(i);
            if (NamespaceRegistry.NAMESPACE_JCR.equals(propNameInfo.getNamespaceUri()) && "primaryType".equals(propNameInfo.getLocalName())) {
                // jcr:primaryType
                if (!attrValue.isEmpty()) {
                    //TODO
                    nodeTypeName = attrValue;
                }
            } else if (NamespaceRegistry.NAMESPACE_JCR.equals(propNameInfo.getNamespaceUri()) && "mixinTypes".equals(propNameInfo.getLocalName())) {
                // jcr:mixinTypes
                mixinTypes = parseNames(attrValue);
            } else if (NamespaceRegistry.NAMESPACE_JCR.equals(propNameInfo.getNamespaceUri()) && "uuid".equals(propNameInfo.getLocalName())) {
                // jcr:uuid
                if (!attrValue.isEmpty()) {
                    id = attrValue;
                }
            } else {
                // always assume single-valued property for the time being
                // until a way of properly serializing/detecting multi-valued
                // properties on re-import is found (see JCR-325);
                // see also DocViewSAXEventGenerator#leavingProperties(Node, int)
                // TODO proper multi-value serialization support
                TextValue tv = new StringValue(attrValue, sessionContext.getValueFactory(), currentNamePathMapper());
                props.add(new PropInfo(propNameInfo.getRepoQualifiedName(), PropertyType.UNDEFINED, tv));
            }
        }
        NodeInfo node = new NodeInfo(nameInfo.getRepoQualifiedName(), nodeTypeName, mixinTypes, id);
        // all information has been collected, now delegate to importer
        importer.startNode(node, props);
        // push current node data onto stack
        stack.push(node);
    } catch (RepositoryException re) {
        throw new SAXException(re);
    }
}
Also used : TextValue(org.apache.jackrabbit.oak.spi.xml.TextValue) NodeInfo(org.apache.jackrabbit.oak.spi.xml.NodeInfo) ArrayList(java.util.ArrayList) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) RepositoryException(javax.jcr.RepositoryException) SAXException(org.xml.sax.SAXException)

Example 15 with PropInfo

use of org.apache.jackrabbit.oak.spi.xml.PropInfo in project jackrabbit-oak by apache.

the class CugImporterTest method testInvalidPropInfo.

@Test
public void testInvalidPropInfo() throws Exception {
    createCug(root, SUPPORTED_PATH, "principalName");
    Tree parent = root.getTree(SUPPORTED_PATH);
    PropInfo propInfo = new PropInfo(JcrConstants.JCR_PRIMARYTYPE, PropertyType.STRING, ImmutableList.of(new TextValue() {

        @Override
        public String getString() {
            return "principalName";
        }

        @Override
        public Value getValue(int targetType) throws RepositoryException {
            return getValueFactory(root).createValue("principalName", PropertyType.STRING);
        }

        @Override
        public void dispose() {
        }
    }));
    PropertyDefinition propDef = Mockito.mock(PropertyDefinition.class);
    assertFalse(importer.handlePropInfo(parent, propInfo, propDef));
}
Also used : TextValue(org.apache.jackrabbit.oak.spi.xml.TextValue) Tree(org.apache.jackrabbit.oak.api.Tree) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Test(org.junit.Test)

Aggregations

PropInfo (org.apache.jackrabbit.oak.spi.xml.PropInfo)15 Test (org.junit.Test)8 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)5 RepositoryException (javax.jcr.RepositoryException)4 SAXException (org.xml.sax.SAXException)4 Tree (org.apache.jackrabbit.oak.api.Tree)3 NodeInfo (org.apache.jackrabbit.oak.spi.xml.NodeInfo)3 TextValue (org.apache.jackrabbit.oak.spi.xml.TextValue)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Reader (java.io.Reader)1 InvalidSerializedDataException (javax.jcr.InvalidSerializedDataException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)1 AccessControlManager (javax.jcr.security.AccessControlManager)1 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)1