private RoleGroupCollection GetInvalidRoleGroups()
        {
            bool flag = Datacenter.IsPartnerHostedOnly(false);
            RoleGroupCollection roleGroupCollection = new RoleGroupCollection();
            List <string>       enabledRoleGroupRoleAssignmentFeatures = this.ServicePlanSettings.Organization.GetEnabledRoleGroupRoleAssignmentFeatures();

            using (List <RoleGroupDefinition> .Enumerator enumerator = RoleGroupDefinitions.RoleGroups.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    RoleGroupDefinition  roleGroupDefinition = enumerator.Current;
                    RoleGroupRoleMapping roleGroupRoleMapping;
                    if (flag)
                    {
                        roleGroupRoleMapping = HostedTenant_RoleGroupDefinition.Definition.FirstOrDefault((RoleGroupRoleMapping x) => x.RoleGroup.Equals(roleGroupDefinition.Name, StringComparison.OrdinalIgnoreCase));
                    }
                    else
                    {
                        roleGroupRoleMapping = Tenant_RoleGroupDefinition.Definition.FirstOrDefault((RoleGroupRoleMapping x) => x.RoleGroup.Equals(roleGroupDefinition.Name, StringComparison.OrdinalIgnoreCase));
                    }
                    if (roleGroupRoleMapping != null && roleGroupRoleMapping.GetRolesAssignments(enabledRoleGroupRoleAssignmentFeatures).Count == 0)
                    {
                        roleGroupCollection.Add(new RoleGroupDefinition(roleGroupDefinition));
                    }
                }
            }
            return(roleGroupCollection);
        }
        private void CreateAndValidateRoleGroups(ADObjectId usgContainerId, RoleGroupCollection roleGroups)
        {
            RoleGroupDefinition roleGroupDefinition = roleGroups.FirstOrDefault((RoleGroupDefinition x) => x.RoleGroupGuid.Equals(RoleGroup.OrganizationManagement_InitInfo.WellKnownGuid));

            if (roleGroupDefinition == null)
            {
                base.WriteError(new ExOrgAdminSGroupNotFoundException(WellKnownGuid.EoaWkGuid), ErrorCategory.ObjectNotFound, null);
            }
            roleGroups.Remove(roleGroupDefinition);
            roleGroupDefinition.ADGroup = this.CreateRoleGroup(usgContainerId, roleGroupDefinition, null);
            if (!roleGroupDefinition.ADGroup.ManagedBy.Contains(roleGroupDefinition.ADGroup.Id))
            {
                roleGroupDefinition.ADGroup.ManagedBy.Add(roleGroupDefinition.ADGroup.Id);
                this.orgDomainRecipientSession.Save(roleGroupDefinition.ADGroup);
                base.LogWriteObject(roleGroupDefinition.ADGroup);
            }
            List <ADObjectId> manageBy = new List <ADObjectId>
            {
                roleGroupDefinition.ADGroup.Id
            };

            foreach (RoleGroupDefinition roleGroupDefinition2 in roleGroups)
            {
                roleGroupDefinition2.ADGroup = this.CreateRoleGroup(usgContainerId, roleGroupDefinition2, manageBy);
            }
            roleGroups.Add(roleGroupDefinition);
        }
        private ADGroup CreateRoleGroup(ADObjectId usgContainerId, RoleGroupDefinition roleGroup, List <ADObjectId> manageBy)
        {
            ADGroup adgroup = this.CreateGroup(this.organization.OrganizationId, usgContainerId, roleGroup.Name, roleGroup.Id, roleGroup.RoleGroupGuid, roleGroup.Description, GroupTypeFlags.Universal | GroupTypeFlags.SecurityEnabled, manageBy);

            if (adgroup == null)
            {
                base.WriteError(roleGroup.GuidNotFoundException, ErrorCategory.ObjectNotFound, null);
            }
            base.LogWriteObject(adgroup);
            return(adgroup);
        }
        private ADGroup FindCannedRoleGroupByName(string rgName)
        {
            RoleGroupDefinition roleGroupDefinition = RoleGroupDefinitions.RoleGroups.FirstOrDefault((RoleGroupDefinition x) => x.Name.Equals(rgName, StringComparison.OrdinalIgnoreCase));
            Guid guid = Guid.Empty;

            if (roleGroupDefinition != null)
            {
                guid = roleGroupDefinition.RoleGroupGuid;
            }
            ADGroup adgroup = this.ResolveWellKnownGuid(guid);

            if (adgroup == null)
            {
                base.WriteError(new ExRbacRoleGroupNotFoundException(guid, (roleGroupDefinition != null) ? roleGroupDefinition.Name : string.Empty), ErrorCategory.InvalidData, null);
            }
            base.LogReadObject(adgroup);
            return(adgroup);
        }
        internal static RoleGroupCollection RoleGroupsToCreate()
        {
            RoleGroupCollection roleGroupCollection = new RoleGroupCollection();

            Datacenter.ExchangeSku exchangeSku = Datacenter.GetExchangeSku();
            RoleGroupRoleMapping[] definition;
            if (Datacenter.IsMicrosoftHostedOnly(false))
            {
                definition = Datacenter_RoleGroupDefinition.Definition;
            }
            else if (Datacenter.IsPartnerHostedOnly(false))
            {
                definition = Hosting_RoleGroupDefinition.Definition;
            }
            else if (Datacenter.IsDatacenterDedicated(false))
            {
                definition = Dedicated_RoleGroupDefinition.Definition;
            }
            else
            {
                definition = Enterprise_RoleGroupDefinition.Definition;
            }
            using (List <RoleGroupDefinition> .Enumerator enumerator = RoleGroupDefinitions.RoleGroups.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    RoleGroupDefinition roleGroup = enumerator.Current;
                    if (roleGroup.AlwaysCreateOnSku != null && roleGroup.AlwaysCreateOnSku.Contains(exchangeSku))
                    {
                        roleGroupCollection.Add(new RoleGroupDefinition(roleGroup));
                    }
                    else
                    {
                        RoleGroupRoleMapping roleGroupRoleMapping = definition.FirstOrDefault((RoleGroupRoleMapping x) => x.RoleGroup.Equals(roleGroup.Name, StringComparison.OrdinalIgnoreCase));
                        if (roleGroupRoleMapping != null)
                        {
                            roleGroupCollection.Add(new RoleGroupDefinition(roleGroup));
                        }
                    }
                }
            }
            return(roleGroupCollection);
        }
        private void CreateRoleGroup(ADOrganizationalUnit usgContainer, RoleGroupDefinition roleGroup)
        {
            ADGroup adgroup = this.CreateGroup(usgContainer, roleGroup.Name, roleGroup.Id, roleGroup.RoleGroupGuid, roleGroup.Description, GroupTypeFlags.Universal | GroupTypeFlags.SecurityEnabled, true);

            if (adgroup == null)
            {
                base.WriteError(roleGroup.GuidNotFoundException, ErrorCategory.ObjectNotFound, null);
            }
            base.LogReadObject(adgroup);
            foreach (Guid wkg in roleGroup.E12USG)
            {
                ADGroup adgroup2 = base.ResolveExchangeGroupGuid <ADGroup>(wkg);
                if (adgroup2 != null && adgroup2.RecipientType == RecipientType.Group)
                {
                    base.LogReadObject(adgroup2);
                    TaskLogger.Trace("Adding old USG {0} as member of RG {1}", new object[]
                    {
                        adgroup2.Name,
                        adgroup.Name
                    });
                    InitializeExchangeUniversalGroups.AddMember(adgroup2, this.rootDomainRecipientSession, adgroup, new WriteVerboseDelegate(base.WriteVerbose));
                }
            }
        }
 private static bool IsDehydrateable(RoleGroupDefinition roleGroupDefinition)
 {
     return(false);
 }
 public RoleGroupDefinition(RoleGroupDefinition roleGroup) : this(roleGroup.Name, roleGroup.Id, roleGroup.RoleGroupGuid, roleGroup.Description, roleGroup.AlwaysCreateOnSku, roleGroup.E12USG.ToArray())
 {
 }