Ticket T116745
Visible to All Users

Non persistent type doesn't appear in combobox for targettypes with SecurityComplex

created 11 years ago

Hello,

i have added a nonpersistent type through AdditionalSecuredTypes, but i don't see the type in the combobox of object types in the object access permission dialog. Please see the atttached sample. I am using SecurityComplex, not SecurityStrategyComplex. With SeceurityStrategyComplex it works.

Comments (1)
Dennis Garavsky (DevExpress) 11 years ago

    Hello Dominic,

    Thank you for your sample. We need some additional time to research it. Please bear with it.

    Answers approved by DevExpress Support

    created 11 years ago

    Hello Dominic,
    Thank you for the sample project. We have found that the SecurityComplex is not designed to manage access permissions for non persistent objects. As you can see there is only the "Persistent Permissions" tab.
    By default both SecurityComplex and SecurityStrategyComplex exclude non persistent types from permissions by checking the typesInfo.IsPersistent property:

    C#
    if(currentType == typeof(object)) { if((objectType != null) && typesInfo.FindTypeInfo(objectType).IsPersistent) { ParticularAccessItem persistentBaseObjectItem = FindExactItem(PermissionTargetBusinessClassListConverter.PersistentBaseObjectType, access); if(persistentBaseObjectItem != null) { return persistentBaseObjectItem; } } }

    In the new SecurityStrategyComplex we have represented the AdditionalSecuredTypes static collection which allows you to add non persistent types.

    So that is why non persistent types are shown in the SecurityStrategyComplex but not in the SecurityComplex.

    Please let me know if you need further assistance.

      Comments (2)

        Hello,
        What can i do, if i want to check permissions (in fact only navigation access) of non persistent types with SecurityComplex.

        DevExpress Support Team 11 years ago

          The best solution is to use the SecurityStrategyComplex instead of SecurityComplex, because SecurityStrategyComplex provides a great mechanism for working with non persistent types.

          As for the SecurityComplex, it is possible to define permissions for all business objects using the AllBusinessObject value in the ObjectType ComboBox. But if you need control permission for persistent types separately, I recommend you extend the Role class and add required properties to store permissions for non persistent classes. Using permissions there you can hide a corresponding navigation item. For example, you can use the approach described in the Unable to Hide navigation item via Active property thread.

          Currently, I strongly recommend you use the SecurityStrategyComplex, because it already provides a mechanism to apply permissions to non persistent types and other useful features.

          Do not hesitate to ask additional question. I'm always happy to help you.

          Other Answers

          created 9 years ago (modified 9 years ago)

          Hello, maybe this solution will be helpful for somebody:
          XAF uses TypePropertyEditor for properties of System.Type type. The list of available types that shown in drop down of this property editor is defined by Type Converter that is specified as attribute on the property.
          The ObjectAccessPermission.ObjectType property decorated by PermissionTargetBusinessClassListConverter Type Converter.
          The idea is to create own TypeConverter class and specify it for ObjectAccessPermission.ObjectType property instead of default one using approaches described in Customize Business Object's Metadata. Here is code (tested in DevExpress v11.1):

          C#
          //override CustomizeTypesInfo method of module or controller public override void CustomizeTypesInfo(ITypesInfo typesInfo) { base.CustomizeTypesInfo(typesInfo); var permissionType = typeof(DevExpress.ExpressApp.Security.ObjectAccessPermission); var permissionTypeInfo = typesInfo.FindTypeInfo(permissionType); var objectTypeMemberInfo = permissionTypeInfo.FindMember("ObjectType"); var attr = objectTypeMemberInfo.FindAttribute<System.ComponentModel.TypeConverterAttribute>(); //First add new attribute than remove old. Otherwise removed attribute will be added back (may be bug) objectTypeMemberInfo.AddAttribute(new System.ComponentModel.TypeConverterAttribute(typeof(AllBusinessObjectsTypeConverter))); if (attr != null) ((BaseInfo)objectTypeMemberInfo).RemoveAttribute(attr); } //... //this is custom TypeConverter public class AllBusinessObjectsTypeConverter : LocalizedClassInfoTypeConverter { public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { // Below is just example of how to retreive required types. // It is not good idea to retrieve all available non persistent types // because there is a lot of build-in non persistent types that supports XAF infrastructure // and otherwise they will litter the drop-down list of types. // Here types are retreived from ApplicationModel that obtained from CaptionHelper. // It's not so good. You can retrieve required types using XafTypesInfo class. var model = CaptionHelper.ApplicationModel; if (model != null) { var types = new List<Type>(); types.Add(PermissionTargetBusinessClassListConverter.CommonBaseObjectType); types.Add(PermissionTargetBusinessClassListConverter.PersistentBaseObjectType); var bOTypes = model.BOModel .Select(cl => cl.TypeInfo) .Where(t => t.IsVisible && t.Type != null) .Select(t => t.Type); types.AddRange(bOTypes); return new StandardValuesCollection(types); } return base.GetStandardValues(context); } protected override string GetClassCaption(string fullName) { var typeInfo = XafTypesInfo.Instance.FindTypeInfo(fullName); if (typeInfo != null) { if (typeInfo.Type == PermissionTargetBusinessClassListConverter.CommonBaseObjectType) return PermissionTargetBusinessClassListConverter.CommonBaseObjectTypeCaption; if (typeInfo.Type == PermissionTargetBusinessClassListConverter.PersistentBaseObjectType) return PermissionTargetBusinessClassListConverter.PersistentBaseObjectTypeCaption; } return base.GetClassCaption(fullName); } }
            Comments (1)
            Dennis Garavsky (DevExpress) 9 years ago

              Thanks for sharing your solution, Sargis. Indeed, it can be used here and we described it in greater detail at How to hide or filter out certain types from the drop-down editor for the System.Type properties a few days ago.

              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.