JobRunner, ADInterface

This commit is contained in:
Jonathan Jenne
2019-04-18 16:33:40 +02:00
parent 2296b31519
commit a8ed35aee2
27 changed files with 565 additions and 426 deletions

View File

@@ -34,10 +34,17 @@ Public Class ActiveDirectoryInterface
Else
_rootPath = RootPath
End If
_logger.Info("Using RootPath {0}", _rootPath)
End Sub
Public Function SyncUsersForGroup(GroupName As String) As List(Of ADUser)
Return SyncUsersForGroup(GroupName, New List(Of AttributeMapping))
Try
Return SyncUsersForGroup(GroupName, New List(Of AttributeMapping))
Catch ex As Exception
_logger.Error(ex)
Return Nothing
End Try
End Function
Public Function SyncUsersForGroup(GroupName As String, AttributeMappings As List(Of AttributeMapping)) As List(Of ADUser)
@@ -143,39 +150,53 @@ Public Class ActiveDirectoryInterface
Return oUsers
End If
_logger.Debug("Listing members of Group {0}", GroupName)
Using oMembers = oGroupPrincipal.GetMembers(True)
For Each oMember As Principal In oMembers
If TypeOf oMember Is UserPrincipal Then
Dim oUser As UserPrincipal = DirectCast(oMember, UserPrincipal)
Dim oUserEx As UserPrincipalEx = UserPrincipalEx.FindByIdentity(oContext, oUser.SamAccountName)
Dim oCustomAttributes As New List(Of ADUser.CustomAttribute)
Try
If TypeOf oMember Is UserPrincipal Then
Dim oUser As UserPrincipal = DirectCast(oMember, UserPrincipal)
Dim oUserEx As UserPrincipalEx = UserPrincipalEx.FindByIdentity(oContext, oUser.SamAccountName)
Dim oCustomAttributes As New List(Of ADUser.CustomAttribute)
For Each oMap As AttributeMapping In AttributeMappings
Dim oAttributeValue = oUserEx.GetAttributeValue(oMap.AttributeName)
' TODO: Figure out why oUserEx can be nothing for certain users
If oUserEx IsNot Nothing Then
For Each oMap As AttributeMapping In AttributeMappings
Dim oAttributeValue = oUserEx.GetAttributeValue(oMap.AttributeName)
If oAttributeValue <> String.Empty Then
_logger.Debug("Attribute {0} is not empty.", oMap.AttributeName)
If oAttributeValue <> String.Empty Then
_logger.Debug("Attribute {0} is not empty.", oMap.AttributeName)
oCustomAttributes.Add(New ADUser.CustomAttribute() With {
.Name = oMap.AttributeName,
.Value = oAttributeValue,
.FirebirdSyskey = oMap.FirebirdSyskey,
.MSSQLColumn = oMap.MSSQLColumn
})
oCustomAttributes.Add(New ADUser.CustomAttribute() With {
.Name = oMap.AttributeName,
.Value = oAttributeValue,
.FirebirdSyskey = oMap.FirebirdSyskey,
.MSSQLColumn = oMap.MSSQLColumn
})
End If
Next
Else
_logger.Warn("Could not fetch CustomAttributes for user {0}", oUser)
End If
Next
oUsers.Add(New ADUser() With {
.GUID = oUserEx.Guid,
.SId = oUserEx.Sid,
.samAccountName = oUserEx.SamAccountName,
.Surname = oUserEx.Surname,
.Middlename = oUserEx.MiddleName,
.GivenName = oUserEx.GivenName,
.Email = oUserEx.EmailAddress,
.CustomAttributes = oCustomAttributes
})
End If
_logger.Info("Trying to add User {0} to user list", oUser)
Dim oNewUser As New ADUser With {
.SId = oUser.Sid,
.samAccountName = oUser.SamAccountName,
.Middlename = oUser.MiddleName,
.GivenName = oUser.GivenName,
.Email = oUser.EmailAddress,
.CustomAttributes = oCustomAttributes
}
oUsers.Add(oNewUser)
End If
Catch ex As Exception
_logger.Warn("User could not be processed")
_logger.Error(ex)
End Try
Next
End Using
End Using
@@ -184,7 +205,7 @@ Public Class ActiveDirectoryInterface
Return oUsers
Catch ex As Exception
_logger.Error(ex)
Throw ex
Return oUsers
End Try
End Function
@@ -229,7 +250,7 @@ Public Class ActiveDirectoryInterface
Try
Return Result.Properties.Item(PropertyName).Item(0)
Catch ex As Exception
_logger.Warn("Property {0} not found")
_logger.Warn("Property {0} not found", PropertyName)
Return String.Empty
End Try
End Function