Esempio n. 1
0
        internal static MailboxSession GetMailboxSession(OrganizationId organizationId, string action)
        {
            ADSessionSettings sessionSettings = organizationId.ToADSessionSettings();
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.FullyConsistent, sessionSettings, 99, "GetMailboxSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\AuditLogSearch\\AuditLogSearchDataProvider.cs");
            ADUser            discoveryMailbox = MailboxDataProvider.GetDiscoveryMailbox(tenantOrRootOrgRecipientSession);

            return(AuditLogSearchDataProviderBase.GetMailboxSession(discoveryMailbox, action));
        }
Esempio n. 2
0
        protected override ExchangePrincipal CreateOnCacheMiss(MultiValueKey cacheKey, ref bool shouldAdd)
        {
            if (cacheKey.KeyLength != 2)
            {
                throw new ArgumentException(string.Format("Unexpected cacheKey length: {0}", cacheKey.KeyLength), "cacheKey");
            }
            OrganizationId    organizationId = (OrganizationId)cacheKey.GetKey(0);
            Guid              mailboxGuid    = (Guid)cacheKey.GetKey(1);
            ExchangePrincipal result         = ExchangePrincipal.FromMailboxGuid(organizationId.ToADSessionSettings(), mailboxGuid, RemotingOptions.AllowCrossSite, null);

            shouldAdd = true;
            return(result);
        }
Esempio n. 3
0
 private void ResolveAccessedUser()
 {
     if (string.IsNullOrEmpty(this.accessedUserSmtpAddress))
     {
         this.accessedUserExchangePrincipal = ExchangePrincipal.FromUserSid(this.GetOrganizationIdFromIdentity(this.accessedUserIdentity).ToADSessionSettings(), this.accessedUserSid);
         this.logonUserPrincipal            = new GenericPrincipal(this.LogonUserIdentity, null);
     }
     else
     {
         OrganizationId   organizationId   = OrganizationId.ForestWideOrgId;
         SidBasedIdentity sidBasedIdentity = this.LogonUserIdentity as SidBasedIdentity;
         if (sidBasedIdentity != null)
         {
             organizationId = sidBasedIdentity.UserOrganizationId;
         }
         else
         {
             DelegatedPrincipal delegatedPrincipal = this.logonUserPrincipal as DelegatedPrincipal;
             if (delegatedPrincipal != null)
             {
                 SmtpDomain domain;
                 if (SmtpDomain.TryParse(delegatedPrincipal.DelegatedOrganization, out domain))
                 {
                     organizationId = DomainCache.Singleton.Get(new SmtpDomainWithSubdomains(domain, false)).OrganizationId;
                 }
             }
             else
             {
                 ExchangePrincipal exchangePrincipal = this.GetLogonUserExchangePrincipal();
                 if (exchangePrincipal != null)
                 {
                     organizationId = exchangePrincipal.MailboxInfo.OrganizationId;
                 }
             }
         }
         ADSessionSettings adSettings  = organizationId.ToADSessionSettings();
         string            partitionId = null;
         if (organizationId != null && organizationId != OrganizationId.ForestWideOrgId && organizationId.PartitionId != null)
         {
             partitionId = organizationId.PartitionId.ToString();
         }
         this.accessedUserExchangePrincipal = ExchangePrincipal.FromProxyAddress(adSettings, this.accessedUserSmtpAddress, RemotingOptions.AllowCrossSite);
         this.accessedUserIdentity          = new GenericSidIdentity(this.accessedUserExchangePrincipal.Sid.Value, this.LogonUserIdentity.AuthenticationType + "-ExplicitSignOn", this.accessedUserExchangePrincipal.Sid, partitionId);
         this.accessedUserSid = this.accessedUserIdentity.GetSecurityIdentifier();
     }
     this.hasFullAccess    = this.CanOpenAccessedUserMailbox();
     this.identityResolved = true;
 }
		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;
		}
