当前位置: 首页>>代码示例>>C#>>正文


C# Evidence.GetHostEvidence方法代码示例

本文整理汇总了C#中System.Security.Policy.Evidence.GetHostEvidence方法的典型用法代码示例。如果您正苦于以下问题:C# Evidence.GetHostEvidence方法的具体用法?C# Evidence.GetHostEvidence怎么用?C# Evidence.GetHostEvidence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Policy.Evidence的用法示例。


在下文中一共展示了Evidence.GetHostEvidence方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: URLString

        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = null;

            if (evidence == null)
                return false;

            ApplicationDirectory dir = evidence.GetHostEvidence<ApplicationDirectory>();
            Url url = evidence.GetHostEvidence<Url>();

            if (dir != null && url != null)
            {
                // We need to add a wildcard at the end because IsSubsetOf keys off of it.
                String appDir = dir.Directory;
                
                if (appDir != null && appDir.Length > 1)
                {
                    if (appDir[appDir.Length-1] == '/')
                        appDir += "*";
                    else
                        appDir += "/*";
                    
                    URLString appDirString = new URLString(appDir);
                    if (url.GetURLString().IsSubsetOf(appDirString))
                    {
                        usedEvidence = dir;
                        return true;
                    }
                }
            }
            
            return false;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:33,代码来源:ApplicationDirectoryMembershipCondition.cs

