26. One Identity Skype

21 февраля 2020 г.

15:02

Public Function Z_Connector_Skype_Add_Account(account As SingleDbObjectSnapshot) As String

Dim scriptText As String = Z_Get_Email_Template_Body("Z_Skype_Create")

Dim output As New List(Of String)

'output.Add("userDataJSON")

Dim scriptParams As New Dictionary(Of String, Object)

scriptParams.Add("guid", account.GetValue("ObjectGUID").String)

scriptParams.Add("pool", account.GetValue("CCC_RegistrarPool").String)

scriptParams.Add("sip", account.GetValue("CCC_SipAddress").String)

Dim results As IDictionary(Of String, Object) = Z_Run_PowerShell(scriptText, scriptParams, output)

'Dim outputLines = CType(results.Item("__OUTPUT__"), List(Of String))

'logger.Trace("outputLines = " & String.Join(vbCrLf, outputLines))

Try

Z_Send_Mail_New_Account_To_ISA(account.GetValue("XObjectKey").String)

Catch ex As Exception

logger.Error(ex, "error while sending mail to ISA")

End Try

Z_Assign_Add_Group(account.GetValue("UID_Person").String, Connection.GetConfigParm("TargetSystem\UNS\ITResource\Skype\DefaultGroupCN"))

Return account.GetValue("ObjectGUID").String

End Function

Public Function Z_Connector_Skype_Recon() As String

Dim scriptText As String = Z_Get_Email_Template_Body("Z_Skype_Recon")

Dim output As New List(Of String)

output.Add("userDataJSON")

Dim scriptParams As New Dictionary(Of String, Object)

Dim results As IDictionary(Of String, Object) = Z_Run_PowerShell(scriptText, scriptParams, output)

Dim obj = results.Item("userDataJSON")

logger.Trace("data from skype = " & results.Item("userDataJSON").ToString())

Dim skypeUsers As List(Of Dictionary(Of String, String)) = JsonConvert.DeserializeObject(Of List(Of Dictionary(Of String, String)))(results.Item("userDataJSON").ToString())

Dim f As ISqlFormatter = Connection.SqlFormatter

Dim skypeSystemId As String = Z_Get_UNS_System_Id("Skype")

Connection.Variables.Put("FULLSYNC", True)

Try

For Each nextAccnt As Dictionary(Of String, String) In skypeUsers

Dim login As String = nextAccnt.Item("samaccountname")

Dim currentAccntId As String = Connection.GetSingleProperty("UNSAccountB", "UID_UNSAccountB", f.UidComparison("UID_UNSRootB", skypeSystemId) & " and " & f.Comparison("ObjectGUID", nextAccnt.Item("objectguid"), ValType.String))

Dim account As ISingleDbObject = If (String.IsNullOrEmpty(currentAccntId), Connection.CreateSingle("UNSAccountB"), Connection.CreateSingle("UNSAccountB", currentAccntId))

If String.IsNullOrEmpty(currentAccntId) Then

VID_PutValueSafe(account, "UID_UNSRootB", skypeSystemId)

VID_PutValueSafe(account, "IsGroupAccount", 0)

VID_PutValueSafe(account, "ObjectGUID", nextAccnt.Item("objectguid"))

VID_PutValueSafe(account, "UID_TSBBehavior", "TSB-FullManaged")

VID_PutValueSafe(account, "cn", login)

VID_PutValueSafe(account, "AccountName", login)

'VID_PutValueSafe(account, "UID_Person", personId)

account.Save()

account = Connection.CreateSingle("UNSAccountB", account.GetValue("UID_UNSAccountB").String)

End If

'logger.Trace("pool 3 from db = " & account.GetValue("CCC_RegistrarPool").String)

VID_PutValueSafe(account, "CCC_RegistrarPool", nextAccnt.Item("pool"))

'logger.Trace("pool from sys = " & nextAccnt.Item("pool"))

VID_PutValueSafe(account, "CCC_SipAddress", nextAccnt.Item("sipaddress"))

'logger.Trace("pool from db = " & account.GetValue("CCC_RegistrarPool").String)

'logger.Trace("sipaddress = " & nextAccnt.Item("sipaddress"))

'logger.Trace("pool 3a from db = " & account.GetValue("CCC_RegistrarPool").String)

'logger.Trace("sip 3a from db = " & account.GetValue("CCC_SipAddress").String)

account.Save()

Next

Finally

Connection.Variables.Remove("FULLSYNC")

End Try

Return "success" & skypeUsers.Count

End Function

Public Function Z_Connector_Skype_Recon_Incremental() As String

logger.trace("ENTER")

Dim scriptText As String = Z_Get_Email_Template_Body("Z_Skype_Recon")

Dim skypeSystemId As String = Z_Get_UNS_System_Id("Skype")

Dim output As New List(Of String)

output.Add("userDataJSON")

Dim scriptParams As New Dictionary(Of String, Object)

Dim f As ISqlFormatter = Connection.SqlFormatter

Dim results As IDictionary(Of String, Object) = Z_Run_PowerShell(scriptText, scriptParams, output)

