Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to PrincipalPermissionAttribute to secure a class?

1 view
Skip to first unread message

xamman

unread,
Mar 25, 2007, 1:53:06 PM3/25/07
to
hello! anyone ever manage to do this? after trying nearly everything i
can think of my code (below) still gives 'request for principal
permissions failed' .

many thanks


my original post with code and details:

hi there! according to msdn (link at bottom) i should be able to
protect a whole class declaratively as above. However i keep getting
'request for principal permissions failed' exceptions.

in the msdn article a reference is made to include
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal­)
in your code to set the appdomain principal.I can understand how to
use setprincipalpolicy to protect a method declaratively (working
code
example at bottom)


but how do i protect a CLASS?


the question is where & how to SetPrincipalPolicy Declaratively? is
there an attribute in assemblyinfo.vb for this?


many thanks,
X


a)msdn link:
http://msdn2.microsoft.com/en-us/library/system.security.permissions....


b)Protecting a class - this doesnt work (& i tried
role:="administrators", name:="administrator" etc)
<PrincipalPermissionAttribute(SecurityAction.Demand, Role:="BUILTIN
\Administrators") _
Public Class Form1 Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Messagebox("form should load if user is admin")
End Sub


c)Protecting a method - this works ok
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load


AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal­)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
dowork()
End Sub
<PrincipalPermissionAttribute(SecurityAction.Demand,
Role:="BUILTIN
\Administrators")> Sub dowork()
MessageBox.Show("protected")
End Sub
end class

0 new messages