本文整理汇总了C#中System.Security.Policy.Evidence.AddHost方法的典型用法代码示例。如果您正苦于以下问题:C# Evidence.AddHost方法的具体用法?C# Evidence.AddHost怎么用?C# Evidence.AddHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Policy.Evidence
的用法示例。
在下文中一共展示了Evidence.AddHost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDomain
/// <summary>
/// Construct an application domain for running a test package
/// </summary>
/// <param name="package">The TestPackage to be run</param>
public AppDomain CreateDomain( TestPackage package )
{
AppDomainSetup setup = CreateAppDomainSetup(package);
string domainName = "test-domain-" + package.Name;
// Setup the Evidence
Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
if (evidence.Count == 0)
{
Zone zone = new Zone(SecurityZone.MyComputer);
evidence.AddHost(zone);
Assembly assembly = Assembly.GetExecutingAssembly();
Url url = new Url(assembly.CodeBase);
evidence.AddHost(url);
Hash hash = new Hash(assembly);
evidence.AddHost(hash);
}
log.Info("Creating AppDomain " + domainName);
AppDomain runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup);
// Set PrincipalPolicy for the domain if called for in the settings
if (_settingsService != null && _settingsService.GetSetting("Options.TestLoader.SetPrincipalPolicy", false))
{
runnerDomain.SetPrincipalPolicy(_settingsService.GetSetting(
"Options.TestLoader.PrincipalPolicy",
PrincipalPolicy.UnauthenticatedPrincipal));
}
return runnerDomain;
}
示例2: Check
public void Check ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
Evidence e = null;
Assert.IsFalse (ad.Check (e), "Check (null)");
e = new Evidence ();
Assert.IsFalse (ad.Check (e), "Check (empty)");
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsFalse (ad.Check (e), "Check (zone)");
string codebase = Assembly.GetExecutingAssembly ().CodeBase;
Url u = new Url (codebase);
ApplicationDirectory adir = new ApplicationDirectory (codebase);
e.AddHost (u);
Assert.IsFalse (ad.Check (e), "Check (url-host)"); // not enough
e.AddAssembly (adir);
Assert.IsFalse (ad.Check (e), "Check (url-host+adir-assembly)");
e = new Evidence ();
e.AddHost (adir);
Assert.IsFalse (ad.Check (e), "Check (adir-host)"); // not enough
e.AddAssembly (u);
Assert.IsFalse (ad.Check (e), "Check (url-assembly+adir-host)");
e = new Evidence ();
e.AddHost (u);
e.AddHost (adir);
Assert.IsTrue (ad.Check (e), "Check (url+adir host)"); // both!!
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:30,代码来源:ApplicationDirectoryMembershipConditionTest.cs
示例3: CreateEvidenceForUrl
public static Evidence CreateEvidenceForUrl (string securityUrl)
{
Evidence e = new Evidence ();
if ((securityUrl != null) && (securityUrl.Length > 0)) {
try {
Url url = new Url (securityUrl);
e.AddHost (url);
} catch (ArgumentException) {
}
try {
Zone zone = Zone.CreateFromUrl (securityUrl);
e.AddHost (zone);
} catch (ArgumentException) {
}
try {
Site site = Site.CreateFromUrl (securityUrl);
e.AddHost (site);
} catch (ArgumentException) {
}
}
return e;
}
示例4: CreateDomain
/// <summary>
/// Construct an application domain for running a test package
/// </summary>
/// <param name="package">The TestPackage to be run</param>
public AppDomain CreateDomain( TestPackage package )
{
AppDomainSetup setup = CreateAppDomainSetup(package);
string domainName = "test-domain-" + package.Name;
// Setup the Evidence
Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
if (evidence.Count == 0)
{
Zone zone = new Zone(SecurityZone.MyComputer);
evidence.AddHost(zone);
Assembly assembly = Assembly.GetExecutingAssembly();
Url url = new Url(assembly.CodeBase);
evidence.AddHost(url);
Hash hash = new Hash(assembly);
evidence.AddHost(hash);
}
log.Info("Creating AppDomain " + domainName);
AppDomain runnerDomain;
// TODO: Find an approach that works across all platforms
//// TODO: Try to eliminate this test. Currently, running on
//// Linux with the permission set specified causes an
//// unexplained crash when unloading the domain.
//if (Environment.OSVersion.Platform == PlatformID.Win32NT)
//{
// PermissionSet permissionSet = new PermissionSet( PermissionState.Unrestricted );
// runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup, permissionSet, null);
//}
//else
runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup);
// Set PrincipalPolicy for the domain if called for in the settings
if (ServiceContext.UserSettings.GetSetting("Options.TestLoader.SetPrincipalPolicy", false))
runnerDomain.SetPrincipalPolicy((PrincipalPolicy)ServiceContext.UserSettings.GetSetting(
"Options.TestLoader.PrincipalPolicy", PrincipalPolicy.UnauthenticatedPrincipal));
//// HACK: Only pass down our AddinRegistry one level so that tests of NUnit
//// itself start without any addins defined.
//if ( !IsTestDomain( AppDomain.CurrentDomain ) )
// runnerDomain.SetData("AddinRegistry", Services.AddinRegistry);
//// Inject DomainInitializer into the remote domain - there are other
//// approaches, but this works for all CLR versions.
//DomainInitializer initializer = DomainInitializer.CreateInstance(runnerDomain);
//// HACK: Under nunit-console, direct use of the enum fails
//int traceLevel = IsTestDomain(AppDomain.CurrentDomain)
// ? (int)InternalTraceLevel.Off : (int)InternalTrace.Level;
//initializer.InitializeDomain(traceLevel);
return runnerDomain;
}
示例5: CreateEvidenceForUrl
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;
}
示例6: Check
public void Check ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
Evidence e = null;
Assert.IsFalse (gac.Check (e), "Check (null)");
e = new Evidence ();
Assert.IsFalse (gac.Check (e), "Check (empty)");
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsFalse (gac.Check (e), "Check (zone)");
GacInstalled g = new GacInstalled ();
e.AddAssembly (g);
Assert.IsFalse (gac.Check (e), "Check (gac-assembly)");
e.AddHost (g);
Assert.IsTrue (gac.Check (e), "Check (gac-host)");
}
示例7: CreateInstanceHelper
protected static ObjectHandle CreateInstanceHelper (AppDomainSetup adSetup)
{
if (adSetup == null)
throw new ArgumentNullException ("adSetup");
if (adSetup.ActivationArguments == null) {
string msg = Locale.GetText ("{0} is missing it's {1} property");
throw new ArgumentException (String.Format (msg, "AppDomainSetup", "ActivationArguments"), "adSetup");
}
HostSecurityManager hsm = null;
if (AppDomain.CurrentDomain.DomainManager != null)
hsm = AppDomain.CurrentDomain.DomainManager.HostSecurityManager;
else
hsm = new HostSecurityManager (); // default
Evidence applicationEvidence = new Evidence ();
applicationEvidence.AddHost (adSetup.ActivationArguments);
TrustManagerContext context = new TrustManagerContext ();
ApplicationTrust trust = hsm.DetermineApplicationTrust (applicationEvidence, null, context);
if (!trust.IsApplicationTrustedToRun) {
string msg = Locale.GetText ("Current policy doesn't allow execution of addin.");
throw new PolicyException (msg);
}
// FIXME: we're missing the information from the manifest
AppDomain ad = AppDomain.CreateDomain ("friendlyName", null, adSetup);
return ad.CreateInstance ("assemblyName", "typeName", null);
}
示例8: Check
public void Check ()
{
AllMembershipCondition all = new AllMembershipCondition ();
Evidence e = null;
Assert.IsTrue (all.Check (e), "Check (null)");
e = new Evidence ();
Assert.IsTrue (all.Check (e), "Check (empty)");
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsTrue (all.Check (e), "Check (zone)");
Url u = new Url ("http://www.go-mono.com/");
e.AddAssembly (u);
Assert.IsTrue (all.Check (e), "Check (all-assembly)");
Site s = new Site ("www.go-mono.com");
e.AddHost (s);
Assert.IsTrue (all.Check (e), "Check (all-host)");
}
示例9: Check
public void Check ()
{
ApplicationMembershipCondition app = new ApplicationMembershipCondition ();
Evidence e = null;
Assert.IsFalse (app.Check (e), "Check (null)");
e = new Evidence ();
Assert.IsFalse (app.Check (e), "Check (empty)");
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsFalse (app.Check (e), "Check (zone)");
// TODO - more (non failing ;) tests
}
示例10: ProvideAppDomainEvidence
public void ProvideAppDomainEvidence ()
{
HostSecurityManager hsm = new HostSecurityManager ();
Assert.IsNull (hsm.ProvideAppDomainEvidence (null), "null");
Evidence e = new Evidence ();
Evidence result = hsm.ProvideAppDomainEvidence (e);
Assert.IsNotNull (result, "empty");
Assert.AreEqual (0, result.Count, "Count-0");
e.AddHost (new Zone (SecurityZone.Untrusted));
result = hsm.ProvideAppDomainEvidence (e);
Assert.AreEqual (1, result.Count, "Count-1");
}
示例11: ScriptCompiler
static ScriptCompiler()
{
cParams = new CompilerParameters();
cParams.GenerateExecutable = false;
cParams.GenerateInMemory = false;
cParams.IncludeDebugInformation = false;
//cParams.OutputAssembly=ScriptOutputPath;
cParams.ReferencedAssemblies.Add(System.IO.Path.Combine(Program.ExecutableDirectory, "fomm.Scripting.dll"));
cParams.ReferencedAssemblies.Add("System.dll");
cParams.ReferencedAssemblies.Add("System.Drawing.dll");
cParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
cParams.ReferencedAssemblies.Add("System.Xml.dll");
evidence = new Evidence();
evidence.AddHost(new Zone(System.Security.SecurityZone.Internet));
}
示例12: GenerateShellEvidence
static Evidence GenerateShellEvidence( String fileName, String option )
{
Assembly asm = LoadAssembly( fileName, option, false );
if (asm == null)
{
String fullPath = Path.GetFullPath( fileName );
if (fullPath == null || !File.Exists( fullPath ))
Error( option, manager.GetString( "Error_UnableToLoadAssembly" ), -1 );
if (PolicyPrompt)
{
PauseCapableWriteLine( String.Format( manager.GetString( "Dialog_UseFakeEvidenceQuestion" ), fileName ) );
if (!GetAnswer())
{
PauseCapableWriteLine( manager.GetString( "Dialog_OperationAborted" ) );
throw new ExitException();
}
}
else
{
PauseCapableWriteLine( String.Format( manager.GetString( "Dialog_UseFakeEvidence" ), fileName ) );
}
String fileUrl = "file:///" + fullPath;
Evidence evidence = new Evidence();
evidence.AddHost( Zone.CreateFromUrl( fileUrl ) );
evidence.AddHost( new Url( fileUrl ) );
return evidence;
}
else
{
return asm.Evidence;
}
}
示例13: CheckAddedAssemblies
private static void CheckAddedAssemblies( PolicyLevel level, ref ArrayList assemblies )
{
try
{
if (assemblies == null || level == null)
return;
IEnumerator enumerator = assemblies.GetEnumerator();
while (enumerator.MoveNext())
{
Assembly assembly = (Assembly)enumerator.Current;
StrongName sn = FindStrongName( assembly.Evidence );
if (sn == null)
{
PauseCapableWriteLine( manager.GetString( "Dialog_AssemblyNotStrongNamed" ) );
if (!GetAnswer())
throw new ExitException();
}
else if (!sn.Name.Equals( "mscorlib" ))
{
IEnumerator snEnumerator = level.FullTrustAssemblies.GetEnumerator();
bool found = false;
Evidence evidence = new Evidence();
evidence.AddHost( sn );
while (snEnumerator.MoveNext())
{
if (((StrongNameMembershipCondition)snEnumerator.Current).Check( evidence ))
{
found = true;
break;
}
}
if (!found)
{
PauseCapableWriteLine( manager.GetString( "Dialog_StrongNameAssemblyAdded1" ) );
PauseCapableWriteLine( sn.Name + " " + sn.Version );
PauseCapableWriteLine( manager.GetString( "Dialog_StrongNameAssemblyAdded2" ) );
if (GetAnswer())
{
level.AddFullTrustAssembly( sn );
}
}
}
}
}
finally
{
assemblies = new ArrayList();
}
}
示例14: GetDefaultDomainIdentity
private static Evidence GetDefaultDomainIdentity()
{
Evidence evidence = new Evidence();
bool zoneEvidence = false;
IEnumerator hostEnumerator = AppDomain.CurrentDomain.Evidence.GetHostEnumerator();
while (hostEnumerator.MoveNext())
{
if (hostEnumerator.Current is Zone)
zoneEvidence = true;
evidence.AddHost(hostEnumerator.Current);
}
hostEnumerator = AppDomain.CurrentDomain.Evidence.GetAssemblyEnumerator();
while (hostEnumerator.MoveNext())
{
evidence.AddAssembly(hostEnumerator.Current);
}
if (!zoneEvidence)
evidence.AddHost(new Zone(SecurityZone.MyComputer));
return evidence;
}
示例15: Resolve
// Code Access Security
internal void Resolve ()
{
lock (this) {
// FIXME: As we (currently) delay the resolution until the first CAS
// Demand it's too late to evaluate the Minimum permission set as a
// condition to load the assembly into the AppDomain
LoadAssemblyPermissions ();
Evidence e = new Evidence (UnprotectedGetEvidence ()); // we need a copy to add PRE
e.AddHost (new PermissionRequestEvidence (_minimum, _optional, _refuse));
_granted = SecurityManager.ResolvePolicy (e,
_minimum, _optional, _refuse, out _denied);
}
}