import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
* @param baseURI the base URI to resolve resource URIs against
* @return the requested FopFactory instance.
*/
- public static FopFactory newInstance(URI baseURI) {
- return new FopFactoryBuilder(baseURI).build();
+ public static FopFactory newInstance(final URI baseURI) {
+ return AccessController.doPrivileged(
+ new PrivilegedAction<FopFactory>() {
+ public FopFactory run() {
+ return new FopFactoryBuilder(baseURI).build();
+ }
+ }
+ );
}
/**
package org.apache.fop.fo;
import java.io.OutputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
}
/** {@inheritDoc} */
- public void startElement(String namespaceURI, String localName, String rawName,
- Attributes attlist) throws SAXException {
+ public void startElement(final String namespaceURI, final String localName, final String rawName,
+ final Attributes attlist) throws SAXException {
this.depth++;
errorinstart = false;
- try {
- delegate.startElement(namespaceURI, localName, rawName, attlist);
- } catch (SAXException e) {
+ final ContentHandler contentHandler = delegate;
+ SAXException saxException = AccessController.doPrivileged(
+ new PrivilegedAction<SAXException>() {
+ public SAXException run() {
+ try {
+ contentHandler.startElement(namespaceURI, localName, rawName, attlist);
+ } catch (SAXException e) {
+ return e;
+ }
+ return null;
+ }
+ }
+ );
+ if (saxException != null) {
errorinstart = true;
- throw e;
+ throw saxException;
}
}
/** {@inheritDoc} */
- public void endElement(String uri, String localName, String rawName)
- throws SAXException {
+ public void endElement(final String uri, final String localName, final String rawName) throws SAXException {
if (!errorinstart) {
- this.delegate.endElement(uri, localName, rawName);
+ final ContentHandler contentHandler = delegate;
+ SAXException saxException = AccessController.doPrivileged(
+ new PrivilegedAction<SAXException>() {
+ public SAXException run() {
+ try {
+ contentHandler.endElement(uri, localName, rawName);
+ } catch (SAXException e) {
+ return e;
+ }
+ return null;
+ }
+ }
+ );
+ if (saxException != null) {
+ throw saxException;
+ }
+
this.depth--;
if (depth == 0) {
if (delegate != mainFOHandler) {
package org.apache.fop.apps;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.net.URI;
+import java.security.Permission;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
import org.junit.Test;
import org.xml.sax.SAXException;
fail(e.getMessage());
}
}
+
+ @Test
+ public void testSecurityManager() throws Exception {
+ System.setSecurityManager(new SecurityManager() {
+ public void checkPermission(Permission perm) {
+ for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
+ if (element.toString().contains("java.security.AccessController.doPrivileged")
+ || element.toString().contains("newFop(")
+ || element.toString().contains("setSecurityManager(")) {
+ return;
+ }
+ }
+ throw new RuntimeException("doPrivileged not used for " + perm);
+ }
+ });
+ FopFactory fopFactory = FopFactory.newInstance(new URI("."));
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ String fo = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\" "
+ + "xmlns:fox=\"http://xmlgraphics.apache.org/fop/extensions\">\n"
+ + " <fo:layout-master-set>\n"
+ + " <fo:simple-page-master master-name=\"simple\" page-height=\"27.9cm\" page-width=\"21.6cm\">\n"
+ + " <fo:region-body />\n"
+ + " </fo:simple-page-master>\n"
+ + " </fo:layout-master-set>\n"
+ + " <fo:page-sequence master-reference=\"simple\">\n"
+ + " <fo:flow flow-name=\"xsl-region-body\">\n"
+ + " <fo:block font-size=\"100pt\">test2test2test2test2test2test2test2test2test2test2te"
+ + "st2test2test2test2test2test2test2</fo:block> \n"
+ + "</fo:flow>\n"
+ + " </fo:page-sequence>\n"
+ + "</fo:root>\n";
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, fopFactory.newFOUserAgent(), out);
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ Source src = new StreamSource(new ByteArrayInputStream(fo.getBytes()));
+ Result res = new SAXResult(fop.getDefaultHandler());
+ transformer.transform(src, res);
+ System.setSecurityManager(null);
+ }
}