Verifies a member’s ability to perform a specified operation within a security context.
Parameter |
Type |
Description |
---|---|---|
member |
The logon name of the user who is requesting access. The property should be set to the logon name in the form: DOMAIN\USERNAME. |
|
operationKey |
The operation key object that uniquely identifies the operation the member is requesting to access. |
|
context |
A security context object that specifies the application and scope properties of the request. |
Value |
Type |
Description |
---|---|---|
CheckAccessResult |
Specifies whether the member is granted access to the operation. True indicates access is granted. False indicates access is denied. |
The following C# example identifies whether a member has been granted access to an operation. The operation is identified by an operation key. The application defines operations and specifies the key used to uniquely identify each operation. The example uses the Microsoft Dynamics GP web service application. The member is identified by the logon name “DOMAIN\\username“. The example uses the operation key Id of “058300c6-b6da-4391-8708-74db75ed33eeCreate” to determine whether the member can create cash receipts. A message box displays whether or not access has been granted.
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using DynamicsSecurityServiceSample.DynamicsSecurityWebService; namespace DynamicsSecurityServiceSample { class Program { static void Main(string[] args) { ApplicationKey applicationKey; ScopeKey scopeKey; SecurityContext securityContext; OperationKey operationKey; bool accessGranted; // Create an instance of the security service DynamicsSecurityService wsDynamicsSecurity = new DynamicsSecurityService(); // Use default credentials wsDynamicsSecurity.UseDefaultCredentials = true; // Create a security context object securityContext = new SecurityContext(); // Create the application key and add it to the security context object // Use the ID of the Dynamics GP web service application applicationKey = new ApplicationKey(); applicationKey.Id = "25cc1a21-2cc4-4b13-a1c8-eea186fb688a"; securityContext.ApplicationKey = applicationKey; // Create the scope key and add it to the security context object // Use the id of the sample company scopeKey = new ScopeKey(); scopeKey.Id = "-1"; securityContext.ScopeKey = scopeKey; // Create an operation key object to specify the object operationKey = new OperationKey(); operationKey.Id = "058300c6-b6da-4391-8708-74db75ed33eeCreate"; // Determine whether a user has been granted access to the operation accessGranted = wsDynamicsSecurity.CheckAccess("DOMAIN\\username", operationKey, securityContext); // Display a message indicating whether the member can access the operation if(accessGranted == true) { MessageBox.Show("Access has been granted to create cash receipts"); } else { MessageBox.Show("Access has not been granted to create cash receipts"); } } } }