예제 #1
0
        public void Entity_Not_Granted_Access_Does_Not_Have_Access()
        {
            var context = new XrmFakedContext();
            var contact = new Contact {
                Id = Guid.NewGuid()
            };
            var user = new SystemUser {
                Id = Guid.NewGuid()
            };

            context.Initialize(new List <Entity>
            {
                contact, user
            });

            var service = context.GetFakedOrganizationService();

            RetrievePrincipalAccessRequest rpar = new RetrievePrincipalAccessRequest
            {
                Target    = contact.ToEntityReference(),
                Principal = user.ToEntityReference()
            };

            RetrievePrincipalAccessResponse rpaResp = (RetrievePrincipalAccessResponse)service.Execute(rpar);

            Assert.Equal(AccessRights.None, rpaResp.AccessRights);
        }
        internal override OrganizationResponse Execute(OrganizationRequest orgRequest, EntityReference userRef)
        {
            var request = MakeRequest <RetrievePrincipalAccessRequest>(orgRequest);
            var resp    = new RetrievePrincipalAccessResponse();

            resp.Results["AccessRights"] = security.GetAccessRights(request.Target, request.Principal);
            return(resp);
        }
예제 #3
0
        public AccessRights GetAccessRights(EntityReference Record, EntityReference Principal)
        {
            RetrievePrincipalAccessRequest req = new RetrievePrincipalAccessRequest
            {
                Principal = Principal,
                Target    = Record
            };

            RetrievePrincipalAccessResponse resp = (RetrievePrincipalAccessResponse)OrganizationService.Execute(req);

            return(resp.AccessRights);
        }
예제 #4
0
        /// <summary>
        /// Retrieves the RetrievePrincipalAccessResponse for the specified security principal (user or team) and record
        /// </summary>
        /// <param name="er"></param>
        /// <param name="principal"></param>
        public RetrievePrincipalAccessResponse RetrievePrincipalAccess(EntityReference er, EntityReference principal)
        {
            List <PrincipalAccess>          accessList = GetAccessListForRecord(er);
            PrincipalAccess                 pAcc       = accessList.Where(pa => pa.Principal.Id == principal.Id).SingleOrDefault();
            RetrievePrincipalAccessResponse resp       = new RetrievePrincipalAccessResponse();

            if (pAcc != null)
            {
                resp.Results["AccessRights"] = pAcc.AccessMask;
            }

            return(resp);
        }