Esempio n. 5
0
        public bool IsExternalAccess(OrganizationId organizationId, SecurityIdentifier logonSid)
        {
            this.recipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, organizationId.ToADSessionSettings(), 332, "IsExternalAccess", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Auditing\\AuditCaches.cs");
            Util.ThrowOnNullArgument(organizationId, "organizationId");
            Util.ThrowOnNullArgument(logonSid, "logonSid");
            Guid guid = Guid.Empty;
            bool flag = false;

            lock (this.externalAccessCache)
            {
                ExternalAccessCache.OrganizationInfo organizationInfo;
                if (this.externalAccessCache.TryGetValue(logonSid, out organizationInfo))
                {
                    organizationInfo.LastAccessed = DateTime.UtcNow;
                    guid = organizationInfo.OrgIdGuid;
                    flag = true;
                }
            }
            if (!flag)
            {
                ExternalAccessCache.OrganizationInfo organizationInfo2 = this.GetOrganizationInfo(logonSid);
                if (organizationInfo2 == null)
                {
                    return(true);
                }
                lock (this.externalAccessCache)
                {
                    if (!this.externalAccessCache.ContainsKey(logonSid))
                    {
                        this.externalAccessCache.Add(logonSid, organizationInfo2);
                    }
                }
                guid = organizationInfo2.OrgIdGuid;
            }
            bool result;

            if (organizationId.OrganizationalUnit == null)
            {
                result = !(guid == Guid.Empty);
            }
            else
            {
                result = !organizationId.OrganizationalUnit.ObjectGuid.Equals(guid);
            }
            return(result);
        }
        public IConfigurationSession GetSystemConfigurationSession(OrganizationId organizationId)
        {
            ADSessionSettings sessionSettings = organizationId.ToADSessionSettings();

            return(DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, sessionSettings, 80, "GetSystemConfigurationSession", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Management\\XsoDriver\\XsoStoreDataProviderBase.cs"));
        }
        public static ExchangePrincipal GetExchangePrincipalWithAdSessionSettingsForOrg(OrganizationId organizationId, ADUser user)
        {
            ADSessionSettings adSettings = organizationId.ToADSessionSettings();

            return(ExchangePrincipal.FromADUser(adSettings, user, RemotingOptions.AllowCrossSite));
        }
        internal static SmtpAddress Lookup(RecipientIdParameter recipId, IRecipientSession recipSession, OrganizationId orgId, bool getRecipientType, out Microsoft.Exchange.Data.Directory.Recipient.RecipientType?recipientType)
        {
            recipientType = null;
            bool flag = SmtpAddress.IsValidSmtpAddress(recipId.RawIdentity);

            if (!getRecipientType && flag)
            {
                return(SmtpAddress.Parse(recipId.RawIdentity));
            }
            if (flag)
            {
                SmtpAddress smtpAddress = SmtpAddress.Parse(recipId.RawIdentity);
                ADRecipient adrecipientBySmtpAddress = JournalRuleObject.GetADRecipientBySmtpAddress(smtpAddress);
                if (adrecipientBySmtpAddress != null)
                {
                    recipientType = new Microsoft.Exchange.Data.Directory.Recipient.RecipientType?(adrecipientBySmtpAddress.RecipientType);
                }
                return(smtpAddress);
            }
            IEnumerable <ADRecipient> objects = recipId.GetObjects <ADRecipient>((null == orgId) ? null : orgId.OrganizationalUnit, recipSession ?? DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, orgId.ToADSessionSettings(), 429, "Lookup", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\JournalRule\\JournalRuleObject.cs"));
            ADRecipient adrecipient           = null;

            using (IEnumerator <ADRecipient> enumerator = objects.GetEnumerator())
            {
                if (!enumerator.MoveNext())
                {
                    MimeRecipient mimeRecipient = null;
                    try
                    {
                        mimeRecipient = MimeRecipient.Parse(recipId.RawIdentity, AddressParserFlags.IgnoreComments | AddressParserFlags.AllowSquareBrackets);
                    }
                    catch (MimeException)
                    {
                    }
                    if (mimeRecipient == null || string.IsNullOrEmpty(mimeRecipient.Email) || !SmtpAddress.IsValidSmtpAddress(mimeRecipient.Email))
                    {
                        throw new RecipientInvalidException(Strings.NoRecipients);
                    }
                    return(new SmtpAddress(mimeRecipient.Email));
                }
                else
                {
                    adrecipient = enumerator.Current;
                    if (enumerator.MoveNext())
                    {
                        throw new RecipientInvalidException(Strings.MoreThanOneRecipient);
                    }
                }
            }
            if (adrecipient is IADOrgPerson && adrecipient.PrimarySmtpAddress.Equals(SmtpAddress.Empty))
            {
                throw new RecipientInvalidException(Strings.NoSmtpAddress);
            }
            recipientType = new Microsoft.Exchange.Data.Directory.Recipient.RecipientType?(adrecipient.RecipientType);
            return(adrecipient.PrimarySmtpAddress);
        }