fix finduserwithfilter

This commit is contained in:
Jonathan Jenne 2019-11-12 11:16:02 +01:00
parent a2b0959f22
commit d9df329256

View File

@ -168,10 +168,13 @@ Public Class ActiveDirectoryInterface
Dim oUserEx As UserPrincipalEx = UserPrincipalEx.FindByIdentity(oContext, IdentityType.SamAccountName, oUser.SamAccountName)
Dim oCustomAttributes As New List(Of ADUser.CustomAttribute)
If FindUserWithFilter(oUserEx, Filter) = False Then
Dim oUserFound = FindUserWithFilter(oUserEx, Filter)
If oUserFound = False Then
_logger.Debug("User '{0}' was skipped out due to user filter.", oUserEx.SamAccountName)
Continue For
End If
_logger.Debug("User '{0}' passed the filter.", oUserEx.SamAccountName)
' TODO: Figure out why oUserEx can be nothing for certain users
If oUserEx IsNot Nothing Then
@ -225,9 +228,11 @@ Public Class ActiveDirectoryInterface
End Function
Public Function FindUserWithFilter(User As UserPrincipalEx, Filter As String) As Boolean
Try
Dim oRootPath = String.Join(","c, User.DistinguishedName.Split(","c).Skip(1))
Dim oPlaceholder = "@SAMACCOUNTNAME"
Dim oEntry As New DirectoryEntry("LDAP://" & oRootPath) With {
Dim oProtocol = "LDAP://"
Dim oEntry As New DirectoryEntry(oProtocol & oRootPath) With {
.Username = Nothing,
.Password = Nothing,
.AuthenticationType = AuthenticationTypes.Secure
@ -245,13 +250,18 @@ Public Class ActiveDirectoryInterface
End If
Dim oSearcher As New DirectorySearcher(oEntry, Filter)
Dim oResult = oSearcher.FindOne()
Dim oResult As SearchResult = oSearcher.FindOne()
If oResult Is Nothing Then
Return False
Else
If oResult IsNot Nothing AndAlso oResult.Path.Replace(oProtocol, String.Empty) = User.DistinguishedName Then
Return True
Else
Return False
End If
Catch ex As Exception
_logger.Warn("FindUserWithFilter: Unhandled exception.")
_logger.Error(ex)
Return False
End Try
End Function
Private Function GetRootNode() As DirectoryEntry