G
Guest
I have an issue that is making no sense. I have code that sets up code
access security. In my Windows Form application, I am able to do to create
an instance of the user control "Requisition" with no exceptions if the user
has the proper role:
<Security.Permissions.PrincipalPermissionAttribute(Security.Permissions.SecurityAction.Demand, Role:="Application Administrator")> _
Public Class Requisition
Inherits System.Windows.Forms.UserControl
Using this exact same code in the exact same way fails when I try to create
the user control in a WPF Application. I get a "Request for principal
permission failed" exception message.
I am performing the following code:
System.AppDomain.CurrentDomain.SetPrincipalPolicy(Security.Principal.PrincipalPolicy.WindowsPrincipal)
mPrincipal = System.Threading.Thread.CurrentPrincipal
mUserPrincipalIdentity = mPrincipal.Identity
principalIdentityName = mUserPrincipalIdentity.Name.Split("\")
If principalIdentityName.Length >= 1 Then
principalIdentityUserName = principalIdentityName
(principalIdentityName.Length - 1)
End If
Dim roles As New Roles()
Dim roleCollection As RoleCollection
Dim rolesArray As String()
Dim applicationIdentity As Security.Principal.GenericIdentity
roleCollection = roles.FindByEmployeeId(employeeId)
ReDim rolesArray(roleCollection.Count - 1)
Dim x As Integer
x = 0
For Each role As Role In roleCollection
rolesArray(x) = role.Name
x += 1
Next
' Create generic identity.
applicationIdentity = New
Security.Principal.GenericIdentity(principalIdentityUserName )
' Create generic principal.
mApplicationPrincipal = New
Security.Principal.GenericPrincipal(applicationIdentity, rolesArray)
'set the thread to run under this new identity
System.Threading.Thread.CurrentPrincipal = mApplicationPrincipal
access security. In my Windows Form application, I am able to do to create
an instance of the user control "Requisition" with no exceptions if the user
has the proper role:
<Security.Permissions.PrincipalPermissionAttribute(Security.Permissions.SecurityAction.Demand, Role:="Application Administrator")> _
Public Class Requisition
Inherits System.Windows.Forms.UserControl
Using this exact same code in the exact same way fails when I try to create
the user control in a WPF Application. I get a "Request for principal
permission failed" exception message.
I am performing the following code:
System.AppDomain.CurrentDomain.SetPrincipalPolicy(Security.Principal.PrincipalPolicy.WindowsPrincipal)
mPrincipal = System.Threading.Thread.CurrentPrincipal
mUserPrincipalIdentity = mPrincipal.Identity
principalIdentityName = mUserPrincipalIdentity.Name.Split("\")
If principalIdentityName.Length >= 1 Then
principalIdentityUserName = principalIdentityName
(principalIdentityName.Length - 1)
End If
Dim roles As New Roles()
Dim roleCollection As RoleCollection
Dim rolesArray As String()
Dim applicationIdentity As Security.Principal.GenericIdentity
roleCollection = roles.FindByEmployeeId(employeeId)
ReDim rolesArray(roleCollection.Count - 1)
Dim x As Integer
x = 0
For Each role As Role In roleCollection
rolesArray(x) = role.Name
x += 1
Next
' Create generic identity.
applicationIdentity = New
Security.Principal.GenericIdentity(principalIdentityUserName )
' Create generic principal.
mApplicationPrincipal = New
Security.Principal.GenericPrincipal(applicationIdentity, rolesArray)
'set the thread to run under this new identity
System.Threading.Thread.CurrentPrincipal = mApplicationPrincipal