diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2012-03-23 10:01:07 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2012-03-23 10:01:07 +0000 |
commit | 24419ba73dd90f8f99d7b6b611416a4e3f25e7f7 (patch) | |
tree | aa56f972be1c61dba100fbca3075a86679611978 /sca-java-2.x/trunk | |
parent | cf37829a4e02ff994207c890d40280fc0c2c7fea (diff) |
TUSCANY-4030 - add doPriviliged calls. Thanks for the patch Kaushik.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1304257 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r-- | sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java b/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java index 80bdeb1a41..60a59e62ee 100644 --- a/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java +++ b/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java @@ -23,6 +23,9 @@ import java.io.IOException; 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; @@ -150,7 +153,19 @@ public class XSDModelResolver implements ModelResolver { } 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; @@ -179,14 +194,35 @@ public class XSDModelResolver implements ModelResolver { } 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; @@ -343,7 +379,16 @@ public class XSDModelResolver implements ModelResolver { 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(); + } } } } @@ -381,7 +426,17 @@ public class XSDModelResolver implements ModelResolver { } } } - 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 |