Skip to content

Commit

Permalink
TUSCANY-4030 - add doPriviliged calls. Thanks for the patch Kaushik.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk@1304257 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Simon Laws committed Mar 23, 2012
1 parent 9db9edc commit d85c071
Showing 1 changed file with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -150,7 +153,19 @@ private void loadOnDemand(XSDefinition definition) throws IOException {
}
XmlSchema schema = null;
try {
schema = schemaCollection.read(definition.getDocument(), uri, null);
final XSDefinition finaldef = definition;
final String finaluri = uri;
try {
schema = (XmlSchema) AccessController.doPrivileged(new PrivilegedExceptionAction<XmlSchema>() {
public XmlSchema run() throws IOException {
return schemaCollection.read(finaldef.getDocument(), finaluri, null);
}
});
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}
} catch (IOException e) {
throw new ContributionRuntimeException(e);
} catch (RuntimeException e) {
// find original cause of the problem
Throwable cause = e;
Expand Down Expand Up @@ -179,14 +194,35 @@ private void loadOnDemand(XSDefinition definition) throws IOException {
}
if (schema == null) {
InputSource xsd = null;
final XSDefinition finaldef = definition;
try {
xsd = XMLDocumentHelper.getInputSource(definition.getLocation().toURL());
try {
xsd = (InputSource) AccessController.doPrivileged(new PrivilegedExceptionAction<InputSource>() {
public InputSource run() throws IOException {
return XMLDocumentHelper.getInputSource(finaldef.getLocation().toURL());
}
});
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}
} catch (IOException e) {
throw new ContributionRuntimeException(e);
}

try {
schema = schemaCollection.read(xsd, null);
final InputSource finalxsd = xsd;
try {
schema = (XmlSchema) AccessController.doPrivileged(new PrivilegedExceptionAction<XmlSchema>() {
public XmlSchema run() throws IOException {
return schemaCollection.read(finalxsd, null);
}
});
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}

} catch (IOException e) {
throw new ContributionRuntimeException(e);
} catch (RuntimeException e) {
// find original cause of the problem
Throwable cause = e;
Expand Down Expand Up @@ -343,7 +379,16 @@ public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace,
resolved =
import_.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved, context);
if (!resolved.isUnresolved()) {
return XMLDocumentHelper.getInputSource(resolved.getLocation().toURL());
final XSDefinition finalres = resolved;
try {
return (InputSource)AccessController.doPrivileged( new PrivilegedExceptionAction<InputSource>() {
public InputSource run() throws IOException {
return XMLDocumentHelper.getInputSource(finalres.getLocation().toURL());
}
});
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}
}
}
}
Expand Down Expand Up @@ -381,7 +426,17 @@ public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace,
}
}
}
return XMLDocumentHelper.getInputSource(url);
try {
final URL finalurl = url;
return (InputSource)AccessController.doPrivileged( new PrivilegedExceptionAction<InputSource>() {
public InputSource run() throws IOException {
return XMLDocumentHelper.getInputSource(finalurl);
}
});
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
}

} catch (IOException e) {
// Invalid URI; return a default InputSource so that the
// XmlSchema code will produce a useful diagnostic
Expand Down

0 comments on commit d85c071

Please sign in to comment.