Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Thread.CurrentPrincipal
Message
From
01/10/2009 12:15:49
 
 
To
01/10/2009 11:04:48
General information
Forum:
ASP.NET
Category:
Security
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01426870
Message ID:
01427136
Views:
51
Hmm.
Just checked in Winforms and, as you say, the Thread.CurrentPrincipal worked so it must be a WPF thing. Weird!

>Ah, but when I tried it *without* using SetThreadPrincipal() and only set the Thread.CurrentPrincipal, it *still* worked. Could it be a WPF thing? I've started messing with WPF, maybe I'll give it a quick test there sometime today.
>
>~~Bonnie
>
>
>
>
>>Hi,
>>Yes - using SetThreadPrincipal() worked for me - but just setting the Thread.CurrentPricipal did not change the principal in the second form.
>>Since the Principal supplied in SetThreadPrincipal() becomes the default PrincipaI for any newly created threads it seems to me that the behaviour I'm seeing would make perfect sense if the second form was on a different thread but I don't see that that can be the case :-{
>>IAC using SetThreadPrincipal() gives me the result I want so I'm not going to worry about this for now.
>>My code, BTW, was actually from a WPF application using Pages - but we're seeing the same thing anyway....
>>Best,
>>Viv
>>
>>>Bear in mind that I know absolutely nothing about this security stuff ... but I tried this and it seemed to work ok for me. Doesn't help you much, I know, but I *do* wonder what's different (I didn't set the stuff at app startup ... maybe that makes a difference?).
>>>
>>>I called this from a button click in one Form:
>>>
>>>
>>>private void TestSecurityPrincipal()
>>>{
>>>	System.Security.Principal.GenericIdentity gi = new System.Security.Principal.GenericIdentity("BB");
>>>	System.Security.Principal.GenericPrincipal gp = new System.Security.Principal.GenericPrincipal(gi, new string[] { "Admin", "Backup" });
>>>
>>>	// Test the value of 
>>>	// Thread.CurrentPrincipal.Identity
>>>	// before and after this breakpoint
>>>	Thread.CurrentPrincipal = gp;
>>>	
>>>	// And again after this next statement executes
>>>	System.AppDomain.CurrentDomain.SetThreadPrincipal(gp);
>>>
>>>	// Next, we're going to open another Form, and try some stuff from that Form.
>>>	//System.Security.Principal.IPrincipal g = System.Threading.Thread.CurrentPrincipal;
>>>	//g.Identity
>>>
>>>	Form4 oForm = new Form4();
>>>	oForm.Show();
>>>}
>>>
>>>
>>>Then, put this in a button click in Form4:
>>>
>>>
>>>System.Security.Principal.IPrincipal g = System.Threading.Thread.CurrentPrincipal;
>>>// Test the value:
>>>//g.Identity
>>>
>>>
>>>All seemed to work.
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>
>>>
>>>>Hi,
>>>>Trying stuff out. I have this code at startup:
GenericIdentity g = new GenericIdentity("Viv");
>>>>GenericPrincipal p = new GenericPrincipal(g,new string[]{"Admin","Backup"});
>>>>Thread.CurrentPrincipal = p;                                                  
>>>>// System.AppDomain.CurrentDomain.SetThreadPrincipal(p);  //Works
then later (in a different form)
System.Security.Principal.IPrincipal g = System.Threading.Thread.CurrentPrincipal;
>>>>but g.Identity at this point is an empty,unauthenticated instance (as it is before setting the Thread.CurrentPrincipal). If I use the CurrentDomain.SetThreadPrincipal version above instead then g.Identity is as expected. AFAICS this is still the same thread so why the difference?
>>>>
>>>>TIA,
>>>>Viv
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform