Interfaces V 2.3
This commit is contained in:
@@ -221,9 +221,12 @@ Public Class ActiveDirectoryInterface
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function FindUserWithFilter(User As UserPrincipalEx, Filter As String) As Boolean
|
||||
Public Function FindUserWithFilter(pUser As UserPrincipalEx, pFilter As String) As Boolean
|
||||
Try
|
||||
Dim oRootPath = String.Join(","c, User.DistinguishedName.Split(","c).Skip(1))
|
||||
Dim oRootPath = String.Join(","c, pUser.DistinguishedName.Split(","c).Skip(1))
|
||||
_logger.Debug("FindUserWithFilter: pUser.DistinguishedName: [{0}]", pUser.DistinguishedName)
|
||||
_logger.Debug("FindUserWithFilter: oRootPath from User.DistinguishedName - oRootPath: [{0}]", oRootPath)
|
||||
|
||||
Dim oPlaceholder = "@SAMACCOUNTNAME"
|
||||
Dim oProtocol = "LDAP://"
|
||||
Dim oEntry As New DirectoryEntry(oProtocol & oRootPath) With {
|
||||
@@ -231,22 +234,24 @@ Public Class ActiveDirectoryInterface
|
||||
.Password = Nothing,
|
||||
.AuthenticationType = AuthenticationTypes.Secure
|
||||
}
|
||||
|
||||
If Filter = String.Empty Then
|
||||
_logger.Debug("FindUserWithFilter: Filter was empty, returning True for User [{0}]", User.SamAccountName)
|
||||
_logger.Debug("FindUserWithFilter: got oDirectoryEntry (Path): [{0}]", oProtocol & oRootPath)
|
||||
If pFilter = String.Empty Then
|
||||
_logger.Debug("FindUserWithFilter: Filter was empty, returning True for User [{0}]", pUser.SamAccountName)
|
||||
Return True
|
||||
End If
|
||||
|
||||
If Filter.Contains(oPlaceholder) Then
|
||||
Filter = Filter.Replace(oPlaceholder, User.SamAccountName)
|
||||
If pFilter.Contains(oPlaceholder) Then
|
||||
pFilter = pFilter.Replace(oPlaceholder, pUser.SamAccountName)
|
||||
_logger.Debug("FindUserWithFilter: Filter.Contains(oPlaceholder) [{0}]", pFilter)
|
||||
Else
|
||||
_logger.Warn("FindUserWithFilter: Placeholder [{0}] was not found in filter. Results may not be correct.")
|
||||
End If
|
||||
|
||||
Dim oSearcher As New DirectorySearcher(oEntry, Filter)
|
||||
Dim oSearcher As New DirectorySearcher(oEntry, pFilter)
|
||||
_logger.Debug("FindUserWithFilter: oSearcher created! Now executing DirectoryServices.SearchResult with .FindOne ...")
|
||||
Dim oResult As SearchResult = oSearcher.FindOne()
|
||||
|
||||
If oResult IsNot Nothing AndAlso oResult.Path.Replace(oProtocol, String.Empty) = User.DistinguishedName Then
|
||||
_logger.Debug("FindUserWithFilter: We have an oResult - oResult.Path: [{0}]", oResult.Path)
|
||||
If oResult IsNot Nothing AndAlso oResult.Path.Replace(oProtocol, String.Empty) = pUser.DistinguishedName Then
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
|
||||
Reference in New Issue
Block a user