internal static PolicyStatement ResolveCodeGroup(CodeGroup codeGroup, Evidence evidence) { if (codeGroup.GetType().Assembly != typeof(UnionCodeGroup).Assembly) { evidence.MarkAllEvidenceAsUsed(); } return(codeGroup.Resolve(evidence)); }
#pragma warning disable 618 internal static PolicyStatement ResolveCodeGroup(CodeGroup codeGroup, Evidence evidence) { // Custom code groups won't know how to mark the evidence they're using, so we need to // be pessimistic and mark it all as used if we encounter a code group from outside of mscorlib. if (codeGroup.GetType().Assembly != typeof(UnionCodeGroup).Assembly) { evidence.MarkAllEvidenceAsUsed(); } return(codeGroup.Resolve(evidence)); }
// Retrieve the resolved policy based on Evidence from the executing // assembly found in the specified code group. private static string ResolveEvidence(CodeGroup fileCodeGroup) { string policyString = ""; // Resolve the policy based on evidence in the executing assembly. Assembly assembly = typeof(Members).Assembly; Evidence executingEvidence = assembly.Evidence; PolicyStatement policy = fileCodeGroup.Resolve(executingEvidence); if (policy != null) { policyString = policy.ToString(); } return(policyString); }
internal static PermissionSet AddPermissionForUri(PermissionSet originalPermSet, Uri srcUri) { PermissionSet result = originalPermSet; if (srcUri != null) { Evidence evidence = new Evidence(); evidence.AddHost(new Url(BindUriHelper.UriToString(srcUri))); IMembershipCondition membershipCondition = new UrlMembershipCondition(BindUriHelper.UriToString(srcUri)); CodeGroup codeGroup = srcUri.IsFile ? new FileCodeGroup(membershipCondition, FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery) : new NetCodeGroup(membershipCondition); PolicyStatement policyStatement = codeGroup.Resolve(evidence); if (!policyStatement.PermissionSet.IsEmpty()) { result = originalPermSet.Union(policyStatement.PermissionSet); } } return(result); }
internal static PermissionSet AddPermissionForUri(PermissionSet originalPermSet, Uri srcUri) { PermissionSet newPermSet = originalPermSet; if (srcUri != null) { Evidence evidence = new Evidence(); evidence.AddHost(new Url(BindUriHelper.UriToString(srcUri))); // important: the parameter must be a UrL object not a UrI object IMembershipCondition membership = new UrlMembershipCondition(BindUriHelper.UriToString(srcUri)); CodeGroup group = (srcUri.IsFile) ? (CodeGroup) new FileCodeGroup(membership, FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery) :(CodeGroup) new NetCodeGroup(membership); PolicyStatement policy = group.Resolve(evidence); if (!policy.PermissionSet.IsEmpty()) { newPermSet = originalPermSet.Union(policy.PermissionSet); } } return(newPermSet); }
// Retrieve the resolved policy based on executing evidence found // in the specified code group. private static string ResolveEvidence(CodeGroup codeGroup) { string policyString = "None"; // Resolve the policy based on the executing assembly's evidence. //<Snippet19> Assembly assembly = typeof(Members).Assembly; Evidence executingEvidence = assembly.Evidence; PolicyStatement policy = codeGroup.Resolve(executingEvidence); //</Snippet19> if (policy != null) { policyString = policy.ToString(); } return(policyString); }