Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Thread.CurrentPrincipal
Message
De
01/10/2009 04:13:06
 
 
À
30/09/2009 21:03:00
Information générale
Forum:
ASP.NET
Catégorie:
Securité
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01426870
Message ID:
01427050
Vues:
51
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform