internal static ADUser FetchRecipientFromMailboxId(string domainController, MailboxIdParameter mailbox, out IRecipientSession session, OrganizationId orgId)
		{
			session = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(domainController, true, ConsistencyMode.IgnoreInvalid, orgId.ToADSessionSettings(), 191, "FetchRecipientFromMailboxId", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Elc\\StoreRetentionPolicyTagHelper.cs");
			LocalizedString? localizedString = null;
			IEnumerable<ADUser> objects = mailbox.GetObjects<ADUser>(null, session, null, out localizedString);
			ADUser aduser = null;
			if (objects != null)
			{
				foreach (ADUser aduser2 in objects)
				{
					if (aduser != null)
					{
						throw new ManagementObjectAmbiguousException(Strings.ErrorRecipientNotUnique(mailbox.ToString()));
					}
					aduser = aduser2;
				}
			}
			if (aduser == null)
			{
				throw new ManagementObjectNotFoundException(localizedString ?? Strings.ErrorObjectNotFound(mailbox.ToString()));
			}
			return aduser;
		}
        private void ValidateCSV()
        {
            Stream stream = null;

            try
            {
                Stream stream2;
                if (this.CSVStream != null)
                {
                    stream2 = this.CSVStream;
                }
                else
                {
                    stream2 = new MemoryStream(this.CSVData);
                    stream  = stream2;
                }
                PublicFolderMigrationRequestCsvSchema publicFolderMigrationRequestCsvSchema = new PublicFolderMigrationRequestCsvSchema();
                publicFolderMigrationRequestCsvSchema.PropertyValidationError += delegate(CsvRow row, string columnName, PropertyValidationError error)
                {
                    base.WriteError(new RecipientTaskException(Strings.ErrorParsingCSV(row.Index, columnName, error.Description)), ExchangeErrorCategory.Client, null);
                };
                Dictionary <string, Guid> dictionary  = new Dictionary <string, Guid>();
                Dictionary <string, Guid> dictionary2 = null;
                bool flag = false;
                foreach (CsvRow csvRow in publicFolderMigrationRequestCsvSchema.Read(stream2))
                {
                    if (csvRow.Index != 0)
                    {
                        if (!flag)
                        {
                            dictionary2 = this.CreateMailboxNameToGuidMap();
                            flag        = true;
                        }
                        string             text               = csvRow["FolderPath"];
                        string             identity           = csvRow["TargetMailbox"];
                        MailboxIdParameter mailboxIdParameter = MailboxIdParameter.Parse(identity);
                        ADUser             aduser             = (ADUser)base.GetDataObject <ADUser>(mailboxIdParameter, this.recipientSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(mailboxIdParameter.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(mailboxIdParameter.ToString())));
                        if (dictionary.ContainsKey(text))
                        {
                            base.WriteError(new RecipientTaskException(Strings.ErrorParsingCSV(csvRow.Index, "FolderPath", "DuplicateFolderPathEntry")), ExchangeErrorCategory.Client, null);
                        }
                        else if (!dictionary2.ContainsValue(aduser.ExchangeGuid))
                        {
                            base.WriteError(new RecipientTaskException(Strings.ErrorParsingCSV(csvRow.Index, "TargetMailbox", "InvalidPublicFolderMailbox")), ExchangeErrorCategory.Client, null);
                        }
                        dictionary.Add(text, aduser.ExchangeGuid);
                        this.folderToMailboxMapping.Add(new FolderToMailboxMapping(text, aduser.ExchangeGuid));
                    }
                }
                if (!flag)
                {
                    base.WriteError(new RecipientTaskException(Strings.ErrorParsingCSV(1, "FolderPath", "NoInputDataFound")), ExchangeErrorCategory.Client, null);
                }
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                    stream = null;
                }
            }
        }
