I have the following piece of code. It's fired when a user double-clicks a Listview entry that could be either a user or a group.
If it's a user it calls GetUserInfo which receives my ExtendedUserPrincipal class (an extension of UserPrincipal)
If it's a group it calls GetGroupInfo which receives the standard GroupPrincipal class.
The call to GetUserInfo fails with a "Unable to cast Principal to ExtendedUserPrincipal" error.
Obviously I'm not casting it correctly so what is the best approach to ensure that the principal returned from the FindByIdentity method can be passed to the GetUserInfo sub as ExtendedUserPrincipal?
If it's a user it calls GetUserInfo which receives my ExtendedUserPrincipal class (an extension of UserPrincipal)
If it's a group it calls GetGroupInfo which receives the standard GroupPrincipal class.
The call to GetUserInfo fails with a "Unable to cast Principal to ExtendedUserPrincipal" error.
Obviously I'm not casting it correctly so what is the best approach to ensure that the principal returned from the FindByIdentity method can be passed to the GetUserInfo sub as ExtendedUserPrincipal?
Code:
Dim GroupOrUserObject As Principal = Principal.FindByIdentity(Me.AllEEASObjectsPrincipalContext, IdentityType.Name, GroupOrUserName)
Select Case GroupOrUserObject.StructuralObjectClass.ToUpper
Case "USER"
Lv = Me.UserList
Me.GetUserInfo(DirectCast(GroupOrUserObject, ExtendedUserPrincipal))
Case "GROUP"
Lv = Me.GroupsList
Me.GetGroupInfo(DirectCast(GroupOrUserObject, GroupPrincipal))
Case Else
Return
End Select