Active Directory Sync.

This commit is contained in:
2023-05-12 16:38:13 +02:00
parent abcd0dfeac
commit fa193fcfbd
6 changed files with 7146 additions and 275 deletions

View File

@@ -1,4 +1,5 @@

Imports System.DirectoryServices
Imports System.IO
Imports System.Net
Imports System.Net.Http
@@ -6,6 +7,8 @@ Imports System.Net.WebRequestMethods
Imports System.Security.Policy
Imports System.Text
Imports System.Windows
Imports DAKOSY_Worker.DEERRE
Imports GrapeCity.Enterprise.Data.Expressions.Evaluation
Imports Newtonsoft.Json
Imports VERAG_PROG_ALLGEMEIN
@@ -36,6 +39,7 @@ Public Class frmMitarbDetails
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
Me.FirmaTmp = Firma
btnADladen.Visible = True
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
End Sub
@@ -879,5 +883,106 @@ Public Class frmMitarbDetails
Private Sub cbxShowPW_CheckedChanged(sender As Object, e As EventArgs) Handles cbxShowPW.CheckedChanged
txtCSPW.UseSystemPasswordChar = Not cbxShowPW.Checked
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles btnADladen.Click
Dim frmAD = New frmADsearch()
If frmAD.ShowDialog = DialogResult.OK Then
txtEmail.Text = ""
txtUsername.Text = ""
txtVname.Text = ""
txtNname.Text = ""
txtDurchwahl.Text = ""
txtALIASUser.Text = ""
txtEmailExtension.Text = ""
txtEmail.Text = frmAD.activeDirectoryObj.mail
txtUsername.Text = frmAD.activeDirectoryObj.sAMAccountName
txtVname.Text = frmAD.activeDirectoryObj.givenName
txtNname.Text = frmAD.activeDirectoryObj.sn
txtDurchwahl.Text = frmAD.activeDirectoryObj.telephoneNumber
txtALIASUser.Text = frmAD.activeDirectoryObj.sAMAccountName
txtEmailExtension.Text = frmAD.activeDirectoryObj.emailextension
cboALIASDomain.changeItem(frmAD.activeDirectoryObj.domain)
cboAbteilung.changeItem(frmAD.activeDirectoryObj.department)
cboNiederlassung.changeItem(frmAD.activeDirectoryObj.company)
End If
End Sub
Private Sub btnUpdateAD_Click(sender As Object, e As EventArgs) Handles btnUpdateAD.Click
If cboALIASDomain._value = "" Or txtALIASUser.Text = "" Then
Exit Sub
End If
Dim a As MsgBoxResult = MsgBox("Die Daten des Mitarbeiters mit dem AD synchronisieren?", vbYesNo)
If a = vbYes Then
Dim domainName As String = ""
Dim ldap As String = ""
Select Case cboALIASDomain._value
Case "imex.local"
ldap = "LDAP://DC=IMEX,DC=LOCAL"
Case "VERAGNEUHAUS.local"
ldap = "LDAP://DC=VERAGNEUHAUS,DC=LOCAL"
Case "VERAGOST"
ldap = "LDAP://DC=VERAG,DC=OST,DC=DMN"
End Select
Dim dirEntry As System.DirectoryServices.DirectoryEntry
Dim dirSearcher As System.DirectoryServices.DirectorySearcher
Try
dirEntry = New System.DirectoryServices.DirectoryEntry(ldap)
dirSearcher = New System.DirectoryServices.DirectorySearcher(dirEntry)
dirSearcher.Filter = "(samAccountName=" & txtALIASUser.Text & ")"
dirSearcher.PropertiesToLoad.Add("GivenName")
dirSearcher.PropertiesToLoad.Add("sn")
Dim sr As DirectoryServices.SearchResult = dirSearcher.FindOne()
If sr Is Nothing Then
Dim b As MsgBoxResult = MsgBox("Mitarbeiterdaten sind im AD nicht vorhanden?" & vbNewLine & "Solle der Mitarbeiter " & txtALIASUser.Text & " in der Domain " & cboALIASDomain.Text & " angelegt werden?", vbYesNo)
If b = vbYes Then
Dim frmAD = New frmADsearch("Referenzuser (Gruppen werden von diesem User übernommen)!")
If frmAD.ShowDialog = DialogResult.OK Then
'frmAD.activeDirectoryObj.ADEntry.CopyTo(New DirectoryEntry(frmAD.activeDirectoryObj.ADEntry.Parent.Path, txtALIASUser.Text, txtPwd.Text))
End If
Else
Exit Sub
End If
End If
Dim de As System.DirectoryServices.DirectoryEntry = sr.GetDirectoryEntry()
de.Properties("givenName").Value = txtVname.Text
'de.Properties("sAMAccountName").Value.ToString()
de.Properties("department").Value = cboAbteilung._value
de.Properties("company").Value = cboFirma.SelectedValue
de.Properties("sn").Value = txtNname.Text
'de.Properties("extensionAttribute7").Value = txtEmailExtension.Text
de.Properties("mail").Value = txtEmail.Text
de.CommitChanges()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Private Function setNoNullableValue(value As String) As String
If value IsNot Nothing Then
If value <> "" Then
Return value
End If
End If
End Function
End Class