3.5 Получить объект на основе ObjectKey
9 апреля 2025 г.
11:39
Public Function SDK_IPasswordManager_CreatePassword(ObjectKey As String, pwdColumn As String) As String
If String.IsNullOrEmpty(ObjectKey) Then
Return String.Empty
Else
Dim objKey = New DbObjectKey(ObjectKey)
Dim entity As IEntity = Nothing
' try to load the entity
If Session.Source.TryGet(objKey, EntityLoadType.Interactive, entity) Then
' The base entity has to be provided if the policy is based on a
' specific entity (i.e. IsElementPropertiesDenied, CheckScriptName
' or CreateScriptName are set).
' Password will be stored in a SecureString
Dim password As SecureString = New SecureString
' Retrieve an IPasswordManager instance
Dim passwordManager = Session.Resolve(Of IPasswordManager)()
' Retrieve the uid of the policy used for the pwdColumn of the entity
' and include the fallback to the default policy.
'
' GetPwdPolicyUidForColumn(myEntity as IEntity, columnName As String, addDefault As Boolean)
'
Dim uidPolicy As String = passwordManager.GetPolicyUidForColumn(entity, pwdColumn, True)
' Retrieve the policy
Dim passwordPolicy = passwordManager.GetPolicy(uidPolicy)
' Generate random password
password = [REDACTED]
Return password.ToInsecure()
Else
Return String.Empty
End If
End If
End Function