Ticket Q361586
Visible to All Users

Create Member Level And Object Permissions Via Code For Improved Security In XAF

created 13 years ago

I have reviewed the documentation for the new Improved Security in XAF and do not see any information on setting member level permissions or object permissions via code. I need to be able to create Object Permissions and Member Permissions via code during the initial setup of the application.
Please let me know where the documentation illustrating these two specific scenarios is or please provide a simple example of creating each permission. I have already reviewed the documentation at http://documentation.devexpress.com/#Xaf/CustomDocument3361. Of course I may have missed something but I don't see any code examples showing how to set the Member or Object permissions.

Comments (1)
DevExpress Support Team 13 years ago

    Hello, Mark.
    Currently, we do not have such an example in documentation, but we will add it in the next update. Below is the snippet that illustrates how to create member-level and object-level permissions in Updater.

    C#
    private SecurityRole CreateDefaultRole() { SecurityRole defaultRole = ObjectSpace.FindObject<SecurityRole>(new BinaryOperator("Name", "Default")); if(defaultRole == null) { defaultRole = ObjectSpace.CreateObject<SecurityRole>(); defaultRole.Name = "Default"; ObjectOperationPermissionData myDetailsPermission = ObjectSpace.CreateObject<ObjectOperationPermissionData>(); myDetailsPermission.TargetType = typeof(SecurityUser); myDetailsPermission.Criteria = "[Oid] = CurrentUserId()"; myDetailsPermission.AllowNavigate = true; myDetailsPermission.AllowRead = true; myDetailsPermission.Save(); defaultRole.PersistentPermissions.Add(myDetailsPermission); MemberOperationPermissionData userNamePermission = ObjectSpace.CreateObject<MemberOperationPermissionData>(); userNamePermission.TargetType = typeof(SecurityUser); userNamePermission.Members = "ChangePasswordOnFirstLogon"; userNamePermission.AllowWrite = true; userNamePermission.Save(); defaultRole.PersistentPermissions.Add(userNamePermission); MemberOperationPermissionData ownPasswordPermission = ObjectSpace.CreateObject<MemberOperationPermissionData>(); ownPasswordPermission.TargetType = typeof(SecurityUser); ownPasswordPermission.Members = "StoredPassword"; ownPasswordPermission.AllowWrite = true; ownPasswordPermission.Save(); defaultRole.PersistentPermissions.Add(ownPasswordPermission); ObjectOperationPermissionData defaultRolePermission = ObjectSpace.CreateObject<ObjectOperationPermissionData>(); defaultRolePermission.TargetType = typeof(SecurityRole); defaultRolePermission.Criteria = "[Name] = 'Default'"; defaultRolePermission.AllowNavigate = true; defaultRolePermission.AllowRead = true; defaultRolePermission.Save(); defaultRole.PersistentPermissions.Add(defaultRolePermission); } return defaultRole; }

    You can also refer to the SecurityDemo sources to see more examples.
    Thanks,
    Konstantin B

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.