Kevin Robinson
asked on
IsInRole is returning false
This is part of my security class. but when i call the is in role function it always return false. The current user (administrator) is a member of the VBIGrantsAdministrator group in active directory.
When i show message box of what strings are being return it looks OK.
Private Function GetUsername() As String
Dim Principal As System.Security.Principal. IPrincipal = Nothing
Principal = System.Threading.Thread.Cu rrentPrinc ipal
Dim User As String
User = Principal.Identity.Name
Return User
End Function
Private Function GetDomain() As String
Dim Domain As String = GetUsername().Substring(0, GetUsername().IndexOf("\") + 1)
Return Domain
End Function
Private Function GetIsInRole() As Boolean
Return System.Threading.Thread.Cu rrentPrinc ipal.IsInR ole(Me.Get Domain & "VBIGrantsAdministrator")
End Function
When i show message box of what strings are being return it looks OK.
Private Function GetUsername() As String
Dim Principal As System.Security.Principal.
Principal = System.Threading.Thread.Cu
Dim User As String
User = Principal.Identity.Name
Return User
End Function
Private Function GetDomain() As String
Dim Domain As String = GetUsername().Substring(0,
Return Domain
End Function
Private Function GetIsInRole() As Boolean
Return System.Threading.Thread.Cu
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Imports System.Threading
Public Class Authentication
Public Enum Group
CVSGrantsAdministrator
VBIGrantsAdministrator
MVGrantsAdministrator
End Enum
Function IsInRole(ByVal Group As Group) As Boolean
Dim ReturnValue As Boolean = False
Select Case Group
Case Authentication.Group.CVSGr
ReturnValue = Me.CheckRole("CVSGrantsAdm
Case Authentication.Group.MVGra
ReturnValue = Me.CheckRole("MVGrantsAdmi
Case Authentication.Group.VBIGr
ReturnValue = Me.CheckRole("VBIGrantsAdm
End Select
Return ReturnValue
End Function
Private Function CheckRole(ByVal Group As String) As Boolean
Dim MyPrincipal As System.Security.Principal.
' set the stage by picking type of security principal
AppDomain.CurrentDomain.Se
' get the security principal for this thread
MyPrincipal = CType(System.Threading.Thr
If MyPrincipal.IsInRole(Group
Return True
Else
Return False
End If
End Function
End Class