Skip to main content
.NET 6.0+

IsGrantedExtensions.CanReadByRole<T>(SecurityStrategy, IPermissionPolicyRole, IObjectSpace, Object, String) Method

Checks whether the specified role allows reading an object with the specified key or this object’s member.

Namespace: DevExpress.ExpressApp.Security

Assembly: DevExpress.ExpressApp.Security.v23.2.dll

Declaration

public static bool CanReadByRole<T>(
    this SecurityStrategy security,
    IPermissionPolicyRole targetRole,
    IObjectSpace objectSpace,
    object targetObjectKey,
    string memberName = null
)

Parameters

Name Type Description
security SecurityStrategy

A SecurityStrategy object that specifies an application’s Security Strategy.

targetRole IPermissionPolicyRole

An IPermissionPolicyRole object that is a role this method checks.

objectSpace IObjectSpace

An Object Space this method uses to get an object to check.

targetObjectKey Object

An Object that is a key of an object this method checks.

Optional Parameters

Name Type Default Description
memberName String null

A String that is a name of the target object’s member this method checks. This parameter is optional.

Type Parameters

Name Description
T

A Type of an object this method checks.

Returns

Type Description
Boolean

true, if the specified role allows reading an object with the specified key or this object’s member; otherwise, false.

Remarks

The following example shows how to use this method.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Security;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EF.PermissionPolicy;
using System;
// ...
public class CheckReadPermissionController : ObjectViewController<ListView, Contact> {
    SecurityStrategy securityStrategy;
    protected override void OnActivated() {
        base.OnActivated();
        securityStrategy = Application.GetSecurityStrategy();
        View.CurrentObjectChanged += View_CurrentObjectChanged;
    }
    private void View_CurrentObjectChanged(object sender, EventArgs e) {
        Department department = ViewCurrentObject.Department;
        if (department != null) {
            object key = ObjectSpace.GetKeyValue(department);
            foreach (IPermissionPolicyRole role in ObjectSpace.GetObjects<PermissionPolicyRole>()) {
                if (!securityStrategy.CanReadByRole<Department>(role, ObjectSpace, key, nameof(Department.Office))) {
                    // ...
                }
            }
        }
    }
}
See Also