2 Commits

Author SHA1 Message Date
Developer01
f7f4b05df5 ActiveDirectoryInterfaces Split Distinguished Name 2025-05-21 14:00:44 +02:00
Developer01
766737b4b5 Interfaces V 2.3 2025-05-21 13:11:13 +02:00
2 changed files with 28 additions and 12 deletions

View File

@@ -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

View File

@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("Modules.Interfaces")>
<Assembly: AssemblyCopyright("Copyright © 2025")>
<Assembly: AssemblyTrademark("2.2.9.0")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("2.2.9.0")>
<Assembly: AssemblyFileVersion("2.2.9.0")>
<Assembly: AssemblyVersion("2.3.0.0")>
<Assembly: AssemblyFileVersion("2.3.0.0")>