Skip to main content
A newer version of this page is available. .

Access the Security System in Code

  • 2 minutes to read

This lesson will guide you through using the static SecuritySystem class to check whether or not a user has particular permission. The SetTask Action will be accessible to users who have permission to modify DemoTask objects.

 

Note

Before proceeding, we recommend that you review the following lessons.

  • Open the TaskActionsController.cs (TaskActionsController.vb) file you created in the Add an Action with Option Selection lesson. Add the “using” directive and modify the Activated event handler as shown below.

    using DevExpress.ExpressApp.Security;
    //...
    public partial class TaskActionsController : ViewController {
        // ...
        private void TaskActionsController_Activated(object sender, EventArgs e) {
            View.SelectionChanged += new EventHandler(View_SelectionChanged);
            UpdateSetTaskActionState();
        }
        void View_SelectionChanged(object sender, EventArgs e) {
            UpdateSetTaskActionState();
        }
        private void UpdateSetTaskActionState() {
            bool isGranted = true;
            foreach(object selectedObject in View.SelectedObjects) {
                bool isPriorityGranted = SecuritySystem.IsGranted(new PermissionRequest(ObjectSpace, 
                typeof(DemoTask), SecurityOperations.Write, selectedObject, "Priority"));
                bool isStatusGranted = SecuritySystem.IsGranted(new PermissionRequest(ObjectSpace, 
                typeof(DemoTask), SecurityOperations.Write, selectedObject, "Status"));
                if(!isPriorityGranted || !isStatusGranted) {
                    isGranted = false;
                }
            }
            SetTaskAction.Enabled.SetItemValue("SecurityAllowance", isGranted);
        }
    }
    

    With the added code, the Set Task Action will be activated for users who have write permissions for the Priority and Status properties of the selected DemoTask objects.

  • Add a user who does not have permission to modify the DemoTask objects (see Using the Security System). Run the application as this new user. The Set Task Action will not be visible when you display the Demo Task List View.

 

This is the last lesson of the Comprehensive Tutorial. To learn more about the main concepts for building business applications and extending XAF tools, refer to the Concepts section. If you need task-based help, take a look at the Task-Based Help section. To learn how to deploy XAF applications, review the Deployment Tutorial.

See Also