Пример #1
0
        private void RemoveRolePrincipalsSelected()
        {
            string secondaryEntityName = null;

            switch (PrincipalType)
            {
            case CrmPrincipalType.User:
                secondaryEntityName = "systemuser";
                break;

            case CrmPrincipalType.Team:
                secondaryEntityName = "team";
                break;

            default:
                break;
            }

            string primaryEntityName = "role";

            foreach (Guid roleId in Role)
            {
                Guid   primaryEntityId    = roleId;
                Guid[] secondaryEntityIds = Principals;
                Guid[] currentSetIds      = SecurityManagementHelper.GetPrincipalsInRole(_repository, PrincipalType.Value, roleId).Select(e => e.Id).ToArray();
                Guid[] removeSet          = secondaryEntityIds.Intersect(currentSetIds).ToArray();

                if (removeSet != null && removeSet.Length > 0)
                {
                    SecurityManagementHelper.UnlinkPrincipalRoles(_repository, primaryEntityName, primaryEntityId, secondaryEntityName, removeSet);
                }
            }
        }
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            IEnumerable <Entity> teams = SecurityManagementHelper.GetPrincipalsInRole(_repository, CrmPrincipalType.Team, Role);

            WriteObject(teams, true);

            IEnumerable <Entity> users = SecurityManagementHelper.GetPrincipalsInRole(_repository, CrmPrincipalType.User, Role);

            WriteObject(users, true);
        }
Пример #3
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            string secondaryEntityName = null;

            switch (PrincipalType)
            {
            case CrmPrincipalType.User:
                secondaryEntityName = "systemuser";
                break;

            case CrmPrincipalType.Team:
                secondaryEntityName = "team";
                break;

            default:
                break;
            }

            string primaryEntityName = "role";

            foreach (Guid roleId in Role)
            {
                Guid   primaryEntityId    = roleId;
                Guid[] secondaryEntityIds = Principals;
                Guid[] currentSetIds      = SecurityManagementHelper.GetPrincipalsInRole(_repository, PrincipalType, roleId).Select(e => e.Id).ToArray();

                Guid[] addSet = secondaryEntityIds.Except(currentSetIds).ToArray();
                if (addSet != null && addSet.Length > 0)
                {
                    SecurityManagementHelper.LinkPrincipalRoles(_repository, primaryEntityName, primaryEntityId, secondaryEntityName, addSet);
                }
                //Remove associations which are in current and not in new
                if (Overwrite)
                {
                    Guid[] removeSet = currentSetIds.Except(secondaryEntityIds).ToArray();
                    if (removeSet != null && removeSet.Length > 0)
                    {
                        SecurityManagementHelper.UnlinkPrincipalRoles(_repository, primaryEntityName, primaryEntityId, secondaryEntityName, removeSet);
                    }
                }

                if (PassThru)
                {
                    WriteObject(_repository.Get(primaryEntityName, primaryEntityId));
                }
            }
        }
Пример #4
0
        private void RemoveRoleTeamsAll(Guid roleId)
        {
            string secondaryEntityName = "team";
            string primaryEntityName   = "role";
            Guid   primaryEntityId     = roleId;

            Guid[] secondaryEntityIds = Principals;
            Guid[] currentSetIds      = SecurityManagementHelper.GetPrincipalsInRole(_repository, PrincipalType.Value, roleId).Select(e => e.Id).ToArray();
            Guid[] removeSet          = secondaryEntityIds.Intersect(currentSetIds).ToArray();

            if (removeSet != null && removeSet.Length > 0)
            {
                SecurityManagementHelper.UnlinkPrincipalRoles(_repository, primaryEntityName, primaryEntityId, secondaryEntityName, removeSet);
            }
        }