示例2: URLString

 bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
 {
     usedEvidence = null;
     if (evidence != null)
     {
         ApplicationDirectory hostEvidence = evidence.GetHostEvidence<ApplicationDirectory>();
         Url url = evidence.GetHostEvidence<Url>();
         if ((hostEvidence != null) && (url != null))
         {
             string directory = hostEvidence.Directory;
             if ((directory != null) && (directory.Length > 1))
             {
                 if (directory[directory.Length - 1] == '/')
                 {
                     directory = directory + "*";
                 }
                 else
                 {
                     directory = directory + "/*";
                 }
                 URLString operand = new URLString(directory);
                 if (url.GetURLString().IsSubsetOf(operand))
                 {
                     usedEvidence = hostEvidence;
                     return true;
                 }
             }
         }
     }
     return false;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:31,代码来源:ApplicationDirectoryMembershipCondition.cs

示例3: CalculateAssemblyPolicy

 private PolicyStatement CalculateAssemblyPolicy(Evidence evidence)
 {
     Url hostEvidence = evidence.GetHostEvidence<Url>();
     if (hostEvidence != null)
     {
         return this.CalculatePolicy(hostEvidence);
     }
     return new PolicyStatement(new PermissionSet(false), PolicyStatementAttribute.Nothing);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:FileCodeGroup.cs

示例4:

        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = null;

            if (evidence == null)
                return false;

            return evidence.GetHostEvidence<GacInstalled>() != null;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:9,代码来源:GACMembershipCondition.cs

示例5: DetermineApplicationTrust

 public virtual ApplicationTrust DetermineApplicationTrust(Evidence applicationEvidence, Evidence activatorEvidence, TrustManagerContext context)
 {
     if (applicationEvidence == null)
     {
         throw new ArgumentNullException("applicationEvidence");
     }
     ActivationArguments hostEvidence = applicationEvidence.GetHostEvidence<ActivationArguments>();
     if (hostEvidence == null)
     {
         throw new ArgumentException(Environment.GetResourceString("Policy_MissingActivationContextInAppEvidence"));
     }
     ActivationContext activationContext = hostEvidence.ActivationContext;
     if (activationContext == null)
     {
         throw new ArgumentException(Environment.GetResourceString("Policy_MissingActivationContextInAppEvidence"));
     }
     ApplicationTrust applicationTrust = applicationEvidence.GetHostEvidence<ApplicationTrust>();
     if ((applicationTrust != null) && !CmsUtils.CompareIdentities(applicationTrust.ApplicationIdentity, hostEvidence.ApplicationIdentity, ApplicationVersionMatch.MatchExactVersion))
     {
         applicationTrust = null;
     }
     if (applicationTrust == null)
     {
         if ((AppDomain.CurrentDomain.ApplicationTrust != null) && CmsUtils.CompareIdentities(AppDomain.CurrentDomain.ApplicationTrust.ApplicationIdentity, hostEvidence.ApplicationIdentity, ApplicationVersionMatch.MatchExactVersion))
         {
             applicationTrust = AppDomain.CurrentDomain.ApplicationTrust;
         }
         else
         {
             applicationTrust = ApplicationSecurityManager.DetermineApplicationTrustInternal(activationContext, context);
         }
     }
     ApplicationSecurityInfo info = new ApplicationSecurityInfo(activationContext);
     if (((applicationTrust != null) && applicationTrust.IsApplicationTrustedToRun) && !info.DefaultRequestSet.IsSubsetOf(applicationTrust.DefaultGrantSet.PermissionSet))
     {
         throw new InvalidOperationException(Environment.GetResourceString("Policy_AppTrustMustGrantAppRequest"));
     }
     return applicationTrust;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:39,代码来源:HostSecurityManager.cs

示例6: CalculateAssemblyPolicy

 private PolicyStatement CalculateAssemblyPolicy(Evidence evidence)
 {
     PolicyStatement statement = null;
     Url hostEvidence = evidence.GetHostEvidence<Url>();
     if (hostEvidence != null)
     {
         statement = this.CalculatePolicy(hostEvidence.GetURLString().Host, hostEvidence.GetURLString().Scheme, hostEvidence.GetURLString().Port);
     }
     else
     {
         Site site = evidence.GetHostEvidence<Site>();
         if (site != null)
         {
             statement = this.CalculatePolicy(site.Name, null, null);
         }
     }
     if (statement == null)
     {
         statement = new PolicyStatement(new PermissionSet(false), PolicyStatementAttribute.Nothing);
     }
     return statement;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:22,代码来源:NetCodeGroup.cs

示例7: TryResolveGrantSet

        internal static bool TryResolveGrantSet(Evidence evidence, out PermissionSet grantSet)
        {
            Contract.Assert(evidence != null);

            HostSecurityManager securityManager = AppDomain.CurrentDomain.HostSecurityManager;

            // GAC assemblies always are fully trusted
            if (evidence.GetHostEvidence<GacInstalled>() != null)
            {
                grantSet = new PermissionSet(PermissionState.Unrestricted);
                return true;
            }
            // If the host wants to participate in policy resolution, then our next option is to ask it for
            // a grant set
            else if ((securityManager.Flags & HostSecurityManagerOptions.HostResolvePolicy) == HostSecurityManagerOptions.HostResolvePolicy)
            {
                PermissionSet hostGrantSet = securityManager.ResolvePolicy(evidence);

                if (hostGrantSet == null)
                {
                    throw new PolicyException(Environment.GetResourceString("Policy_NullHostGrantSet", securityManager.GetType().FullName));
                }

                // If we're in a homogenous domain, we don't want to allow the host to create multiple
                // levels of permissions within the domain.  So, if we see the host return something other
                // than full trust or the homogenous grant set, we reject the grant set.
                if (AppDomain.CurrentDomain.IsHomogenous)
                {
                    // Some hosts, such as ASP.NET, return Nothing as a way of saying that the assembly should
                    // not be allowed to run in the AppDomain.  Reject that with a specific
                    // no-execution-allowed-here exception message, rather than the return value validation
                    // exception message we'd hit below.
                    if (hostGrantSet.IsEmpty())
                    {
                        throw new PolicyException(Environment.GetResourceString("Policy_NoExecutionPermission"));
                    }

                    PermissionSet homogenousGrantSet = AppDomain.CurrentDomain.ApplicationTrust.DefaultGrantSet.PermissionSet;
                    bool isValidGrantSet = hostGrantSet.IsUnrestricted() ||
                                           (hostGrantSet.IsSubsetOf(homogenousGrantSet) && homogenousGrantSet.IsSubsetOf(hostGrantSet));

                    if (!isValidGrantSet)
                    {
                        throw new PolicyException(Environment.GetResourceString("Policy_GrantSetDoesNotMatchDomain", securityManager.GetType().FullName));
                    }
                }

                grantSet = hostGrantSet;
                return true;
            }
            // If we're in a homogenous domain, we can get the grant set directly from the application trust
            else if (AppDomain.CurrentDomain.IsHomogenous)
            {
                grantSet = AppDomain.CurrentDomain.GetHomogenousGrantSet(evidence);
                return true;
            }
            // Otherwise we have no way to figure out what the grant set is
            else
            {
                grantSet = null;
                return false;
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:63,代码来源:codeaccesssecurityengine.cs

示例8: GetAlternateAppSettingsFolder

		/// <summary>
		/// Determines an alternate application settings folder for the provided details. (This overload really only exists for unit test purposes)
		/// </summary>
		internal static string GetAlternateAppSettingsFolder(string previousInstallDir, Evidence appDomainEvidence, string configurationFilePath)
		{
			try
			{
                //NOTE: the GetHostEvidence<T> method is not implemented on Mono, and this will throw an exception.

				// if the strong name evidence is available for the appdomain, it would've been used and there wouldn't be an 'alternate'
				if (appDomainEvidence.GetHostEvidence<StrongName>() != null) return null;

				// get the current app settings folder name
				var currentAppConfigFolder = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(configurationFilePath)));
				if (string.IsNullOrWhiteSpace(currentAppConfigFolder) || currentAppConfigFolder.Length <= 32) return null;

				// check that it uses the 'Url' type and strip off the hash
				var baseAppConfigFolder = currentAppConfigFolder.Substring(0, currentAppConfigFolder.Length - 32);
				if (!baseAppConfigFolder.EndsWith("_Url_", StringComparison.InvariantCultureIgnoreCase)) return null;

				// get the url evidence for the appdomain
				var urlEvidence = appDomainEvidence.GetHostEvidence<Url>();
				if (urlEvidence == null) return null;

				// if a previous install directory is known, figure out what the url evidence would have looked like for the same executable in that directory
				// otherwise, just assume it would be same as the current url evidence
				var evidenceInfo = string.IsNullOrWhiteSpace(previousInstallDir) ? urlEvidence.Value : "file:///" + previousInstallDir.TrimEnd('/', '\\') + '/' + Path.GetFileName(new Uri(urlEvidence.Value).LocalPath);

				// normalize the evidence info: this is what changed between CLR 2.0 and 4.0 - the choice of slash type!
				// if the slash behavior changes again in a future CLR, this code may need to be modified to compute and try multiple possibilities
				evidenceInfo = evidenceInfo.Replace('\\', '/').ToUpperInvariant();

				// now concatenate the base folder name with the evidence hash to get the 'alternate' folder name, and return it if it's actually different
				var formerAppConfigFolder = baseAppConfigFolder + ComputeEvidenceHash(evidenceInfo);
				return formerAppConfigFolder != currentAppConfigFolder ? formerAppConfigFolder : null;
			}
			catch (Exception ex)
			{
				// if any exception is thrown, just log and continue
				Platform.Log(LogLevel.Debug, ex, "Failure while attempting to determine an alternate application settings directory");
				return null;
			}
		}
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:43,代码来源:UserUpgradeStrategy.cs

示例9:

 bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
 {
     usedEvidence = null;
     if (evidence != null)
     {
         Zone hostEvidence = evidence.GetHostEvidence<Zone>();
         if (hostEvidence != null)
         {
             if ((this.m_zone == System.Security.SecurityZone.NoZone) && (this.m_element != null))
             {
                 this.ParseZone();
             }
             if (hostEvidence.SecurityZone == this.m_zone)
             {
                 usedEvidence = hostEvidence;
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:21,代码来源:ZoneMembershipCondition.cs

示例10: ParseURL

        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = null;

            if (evidence == null)
                return false;

            Url url = evidence.GetHostEvidence<Url>();
            if (url != null)
            {
                if (m_url == null && m_element != null)
                {
                    ParseURL();
                }

                if (url.GetURLString().IsSubsetOf(m_url))
                {
                    usedEvidence = url;
                    return true;
                }
            }

            return false;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:24,代码来源:URLMembershipCondition.cs

示例11: lock

 bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
 {
     usedEvidence = null;
     if (evidence != null)
     {
         Hash hostEvidence = evidence.GetHostEvidence<Hash>();
         if (hostEvidence != null)
         {
             if ((this.m_value == null) && (this.m_element != null))
             {
                 this.ParseHashValue();
             }
             if ((this.m_hashAlg == null) && (this.m_element != null))
             {
                 this.ParseHashAlgorithm();
             }
             byte[] first = null;
             lock (this.InternalSyncObject)
             {
                 first = hostEvidence.GenerateHash(this.m_hashAlg);
             }
             if ((first != null) && CompareArrays(first, this.m_value))
             {
                 usedEvidence = hostEvidence;
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:HashMembershipCondition.cs

示例12: GetStandardSandbox

 public static PermissionSet GetStandardSandbox(Evidence evidence)
 {
     if (evidence == null)
     {
         throw new ArgumentNullException("evidence");
     }
     Zone hostEvidence = evidence.GetHostEvidence<Zone>();
     if (hostEvidence == null)
     {
         return new PermissionSet(PermissionState.None);
     }
     if (hostEvidence.SecurityZone == SecurityZone.MyComputer)
     {
         return new PermissionSet(PermissionState.Unrestricted);
     }
     if (hostEvidence.SecurityZone == SecurityZone.Intranet)
     {
         PermissionSet localIntranet = BuiltInPermissionSets.LocalIntranet;
         PolicyStatement statement = new NetCodeGroup(new AllMembershipCondition()).Resolve(evidence);
         PolicyStatement statement2 = new FileCodeGroup(new AllMembershipCondition(), FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read).Resolve(evidence);
         if (statement != null)
         {
             localIntranet.InplaceUnion(statement.PermissionSet);
         }
         if (statement2 != null)
         {
             localIntranet.InplaceUnion(statement2.PermissionSet);
         }
         return localIntranet;
     }
     if ((hostEvidence.SecurityZone != SecurityZone.Internet) && (hostEvidence.SecurityZone != SecurityZone.Trusted))
     {
         return new PermissionSet(PermissionState.None);
     }
     PermissionSet internet = BuiltInPermissionSets.Internet;
     PolicyStatement statement3 = new NetCodeGroup(new AllMembershipCondition()).Resolve(evidence);
     if (statement3 != null)
     {
         internet.InplaceUnion(statement3.PermissionSet);
     }
     return internet;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:42,代码来源:SecurityManager.cs

示例13: ParseHashValue

        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence) {
            usedEvidence = null;

            if (evidence == null)
                return false;

            Hash hash = evidence.GetHostEvidence<Hash>();
            if (hash != null) {
                if (m_value == null && m_element != null)
                    ParseHashValue();

                if (m_hashAlg == null && m_element != null)
                    ParseHashAlgorithm();

                byte[] asmHash = null;
                lock (InternalSyncObject) {
                    asmHash = hash.GenerateHash(m_hashAlg);
                }

                if (asmHash != null && CompareArrays(asmHash, m_value)) {
                    usedEvidence = hash;
                    return true;
                }
            }

            return false;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:27,代码来源:hashmembershipcondition.cs

示例14: ParseCertificate

        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = null;

            if (evidence == null)
                return false;

            Publisher publisher = evidence.GetHostEvidence<Publisher>();
            if (publisher != null)
            {
                if (m_certificate == null && m_element != null)
                    ParseCertificate();

                // We can't just compare certs directly here because Publisher equality
                // depends only on the keys inside the certs.
                if (publisher.Equals(new Publisher(m_certificate)))
                {
                    usedEvidence = publisher;
                    return true;
                }
            }

            return false;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:24,代码来源:publishermembershipcondition.cs

示例15: ResolvePolicy

        // Query the CLR to see what it would have granted a specific set of evidence
        public virtual PermissionSet ResolvePolicy(Evidence evidence)
        {
            if (evidence == null)
                throw new ArgumentNullException("evidence");
            Contract.EndContractBlock();

            //
            // If the evidence is from the GAC then the result is full trust.
            // In a homogenous domain, then the application trust object provides the grant set.
            // When CAS policy is disabled, the result is full trust.
            // Otherwise, the result comes from evaluating CAS policy.
            //

            if (evidence.GetHostEvidence<GacInstalled>() != null)
            {
                return new PermissionSet(PermissionState.Unrestricted);
            }
            else if (AppDomain.CurrentDomain.IsHomogenous)
            {
                return AppDomain.CurrentDomain.GetHomogenousGrantSet(evidence);
            }
            else if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
            {
                return new PermissionSet(PermissionState.Unrestricted);
            }
            else
            {
                return SecurityManager.PolicyManager.CodeGroupResolve(evidence, false);
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:31,代码来源:hostsecuritymanager.cs


注:本文中的System.Security.Policy.Evidence.GetHostEvidence方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。