|
|
|
|
@@ -220,10 +220,23 @@ Public Class ActiveDirectoryInterface
|
|
|
|
|
Return oUsers
|
|
|
|
|
End Try
|
|
|
|
|
End Function
|
|
|
|
|
Private Function GetPartFromFirstOU(dnString As String) As String
|
|
|
|
|
Dim keyword As String = "OU="
|
|
|
|
|
Dim index As Integer = dnString.IndexOf(keyword)
|
|
|
|
|
|
|
|
|
|
Public Function FindUserWithFilter(User As UserPrincipalEx, Filter As String) As Boolean
|
|
|
|
|
If index <> -1 Then
|
|
|
|
|
Return dnString.Substring(index)
|
|
|
|
|
Else
|
|
|
|
|
Return "No_Result_from_GetPartFromFirstOU"
|
|
|
|
|
End If
|
|
|
|
|
End Function
|
|
|
|
|
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))
|
|
|
|
|
Dim oRootPath = GetPartFromFirstOU(pUser.DistinguishedName)
|
|
|
|
|
_logger.Debug("FindUserWithFilter: pUser.DistinguishedName: [{0}]", pUser.DistinguishedName)
|
|
|
|
|
_logger.Debug("FindUserWithFilter: oRootPath from User.DistinguishedName: [{0}]", oRootPath)
|
|
|
|
|
|
|
|
|
|
Dim oPlaceholder = "@SAMACCOUNTNAME"
|
|
|
|
|
Dim oProtocol = "LDAP://"
|
|
|
|
|
Dim oEntry As New DirectoryEntry(oProtocol & oRootPath) With {
|
|
|
|
|
@@ -231,22 +244,25 @@ 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
|
|
|
|
|
If oResult IsNot Nothing AndAlso oResult.Path.Replace(oProtocol, String.Empty) = pUser.DistinguishedName Then
|
|
|
|
|
_logger.Debug("FindUserWithFilter: We have an oResult - oResult.Path: [{0}]", oResult.Path)
|
|
|
|
|
Return True
|
|
|
|
|
Else
|
|
|
|
|
Return False
|
|
|
|
|
|