diff --git a/GUIs.Test.ADSyncTest/ADConfig.vb b/GUIs.Test.ADSyncTest/ADConfig.vb new file mode 100644 index 00000000..893623ac --- /dev/null +++ b/GUIs.Test.ADSyncTest/ADConfig.vb @@ -0,0 +1,7 @@ +Friend Class ADConfig + + Public Class AttributeMap + Public AttributeName As String + Public ColumnName As String + End Class +End Class diff --git a/GUIs.Test.ADSyncTest/ADSyncTest.vbproj b/GUIs.Test.ADSyncTest/ADSyncTest.vbproj index 8d9c8289..565f109d 100644 --- a/GUIs.Test.ADSyncTest/ADSyncTest.vbproj +++ b/GUIs.Test.ADSyncTest/ADSyncTest.vbproj @@ -81,6 +81,7 @@ + Form @@ -133,6 +134,10 @@ {39ec839a-3c30-4922-a41e-6b09d1dde5c3} Jobs + + {44982f9b-6116-44e2-85d0-f39650b1ef99} + Config + {EAF0EA75-5FA7-485D-89C7-B2D843B03A96} Database diff --git a/GUIs.Test.ADSyncTest/Form1.vb b/GUIs.Test.ADSyncTest/Form1.vb index b3dc7359..8e546f27 100644 --- a/GUIs.Test.ADSyncTest/Form1.vb +++ b/GUIs.Test.ADSyncTest/Form1.vb @@ -1,64 +1,33 @@ Imports DigitalData.Modules.Interfaces Imports DigitalData.Modules.Logging -Imports DigitalData.Modules.Interfaces.ActiveDirectoryInterface Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Config Public Class Form1 Private _sync As ActiveDirectoryInterface Private _logConfig As LogConfig Private _logger As Logger Private _firebird As Firebird + Private _sql As MSSQLServer + Private _configManager As ConfigManager(Of ADConfig) Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load _logConfig = New LogConfig(LogConfig.PathType.CurrentDirectory) _logConfig.Debug = True _logger = _logConfig.GetLogger() _firebird = New Firebird(_logConfig, "172.24.12.41", "172.24.12.41:E:\DB\Firebird\Databases\DD_ICM.fdb", "sysdba", "dd") + _sql = New MSSQLServer(_logConfig, "Server=172.24.12.41\tests;Database=DD_ECM_TEST;User Id=sa; Password=dd") - _sync = New ActiveDirectoryInterface(_logConfig, _firebird) + _sync = New ActiveDirectoryInterface(_logConfig, Nothing, _sql) _sync.Authenticate() - Dim oType As Type = Type.GetType("DigitalData.Modules.Jobs.ADSyncJob") - Activator.CreateInstance(oType) + End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim oGroup As String = ListBox1.SelectedItem - _sync.SyncUsersForGroup(oGroup) - - '' STEP 1: Get all Groups that have AD_SYNC enabled - 'Dim oSQL As String = $"SELECT RECORD_ID, GROUP_NAME FROM VWICM_GROUP WHERE AD_SYNC = 1" - 'Dim oResult As DataTable = _firebird.GetDatatable(oSQL) - - - 'For Each oRow As DataRow In oResult.Rows - ' Dim oGroupName As String = oRow.Item("GROUP_NAME") - ' Dim oGroupId As Int64 = oRow.Item("RECORD_ID") - - ' ' STEP 2: List all Users for that Group - ' Dim oUsers As List(Of ADUser) = _sync.ListUsers(oGroupName) - - ' For Each oUser In oUsers - ' ' STEP 3: Check if user exists in DB - ' oSQL = $"SELECT FNICM_GET_RECORD4SYSKEY('{oUser.samAccountName}','001-USRNAME') from RDB$DATABASE" - ' Dim oResult2 = _firebird.GetScalarValue(oSQL) - ' Dim oUserId - - ' ' STEP 3.A: If user does not exists, create and add to group - ' If IsDBNull(oResult2) Then - ' 'Create user - ' oSQL = $"SELECT FNICM_RADM_NEW_USER('{oUser.GivenName}', '{oUser.Surname}', '{oUser.samAccountName}', 'AD-Sync') from RDB$DATABASE" - ' Dim oResult3 = _firebird.GetScalarValue(oSQL) - ' oUserId = oResult3 - ' Else - ' oUserId = oResult2 - ' End If - - ' ' STEP 4: Add user to group - ' oSQL = $"SELECT FNICM_RADM_NEW_USER2GROUP({oUserId}, {oGroupId}, 'AD-Sync') from RDB$DATABASE" - ' Dim oResult4 = _firebird.GetScalarValue(oSQL) - ' Next - 'Next + Dim oAttributeMappings = GetAttributeMappings() + _sync.SyncUsersForGroup(oGroup, oAttributeMappings) End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click @@ -71,7 +40,9 @@ Public Class Form1 Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Dim oGroup As String = ListBox1.SelectedItem - Dim oUsers = _sync.ListUsers(oGroup) + Dim oAttributeMappings = GetAttributeMappings() + + Dim oUsers = _sync.ListUsers(oGroup, oAttributeMappings) ListBox2.Items.Clear() For Each oUser In oUsers @@ -82,4 +53,22 @@ Public Class Form1 ListBox2.Items.Add("No users found ¯\_(ツ)_/¯") End If End Sub + + Private Function GetAttributeMappings() As List(Of AttributeMapping) + Dim oDatatable = _sql.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 + + End Class