本文整理汇总了C#中System.Security.Policy.Evidence类的典型用法代码示例。如果您正苦于以下问题:C# Evidence类的具体用法?C# Evidence怎么用?C# Evidence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Evidence类属于System.Security.Policy命名空间,在下文中一共展示了Evidence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDomainHelper
protected static AppDomain CreateDomainHelper(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
{
if (friendlyName == null)
{
throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_String"));
}
if (securityInfo != null)
{
new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
AppDomain.CheckDomainCreationEvidence(appDomainInfo, securityInfo);
}
if (appDomainInfo == null)
{
appDomainInfo = new AppDomainSetup();
}
if ((appDomainInfo.AppDomainManagerAssembly == null) || (appDomainInfo.AppDomainManagerType == null))
{
string str;
string str2;
AppDomain.CurrentDomain.GetAppDomainManagerType(out str, out str2);
if (appDomainInfo.AppDomainManagerAssembly == null)
{
appDomainInfo.AppDomainManagerAssembly = str;
}
if (appDomainInfo.AppDomainManagerType == null)
{
appDomainInfo.AppDomainManagerType = str2;
}
}
return AppDomain.nCreateDomain(friendlyName, appDomainInfo, securityInfo, (securityInfo == null) ? AppDomain.CurrentDomain.InternalEvidence : null, AppDomain.CurrentDomain.GetSecurityDescriptor());
}
示例2: BuildChildDomain
/// <summary>
/// Creates a new child domain and copies the evidence from a parent domain.
/// </summary>
/// <param name="parentDomain">The parent domain.</param>
/// <returns>The new child domain.</returns>
/// <remarks>
/// Grabs the <paramref name="parentDomain"/> evidence and uses it to construct the new
/// <see cref="AppDomain"/> because in a ClickOnce execution environment, creating an
/// <see cref="AppDomain"/> will by default pick up the partial trust environment of
/// the AppLaunch.exe, which was the root executable. The AppLaunch.exe does a
/// create domain and applies the evidence from the ClickOnce manifests to
/// create the domain that the application is actually executing in. This will
/// need to be Full Trust for Composite Application Library applications.
/// </remarks>
protected virtual AppDomain BuildChildDomain(AppDomain parentDomain)
{
Evidence evidence = new Evidence(parentDomain.Evidence);
AppDomainSetup setup = parentDomain.SetupInformation;
var domain = AppDomain.CreateDomain("DiscoveryRegion", evidence, setup);
return domain;
}
示例3: BuildChildDomain
/// <summary>
/// Creates a new AppDomain based on the parent AppDomains
/// Evidence and AppDomainSetup
/// </summary>
/// <param name="parentDomain">The parent AppDomain</param>
/// <returns>A newly created AppDomain</returns>
private AppDomain BuildChildDomain(AppDomain parentDomain)
{
Evidence evidence = new Evidence(parentDomain.Evidence);
AppDomainSetup setup = parentDomain.SetupInformation;
return AppDomain.CreateDomain("DiscoveryRegion",
evidence, setup);
}
示例4: Start
/// <summary>
/// Starts this instance.
/// </summary>
/// <exception cref="System.InvalidOperationException">Job already started.</exception>
public static void Start()
{
if (_job != null)
throw new InvalidOperationException("Job already started.");
var evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
var setup = new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
ShadowCopyFiles = "false"
};
_appDomain = AppDomain.CreateDomain("eSync-" + Guid.NewGuid(), evidence, setup);
try
{
var assembly = _appDomain.Load(typeof(SyncServiceJob).Assembly.GetName());
var jobTypeName = typeof(SyncServiceJob).FullName;
_job = (IJob)_appDomain.CreateInstanceAndUnwrap(assembly.FullName, jobTypeName);
_job.Start();
}
catch
{
_job = null;
AppDomain.Unload(_appDomain);
_appDomain = null;
throw;
}
}
示例5: RemoteDebugger
public RemoteDebugger()
{
// Create a new debugger session
mSessionId = Guid.NewGuid().ToString();
Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
AppDomainSetup appDomainSetup = AppDomain.CurrentDomain.SetupInformation;
mAppDomain = AppDomain.CreateDomain(String.Format("Debugger-{0}", mSessionId), evidence, appDomainSetup);
/*
Type assemblyLoaderType = typeof(AssemblyLoader);
AssemblyLoader loader = mAppDomain.CreateInstanceAndUnwrap(assemblyLoaderType.Assembly.GetName().Name, assemblyLoaderType.FullName) as AssemblyLoader;
foreach (String assemblyPath in Directory.GetFiles(DebuggerConfig.ApplicationPath, "Tridion*.dll"))
{
loader.LoadAssembly(assemblyPath);
}
*/
Type debuggerHostType = typeof(DebugEngineServer);
mDebuggerHost = mAppDomain.CreateInstanceAndUnwrap(
debuggerHostType.Assembly.GetName().Name,
debuggerHostType.FullName,
true,
BindingFlags.Default,
null,
new Object[] { mSessionId },
null,
null) as DebugEngineServer;
}
示例6: 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
示例7: BaseVsaEngine
// Constructor.
internal BaseVsaEngine(String language, String version, bool supportDebug)
{
applicationPath = String.Empty;
assemblyVersion = version;
compiledRootNamespace = null;
engineMoniker = String.Empty;
engineName = String.Empty;
engineSite = null;
errorLocale = CultureInfo.CurrentCulture.LCID;
executionEvidence = null;
failedCompilation = false;
genDebugInfo = false;
haveCompiledState = false;
isClosed = false;
isDebugInfoSupported = supportDebug;
isEngineCompiled = false;
isEngineDirty = false;
isEngineInitialized = false;
isEngineRunning = false;
loadedAssembly = null;
rootNamespace = String.Empty;
scriptLanguage = language;
startupClass = null;
startupInstance = null;
vsaItems = null;
}
示例8: BaseVsaEngine
internal BaseVsaEngine(string language, string version, bool supportDebug)
{
this.scriptLanguage = language;
this.assemblyVersion = version;
this.isDebugInfoSupported = supportDebug;
this.executionEvidence = null;
}
示例9: SandboxCreator
public static AppDomain SandboxCreator()
{
CheckMono();
#if RAZOR4
Assert.Ignore("IsolatedRazorEngineServiceTestFixture is not tested with razor 4 as it is not signed!");
#endif
#if MONO
// Mono has no AddHostEvidence or GetHostEvidence.
// We do not run the tests anyway.
return null;
#else
Evidence ev = new Evidence();
ev.AddHostEvidence(new Zone(SecurityZone.Internet));
PermissionSet permSet = SecurityManager.GetStandardSandbox(ev);
// We have to load ourself with full trust
StrongName razorEngineAssembly = typeof(RazorEngineService).Assembly.Evidence.GetHostEvidence<StrongName>();
// We have to load Razor with full trust (so all methods are SecurityCritical)
// This is because we apply AllowPartiallyTrustedCallers to RazorEngine, because
// We need the untrusted (transparent) code to be able to inherit TemplateBase.
// Because in the normal environment/appdomain we run as full trust and the Razor assembly has no security attributes
// it will be completely SecurityCritical.
// This means we have to mark a lot of our members SecurityCritical (which is fine).
// However in the sandbox domain we have partial trust and because razor has no Security attributes that means the
// code will be transparent (this is where we get a lot of exceptions, because we now have different security attributes)
// To work around this we give Razor full trust in the sandbox as well.
StrongName razorAssembly = typeof(RazorTemplateEngine).Assembly.Evidence.GetHostEvidence<StrongName>();
// We trust ourself as well
StrongName testAssembly = typeof(IsolatedRazorEngineServiceTestFixture).Assembly.Evidence.GetHostEvidence<StrongName>();
AppDomainSetup adSetup = new AppDomainSetup();
adSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
AppDomain newDomain = AppDomain.CreateDomain("Sandbox", null, adSetup, permSet, razorEngineAssembly, razorAssembly, testAssembly);
return newDomain;
#endif
}
示例10: Arrange
protected override void Arrange()
{
base.Arrange();
var fullyTrustedAssemblies = this.GetFullyTrustedAssemblies().ToArray();
var unsignedAssemblies = fullyTrustedAssemblies.Where(sn => sn.PublicKey.ToString() == "");
if (unsignedAssemblies.Any())
{
Assert.Inconclusive("Full trust assemblies must be signed. This test will be ignored. Unsigned assemblies: " + unsignedAssemblies.Aggregate("", (a, sn) => a + sn.Name + " "));
}
var evidence = new Evidence();
evidence.AddHostEvidence(new Zone(SecurityZone.Intranet));
var set = SecurityManager.GetStandardSandbox(evidence);
this.AddPermissions(set);
this.appDomain =
AppDomain.CreateDomain(
"partial trust",
null,
AppDomain.CurrentDomain.SetupInformation,
set,
fullyTrustedAssemblies);
this.loggerProxy = ((LoggerProxy)this.appDomain.CreateInstanceAndUnwrap(typeof(LoggerProxy).Assembly.FullName, typeof(LoggerProxy).FullName));
this.loggerProxy.Setup();
}
示例11: compile
private Result compile(Input input)
{
Compiler compiler;
Result r;
System.AppDomain unitDomain = null;
try
{
Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
unitDomain = AppDomain.CreateDomain("uTestDomain", evidence, setup);
Type type = typeof(Compiler);
compiler = (Compiler)unitDomain.CreateInstanceFrom(
type.Assembly.Location,
type.FullName).Unwrap();
foreach (string s in GetAssemblies(Assembly.GetExecutingAssembly()))
{
compiler.LoadAssembly(s);
}
r = compiler.Compile(input);
}
finally
{
if (unitDomain != null) System.AppDomain.Unload(unitDomain);
}
return r;
}
示例12: CreatePermissionSet
/*!*/
private static PermissionSet CreatePermissionSet()
{
#if CLR2
string name = "Internet";
bool foundName = false;
PermissionSet setIntersection = new PermissionSet(PermissionState.Unrestricted);
// iterate over each policy level
IEnumerator e = SecurityManager.PolicyHierarchy();
while (e.MoveNext()) {
PolicyLevel level = (PolicyLevel)e.Current;
PermissionSet levelSet = level.GetNamedPermissionSet(name);
if (levelSet != null) {
foundName = true;
setIntersection = setIntersection.Intersect(levelSet);
}
}
if (setIntersection == null || !foundName) {
setIntersection = new PermissionSet(PermissionState.None);
} else {
setIntersection = new NamedPermissionSet(name, setIntersection);
}
return setIntersection;
#else
// this functionality is not available on Mono (AddHostEvidence is undefined), use dynamic to resolve it at runtime
dynamic e = new Evidence();
e.AddHostEvidence(new Zone(SecurityZone.Internet));
return SecurityManager.GetStandardSandbox((Evidence)e);
#endif
}
示例13: Main
static void Main(string[] args)
{
// Create the permission set to grant to other assemblies.
// In this case we are granting the permissions found in the LocalIntranet zone.
PermissionSet permissionSet = GetNamedPermissionSet("LocalIntranet");
if (permissionSet == null)
return;
AppDomainSetup appDomainSetup = new AppDomainSetup();
// Identify the folder to use for the sandbox.
Directory.CreateDirectory("C:\\Sandbox");
appDomainSetup.ApplicationBase = "C:\\Sandbox";
// Copy the application to be executed to the sandbox.
File.Copy(@"..\..\..\NewConsoleApp\Bin\Debug\NewConsoleApp.exe",
"C:\\sandbox\\NewConsoleApp.exe", true);
File.Copy(@"..\..\..\NewConsoleApp\Bin\Debug\NewConsoleApp.pdb",
"C:\\sandbox\\NewConsoleApp.pdb", true);
Evidence hostEvidence = new Evidence();
// Create the sandboxed domain.
AppDomain sandbox = AppDomain.CreateDomain(
"Sandboxed Domain",
hostEvidence,
appDomainSetup,
permissionSet,
GetStrongName(Assembly.GetExecutingAssembly()));
sandbox.ExecuteAssemblyByName("NewConsoleApp");
}
示例14: Load
public static LoadedAssembly Load(String assemblyFilePath)
{
string currentExecutingAssemblyPath = Assembly.GetExecutingAssembly().Location;
if (currentExecutingAssemblyPath.StartsWith("File:"))
currentExecutingAssemblyPath = currentExecutingAssemblyPath.Substring(9).Replace("/", "\\");
else if (string.IsNullOrWhiteSpace(currentExecutingAssemblyPath))
currentExecutingAssemblyPath = Assembly.GetExecutingAssembly().CodeBase.Substring(9).Replace("/", "\\");
string newAppDomainFolderPath = currentExecutingAssemblyPath.Substring(0, currentExecutingAssemblyPath.LastIndexOf("\\"));
string tempAppDomainName = Guid.NewGuid().ToString();
var appDomainSecurity = new Evidence(AppDomain.CurrentDomain.Evidence);
AppDomain appDomain = AppDomain.CreateDomain(
friendlyName: tempAppDomainName,
securityInfo: appDomainSecurity,
appBasePath: newAppDomainFolderPath,
appRelativeSearchPath: null,
shadowCopyFiles: true);
FileLoader fileLoader = (FileLoader)appDomain.CreateInstanceAndUnwrap(
Assembly.GetExecutingAssembly().FullName, typeof(FileLoader).FullName);
Assembly assembly = fileLoader.LoadAssembly(assemblyFilePath);
return new LoadedAssembly { Module = assembly, Domain = appDomain };
}
示例15: 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;
}