fix finduserwithfilter
This commit is contained in:
parent
a2b0959f22
commit
d9df329256
@ -168,10 +168,13 @@ Public Class ActiveDirectoryInterface
|
|||||||
Dim oUserEx As UserPrincipalEx = UserPrincipalEx.FindByIdentity(oContext, IdentityType.SamAccountName, oUser.SamAccountName)
|
Dim oUserEx As UserPrincipalEx = UserPrincipalEx.FindByIdentity(oContext, IdentityType.SamAccountName, oUser.SamAccountName)
|
||||||
Dim oCustomAttributes As New List(Of ADUser.CustomAttribute)
|
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)
|
_logger.Debug("User '{0}' was skipped out due to user filter.", oUserEx.SamAccountName)
|
||||||
Continue For
|
Continue For
|
||||||
End If
|
End If
|
||||||
|
_logger.Debug("User '{0}' passed the filter.", oUserEx.SamAccountName)
|
||||||
|
|
||||||
' TODO: Figure out why oUserEx can be nothing for certain users
|
' TODO: Figure out why oUserEx can be nothing for certain users
|
||||||
If oUserEx IsNot Nothing Then
|
If oUserEx IsNot Nothing Then
|
||||||
@ -225,33 +228,40 @@ Public Class ActiveDirectoryInterface
|
|||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Function FindUserWithFilter(User As UserPrincipalEx, Filter As String) As Boolean
|
Public Function FindUserWithFilter(User As UserPrincipalEx, Filter As String) As Boolean
|
||||||
Dim oRootPath = String.Join(","c, User.DistinguishedName.Split(","c).Skip(1))
|
Try
|
||||||
Dim oPlaceholder = "@SAMACCOUNTNAME"
|
Dim oRootPath = String.Join(","c, User.DistinguishedName.Split(","c).Skip(1))
|
||||||
Dim oEntry As New DirectoryEntry("LDAP://" & oRootPath) With {
|
Dim oPlaceholder = "@SAMACCOUNTNAME"
|
||||||
.Username = Nothing,
|
Dim oProtocol = "LDAP://"
|
||||||
.Password = Nothing,
|
Dim oEntry As New DirectoryEntry(oProtocol & oRootPath) With {
|
||||||
.AuthenticationType = AuthenticationTypes.Secure
|
.Username = Nothing,
|
||||||
}
|
.Password = Nothing,
|
||||||
|
.AuthenticationType = AuthenticationTypes.Secure
|
||||||
|
}
|
||||||
|
|
||||||
If Filter = String.Empty Then
|
If Filter = String.Empty Then
|
||||||
_logger.Warn("FindUserWithFilter: Filter was empty, returning True for User {0}", User.SamAccountName)
|
_logger.Warn("FindUserWithFilter: Filter was empty, returning True for User {0}", User.SamAccountName)
|
||||||
Return True
|
Return True
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If Filter.Contains(oPlaceholder) Then
|
If Filter.Contains(oPlaceholder) Then
|
||||||
Filter = Filter.Replace(oPlaceholder, User.SamAccountName)
|
Filter = Filter.Replace(oPlaceholder, User.SamAccountName)
|
||||||
Else
|
Else
|
||||||
_logger.Warn("FindUserWithFilter: Placeholder '{0}' was not found in filter. Results may not be correct.")
|
_logger.Warn("FindUserWithFilter: Placeholder '{0}' was not found in filter. Results may not be correct.")
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Dim oSearcher As New DirectorySearcher(oEntry, Filter)
|
Dim oSearcher As New DirectorySearcher(oEntry, Filter)
|
||||||
Dim oResult = oSearcher.FindOne()
|
Dim oResult As SearchResult = oSearcher.FindOne()
|
||||||
|
|
||||||
If oResult Is Nothing Then
|
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
|
Return False
|
||||||
Else
|
End Try
|
||||||
Return True
|
|
||||||
End If
|
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function GetRootNode() As DirectoryEntry
|
Private Function GetRootNode() As DirectoryEntry
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user