Search in sources :

Example 16 with ParsingContentHandler

use of org.apache.jackrabbit.commons.xml.ParsingContentHandler in project jackrabbit by apache.

the class AccessControlImporterTest method testImportACLOnly.

/**
     * Imports a resource-based ACL containing a single entry.
     *
     * @throws Exception
     */
public void testImportACLOnly() throws Exception {
    try {
        NodeImpl target = (NodeImpl) testRootNode.addNode(nodeName1);
        target.addMixin("rep:AccessControllable");
        InputStream in = new ByteArrayInputStream(XML_POLICY_TREE_3.getBytes("UTF-8"));
        SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new PseudoConfig());
        ImportHandler ih = new ImportHandler(importer, sImpl);
        new ParsingContentHandler(ih).parse(in);
        String path = target.getPath();
        AccessControlManager acMgr = sImpl.getAccessControlManager();
        AccessControlPolicy[] policies = acMgr.getPolicies(path);
        assertEquals(1, policies.length);
        assertTrue(policies[0] instanceof JackrabbitAccessControlList);
        AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
        assertEquals(2, entries.length);
        AccessControlEntry entry = entries[0];
        assertEquals("everyone", entry.getPrincipal().getName());
        assertEquals(1, entry.getPrivileges().length);
        assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
        entry = entries[1];
        assertEquals("admin", entry.getPrincipal().getName());
        assertEquals(1, entry.getPrivileges().length);
        assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
        if (entry instanceof JackrabbitAccessControlEntry) {
            assertTrue(((JackrabbitAccessControlEntry) entry).isAllow());
        }
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NodeImpl(org.apache.jackrabbit.core.NodeImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 17 with ParsingContentHandler

use of org.apache.jackrabbit.commons.xml.ParsingContentHandler in project jackrabbit by apache.

the class AbstractSession method importXML.

/**
     * Parses the given input stream as an XML document and processes the
     * SAX events using the {@link ContentHandler} returned by
     * {@link Session#getImportContentHandler(String, int)}.
     *
     * @param parentAbsPath passed through
     * @param in input stream to be parsed as XML and imported
     * @param uuidBehavior passed through
     * @throws IOException if an I/O error occurs
     * @throws InvalidSerializedDataException if an XML parsing error occurs
     * @throws RepositoryException if a repository error occurs
     */
public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, InvalidSerializedDataException, RepositoryException {
    try {
        ContentHandler handler = getImportContentHandler(parentAbsPath, uuidBehavior);
        new ParsingContentHandler(handler).parse(in);
    } catch (SAXException e) {
        Throwable exception = e.getException();
        if (exception instanceof RepositoryException) {
            throw (RepositoryException) exception;
        } else if (exception instanceof IOException) {
            throw (IOException) exception;
        } else {
            throw new InvalidSerializedDataException("XML parse error", e);
        }
    } finally {
        // JCR-2903
        if (in != null) {
            try {
                in.close();
            } catch (IOException ignore) {
            }
        }
    }
}
Also used : ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ContentHandler(org.xml.sax.ContentHandler) ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) ToXmlContentHandler(org.apache.jackrabbit.commons.xml.ToXmlContentHandler) SAXException(org.xml.sax.SAXException)

Example 18 with ParsingContentHandler

use of org.apache.jackrabbit.commons.xml.ParsingContentHandler in project jackrabbit-oak by apache.

the class SessionImpl method importXML.

@Override
public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, RepositoryException {
    try {
        ContentHandler handler = getImportContentHandler(checkNotNull(parentAbsPath), uuidBehavior);
        new ParsingContentHandler(handler).parse(in);
    } catch (SAXException e) {
        Throwable exception = e.getException();
        if (exception instanceof RepositoryException) {
            throw (RepositoryException) exception;
        } else if (exception instanceof IOException) {
            throw (IOException) exception;
        } else {
            throw new InvalidSerializedDataException("XML parse error", e);
        }
    } finally {
        // JCR-2903
        if (in != null) {
            try {
                in.close();
            } catch (IOException ignore) {
            }
        }
    }
}
Also used : ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ContentHandler(org.xml.sax.ContentHandler) ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) ToXmlContentHandler(org.apache.jackrabbit.commons.xml.ToXmlContentHandler) SAXException(org.xml.sax.SAXException)

Aggregations

ParsingContentHandler (org.apache.jackrabbit.commons.xml.ParsingContentHandler)18 ByteArrayInputStream (java.io.ByteArrayInputStream)14 InputStream (java.io.InputStream)14 NodeImpl (org.apache.jackrabbit.core.NodeImpl)12 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)10 AccessControlManager (javax.jcr.security.AccessControlManager)9 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)9 AccessControlEntry (javax.jcr.security.AccessControlEntry)8 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)8 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)8 SAXException (org.xml.sax.SAXException)7 IOException (java.io.IOException)6 InvalidSerializedDataException (javax.jcr.InvalidSerializedDataException)4 RepositoryException (javax.jcr.RepositoryException)4 ContentHandler (org.xml.sax.ContentHandler)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)3 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)3 AccessControlList (javax.jcr.security.AccessControlList)2 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)2 ToXmlContentHandler (org.apache.jackrabbit.commons.xml.ToXmlContentHandler)2