Exemple #3
0
        internal static ExchangePrincipal GetExchangePrincipal(ADSessionSettings sessionSettings, IRecipientSession recipientSession, MailboxIdParameter mailbox, string cmdletName, out Exception localizedError, out ADUser adUser)
        {
            localizedError = null;
            adUser         = null;
            mailbox.SearchWithDisplayName = false;
            IEnumerable <ADRecipient> objects = mailbox.GetObjects <ADRecipient>(null, recipientSession);
            ExchangePrincipal         result;

            using (IEnumerator <ADRecipient> enumerator = objects.GetEnumerator())
            {
                if (!enumerator.MoveNext())
                {
                    localizedError = new RecipientNotFoundException(mailbox.ToString());
                    result         = null;
                }
                else
                {
                    ADUser aduser = enumerator.Current as ADUser;
                    if (enumerator.MoveNext())
                    {
                        localizedError = new RecipientNotUniqueException(mailbox.ToString());
                        result         = null;
                    }
                    else if (aduser == null || (aduser.RecipientType != RecipientType.UserMailbox && aduser.RecipientType != RecipientType.MailUser))
                    {
                        localizedError = new RecipientNotValidException(mailbox.ToString());
                        result         = null;
                    }
                    else if ((int)aduser.ExchangeVersion.ExchangeBuild.Major > Server.CurrentExchangeMajorVersion || (int)aduser.ExchangeVersion.ExchangeBuild.Major < Server.Exchange2009MajorVersion)
                    {
                        localizedError = new ServerVersionNotSupportedException(cmdletName, Server.CurrentExchangeMajorVersion, (int)aduser.ExchangeVersion.ExchangeBuild.Major);
                        result         = null;
                    }
                    else
                    {
                        ADSessionSettings adSettings = sessionSettings;
                        IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.FullyConsistent, sessionSettings, 125, "GetExchangePrincipal", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\AirSync\\MobileDeviceTaskHelper.cs");
                        if (TaskHelper.ShouldUnderscopeDataSessionToOrganization(tenantOrRootOrgRecipientSession, aduser))
                        {
                            IDirectorySession directorySession = TaskHelper.UnderscopeSessionToOrganization(tenantOrRootOrgRecipientSession, aduser.OrganizationId, sessionSettings, true);
                            adSettings = directorySession.SessionSettings;
                        }
                        ExchangePrincipal exchangePrincipal = null;
                        try
                        {
                            adUser            = aduser;
                            exchangePrincipal = ExchangePrincipal.FromADUser(adSettings, aduser, RemotingOptions.AllowCrossSite);
                        }
                        catch (UserHasNoMailboxException ex)
                        {
                            localizedError = ex;
                            return(null);
                        }
                        if (exchangePrincipal == null)
                        {
                            localizedError = new ExchangePrincipalNotFoundException(aduser.ToString());
                            result         = null;
                        }
                        else
                        {
                            result = exchangePrincipal;
                        }
                    }
                }
            }
            return(result);
        }
Exemple #4
0
        protected override IConfigDataProvider CreateSession()
        {
            ADObjectId executingUserId;

            if (!base.TryGetExecutingUserId(out executingUserId) && this.Mailbox == null)
            {
                return(this.CreateDataProviderForNonMailboxUser());
            }
            MailboxIdParameter mailboxIdParameter = this.Mailbox ?? MailboxTaskHelper.ResolveMailboxIdentity(executingUserId, new Task.ErrorLoggerDelegate(base.WriteError));

            try
            {
                this.adUser = (ADUser)base.GetDataObject <ADUser>(mailboxIdParameter, base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(mailboxIdParameter.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(mailboxIdParameter.ToString())));
            }
            catch (ManagementObjectNotFoundException)
            {
                return(this.CreateDataProviderForNonMailboxUser());
            }
            this.isBposUser = CapabilityHelper.HasBposSKUCapability(this.adUser.PersistedCapabilities);
            ADScopeException ex;

            if (!TaskHelper.UnderscopeSessionToOrganization(base.TenantGlobalCatalogSession, this.adUser.OrganizationId, true).TryVerifyIsWithinScopes(this.adUser, true, out ex))
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorCannotChangeMailboxOutOfWriteScope(this.adUser.Identity.ToString(), (ex == null) ? string.Empty : ex.Message), ex), ErrorCategory.InvalidOperation, this.adUser.Identity);
            }
            IConfigDataProvider configDataProvider = GetApp.CreateOwaExtensionDataProvider(null, base.TenantGlobalCatalogSession, base.SessionSettings, !this.OrganizationApp, this.adUser, "New-App", false, new Task.ErrorLoggerDelegate(base.WriteError));

            this.mailboxOwner = ((OWAExtensionDataProvider)configDataProvider).MailboxSession.MailboxOwner.ObjectId.ToString();
            return(configDataProvider);
        }
