Finish Attribute syncing

This commit is contained in:
Jonathan Jenne 2019-04-30 17:26:07 +02:00
parent 7d1c2ced5a
commit 9e330bd52e
2 changed files with 38 additions and 13 deletions

View File

@ -18,7 +18,6 @@ Public Class ADSyncJob
Try
Dim oSync = New ActiveDirectoryInterface(_LogConfig, _Firebird, _MSSQL, Arguments.RootPath)
_Logger.Info("Running job {0}", oJobName)
If oSync.Authenticate() = False Then
@ -26,21 +25,13 @@ Public Class ADSyncJob
Exit Sub
End If
'Dim oGroups As List(Of ADGroup) = oSync.ListGroups()
' 30.04.19: MSSQL als führendes System
Dim oGroups As New List(Of String)
Dim oDatatable = _MSSQL.GetDatatable("SELECT NAME FROM TBDD_GROUPS WHERE AD_SYNC = 1 AND ACTIVE = 1")
_Logger.Debug("Found {0} Groups", oDatatable.Rows.Count)
For Each oRow As DataRow In oDatatable.Rows
oGroups.Add(oRow.Item("NAME"))
Next
Dim oGroups = GetGroups()
Dim oAttributeMappings = GetAttributeMappings()
_Logger.Debug("Found {0} Groups", oGroups)
For Each oGroup In oGroups
_Logger.Debug("Syncing Group {0}", oGroup)
Dim oSyncedUsers = oSync.SyncUsersForGroup(oGroup)
Dim oSyncedUsers = oSync.SyncUsersForGroup(oGroup, oAttributeMappings)
If oSyncedUsers Is Nothing Then
_Logger.Warn("Group {0} could not be synced!", oGroup)
@ -56,6 +47,38 @@ Public Class ADSyncJob
End Try
End Sub
Private Function GetGroups() As List(Of String)
Try
Dim oGroups As New List(Of String)
Dim oDatatable = _MSSQL.GetDatatable("SELECT NAME FROM TBDD_GROUPS WHERE AD_SYNC = 1 AND ACTIVE = 1")
For Each oRow As DataRow In oDatatable.Rows
oGroups.Add(oRow.Item("NAME"))
Next
Return oGroups
Catch ex As Exception
_Logger.Error(ex)
Return New List(Of String)
End Try
End Function
Private Function GetAttributeMappings() As List(Of AttributeMapping)
Dim oDatatable = _MSSQL.GetDatatable("SELECT * FROM TBDD_EXTATTRIBUTES_MATCHING")
Dim oAttributeMappings = New List(Of AttributeMapping)
For Each oRow As DataRow In oDatatable.Rows
oAttributeMappings.Add(New AttributeMapping() With {
.AttributeName = oRow.Item("EXT_ATTRIBUTE"),
.FirebirdSyskey = oRow.Item("FB_SYS_KEY"),
.MSSQLColumn = oRow.Item("TBDD_USER_COLUMN")
})
Next
Return oAttributeMappings
End Function
Public Function ShouldStart(Arguments As ADSyncArgs) As Boolean Implements IJob(Of ADSyncArgs).ShouldStart
Return Arguments.Enabled
End Function

View File

@ -155,6 +155,8 @@ Namespace SyncUsers
Public Sub AddCustomAttributesToUser(User As ADUser, UserId As Integer) Implements ISyncUsers.AddCustomAttributesToUser
Dim oCustomAttributes = User.CustomAttributes
_logger.Debug("Adding {0} Custom Attributes to User {1}", oCustomAttributes.Count, User)
For Each oAttribute In oCustomAttributes
Dim oSQL As String = $"UPDATE TBDD_USER SET {oAttribute.MSSQLColumn} = '{oAttribute.Value}', CHANGED_WHO = '{ADDED_WHO}' WHERE GUID = {UserId}"
Dim oResult = _mssql.NewExecutenonQuery(oSQL)