From dee5d33bb974cbd92d62503d0b2776bb1a184a44 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 10 Apr 2019 11:58:17 +0200 Subject: [PATCH] first pass of jobrunner with adsync --- Jobs/EDMI/ADSync/ADSyncJob.vb | 30 ++++++++++++++----- .../ActiveDirectoryInterface.vb | 1 - 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Jobs/EDMI/ADSync/ADSyncJob.vb b/Jobs/EDMI/ADSync/ADSyncJob.vb index b0fc49a3..7dc9857a 100644 --- a/Jobs/EDMI/ADSync/ADSyncJob.vb +++ b/Jobs/EDMI/ADSync/ADSyncJob.vb @@ -1,4 +1,5 @@ -Imports DigitalData.Modules.Database +Imports System.Collections.Generic +Imports DigitalData.Modules.Database Imports DigitalData.Modules.Interfaces Imports DigitalData.Modules.Jobs Imports DigitalData.Modules.Logging @@ -7,23 +8,38 @@ Public Class ADSyncJob Inherits JobBase Implements IJob(Of ADSyncArgs) - Private _ADSync As ActiveDirectoryInterface - Public Sub New(LogConfig As LogConfig, Firebird As Firebird) MyBase.New(LogConfig, Firebird) End Sub Public Sub Start(Arguments As ADSyncArgs) Implements IJob(Of ADSyncArgs).Start - _ADSync = New ActiveDirectoryInterface(_LogConfig, _Firebird, Arguments.RootPath) + Dim oSync = New ActiveDirectoryInterface(_LogConfig, _Firebird, Arguments.RootPath) + Dim oJobName As String = [GetType]().Name - 'TODO: Do AD Sync! + _Logger.Info("Running job {0}", oJobName) - If _ADSync.Authenticate() = False Then - _Logger.Warn("Job could not be completed! Authentication failed!") + If oSync.Authenticate() = False Then + _Logger.Warn("Job {0} could not be completed! Authentication failed!", oJobName) Exit Sub End If + Dim oGroups As List(Of ADGroup) = oSync.ListGroups() + + _Logger.Debug("Found {0} Groups", oGroups.Count) + + For Each oGroup In oGroups + _Logger.Debug("Syncing Group {0}", oGroup.Name) + Dim oSyncedUsers = oSync.SyncUsersForGroup(oGroup.Name) + + If oSyncedUsers Is Nothing Then + _Logger.Warn("Group {0} could not be synced!", oGroup) + Else + _Logger.Debug("Group {0} synced", oGroup) + _Logger.Debug("Synced {0} users", oSyncedUsers.Count) + End If + Next + _Logger.Info("Job {0} completed!", oJobName) End Sub Public Function ShouldStart(Arguments As ADSyncArgs) As Boolean Implements IJob(Of ADSyncArgs).ShouldStart diff --git a/Modules.Interfaces/ActiveDirectoryInterface.vb b/Modules.Interfaces/ActiveDirectoryInterface.vb index a9c40555..09ceae2b 100644 --- a/Modules.Interfaces/ActiveDirectoryInterface.vb +++ b/Modules.Interfaces/ActiveDirectoryInterface.vb @@ -56,7 +56,6 @@ Public Class ActiveDirectoryInterface _logger.Debug("Getting group Id for group {0}", GroupName) oGroupId = GetGroupId(GroupName) - If oGroupId = 0 Then _logger.Warn("Group {0} does not exist in database. Exiting", GroupName) Return Nothing