3 using System.Security.Permissions;
4 using System.Security.Principal;
5 using System.Threading;
7 // Note: this should also fail if you replace "me" with your username
9 [PrincipalPermission (SecurityAction.LinkDemand, Name="me")]
10 public class LinkDemand {
12 static public int Test ()
14 Console.WriteLine ("*1* [this should not print]");
19 class LinkDemandTest {
23 Console.WriteLine ("[this should not print - as JIT will reject the LinkDemand]");
25 GenericIdentity identity = new GenericIdentity ("me");
26 string[] roles = new string [1] { "mono hacker" };
27 Thread.CurrentPrincipal = new GenericPrincipal (identity, roles);
29 // Note: if the next line is commented then no exception will
30 // be thrown as the JIT will never reach the LinkDemand class
31 return LinkDemand.Test ();
35 static int Main (string[] args)
40 catch (SecurityException se) {
41 Console.WriteLine ("*0* Expected SecurityException\n{0}", se);
45 Console.WriteLine ("*2* Unexpected Exception\n{0}", e);