Search in sources :

Example 1 with PropInfo

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

the class AccessControlImporterBaseTest method testStartAceChildInfoInvalidPrivilege.

@Test(expected = AccessControlException.class)
public void testStartAceChildInfoInvalidPrivilege() throws Exception {
    init();
    importer.start(aclTree);
    PropInfo invalidPrivInfo = new PropInfo(REP_PRIVILEGES, PropertyType.NAME, createTextValues("jcr:invalidPrivilege"), PropInfo.MultipleStatus.MULTIPLE);
    importer.startChildInfo(aceInfo, ImmutableList.of(invalidPrivInfo));
}
Also used : PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with PropInfo

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

the class AccessControlImporterBesteffortTest 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);
    Tree aceTree = aclTree.getChildren().iterator().next();
    assertEquals(unknownPrincipalInfo.getValue(PropertyType.STRING).getString(), TreeUtil.getString(aceTree, REP_PRINCIPAL_NAME));
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) Test(org.junit.Test)

Example 3 with PropInfo

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

the class AccessControlImporterBaseTest method before.

@Override
public void before() throws Exception {
    super.before();
    Tree t = root.getTree(PathUtils.ROOT_PATH).addChild("testNode");
    t.setProperty(JcrConstants.JCR_PRIMARYTYPE, NodeTypeConstants.NT_OAK_UNSTRUCTURED, Type.NAME);
    AccessControlManager acMgr = getAccessControlManager(root);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, t.getPath());
    acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privilegesFromNames(PrivilegeConstants.JCR_READ));
    acMgr.setPolicy(t.getPath(), acl);
    root.commit();
    accessControlledTree = root.getTree("/testNode");
    aclTree = accessControlledTree.getChild(REP_POLICY);
    importer = new AccessControlImporter();
    principalName = getTestUser().getPrincipal().getName();
    principalInfo = new PropInfo(REP_PRINCIPAL_NAME, PropertyType.STRING, createTextValue(principalName));
    privInfo = new PropInfo(REP_PRIVILEGES, PropertyType.NAME, createTextValues(PrivilegeConstants.JCR_READ, PrivilegeConstants.JCR_ADD_CHILD_NODES));
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Tree(org.apache.jackrabbit.oak.api.Tree) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 4 with PropInfo

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

the class AccessControlImporter method startChildInfo.

@Override
public void startChildInfo(@Nonnull NodeInfo childInfo, @Nonnull List<PropInfo> propInfos) throws RepositoryException {
    checkInitialized();
    String ntName = childInfo.getPrimaryTypeName();
    if (NT_REP_GRANT_ACE.equals(ntName) || NT_REP_DENY_ACE.equals(ntName)) {
        if (entry != null) {
            throw new ConstraintViolationException("Invalid child node sequence: ACEs may not be nested.");
        }
        entry = new MutableEntry(NT_REP_GRANT_ACE.equals(ntName));
        for (PropInfo prop : propInfos) {
            String name = prop.getName();
            if (REP_PRINCIPAL_NAME.equals(name)) {
                entry.setPrincipal(prop.getTextValue());
            } else if (REP_PRIVILEGES.equals(name)) {
                entry.setPrivilegeNames(prop.getTextValues());
            } else {
                entry.addRestriction(prop);
            }
        }
        childStatus = CHILD_STATUS_ACE;
    } else if (NT_REP_RESTRICTIONS.equals(ntName)) {
        if (entry == null) {
            throw new ConstraintViolationException("Invalid child node sequence: Restriction must be associated with an ACE");
        }
        entry.addRestrictions(propInfos);
        childStatus = CHILD_STATUS_RESTRICTION;
    } else {
        throw new ConstraintViolationException("Invalid child node with type " + ntName);
    }
}
Also used : ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo)

Example 5 with PropInfo

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

the class SysViewImportHandler method processNode.

private void processNode(ImportState state, boolean start, boolean end) throws SAXException {
    if (!start && !end) {
        return;
    }
    String id = state.uuid;
    NodeInfo node = new NodeInfo(state.nodeName, state.nodeTypeName, state.mixinNames, id);
    // call Importer
    try {
        if (start) {
            importer.startNode(node, state.props);
            // dispose temporary property values
            for (PropInfo pi : state.props) {
                pi.dispose();
            }
        }
        if (end) {
            importer.endNode(node);
        }
    } catch (RepositoryException re) {
        throw new SAXException(re);
    }
}
Also used : NodeInfo(org.apache.jackrabbit.oak.spi.xml.NodeInfo) PropInfo(org.apache.jackrabbit.oak.spi.xml.PropInfo) RepositoryException(javax.jcr.RepositoryException) SAXException(org.xml.sax.SAXException)

Aggregations

PropInfo (org.apache.jackrabbit.oak.spi.xml.PropInfo)16 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 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)2 Reader (java.io.Reader)1 InvalidSerializedDataException (javax.jcr.InvalidSerializedDataException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 AccessControlManager (javax.jcr.security.AccessControlManager)1 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)1 EffectiveNodeType (org.apache.jackrabbit.oak.spi.nodetype.EffectiveNodeType)1 ProtectedPropertyImporter (org.apache.jackrabbit.oak.spi.xml.ProtectedPropertyImporter)1