XmlSecureResolver.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Xml / System / Xml / XmlSecureResolver.cs / 1 / XmlSecureResolver.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
//-----------------------------------------------------------------------------
namespace System.Xml { 
 
    using System.Net;
    using System.Security; 
    using System.Security.Policy;
    using System.Security.Permissions;

    [PermissionSetAttribute( SecurityAction.InheritanceDemand, Name = "FullTrust" )] 
    public class XmlSecureResolver : XmlResolver {
        XmlResolver resolver; 
        PermissionSet permissionSet; 

        public XmlSecureResolver(XmlResolver resolver, string securityUrl) : this(resolver, CreateEvidenceForUrl(securityUrl)) {} 

        public XmlSecureResolver(XmlResolver resolver, Evidence evidence) : this(resolver, SecurityManager.ResolvePolicy(evidence)) {}

        public XmlSecureResolver(XmlResolver resolver, PermissionSet permissionSet) { 
            this.resolver = resolver;
            this.permissionSet = permissionSet; 
        } 

        public override ICredentials Credentials { 
            set { resolver.Credentials = value; }
        }

        public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn) { 
            permissionSet.PermitOnly();
            return resolver.GetEntity(absoluteUri, role, ofObjectToReturn); 
        } 

        public override Uri ResolveUri(Uri baseUri, string relativeUri) { 
            return resolver.ResolveUri(baseUri, relativeUri);
        }

        public static Evidence CreateEvidenceForUrl(string securityUrl) { 
            Evidence evidence = new Evidence();
            if (securityUrl != null && securityUrl.Length > 0) { 
                evidence.AddHost(new Url(securityUrl)); 
                evidence.AddHost(Zone.CreateFromUrl(securityUrl));
                Uri uri = new Uri(securityUrl, UriKind.RelativeOrAbsolute); 
                if (uri.IsAbsoluteUri && !uri.IsFile) {
                    evidence.AddHost(Site.CreateFromUrl(securityUrl));
                }
            } 
            return evidence;
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK