[Mono-list] Is PrincipalPermissionAttribute working?
DI Mag. Rainer Burgstaller
rainer.burgstaller@web.de
Mon, 17 May 2004 08:57:14 +0200
Hi
It seems that the PrincipalPermissionAttribute is not working as expected
(at least not as I expect it :)
I checked the class status and it says 100% so I guess this means that it
should work.
I got the following code which works just nice under MS.NET.
<snip>
[PrincipalPermissionAttribute(SecurityAction.Demand, Role="root")]
public void UpdateMember( Member aMember )
{
// do something secret here :)
}
</snip>
When Thread.CurrentPrincipal.IsInRole("root") is false then under windows
this raises a SecurityException (which I think is correct). However, under
mono-0.91 it runs through without any problem (i.e. does not generate the
exception). I verified this by modding the code above to
<snip>
[PrincipalPermissionAttribute(SecurityAction.Demand, Role="root")]
public void UpdateMember( Member aMember )
{
IPrincipal princ = System.Threading.Thread.CurrentPrincipal;
bool adminRole = princ.IsInRole("root");
if ( !adminRole )
throw new Exception("You dont belong to the admins. Go
away");
// do something very secret here
}
</snip>
The modified code raises now the exception.
So here are the two options
a) I dont understand how to use PrincipalPermissionAttribute (which could
easily be true)
b) the mono implementation does not work as expected.
Can anybody help me?