Exemple #5
0
        internal static ADObjectId ValidateGeneratingMailbox(IConfigDataProvider session, MailboxIdParameter generatingMailboxId, OfflineAddressBookTaskUtility.GetUniqueObject getAdUser, OfflineAddressBook target, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskErrorLoggingDelegate writeError)
        {
            ADObjectId result = null;

            if (OABVariantConfigurationSettings.IsLinkedOABGenMailboxesEnabled)
            {
                if (generatingMailboxId == null)
                {
                    writeWarning(Strings.WarningGeneratingMailboxIsNullOABWillNotBeGenerated);
                }
                else
                {
                    ADUser aduser = (ADUser)getAdUser(generatingMailboxId, session, null, new LocalizedString?(Strings.ErrorMailboxAddressNotFound(generatingMailboxId.ToString())), new LocalizedString?(Strings.ErrorMailboxAddressNotUnique(generatingMailboxId.ToString())));
                    if (aduser.RecipientTypeDetails != RecipientTypeDetails.ArbitrationMailbox || aduser.PersistedCapabilities == null || !aduser.PersistedCapabilities.Contains(Capability.OrganizationCapabilityOABGen))
                    {
                        writeError(new InvalidOperationException(Strings.ErrorGeneratingMailboxInvalid(aduser.Name)), ErrorCategory.InvalidOperation, target.Identity);
                    }
                    result = aduser.Id;
                }
            }
            else if (generatingMailboxId != null)
            {
                writeError(new InvalidOperationException(Strings.ErrorLinkedMailboxesAreNotSupported), ErrorCategory.InvalidOperation, target.Identity);
            }
            return(result);
        }
Exemple #6
0
 private void ResolveADUser(MailboxIdParameter mailbox)
 {
     this.adUser = (ADUser)base.GetDataObject <ADUser>(mailbox, base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorUserNotFound(mailbox.ToString())), new LocalizedString?(Strings.ErrorUserNotUnique(mailbox.ToString())));
     base.VerifyIsWithinScopes(TaskHelper.UnderscopeSessionToOrganization(base.TenantGlobalCatalogSession, this.adUser.OrganizationId, true), this.adUser, true, new DataAccessTask <UMPhoneSession> .ADObjectOutOfScopeString(Strings.ErrorCannotChangeMailboxOutOfWriteScope));
 }
Exemple #7
0
        protected override IConfigDataProvider CreateSession()
        {
            ADUser     adUser = null;
            ADObjectId executingUserId;

            if (!base.TryGetExecutingUserId(out executingUserId))
            {
                return(this.CreateDataProviderForNonMailboxUser());
            }
            MailboxIdParameter mailboxIdParameter = MailboxTaskHelper.ResolveMailboxIdentity(executingUserId, new Task.ErrorLoggerDelegate(base.WriteError));

            try
            {
                adUser = (ADUser)base.GetDataObject <ADUser>(mailboxIdParameter, base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(mailboxIdParameter.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(mailboxIdParameter.ToString())));
            }
            catch (ManagementObjectNotFoundException)
            {
                return(this.CreateDataProviderForNonMailboxUser());
            }
            if (this.Identity != null && this.Identity.InternalOWAExtensionId == null)
            {
                this.Identity.InternalOWAExtensionId = OWAExtensionHelper.CreateOWAExtensionId(this, new ADObjectId(), null, this.Identity.RawExtensionName);
            }
            if (this.Organization != null)
            {
                this.SetCurrentOrganizationId();
            }
            return(GetApp.CreateOwaExtensionDataProvider(this.Organization, base.TenantGlobalCatalogSession, base.SessionSettings, false, adUser, "Set-App", false, new Task.ErrorLoggerDelegate(base.WriteError)));
        }
