Interfaces/ActiveDirectory: make sync users more resilient form missing attrs
This commit is contained in:
parent
1c3e0b175b
commit
35599a510c
@ -21,15 +21,15 @@ Namespace SyncUsers
|
|||||||
Dim oSyncedUsers As New List(Of ADUser)
|
Dim oSyncedUsers As New List(Of ADUser)
|
||||||
|
|
||||||
Try
|
Try
|
||||||
_logger.Debug("Getting group Id for group {0}", GroupName)
|
_logger.Debug("Getting group Id for group [{0}]", GroupName)
|
||||||
oGroupId = GetGroupId(GroupName)
|
oGroupId = GetGroupId(GroupName)
|
||||||
|
|
||||||
If oGroupId = 0 Then
|
If oGroupId = 0 Then
|
||||||
_logger.Debug("Group {0} does not exist in database or is not enabled for sync.", GroupName)
|
_logger.Debug("Group [{0}] does not exist in database or is not enabled for sync.", GroupName)
|
||||||
Return oSyncedUsers
|
Return oSyncedUsers
|
||||||
End If
|
End If
|
||||||
|
|
||||||
_logger.Debug("Using group Id {0}", oGroupId)
|
_logger.Debug("Using group Id [{0}]", oGroupId)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
Return oSyncedUsers
|
Return oSyncedUsers
|
||||||
@ -41,10 +41,10 @@ Namespace SyncUsers
|
|||||||
|
|
||||||
' Check if user already exists
|
' Check if user already exists
|
||||||
Try
|
Try
|
||||||
_logger.Debug("Checking if user {0} exists", oUser)
|
_logger.Debug("Checking if user [{0}] exists", oUser)
|
||||||
oUserId = GetUserId(oUser.samAccountName)
|
oUserId = GetUserId(oUser.samAccountName)
|
||||||
oUserExists = Not IsNothing(oUserId)
|
oUserExists = Not IsNothing(oUserId)
|
||||||
_logger.Debug("User {0} exists in database: ", oUser, oUserExists)
|
_logger.Debug("User [{0}] exists in database: ", oUser, oUserExists)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
_logger.Warn("Could not get UserId for user. Skipping")
|
_logger.Warn("Could not get UserId for user. Skipping")
|
||||||
@ -54,9 +54,9 @@ Namespace SyncUsers
|
|||||||
' I user does not exist, create a new user
|
' I user does not exist, create a new user
|
||||||
Try
|
Try
|
||||||
If Not oUserExists Then
|
If Not oUserExists Then
|
||||||
_logger.Debug("Creating new user for {0}", oUser)
|
_logger.Debug("Creating new user for [{0}]", oUser)
|
||||||
oUserId = CreateUser(oUser)
|
oUserId = CreateUser(oUser)
|
||||||
_logger.Debug("User created with Id {0}", oUserId)
|
_logger.Debug("User created with Id [{0}]", oUserId)
|
||||||
End If
|
End If
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
@ -128,7 +128,7 @@ Namespace SyncUsers
|
|||||||
End Function
|
End Function
|
||||||
Private Function CreateUser(User As ADUser) As Integer Implements ISyncUsers.CreateUser
|
Private Function CreateUser(User As ADUser) As Integer Implements ISyncUsers.CreateUser
|
||||||
Try
|
Try
|
||||||
Dim oSQL = $"SELECT FNICM_RADM_NEW_USER('{User.GivenName}', '{User.Surname}', '{User.samAccountName}', 'AD-Sync') from RDB$DATABASE"
|
Dim oSQL = $"SELECT FNICM_RADM_NEW_USER('{User?.GivenName}', '{User?.Surname}', '{User?.samAccountName}', 'AD-Sync') from RDB$DATABASE"
|
||||||
Dim oUserId As Integer = _firebird.GetScalarValue(oSQL)
|
Dim oUserId As Integer = _firebird.GetScalarValue(oSQL)
|
||||||
|
|
||||||
Return oUserId
|
Return oUserId
|
||||||
|
|||||||
@ -47,10 +47,10 @@ Namespace SyncUsers
|
|||||||
|
|
||||||
' Check if user already exists
|
' Check if user already exists
|
||||||
Try
|
Try
|
||||||
_logger.Debug("Checking if user {0} exists", oUser)
|
_logger.Debug("Checking if user [{0}] exists", oUser)
|
||||||
oUserId = GetUserId(oUser.samAccountName)
|
oUserId = GetUserId(oUser.samAccountName)
|
||||||
oUserExists = oUserId > 0
|
oUserExists = oUserId > 0
|
||||||
_logger.Debug("User {0} exists in database: {1}", oUser, oUserExists)
|
_logger.Debug("User [{0}] exists in database: [{1}]", oUser, oUserExists)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
_logger.Warn("Could not get UserId for user. Skipping.")
|
_logger.Warn("Could not get UserId for user. Skipping.")
|
||||||
@ -187,9 +187,15 @@ Namespace SyncUsers
|
|||||||
|
|
||||||
Private Function CreateUser(User As ADUser) As Integer Implements ISyncUsers.CreateUser
|
Private Function CreateUser(User As ADUser) As Integer Implements ISyncUsers.CreateUser
|
||||||
Try
|
Try
|
||||||
|
If User Is Nothing Then
|
||||||
|
_logger.Warn("Argument [User] is nothing. Exiting.")
|
||||||
|
Throw New ArgumentNullException("User")
|
||||||
|
End If
|
||||||
|
|
||||||
Dim oUserId As Integer = GetUserId(User.samAccountName)
|
Dim oUserId As Integer = GetUserId(User.samAccountName)
|
||||||
|
|
||||||
If oUserId = 0 Then
|
If oUserId = 0 Then
|
||||||
Dim oSQL As String = $"INSERT INTO TBDD_USER (PRENAME, NAME, USERNAME, EMAIL, ADDED_WHO) VALUES ('{User.GivenName}', '{User.Surname.Replace("'", "''")}', UPPER('{User.samAccountName.Replace("'", "''")}'), '{User.Email.Replace("'", "''")}', '{ADDED_WHO}')"
|
Dim oSQL As String = $"INSERT INTO TBDD_USER (PRENAME, NAME, USERNAME, EMAIL, ADDED_WHO) VALUES ('{User?.GivenName}', '{User?.Surname?.Replace("'", "''")}', UPPER('{User?.samAccountName?.Replace("'", "''")}'), '{User?.Email?.Replace("'", "''")}', '{ADDED_WHO}')"
|
||||||
Dim oResult = _mssql.ExecuteNonQuery(oSQL)
|
Dim oResult = _mssql.ExecuteNonQuery(oSQL)
|
||||||
|
|
||||||
If oResult = True Then
|
If oResult = True Then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user