3 using System.Security.Permissions;
4 using System.Threading;
8 static void ShowStackTrace (object o)
11 Console.WriteLine ((int)o);
14 Console.WriteLine (Environment.UserName);
17 catch (SecurityException se) {
19 Console.WriteLine ("EXPECTED SecurityException {0}", se);
21 catch (Exception ex) {
22 Console.WriteLine ("UNEXPECTED {0}", ex);
28 static int result = 0;
30 // this Deny will prevent the Environment.UserName property from working
31 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
32 static int Main (string[] args)
34 debug = (args.Length > 0);
36 SecurityManager.SecurityEnabled = (args [0] != "off");
39 if (SecurityManager.SecurityEnabled) {
40 Console.WriteLine ("SecurityManager.SecurityEnabled: true");
41 ShowStackTrace ((object)-1);
43 Console.WriteLine ("SecurityManager.SecurityEnabled: false");
47 for (int i=0; i < 5; i++)
48 ThreadPool.QueueUserWorkItem (new WaitCallback (ShowStackTrace), i);
50 System.Threading.Thread.Sleep (5000);