Exemple #8
0
        protected override IConfigDataProvider CreateSession()
        {
            IRecipientSession  tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(base.DomainController, false, ConsistencyMode.PartiallyConsistent, base.SessionSettings, 82, "CreateSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Mobility\\Aggregation\\RemoveSubscriptionBase.cs");
            MailboxIdParameter mailboxIdParameter      = this.GetMailboxIdParameter();
            ADUser             adUser                  = (ADUser)base.GetDataObject <ADUser>(mailboxIdParameter, tenantOrRootOrgRecipientSession, null, new LocalizedString?(Strings.ErrorUserNotFound(mailboxIdParameter.ToString())), new LocalizedString?(Strings.ErrorUserNotUnique(mailboxIdParameter.ToString())));
            IRecipientSession  session                 = AggregationTaskUtils.VerifyIsWithinWriteScopes(tenantOrRootOrgRecipientSession, adUser, new Task.TaskErrorLoggingDelegate(this.WriteDebugInfoAndError));
            AggregationSubscriptionDataProvider result = null;

            try
            {
                AggregationType aggregationType = this.AggregationType;
                if (this.Identity != null && this.Identity.AggregationType != null)
                {
                    aggregationType = this.Identity.AggregationType.Value;
                }
                result = SubscriptionConfigDataProviderFactory.Instance.CreateSubscriptionDataProvider(aggregationType, AggregationTaskType.Remove, session, adUser);
            }
            catch (MailboxFailureException exception)
            {
                this.WriteDebugInfoAndError(exception, ErrorCategory.InvalidArgument, mailboxIdParameter);
            }
            return(result);
        }
        private ADRawEntry FetchADRawEntry(MailboxIdParameter user)
        {
            OrganizationId    organizationId = ((IConfigurationSession)base.DataSession).GetOrgContainer().OrganizationId;
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(organizationId), 105, "FetchADRawEntry", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\ClientAccessRules\\TestClientAccessRule.cs");

            tenantOrRootOrgRecipientSession.UseGlobalCatalog = true;
            List <ADUser> list = new List <ADUser>(base.GetDataObjects <ADUser>(user, tenantOrRootOrgRecipientSession, null));

            if (list.Count != 1)
            {
                base.WriteError(new RecipientTaskException(RulesTasksStrings.TestClientAccessRuleUserNotFoundOrMoreThanOne(user.ToString())), ErrorCategory.InvalidArgument, null);
            }
            return(list[0]);
        }
        protected override IConfigDataProvider CreateSession()
        {
            MailboxIdParameter mailboxIdParameter = null;

            if (this.FromMessageId != null && this.FromMessageId.RawOwner != null)
            {
                mailboxIdParameter = this.FromMessageId.RawOwner;
            }
            if (mailboxIdParameter == null)
            {
                ADObjectId executingUserId;
                base.TryGetExecutingUserId(out executingUserId);
                mailboxIdParameter = (this.Mailbox ?? MailboxTaskHelper.ResolveMailboxIdentity(executingUserId, new Task.ErrorLoggerDelegate(base.WriteError)));
            }
            this.adUser = (ADUser)base.GetDataObject <ADUser>(mailboxIdParameter, base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(mailboxIdParameter.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(mailboxIdParameter.ToString())));
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(base.DomainController, false, ConsistencyMode.PartiallyConsistent, null, base.SessionSettings, 867, "CreateSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\RecipientTasks\\InboxRule\\NewInboxRule.cs");

            base.VerifyIsWithinScopes(TaskHelper.UnderscopeSessionToOrganization(tenantOrRootOrgRecipientSession, this.adUser.OrganizationId, true), this.adUser, true, new DataAccessTask <InboxRule> .ADObjectOutOfScopeString(Strings.ErrorCannotChangeMailboxOutOfWriteScope));
            XsoMailboxDataProviderBase xsoMailboxDataProviderBase;

            if (this.FromMessageId != null)
            {
                xsoMailboxDataProviderBase = new MailMessageDataProvider(base.SessionSettings, this.adUser, (base.ExchangeRunspaceConfig == null) ? null : base.ExchangeRunspaceConfig.SecurityAccessToken, "New-InboxRule");
                this.FromMessageId.InternalStoreObjectId = new MailboxStoreObjectId((ADObjectId)this.adUser.Identity, this.FromMessageId.RawStoreObjectId);
            }
            else
            {
                xsoMailboxDataProviderBase = new InboxRuleDataProvider(base.SessionSettings, this.adUser, "New-InboxRule");
            }
            this.mailboxOwner = xsoMailboxDataProviderBase.MailboxSession.MailboxOwner.ObjectId.ToString();
            return(xsoMailboxDataProviderBase);
        }