[Mono-bugs] [Bug 76332][Maj] New - Thread principal is not copied when a new thread is created

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Oct 4 19:19:58 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by bwalker2002 at hotmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=76332

--- shadow/76332	2005-10-04 19:19:58.000000000 -0400
+++ shadow/76332.tmp.22421	2005-10-04 19:19:58.000000000 -0400
@@ -0,0 +1,157 @@
+Bug#: 76332
+Product: Mono: Runtime
+Version: 1.1
+OS: All
+OS Details: Fedora Core 4
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: misc
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: bwalker2002 at hotmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Thread principal is not copied when a new thread is created
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+Description of Problem: When creating a new thread the principal of the 
+current thread is not copied to the new thread. In Microsoft .NET runtime 
+a principal object is copied from the current thread to the new thread. 
+
+
+Steps to reproduce the problem: Using this test program the principal is 
+set and then a thread is created. In Mono the new thread does not have 
+the principal set correctly. My app requires this behavior to check 
+security on what each thread is allowed to do based on what user 
+information is set for that thread.
+
+
+using System;
+using System.Security.Principal;
+using System.Threading;
+
+namespace fred
+{
+    public class t1
+    {
+	    static void Main(string[] args)
+	    {
+	        t1 x = new t1();
+	        x.Go();
+	    }
+
+	    private void Go()
+	    {
+	        IPrincipal p = Thread.CurrentPrincipal;
+	        Console.WriteLine("Before: p = {0} ({1}/{2}/
+{3}).",p,p.Identity.Name,p.Identity.AuthenticationType,p.Identity.IsAuthen
+ticated);
+
+	        try {
+
+		    Console.WriteLine("Loading user....");
+                MyIdentity identity = new MyIdentity("foo","bar",true);
+                MyPrincipal principal = new MyPrincipal(identity);
+                Thread.CurrentPrincipal = principal;
+		        Console.WriteLine("User loaded successfully!");
+
+	    	    p = Thread.CurrentPrincipal;
+	            Console.WriteLine("After: p = {0} ({1}/{2}/
+{3}).",p,p.Identity.Name,p.Identity.AuthenticationType,p.Identity.IsAuthen
+ticated);
+
+		        Thread t = new Thread(new ThreadStart
+(ThreadMethod));
+		        t.Start();
+
+                Thread.Sleep(2000);
+	        }
+	        catch (Exception ex) {
+		        while (ex != null) {
+		            Console.WriteLine(ex.Message);
+		            ex = ex.InnerException;
+		        }
+	        }
+	    }
+
+	    private void ThreadMethod()
+	    {
+	        IPrincipal p = Thread.CurrentPrincipal;
+	        Console.WriteLine("InThread: p = {0} ({1}/{2}/
+{3}).",p,p.Identity.Name,p.Identity.AuthenticationType,p.Identity.IsAuthen
+ticated);
+	    }
+    }
+
+    public class MyIdentity : IIdentity
+    {
+        private string _name;
+        private string _authType;
+        private bool _isauth;
+
+        public MyIdentity(string name,string authType,bool isauth)
+        {
+            _name = name;
+            _authType = authType;
+            _isauth = isauth;
+        }
+        public string Name
+        {
+            get { return _name; }
+        }
+        public bool IsAuthenticated
+        {
+            get { return _isauth; }
+        }
+        public string AuthenticationType
+        {
+            get { return _authType; }
+        }
+    }
+
+    public class MyPrincipal : IPrincipal
+    {
+        private MyIdentity _identity;
+
+        public MyPrincipal(MyIdentity identity)
+        {
+            _identity = identity;
+        }
+        public IIdentity Identity
+        {
+            get { return _identity; }
+        }
+        public bool IsInRole(string role)
+        {
+            return false;
+        }
+    }
+}
+
+Actual Results: Under Fedora $ running Mono 1.1.9.1 this is the output:
+
+Before: p = System.Security.Principal.GenericPrincipal (//False).
+Loading user....
+User loaded successfully!
+After: p = fred.MyPrincipal (foo/bar/True).
+InThread: p = System.Security.Principal.GenericPrincipal (//False).
+
+
+Expected Results: Under Windows running Microsoft .NET 1.1 this is the 
+output:
+
+Before: p = System.Security.Principal.GenericPrincipal (//False).
+Loading user....
+User loaded successfully!
+After: p = fred.MyPrincipal (foo/bar/True).
+InThread: p = fred.MyPrincipal (foo/bar/True).
+
+
+How often does this happen? Everytime
+
+
+Additional Information:


More information about the mono-bugs mailing list