From f7f4b05df5b2512e83bb8da735ded1dce9f98492 Mon Sep 17 00:00:00 2001 From: Developer01 Date: Wed, 21 May 2025 14:00:44 +0200 Subject: [PATCH] ActiveDirectoryInterfaces Split Distinguished Name --- Interfaces/ActiveDirectoryInterface.vb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Interfaces/ActiveDirectoryInterface.vb b/Interfaces/ActiveDirectoryInterface.vb index 9375aa5d..ff5ea47a 100644 --- a/Interfaces/ActiveDirectoryInterface.vb +++ b/Interfaces/ActiveDirectoryInterface.vb @@ -220,12 +220,22 @@ 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) + 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, pUser.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 - oRootPath: [{0}]", oRootPath) + _logger.Debug("FindUserWithFilter: oRootPath from User.DistinguishedName: [{0}]", oRootPath) Dim oPlaceholder = "@SAMACCOUNTNAME" Dim oProtocol = "LDAP://" @@ -250,8 +260,9 @@ Public Class ActiveDirectoryInterface Dim oSearcher As New DirectorySearcher(oEntry, pFilter) _logger.Debug("FindUserWithFilter: oSearcher created! Now executing DirectoryServices.SearchResult with .FindOne ...") Dim oResult As SearchResult = oSearcher.FindOne() - _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 + _logger.Debug("FindUserWithFilter: We have an oResult - oResult.Path: [{0}]", oResult.Path) Return True Else Return False