Esempio n. 1
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            IEnumerable <Entity> teamRoles = SecurityManagementHelper.GetRolesForPrincipal(_repository, CrmPrincipalType.Team, Principal);

            WriteObject(teamRoles, true);

            IEnumerable <Entity> userRoles = SecurityManagementHelper.GetRolesForPrincipal(_repository, CrmPrincipalType.User, Principal);

            WriteObject(userRoles, true);
        }
Esempio n. 2
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            string primaryEntityName = null;

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

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

            default:
                break;
            }

            string secondaryEntityName = "role";

            foreach (Guid principalId in Principal)
            {
                Guid   primaryEntityId    = principalId;
                Guid[] secondaryEntityIds = Roles;
                Guid[] currentSetIds      = SecurityManagementHelper.GetRolesForPrincipal(_repository, PrincipalType, principalId).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));
                }
            }
        }
Esempio n. 3
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            string primaryEntityName = null;

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

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

            default:
                break;
            }

            string secondaryEntityName = "role";

            foreach (Guid id in Principal)
            {
                Guid   primaryEntityId = id;
                Guid[] currentSetIds   = SecurityManagementHelper.GetRolesForPrincipal(_repository, PrincipalType, id).Select(e => e.Id).ToArray();
                Guid[] removeSet       = Roles;

                if (this.ParameterSetName == RemovePrincipalRolesAllParameterSet)
                {
                    removeSet = currentSetIds;
                }

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