예제 #5
0
        public void Entity_Granted_Multiple_Access_Has_Access()
        {
            var context = new XrmFakedContext();
            var contact = new Contact {
                Id = Guid.NewGuid()
            };
            var user = new SystemUser {
                Id = Guid.NewGuid()
            };

            context.Initialize(new List <Entity>
            {
                contact, user
            });

            var service = context.GetFakedOrganizationService();

            GrantAccessRequest gar = new GrantAccessRequest
            {
                PrincipalAccess = new PrincipalAccess
                {
                    AccessMask = AccessRights.ReadAccess | AccessRights.WriteAccess | AccessRights.DeleteAccess | AccessRights.CreateAccess,
                    Principal  = user.ToEntityReference()
                },
                Target = contact.ToEntityReference()
            };

            service.Execute(gar);

            RetrievePrincipalAccessRequest rpar = new RetrievePrincipalAccessRequest
            {
                Target    = contact.ToEntityReference(),
                Principal = user.ToEntityReference()
            };

            RetrievePrincipalAccessResponse rpaResp = (RetrievePrincipalAccessResponse)service.Execute(rpar);

            Assert.NotEqual(AccessRights.None, rpaResp.AccessRights);
            Assert.True(rpaResp.AccessRights.HasFlag(AccessRights.ReadAccess));
            Assert.False(rpaResp.AccessRights.HasFlag(AccessRights.AppendAccess));
            Assert.False(rpaResp.AccessRights.HasFlag(AccessRights.AppendToAccess));
            Assert.False(rpaResp.AccessRights.HasFlag(AccessRights.AssignAccess));
            Assert.True(rpaResp.AccessRights.HasFlag(AccessRights.CreateAccess));
            Assert.True(rpaResp.AccessRights.HasFlag(AccessRights.DeleteAccess));
            Assert.False(rpaResp.AccessRights.HasFlag(AccessRights.ShareAccess));
            Assert.True(rpaResp.AccessRights.HasFlag(AccessRights.WriteAccess));
        }
        public bool DoesUserHavePrivilage(EntityReference entity, EntityReference systemuser, AccessRights access)
        {
            RetrievePrincipalAccessRequest request = new RetrievePrincipalAccessRequest
            {
                Principal = systemuser,
                Target    = entity
            };
            RetrievePrincipalAccessResponse principalAccessResponse = (RetrievePrincipalAccessResponse)ServiceProxy.Execute(request);

            if ((principalAccessResponse.AccessRights & access) != AccessRights.None)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #7
0
        /// <summary>
        /// Check <c>System User</c> 's access rights on specified record.
        /// <para>
        /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.retrieveprincipalaccessrequest(v=crm.8).aspx
        /// </para>
        /// </summary>
        /// <param name="id"><c>System User</c> Id</param>
        /// <param name="targetRecordLogicalName">Target record <c>logical name</c> for which to retrieve access rights.</param>
        /// <param name="targetRecordId">Target record <c>Id</c> for which to retrieve access rights.</param>
        /// <returns>
        /// <c>True</c> if <c>System User</c> has any access right on the record, otherwise return <c>false</c>
        /// </returns>
        public bool HasAccessRight(Guid id, string targetRecordLogicalName, Guid targetRecordId)
        {
            ExceptionThrow.IfGuidEmpty(id, "id");
            ExceptionThrow.IfGuidEmpty(targetRecordId, "entityId");
            ExceptionThrow.IfNullOrEmpty(targetRecordLogicalName, "entityName");

            bool result = false;

            RetrievePrincipalAccessRequest request = new RetrievePrincipalAccessRequest()
            {
                Principal = new EntityReference(this.EntityName, id),
                Target    = new EntityReference(targetRecordLogicalName, targetRecordId)
            };

            RetrievePrincipalAccessResponse serviceResponse = (RetrievePrincipalAccessResponse)this.OrganizationService.Execute(request);

            if (serviceResponse.AccessRights != AccessRights.None)
            {
                result = true;
            }

            return(result);
        }
예제 #8
0
        private void RetrieveAccessRights()
        {
            if (cBoxEntities.SelectedIndex < 0)
            {
                MessageBox.Show(this, "Please select an entity", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txtObjectId.Text.Length == 0)
            {
                MessageBox.Show(this, "Please specify an object Id", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (textBox_UserID.Text.Length == 0)
            {
                MessageBox.Show(this, "Please select a user", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                var g = new Guid(txtObjectId.Text);
            }
            catch
            {
                MessageBox.Show(this, "The object ID is invalid", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var parameters = new List <string> {
                txtObjectId.Text, textBox_UserID.Tag.ToString(),
                ((EntityInfo)cBoxEntities.SelectedItem).LogicalName,
                ((EntityInfo)cBoxEntities.SelectedItem).PrimaryAttribute
            };

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "Retrieving access rights...",
                AsyncArgument = parameters,
                Work          = (bw, e) =>
                {
                    var crmAccess        = new CrmAccess(Service);
                    var inParameters     = (List <string>)e.Argument;
                    var recordId         = new Guid(inParameters[0]);
                    var userId           = new Guid(inParameters[1]);
                    var entityName       = inParameters[2];
                    var primaryAttribute = inParameters[3];
                    var result           = new CheckAccessResult();

                    RetrievePrincipalAccessResponse response = crmAccess.RetrieveRights(
                        userId,
                        recordId,
                        entityName);

                    Dictionary <string, Guid> privileges = crmAccess.RetrievePrivileges(entityName);

                    // Get primary attribute value for the current record
                    Entity de         = crmAccess.RetrieveDynamicWithPrimaryAttr(recordId, entityName, primaryAttribute);
                    result.RecordName = de.GetAttributeValue <string>(primaryAttribute);

                    // Check Privileges
                    foreach (string privlegeName in privileges.Keys)
                    {
                        if (privlegeName.StartsWith("prvappend"))
                        {
                            result.HasAppendAccess   = (response.AccessRights & AccessRights.AppendAccess) == AccessRights.AppendAccess;
                            result.AppendPrivilegeId = privileges[privlegeName];
                        }

                        if (privlegeName.StartsWith("prvappendto"))
                        {
                            result.HasAppendToAccess   = (response.AccessRights & AccessRights.AppendToAccess) == AccessRights.AppendToAccess;
                            result.AppendToPrivilegeId = privileges[privlegeName];
                        }

                        if (privlegeName.StartsWith("prvassign"))
                        {
                            result.HasAssignAccess   = (response.AccessRights & AccessRights.AssignAccess) == AccessRights.AssignAccess;
                            result.AssignPrivilegeId = privileges[privlegeName];
                        }

                        if (privlegeName.StartsWith("prvcreate"))
                        {
                            result.HasCreateAccess   = (response.AccessRights & AccessRights.CreateAccess) == AccessRights.CreateAccess;
                            result.CreatePrivilegeId = privileges[privlegeName];
                        }

                        if (privlegeName.StartsWith("prvdelete"))
                        {
                            result.HasDeleteAccess   = (response.AccessRights & AccessRights.DeleteAccess) == AccessRights.DeleteAccess;
                            result.DeletePrivilegeId = privileges[privlegeName];
                        }

                        if (privlegeName.StartsWith("prvread"))
                        {
                            result.HasReadAccess   = (response.AccessRights & AccessRights.ReadAccess) == AccessRights.ReadAccess;
                            result.ReadPrivilegeId = privileges[privlegeName];
                        }

                        if (privlegeName.StartsWith("prvshare"))
                        {
                            result.HasShareAccess   = (response.AccessRights & AccessRights.ShareAccess) == AccessRights.ShareAccess;
                            result.SharePrivilegeId = privileges[privlegeName];
                        }

                        if (privlegeName.StartsWith("prvwrite"))
                        {
                            result.HasWriteAccess   = (response.AccessRights & AccessRights.WriteAccess) == AccessRights.WriteAccess;
                            result.WritePrivilegeId = privileges[privlegeName];
                        }
                    }

                    e.Result = result;
                },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        MessageBox.Show(this, "An error occured: " + e.Error.Message, "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    else
                    {
                        var result     = (CheckAccessResult)e.Result;
                        var greenColor = Color.FromArgb(0, 158, 73);
                        var redColor   = Color.FromArgb(232, 17, 35);

                        textBox_PrimaryAttribute.Text = result.RecordName;

                        pnlAppend.BackColor = result.HasAppendAccess
                                                  ? greenColor
                                                  : result.AppendPrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                        pnlAppendTo.BackColor = result.HasAppendToAccess
                                                    ? greenColor
                                                    : result.AppendToPrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                        pnlAssign.BackColor = result.HasAssignAccess
                                                  ? greenColor
                                                  : result.AssignPrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                        pnlCreate.BackColor = result.HasCreateAccess
                                                  ? greenColor
                                                  : result.CreatePrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                        pnlDelete.BackColor = result.HasDeleteAccess
                                                  ? greenColor
                                                  : result.DeletePrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                        pnlRead.BackColor = result.HasReadAccess
                                                ? greenColor
                                                : result.ReadPrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                        pnlShare.BackColor = result.HasShareAccess
                                                 ? greenColor
                                                 : result.SharePrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                        pnlWrite.BackColor = result.HasWriteAccess
                                                 ? greenColor
                                                 : result.WritePrivilegeId != Guid.Empty ? redColor : Color.DarkGray;

                        lblPrivilegeAppend.Text = result.AppendPrivilegeId == Guid.Empty
                                                      ? "Privilege does not exist for this entity"
                                                      : string.Format("Privilege Id: {0}",
                                                                      result.AppendPrivilegeId.ToString("B"));
                        lblPrivilegeAppendTo.Text = result.AppendToPrivilegeId == Guid.Empty
                                                        ? "Privilege does not exist for this entity"
                                                        : string.Format("Privilege Id: {0}",
                                                                        result.AppendToPrivilegeId.ToString("B"));
                        lblPrivilegeAssign.Text = result.AssignPrivilegeId == Guid.Empty
                                                      ? "Privilege does not exist for this entity"
                                                      : string.Format("Privilege Id: {0}",
                                                                      result.AssignPrivilegeId.ToString("B"));
                        lblPrivilegeCreate.Text = result.CreatePrivilegeId == Guid.Empty
                                                      ? "Privilege does not exist for this entity"
                                                      : string.Format("Privilege Id: {0}",
                                                                      result.CreatePrivilegeId.ToString("B"));
                        lblPrivilegeDelete.Text = result.DeletePrivilegeId == Guid.Empty
                                                      ? "Privilege does not exist for this entity"
                                                      : string.Format("Privilege Id: {0}",
                                                                      result.DeletePrivilegeId.ToString("B"));
                        lblPrivilegeRead.Text = result.ReadPrivilegeId == Guid.Empty
                                                    ? "Privilege does not exist for this entity"
                                                    : string.Format("Privilege Id: {0}", result.ReadPrivilegeId.ToString("B"));
                        lblPrivilegeShare.Text = result.SharePrivilegeId == Guid.Empty
                                                     ? "Privilege does not exist for this entity"
                                                     : string.Format("Privilege Id: {0}", result.SharePrivilegeId.ToString("B"));
                        lblPrivilegeWrite.Text = result.WritePrivilegeId == Guid.Empty
                                                     ? "Privilege does not exist for this entity"
                                                     : string.Format("Privilege Id: {0}", result.WritePrivilegeId.ToString("B"));
                    }
                }
            });
        }
        /// <summary>
        /// Demonstrates sharing records by exercising various access messages including:
        /// Grant, Modify, Revoke, RetrievePrincipalAccess, and
        /// RetrievePrincipalsAndAccess.
        /// </summary>
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptforDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete)
        {
            try
            {
                // Connect to the Organization service.
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    _service = (IOrganizationService)_serviceProxy;

                    CreateRequiredRecords();

                    #region GrantAccess Message

                    // Create the request object and set the target and principal access
                    // object.
                    GrantAccessRequest grantRequest = new GrantAccessRequest()
                    {
                        Target          = new EntityReference(Account.EntityLogicalName, _accountId),
                        PrincipalAccess = new PrincipalAccess()
                        {
                            Principal  = new EntityReference(SystemUser.EntityLogicalName, _userId),
                            AccessMask = AccessRights.WriteAccess | AccessRights.ReadAccess | AccessRights.ShareAccess
                        }
                    };

                    // Execute the request.
                    GrantAccessResponse grantResponse =
                        (GrantAccessResponse)_service.Execute(grantRequest);

                    Console.Write("Access Granted ");

                    #endregion

                    #region ModifyAccess Message

                    // Create the request object and set the target and principal access
                    // object.
                    ModifyAccessRequest modifyRequest = new ModifyAccessRequest()
                    {
                        Target          = new EntityReference(Account.EntityLogicalName, _accountId),
                        PrincipalAccess = new PrincipalAccess()
                        {
                            Principal  = new EntityReference(SystemUser.EntityLogicalName, _userId),
                            AccessMask = AccessRights.ReadAccess | AccessRights.ShareAccess
                        }
                    };

                    // Execute the request.
                    ModifyAccessResponse modifyResponse =
                        (ModifyAccessResponse)_service.Execute(modifyRequest);

                    Console.Write("and Modified. ");

                    #endregion

                    #region RetrievePrincipalAccess Message

                    // Create the request object and set the target and principal.
                    RetrievePrincipalAccessRequest retrieveRequest = new RetrievePrincipalAccessRequest()
                    {
                        Target    = new EntityReference(Account.EntityLogicalName, _accountId),
                        Principal = new EntityReference(SystemUser.EntityLogicalName, _userId)
                    };

                    // Execute the request.
                    RetrievePrincipalAccessResponse retrieveResponse =
                        (RetrievePrincipalAccessResponse)_service.Execute(retrieveRequest);

                    Console.Write("Retrieved principal access. ");

                    #endregion

                    #region RetrieveSharedPrincipalsAndAccess Message

                    // Create the request object and set the target.
                    RetrieveSharedPrincipalsAndAccessRequest retrieveSharedRequest =
                        new RetrieveSharedPrincipalsAndAccessRequest()
                    {
                        Target = new EntityReference(Account.EntityLogicalName, _accountId)
                    };

                    // Execute the request.
                    RetrieveSharedPrincipalsAndAccessResponse retrieveSharedResponse =
                        (RetrieveSharedPrincipalsAndAccessResponse)_service.Execute(retrieveSharedRequest);

                    Console.Write("Retrieved principals and access. ");

                    #endregion

                    #region RevokeAccess Message

                    // Create the request object and set the target and revokee.
                    RevokeAccessRequest revokeRequest = new RevokeAccessRequest()
                    {
                        Target  = new EntityReference(Account.EntityLogicalName, _accountId),
                        Revokee = new EntityReference(SystemUser.EntityLogicalName, _userId)
                    };

                    // Execute the request.
                    RevokeAccessResponse revokeResponse =
                        (RevokeAccessResponse)_service.Execute(revokeRequest);

                    Console.Write("Revoked Access.");

                    #endregion

                    DeleteRequiredRecords(promptforDelete);
                }
            }

            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
예제 #10
0
        private void RetrieveAccessRights()
        {
            if (cBoxEntities.SelectedIndex < 0)
            {
                MessageBox.Show(this, "Please select an table", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txtObjectId.Text.Length == 0)
            {
                MessageBox.Show(this, "Please specify an object Id", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (textBox_UserID.Text.Length == 0)
            {
                MessageBox.Show(this, "Please select a user", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                var g = new Guid(txtObjectId.Text);
            }
            catch
            {
                MessageBox.Show(this, "The object ID is invalid", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            ResetPermissions();

            var parameters = new List <object> {
                txtObjectId.Text, textBox_UserID.Tag,
                (EntityInfo)cBoxEntities.SelectedItem
            };

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "Retrieving access rights...",
                AsyncArgument = parameters,
                Work          = (bw, e) =>
                {
                    var crmAccess        = new CrmAccess(Service, ConnectionDetail);
                    var inParameters     = (List <object>)e.Argument;
                    var recordId         = new Guid(inParameters[0].ToString());
                    var user             = (User)inParameters[1];
                    var entityInfo       = (EntityInfo)inParameters[2];
                    var entityName       = entityInfo.LogicalName;
                    var primaryAttribute = entityInfo.PrimaryAttribute;
                    var result           = new CheckAccessResult();

                    if (ConnectionDetail.NewAuthType != Microsoft.Xrm.Tooling.Connector.AuthenticationType.OAuth &&
                        ConnectionDetail.NewAuthType != Microsoft.Xrm.Tooling.Connector.AuthenticationType.Certificate)
                    {
                        RetrievePrincipalAccessResponse response = crmAccess.RetrieveRights(
                            user.Id,
                            recordId,
                            entityName);

                        Dictionary <string, Guid> privileges = crmAccess.RetrievePrivileges(entityName);

                        // Get primary attribute value for the current record
                        Entity de         = crmAccess.RetrieveDynamicWithPrimaryAttr(recordId, entityName, primaryAttribute);
                        result.RecordName = de.GetAttributeValue <string>(primaryAttribute);

                        // Check Privileges
                        foreach (string privlegeName in privileges.Keys)
                        {
                            if (privlegeName.StartsWith("prvappendto"))
                            {
                                result.HasAppendToAccess   = (response.AccessRights & AccessRights.AppendToAccess) == AccessRights.AppendToAccess;
                                result.AppendToPrivilegeId = privileges[privlegeName];
                            }
                            else if (privlegeName.StartsWith("prvappend"))
                            {
                                result.HasAppendAccess   = (response.AccessRights & AccessRights.AppendAccess) == AccessRights.AppendAccess;
                                result.AppendPrivilegeId = privileges[privlegeName];
                            }
                            else if (privlegeName.StartsWith("prvassign"))
                            {
                                result.HasAssignAccess   = (response.AccessRights & AccessRights.AssignAccess) == AccessRights.AssignAccess;
                                result.AssignPrivilegeId = privileges[privlegeName];
                            }
                            else if (privlegeName.StartsWith("prvcreate"))
                            {
                                result.HasCreateAccess   = (response.AccessRights & AccessRights.CreateAccess) == AccessRights.CreateAccess;
                                result.CreatePrivilegeId = privileges[privlegeName];
                            }
                            else if (privlegeName.StartsWith("prvdelete"))
                            {
                                result.HasDeleteAccess   = (response.AccessRights & AccessRights.DeleteAccess) == AccessRights.DeleteAccess;
                                result.DeletePrivilegeId = privileges[privlegeName];
                            }
                            else if (privlegeName.StartsWith("prvread"))
                            {
                                result.HasReadAccess   = (response.AccessRights & AccessRights.ReadAccess) == AccessRights.ReadAccess;
                                result.ReadPrivilegeId = privileges[privlegeName];
                            }
                            else if (privlegeName.StartsWith("prvshare"))
                            {
                                result.HasShareAccess   = (response.AccessRights & AccessRights.ShareAccess) == AccessRights.ShareAccess;
                                result.SharePrivilegeId = privileges[privlegeName];
                            }
                            else if (privlegeName.StartsWith("prvwrite"))
                            {
                                result.HasWriteAccess   = (response.AccessRights & AccessRights.WriteAccess) == AccessRights.WriteAccess;
                                result.WritePrivilegeId = privileges[privlegeName];
                            }

                            e.Result = result;
                        }
                    }
                    else
                    {
                        List <Privilege> privList = crmAccess.RetrieveRightsAPI(user.Id, recordId, entityName);

                        if (privList.Any(priv => priv.Permissions.Any(per => per.PermissionType == PermissionType.Role)))
                        {
                            crmAccess.GetRoleDetail(privList, user, recordId, entityInfo);
                        }

                        if (privList.Any(priv => priv.Permissions.Any(per => per.PermissionType == PermissionType.Shared)))
                        {
                            crmAccess.GetShareDetail(privList, user, recordId, entityInfo);
                        }

                        e.Result = privList;
                    }
                },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        MessageBox.Show(this, "An error occured: " + e.Error.Message, "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    else
                    {
                        if (e.Result is List <Privilege> privList)
                        {
                            var greenColor = Color.LightGreen; // Color.FromArgb(0, 158, 73);
                            var redColor   = Color.LightPink;  // Color.FromArgb(232, 17, 35);

                            foreach (Privilege privilege in privList)
                            {
                                Control panel        = Helper.FindByTag(splitAccess, privilege.PrivilegeType);
                                panel.BackColor      = privilege.HasAccess ? greenColor : redColor;
                                var privLabel        = (TextBox)Helper.FindByTag(panel, privilege.PrivilegeType + "Label");
                                privLabel.BackColor  = panel.BackColor;
                                privLabel.Text       = privilege.PrivilegeId.ToString();
                                FlowLayoutPanel flow = Helper.FindByTag(panel, privilege.PrivilegeType + "Flow") as FlowLayoutPanel;
                                //flow.Controls.Clear();
                                if (flow != null)
                                {
                                    foreach (var permission in privilege.Permissions.Where(per => per.PermissionType != PermissionType.Role && per.PermissionType != PermissionType.Shared))
                                    {
                                        flow.Controls.Add(new DisplayAccess(permission));
                                    }
                                }
                            }
                        }
                        else
                        {
                            var result = (CheckAccessResult)e.Result;

                            var greenColor = Color.FromArgb(0, 158, 73);
                            var redColor   = Color.FromArgb(232, 17, 35);

                            textBox_PrimaryAttribute.Text = result.RecordName;

                            pnlAppend.BackColor = result.HasAppendAccess
                                                      ? greenColor
                                                      : result.AppendPrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                            pnlAppendTo.BackColor = result.HasAppendToAccess
                                                        ? greenColor
                                                        : result.AppendToPrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                            pnlAssign.BackColor = result.HasAssignAccess
                                                      ? greenColor
                                                      : result.AssignPrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                            pnlCreate.BackColor = result.HasCreateAccess
                                                      ? greenColor
                                                      : result.CreatePrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                            pnlDelete.BackColor = result.HasDeleteAccess
                                                      ? greenColor
                                                      : result.DeletePrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                            pnlRead.BackColor = result.HasReadAccess
                                                    ? greenColor
                                                    : result.ReadPrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                            pnlShare.BackColor = result.HasShareAccess
                                                     ? greenColor
                                                     : result.SharePrivilegeId != Guid.Empty ? redColor : Color.DarkGray;
                            pnlWrite.BackColor = result.HasWriteAccess
                                                     ? greenColor
                                                     : result.WritePrivilegeId != Guid.Empty ? redColor : Color.DarkGray;

                            txtAppendPriv.BackColor = pnlAppend.BackColor;
                            txtAppendPriv.Text      = result.AppendPrivilegeId == Guid.Empty
                                                          ? "Privilege does not exist for this entity"
                                                          : result.AppendPrivilegeId.ToString();
                            txtAppendToPriv.BackColor = pnlAppendTo.BackColor;
                            txtAppendToPriv.Text      = result.AppendToPrivilegeId == Guid.Empty
                                                            ? "Privilege does not exist for this entity"
                                                            : result.AppendToPrivilegeId.ToString();
                            txtAssignPriv.BackColor = pnlAssign.BackColor;
                            txtAssignPriv.Text      = result.AssignPrivilegeId == Guid.Empty
                                                          ? "Privilege does not exist for this entity"
                                                          : result.AssignPrivilegeId.ToString();
                            txtCreatePriv.BackColor = pnlCreate.BackColor;
                            txtCreatePriv.Text      = result.CreatePrivilegeId == Guid.Empty
                                                          ? "Privilege does not exist for this entity"
                                                          : result.CreatePrivilegeId.ToString();
                            txtDeletePriv.BackColor = pnlDelete.BackColor;
                            txtDeletePriv.Text      = result.DeletePrivilegeId == Guid.Empty
                                                          ? "Privilege does not exist for this entity"
                                                          : result.DeletePrivilegeId.ToString();
                            txtReadPriv.BackColor = pnlRead.BackColor;
                            txtReadPriv.Text      = result.ReadPrivilegeId == Guid.Empty
                                                        ? "Privilege does not exist for this entity"
                                                        : result.ReadPrivilegeId.ToString();
                            txtSharePriv.BackColor = pnlShare.BackColor;
                            txtSharePriv.Text      = result.SharePrivilegeId == Guid.Empty
                                                         ? "Privilege does not exist for this entity"
                                                         : result.SharePrivilegeId.ToString();
                            txtWritePriv.BackColor = pnlWrite.BackColor;
                            txtWritePriv.Text      = result.WritePrivilegeId == Guid.Empty
                                                         ? "Privilege does not exist for this entity"
                                                         : result.WritePrivilegeId.ToString();
                        }

                        ai.WriteEvent("User Checked", 1);
                    }
                }
            });
        }