Create default Roles

StatusIDPriorityType
Closed25071MajorQuestion
ProfileReply
RossClient

I used to use SecuritySystemRole to create default roles. We have changed this to use Xafari. How do I create a new role now? Some sample VB code would be appreciated.

My code used to be:

Dim defaultRole As SecuritySystemRole = ObjectSpace.FindObject(Of SecuritySystemRole)(
New BinaryOperator("Name", "Default"))
If defaultRole Is Nothing Then
defaultRole = ObjectSpace.CreateObject(Of SecuritySystemRole)()
defaultRole.Name = "Default"
End If
'set defaults
defaultRole.SetTypePermissionsRecursively(Of ModelDifference)(
SecurityOperations.ReadWriteAccess, SecuritySystemModifier.Allow)
defaultRole.SetTypePermissionsRecursively(Of ModelDifference)(
SecurityOperations.Create, SecuritySystemModifier.Allow)
defaultRole.SetTypePermissionsRecursively(Of ModelDifferenceAspect)(
SecurityOperations.ReadWriteAccess, SecuritySystemModifier.Allow)
defaultRole.SetTypePermissionsRecursively(Of ModelDifferenceAspect)(
SecurityOperations.Create, SecuritySystemModifier.Allow)

I assume I should

Replies

UserDescriptionPosted On
Sasha (Xafari Support)Client

Hello Steve,

Thanks for your ticket.

We are working on your issue and will get back to you as soon as we can. Please bear with us.

Best regards,
Sasha.

Sasha (Xafari Support)Client

Hello Steve,

Our apologies for the delay, we had some problem with XafariSecurity.

If you use security of Xafari, you can see the creation of a new role and a new user in next code:

Dim strategy = TryCast(SecuritySystem.Instance, SecurityStrategyComplex)
If strategy Is Nothing Then
Return
End If

Dim defaultRole = DirectCast(ObjectSpace.FindObject(strategy.RoleType, New BinaryOperator("Name", "Default")), IDCSecuritySystemRole)
If defaultRole IsNot Nothing Then
Return
End If
defaultRole = DirectCast(ObjectSpace.CreateObject(strategy.RoleType), IDCSecuritySystemRole)
DirectCast(defaultRole, INameSupport).Name = "Default"

Dim userPermissions = ObjectSpace.Xafari().CreateObject(Of IDCSecuritySystemTypePermissionObject)()
userPermissions.TargetType = strategy.UserType
userPermissions.AllowNavigate = True
'
' Access to system user details for current user
'
Dim myDetailsPermission = ObjectSpace.CreateObject(Of IDCSecuritySystemObjectPermissionsObject)()
myDetailsPermission.Criteria = "[Oid] = CurrentUserId()"
myDetailsPermission.AllowNavigate = True
myDetailsPermission.AllowRead = True

userPermissions.ObjectPermissions.Add(myDetailsPermission)
'
' Password access for users
'
Dim ownPasswordPermission = ObjectSpace.CreateObject(Of IDCSecuritySystemMemberPermissionsObject)()
ownPasswordPermission.Members = "ChangePasswordOnFirstLogon;StoredPassword"
ownPasswordPermission.AllowWrite = True
userPermissions.MemberPermissions.Add(ownPasswordPermission)

defaultRole.TypePermissions.Add(userPermissions)
'
' Read role info for current user
'
Dim securityRolePermissions = ObjectSpace.CreateObject(Of IDCSecuritySystemTypePermissionObject)()
securityRolePermissions.TargetType = strategy.RoleType

Dim defaultRolePermission = ObjectSpace.CreateObject(Of IDCSecuritySystemObjectPermissionsObject)()
defaultRolePermission.Criteria = CriteriaOperator.Parse("[Name] = ?", "Default").ToString()
defaultRolePermission.AllowNavigate = True
defaultRolePermission.AllowRead = True
securityRolePermissions.ObjectPermissions.Add(defaultRolePermission)

defaultRole.TypePermissions.Add(securityRolePermissions)
'
' Create user
'
Dim user = ObjectSpace.FindObject(Of IDCSecuritySystemUser)(New BinaryOperator("UserName", "Sam"))
If user Is Nothing Then
user = ObjectSpace.CreateObject(Of IDCSecuritySystemUser)()
user.UserName = "Sam"
user.SetPassword("")
user.DCRoles.Add(defaultRole)
End If
ObjectSpace.CommitChanges()

Thanks for your patience.
Let us know if you need further assistance.

Best regards,
Sasha.

× This ticket is closed.

Write US