Dim obj = results.Item("userDataJSON")

logger.Trace("data from skype = " & results.Item("userDataJSON").ToString())

Dim skypeUsers As List(Of Dictionary(Of String, String)) = JsonConvert.DeserializeObject(Of List(Of Dictionary(Of String, String)))(results.Item("userDataJSON").ToString())

logger.Trace("skype users amount: " & skypeUsers.count)

'list of skype accounts that are currently present in idm

Dim idmSkypeAccountGUIDs As New List(Of String)

Dim existingObjects As IColDbObject = Connection.CreateCol("UNSAccountB")

Z_Add_All_Columns_To_Output_Result("UNSAccountB", existingObjects)

existingObjects.Prototype.WhereClause = f.UidComparison( "UID_UNSRootB", skypeSystemId)

existingObjects.Load()

For Each nextRow As IColElem In existingObjects

idmSkypeAccountGUIDs.Add( nextRow.getValue("ObjectGUID").string)

Next

logger.Trace("idm skype users amount: " & idmSkypeAccountGUIDs.count)

Dim newUsersCount As Integer = 0

Connection.Variables.Put("FULLSYNC", True)

Try

For Each nextAccnt As Dictionary(Of String, String) In skypeUsers

Try

Dim adguid As String = nextAccnt.Item("objectguid")

If String.IsNullOrEmpty(adguid) OrElse idmSkypeAccountGUIDs.contains(adguid) Then

'account is already loaded in idm

Continue For

End If

'account is not loaded - create it in idm

Dim login As String = nextAccnt.Item("samaccountname")

If String.IsNullOrEmpty(login) Then

'weird account - dont load it

Continue For

End If

Dim account As ISingleDbObject = Connection.CreateSingle("UNSAccountB")

VID_PutValueSafe(account, "UID_UNSRootB", skypeSystemId)

VID_PutValueSafe(account, "IsGroupAccount", 0)

VID_PutValueSafe(account, "ObjectGUID", nextAccnt.Item("objectguid"))

VID_PutValueSafe(account, "UID_TSBBehavior", "TSB-FullManaged")

VID_PutValueSafe(account, "cn", login)

VID_PutValueSafe(account, "AccountName", login)

VID_PutValueSafe(account, "CCC_RegistrarPool", nextAccnt.Item("pool"))

VID_PutValueSafe(account, "CCC_SipAddress", nextAccnt.Item("sipaddress"))

logger.Trace("pool from db = " & account.GetValue("CCC_RegistrarPool").String)

logger.Trace("sipaddress from db = " & account.GetValue("CCC_SipAddress").String)

account.Save()

account = Connection.CreateSingle("UNSAccountB", account.GetValue("UID_UNSAccountB").String)

VID_PutValueSafe(account, "CCC_RegistrarPool", nextAccnt.Item("pool"))

VID_PutValueSafe(account, "CCC_SipAddress", nextAccnt.Item("sipaddress"))

account.Save()

newUsersCount = newUsersCount + 1

'Exit For

Catch ex As Exception

logger.Error(ex, "error linking skype")

End Try

Next

Finally

Connection.Variables.Remove("FULLSYNC")

End Try

logger.trace("EXIT")

Return newUsersCount.ToString()

End Function

Public Function Z_Connector_Skype_Link_By_GUID() As String

logger.Trace("ENTER")

Dim skypeSystemId As String = Z_Get_UNS_System_Id("Skype")

Dim f As ISqlFormatter = Connection.SqlFormatter

Dim accountsToLink As IColDbObject = Connection.CreateCol("UNSAccountB")

Z_Add_All_Columns_To_Output_Result("UNSAccountB", accountsToLink)

'accountsToLink.Prototype.WhereClause = f.UidComparison( "UID_UNSRootB", skypeSystemId) & " and uid_person is null and objectguid is not null and objectguid in (select objectguid from adsaccount where objectguid is not null and uid_person is not null and (samaccountname like 'artyuhin_ia' or samaccountname like 'kurmesov_nm'))"

'accountsToLink.Prototype.WhereClause = f.UidComparison( "UID_UNSRootB", skypeSystemId) & " and uid_person is null and objectguid is not null and objectguid in (select top 25 objectguid from adsaccount where objectguid is not null and uid_person is not null )"

accountsToLink.Prototype.WhereClause = f.UidComparison( "UID_UNSRootB", skypeSystemId) & " and uid_person is null and objectguid is not null and objectguid in (select objectguid from adsaccount where objectguid is not null and uid_person is not null )"

accountsToLink.Load()

For Each nextRow As IColElem In accountsToLink

Dim guid As String = nextRow.getValue("ObjectGUID").string

Dim persId As String = Connection.GetSingleProperty("ADSAccount","UID_Person", f.Comparison("objectguid", guid, ValType.String))

logger.Trace("linking account with objectguid " & guid & " to person " & persId)

Z_Link_Account("AccountDefinition_Skype", nextRow.GetValue("UID_UNSAccountB").String, persId, "UNSAccountB")

'Exit For

Next

logger.Trace("EXIT")

Return "ok"

End Function