internal void SetGroupMailbox(GroupMailboxConfigurationActionType forceConfigurationActionMask, out Exception exception, out ExchangeErrorCategory?errorCategory) { errorCategory = null; try { this.AddVerboseLog("Start: SetGroupMailbox"); if (this.addMembers != null || this.removeMembers != null || !this.groupMailbox.IsGroupMailboxConfigured || this.permissionsVersion != null || forceConfigurationActionMask != (GroupMailboxConfigurationActionType)0) { this.UpdateGroupMailbox(null, forceConfigurationActionMask, this.GetValidGroupMembersFromFromRecipientIds(this.addMembers), this.ResolveUsers(this.removeMembers, new Action <RecipientIdParameter, Exception>(this.ReportResolveUserWarning))); if (this.invalidUsers.Length > 0) { CmdletLogger.SafeAppendGenericError("UsersWithoutSmtpAddress_Set", this.invalidUsers.ToString(), false); this.invalidUsers.Clear(); } } else { this.AddVerboseLog("No members to update on GroupMailbox or configuration action to execute."); } exception = null; } catch (LocalizedException ex) { exception = ex; errorCategory = new ExchangeErrorCategory?(ExchangeErrorCategory.ServerTransient); if (this.IsWellKnownClientException(ex)) { errorCategory = new ExchangeErrorCategory?(ExchangeErrorCategory.Client); } } finally { this.AddVerboseLog("End: SetGroupMailbox"); } }
protected UpdateGroupMailboxBase(ADUser group, ADUser executingUser, GroupMailboxConfigurationActionType forceActionMask, int?permissionsVersion) { ArgumentValidator.ThrowIfNull("group", group); ArgumentValidator.ThrowIfInvalidValue <ADUser>("group", group, (ADUser adUser) => adUser.RecipientTypeDetails == RecipientTypeDetails.GroupMailbox); this.group = group; this.executingUser = executingUser; this.forceActionMask = forceActionMask; this.permissionsVersion = permissionsVersion; }
private void UpdateGroupMailbox(DatabaseLocationInfo databaseLocationInfo, GroupMailboxConfigurationActionType forceConfigurationActionMask, List <ADUser> addedMembersList = null, List <ADUser> removedMembersList = null) { ADUser[] addedMembers = (addedMembersList != null && addedMembersList.Count > 0) ? addedMembersList.ToArray() : null; ADUser[] removedMembers = (removedMembersList != null && removedMembersList.Count > 0) ? removedMembersList.ToArray() : null; this.UpdateMembershipInAD(this.groupMailbox, addedMembers, removedMembers); try { this.AddVerboseLog("Start: UpdateGroupMailbox EWS Call"); using (new StopwatchPerformanceTracker("GroupMailboxContext.UpdateGroupMailbox", GenericCmdletInfoDataLogger.Instance)) { UpdateGroupMailboxBase updateGroupMailboxBase = UpdateGroupMailboxFactory.CreateUpdateGroupMailbox(this.adSession, this.groupMailbox, databaseLocationInfo, this.ExecutingUser, forceConfigurationActionMask, addedMembers, removedMembers, this.permissionsVersion); updateGroupMailboxBase.Execute(); if (updateGroupMailboxBase.Error != null) { if (updateGroupMailboxBase.ResponseCode == null) { throw new LocalizedException(new LocalizedString(updateGroupMailboxBase.Error)); } if (updateGroupMailboxBase.ResponseCode.Value == ResponseCodeType.ErrorOrganizationAccessBlocked) { throw new TenantAccessBlockedException(new LocalizedString(updateGroupMailboxBase.Error)); } if (updateGroupMailboxBase.ResponseCode.Value == ResponseCodeType.ErrorInvalidLicense) { throw new InvalidLicenseException(new LocalizedString(updateGroupMailboxBase.Error)); } throw new LocalizedException(new LocalizedString(updateGroupMailboxBase.Error)); } else if (!this.groupMailbox.IsGroupMailboxConfigured) { this.groupMailbox.IsGroupMailboxConfigured = true; } } } finally { this.AddVerboseLog("End: UpdateGroupMailbox EWS Call"); } }
public UpdateGroupMailboxViaEWS(ADUser group, ADUser executingUser, Uri endpointUrl, GroupMailboxConfigurationActionType forceActionMask, ADUser[] addedMembers, ADUser[] removedMembers, int?permissionsVersion) : base(group, executingUser, forceActionMask, permissionsVersion) { this.endpointUrl = endpointUrl; this.addedMembers = addedMembers; this.removedMembers = removedMembers; }
protected override void InternalProcessRecord() { IRecipientSession recipientSession = (IRecipientSession)base.DataSession; this.groupMailboxContext = new GroupMailboxContext(this.DataObject, base.CurrentOrganizationId, recipientSession, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADUser>), new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADGroup>), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.ErrorLoggerDelegate(base.WriteError)); if (this.ExecutingUser != null) { this.groupMailboxContext.SetExecutingUser(this.ExecutingUser); this.executingUserIsOwner = this.DataObject.Owners.Any((ADObjectId ownerId) => ADObjectId.Equals(this.groupMailboxContext.ExecutingUser.Id, ownerId)); } else { this.executingUserIsOwner = true; } if (base.Fields.IsChanged(ADObjectSchema.Name)) { this.ThrowIfNotOwner("Name"); this.DataObject.Name = (string)base.Fields[ADObjectSchema.Name]; } if (base.Fields.IsChanged(ADRecipientSchema.DisplayName)) { this.ThrowIfNotOwner("DisplayName"); this.DataObject.DisplayName = (string)base.Fields[ADRecipientSchema.DisplayName]; } if (base.Fields.IsChanged(ADRecipientSchema.Description)) { this.ThrowIfNotOwner("Description"); this.DataObject.Description.Clear(); this.DataObject.Description.Add((string)base.Fields[ADRecipientSchema.Description]); } bool flag = false; if (base.Fields.IsChanged(ADUserSchema.Owners) && this.Owners != null) { this.ThrowIfNotOwner("Owners"); flag |= this.groupMailboxContext.SetOwners(this.Owners); } if (base.Fields.IsModified("AddOwners") && this.AddOwners != null) { this.ThrowIfNotOwner("AddOwners"); flag |= this.groupMailboxContext.AddOwners(this.AddOwners); } if (base.Fields.IsModified("RemoveOwners") && this.RemoveOwners != null) { this.ThrowIfNotOwner("RemoveOwners"); flag |= this.groupMailboxContext.RemoveOwners(this.RemoveOwners); } if (base.Fields.IsChanged(ADMailboxRecipientSchema.DelegateListLink)) { this.ThrowIfNotOwner("PublicToGroups"); this.DataObject.DelegateListLink.Clear(); this.groupMailboxContext.AddPublicToGroups(this.PublicToGroups); } if (base.Fields.IsChanged(ADRecipientSchema.ModernGroupType)) { this.DataObject.ModernGroupType = (ModernGroupObjectType)base.Fields[ADRecipientSchema.ModernGroupType]; } if (base.Fields.IsChanged("RequireSenderAuthenticationEnabled")) { this.ThrowIfNotOwner("RequireSenderAuthenticationEnabled"); this.DataObject.RequireAllSendersAreAuthenticated = this.RequireSenderAuthenticationEnabled; } if (base.Fields.IsChanged("YammerGroupEmailAddress")) { this.DataObject.YammerGroupAddress = this.YammerGroupEmailAddress; } if (base.Fields.IsChanged("AutoSubscribeNewGroupMembers")) { this.ThrowIfNotOwner("AutoSubscribeNewGroupMembers"); this.DataObject.AutoSubscribeNewGroupMembers = this.AutoSubscribeNewGroupMembers; } if (base.Fields.IsChanged("Language") && this.Language != null) { this.DataObject.Languages.Clear(); this.DataObject.Languages.Add(this.Language); } if (this.MembersChanged) { this.AuthorizeAddedAndRemovedMembers(this.groupMailboxContext.ExecutingUser); this.groupMailboxContext.AddAndRemoveMembers(this.AddedMembers, this.RemovedMembers); } if (base.Fields.IsModified(ADMailboxRecipientSchema.SharePointUrl)) { this.ThrowIfNotOwner("SharePointUrl"); if (this.DataObject.SharePointResources == null) { this.DataObject.SharePointResources = new MultiValuedProperty <string>(); } else { foreach (string text in this.DataObject.SharePointResources) { if (text.StartsWith("SiteUrl=", StringComparison.OrdinalIgnoreCase)) { this.DataObject.SharePointResources.Remove(text); break; } } } if (this.SharePointUrl != null) { this.DataObject.SharePointResources.Add("SiteUrl=" + this.SharePointUrl); } } if (base.Fields.IsModified(ADMailboxRecipientSchema.SharePointResources)) { this.ThrowIfNotOwner("SharePointResources"); this.DataObject.SharePointResources = this.SharePointResources; this.DataObject.SharePointUrl = null; } if (base.Fields.IsModified("PermissionsVersion")) { this.groupMailboxContext.SetPermissionsVersion(this.PermissionsVersion); } GroupMailboxConfigurationActionType groupMailboxConfigurationActionType = (GroupMailboxConfigurationActionType)0; if (base.Fields.IsModified("ConfigurationActions") && this.ConfigurationActions != null) { foreach (GroupMailboxConfigurationActionType groupMailboxConfigurationActionType2 in this.ConfigurationActions) { groupMailboxConfigurationActionType |= groupMailboxConfigurationActionType2; } } Exception ex; ExchangeErrorCategory?exchangeErrorCategory; this.groupMailboxContext.SetGroupMailbox(groupMailboxConfigurationActionType, out ex, out exchangeErrorCategory); if (ex != null) { base.WriteError(new GroupMailboxFailedToLogonException(Strings.ErrorUnableToLogonGroupMailbox(this.DataObject.ExchangeGuid, string.Empty, recipientSession.LastUsedDc, ex.Message)), exchangeErrorCategory.GetValueOrDefault(ExchangeErrorCategory.ServerTransient), null); } bool flag2 = false; if (!this.FromSyncClient) { if (base.Fields.IsChanged(GroupMailboxSchema.PrimarySmtpAddress)) { this.DataObject.PrimarySmtpAddress = this.PrimarySmtpAddress; flag2 = true; } if (base.Fields.IsChanged(GroupMailboxSchema.EmailAddresses)) { this.DataObject.EmailAddresses = this.EmailAddresses; flag2 = true; } } else if (base.Fields.IsChanged(GroupMailboxSchema.EmailAddresses)) { foreach (ProxyAddress proxyAddress in this.EmailAddresses) { if (!this.DataObject.EmailAddresses.Contains(proxyAddress)) { if (proxyAddress.IsPrimaryAddress && proxyAddress is SmtpProxyAddress) { this.DataObject.EmailAddresses.Add(proxyAddress.ToSecondary()); } else { this.DataObject.EmailAddresses.Add(proxyAddress); } flag2 = true; } } } if (flag2 && this.DataObject.EmailAddressPolicyEnabled) { this.DataObject.EmailAddressPolicyEnabled = false; } if (base.Fields.IsModified(ADRecipientSchema.ExternalDirectoryObjectId)) { this.DataObject.ExternalDirectoryObjectId = this.ExternalDirectoryObjectId; } base.InternalProcessRecord(); this.DataObject = recipientSession.FindADUserByObjectId(this.DataObject.ObjectId); if (flag) { this.groupMailboxContext.RefreshStoreCache(); } if (!this.DataObject.GroupMailboxExternalResourcesSet || this.ForcePublishExternalResources) { this.groupMailboxContext.SetExternalResources(this.FromSyncClient); } this.groupMailboxContext.EnsureGroupIsInDirectoryCache("SetGroupMailbox.InternalProcessRecord"); }
public static UpdateGroupMailboxBase CreateUpdateGroupMailbox(IRecipientSession adSession, ADUser group, DatabaseLocationInfo databaseLocationInfo, ADUser executingUser, GroupMailboxConfigurationActionType forceActionMask, ADUser[] addedMembers, ADUser[] removedMembers, int?permissionsVersion) { ExchangePrincipal exchangePrincipal; using (new StopwatchPerformanceTracker("UpdateGroupMailboxFactory.CreateUpdateGroupMailbox.BuildExchangePrincipal", GenericCmdletInfoDataLogger.Instance)) { exchangePrincipal = ExchangePrincipal.FromADUser(group, databaseLocationInfo, RemotingOptions.AllowCrossSite); } Uri backEndWebServicesUrl; using (new StopwatchPerformanceTracker("UpdateGroupMailboxFactory.CreateUpdateGroupMailbox.GetBackEndHttpService", GenericCmdletInfoDataLogger.Instance)) { backEndWebServicesUrl = BackEndLocator.GetBackEndWebServicesUrl(exchangePrincipal.MailboxInfo); UpdateGroupMailboxFactory.Tracer.TraceDebug(0L, "UpdateGroupMailboxFactory.CreateUpdateGroupMailbox - BackendUrl=" + backEndWebServicesUrl); } if (ExEnvironment.IsTest && !VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled) { UserMailboxLocator[] array; if (addedMembers == null) { array = null; } else { array = (from user in addedMembers select UserMailboxLocator.Instantiate(adSession, user)).ToArray <UserMailboxLocator>(); } UserMailboxLocator[] addedMembers2 = array; UserMailboxLocator[] array2; if (removedMembers == null) { array2 = null; } else { array2 = (from user in removedMembers select UserMailboxLocator.Instantiate(adSession, user)).ToArray <UserMailboxLocator>(); } UserMailboxLocator[] removedMembers2 = array2; return(new UpdateGroupMailboxViaXSO(adSession, group, exchangePrincipal, executingUser, forceActionMask, addedMembers2, removedMembers2, permissionsVersion)); } return(new UpdateGroupMailboxViaEWS(group, executingUser, backEndWebServicesUrl, forceActionMask, addedMembers, removedMembers, permissionsVersion)); }
public UpdateGroupMailboxViaXSO(IRecipientSession adSession, ADUser group, ExchangePrincipal groupMailboxPrincipal, ADUser executingUser, GroupMailboxConfigurationActionType forceActionMask, UserMailboxLocator[] addedMembers, UserMailboxLocator[] removedMembers, int?permissionsVersion) : base(group, executingUser, forceActionMask, permissionsVersion) { ArgumentValidator.ThrowIfNull("adSession", adSession); this.addedMembers = addedMembers; this.removedMembers = removedMembers; this.adSession = adSession; this.groupMailboxPrincipal = groupMailboxPrincipal; }