(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.XML / System.Xml / XmlSecureResolver.cs
blob580d3b56fcf039f4062cf8c72d61adbefcd47fc0
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #if NET_1_0
23 #endif
24 #if NET_1_1
26 // System.Xml.XmlSecureResolver.cs
28 // Author: Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
30 // (C) 2003 Atsushi Enomoto
32 using System;
33 using System.Net;
34 using System.Security;
35 using System.Security.Policy;
36 using System.Security.Permissions;
38 namespace System.Xml
40 public class XmlSecureResolver : XmlResolver
43 #region Static Members
45 public static Evidence CreateEvidenceForUrl (string securityUrl)
47 Evidence e = new Evidence ();
48 Url url = null;
49 Zone zone = null;
50 Site site = null;
52 if (securityUrl != null) {
53 try {
54 if (securityUrl.Length > 0)
55 url = new Url (securityUrl);
56 } catch (ArgumentException) {
59 try {
60 zone = Zone.CreateFromUrl (securityUrl);
61 } catch (ArgumentException) {
64 try {
65 if (securityUrl.Length > 0)
66 site = Site.CreateFromUrl (securityUrl);
67 } catch (ArgumentException) {
71 if (url != null)
72 e.AddHost (url);
73 if (zone != null)
74 e.AddHost (zone);
75 if (site != null)
76 e.AddHost (site);
78 return e;
80 #endregion
82 XmlResolver resolver;
83 PermissionSet permissionSet;
84 // Evidence evidence;
86 #region .ctor and Finalizer
88 public XmlSecureResolver (
89 XmlResolver resolver, Evidence evidence)
91 this.resolver = resolver;
92 // this.evidence = evidence;
93 this.permissionSet = SecurityManager.ResolvePolicy (evidence);
96 public XmlSecureResolver (
97 XmlResolver resolver, PermissionSet permissionSet)
99 this.resolver = resolver;
100 this.permissionSet = permissionSet;
103 public XmlSecureResolver (
104 XmlResolver resolver, string securityUrl)
105 : this (resolver, CreateEvidenceForUrl (securityUrl))
108 #endregion
110 #region Property
112 public override ICredentials Credentials {
113 set { resolver.Credentials = value; }
116 #endregion
118 #region Methods
120 public override object GetEntity (
121 Uri absoluteUri, string role, Type ofObjectToReturn)
123 permissionSet.PermitOnly ();
124 return resolver.GetEntity (absoluteUri, role, ofObjectToReturn);
127 public override Uri ResolveUri (Uri baseUri, string relativeUri)
129 return resolver.ResolveUri (baseUri, relativeUri);
131 #endregion
135 #endif