Exemplo n.º 1
0
        internal BaseQueryResult GetDataInternal(FreeBusyQuery freeBusyQuery, EmailAddress emailAddress)
        {
            BaseQueryResult result;

            try
            {
                TimeSpan t = this.deadline - DateTime.UtcNow;
                if (t <= TimeSpan.Zero)
                {
                    result = this.HandleException(emailAddress, new TimeoutExpiredException("Opening-Mailbox-Session"));
                }
                else
                {
                    using (MailboxSession mailboxSession = MailboxSession.OpenAsSystemService(freeBusyQuery.ExchangePrincipal, CultureInfo.InvariantCulture, "Client=AS"))
                    {
                        mailboxSession.AccountingObject = this.clientContext.Budget;
                        this.clientContext.CheckOverBudget();
                        Microsoft.Exchange.Diagnostics.Components.InfoWorker.Availability.ExTraceGlobals.FaultInjectionTracer.TraceTest(2204511549U);
                        t = this.deadline - DateTime.UtcNow;
                        if (t <= TimeSpan.Zero)
                        {
                            result = this.HandleException(emailAddress, new TimeoutExpiredException("Starting-Calendar-Query"));
                        }
                        else
                        {
                            result = this.InternalGetCalendarData(freeBusyQuery, mailboxSession);
                        }
                    }
                }
            }
            catch (MailboxInSiteFailoverException e)
            {
                result = this.HandleMailboxFailoverException(emailAddress, e);
            }
            catch (MailboxCrossSiteFailoverException e2)
            {
                result = this.HandleMailboxFailoverException(emailAddress, e2);
            }
            catch (VirusScanInProgressException e3)
            {
                LocalizedString message = Strings.descVirusScanInProgress(emailAddress.ToString());
                result = this.HandleException(emailAddress, e3, message);
            }
            catch (VirusDetectedException e4)
            {
                LocalizedString message2 = Strings.descVirusDetected(emailAddress.ToString());
                result = this.HandleException(emailAddress, e4, message2);
            }
            catch (AuthzException innerException)
            {
                result = this.HandleException(emailAddress, new Win32InteropException(innerException));
            }
            catch (LocalizedException e5)
            {
                result = this.HandleConnectionException(emailAddress, e5);
            }
            return(result);
        }
Exemplo n.º 2
0
 public static FreeBusyQuery[] ConvertBaseToFreeBusyQuery(BaseQuery[] baseQueries)
 {
     FreeBusyQuery[] array = new FreeBusyQuery[baseQueries.Length];
     for (int i = 0; i < baseQueries.Length; i++)
     {
         array[i] = (FreeBusyQuery)baseQueries[i];
     }
     return(array);
 }
Exemplo n.º 3
0
        internal override BaseQueryResult GetData(BaseQuery query)
        {
            FreeBusyQuery   freeBusyQuery   = (FreeBusyQuery)query;
            Guid            serverRequestId = Trace.TraceCasStart(CasTraceEventType.Availability);
            EmailAddress    email           = freeBusyQuery.Email;
            BaseQueryResult dataInternal    = this.GetDataInternal(freeBusyQuery, email);

            this.TraceRequestStop(email, serverRequestId);
            return(dataInternal);
        }
Exemplo n.º 4
0
        private void AddAttendeeDataToList(MailboxData mailboxData, FreeBusyQuery freeBusyQuery, List <AttendeeData> attendeeDataList)
        {
            if (freeBusyQuery.Result == null)
            {
                AvailabilityQuery.MeetingSuggestionsTracer.TraceError <object, EmailAddress>((long)this.GetHashCode(), "{0}: Null freebusyquery result for attendee {1}, treating as if we got no data for this attendee", TraceContext.Get(), freeBusyQuery.Email);
            }
            string text = (freeBusyQuery.Result != null) ? freeBusyQuery.Result.MergedFreeBusy : null;

            if (string.IsNullOrEmpty(text) || (this.desiredSuggestionsView.GlobalObjectId != null && mailboxData.AttendeeType == MeetingAttendeeType.Organizer))
            {
                text = MergedFreeBusy.GenerateMergedFreeBusyString(base.ClientContext.TimeZone, this.internalFreeBusyView.MergedFreeBusyIntervalInMinutes, new ExDateTime(base.ClientContext.TimeZone, this.internalFreeBusyView.TimeWindow.StartTime), new ExDateTime(base.ClientContext.TimeZone, this.internalFreeBusyView.TimeWindow.EndTime), (freeBusyQuery.Result != null) ? freeBusyQuery.Result.CalendarEventArrayInternal : null, freeBusyQuery.Result == null || freeBusyQuery.Result.ExceptionInfo != null, this.desiredSuggestionsView.GlobalObjectIdByteArray, base.ClientContext.RequestSchemaVersion);
            }
            AttendeeData item = new AttendeeData(mailboxData.AttendeeType, freeBusyQuery.Email.Address, mailboxData.ExcludeConflicts, new ExDateTime(base.ClientContext.TimeZone, this.internalFreeBusyView.TimeWindow.StartTime), new ExDateTime(base.ClientContext.TimeZone, this.internalFreeBusyView.TimeWindow.EndTime), text, base.ClientContext.RequestSchemaVersion, this.GetAttendeeWorkHours(freeBusyQuery));

            attendeeDataList.Add(item);
        }
Exemplo n.º 5
0
        public void Add(FreeBusyQuery query, bool isFailed)
        {
            string text = query.Target;

            text = ((text == null) ? "NULL" : text);
            Dictionary <string, List <FreeBusyQuery> > dictionary = isFailed ? this.failedQueries : this.succeededQueries;
            List <FreeBusyQuery> list;

            if (dictionary.TryGetValue(text, out list))
            {
                list.Add(query);
                return;
            }
            list = new List <FreeBusyQuery>();
            list.Add(query);
            dictionary[text] = list;
        }
Exemplo n.º 6
0
        private AttendeeWorkHours GetAttendeeWorkHours(FreeBusyQuery freeBusyQuery)
        {
            AttendeeWorkHours attendeeWorkHours = null;

            try
            {
                if (freeBusyQuery != null && freeBusyQuery.Result != null)
                {
                    attendeeWorkHours = new AttendeeWorkHours(freeBusyQuery.Result.WorkingHours);
                }
            }
            catch (ArgumentException arg)
            {
                AvailabilityQuery.MeetingSuggestionsTracer.TraceError <object, string, ArgumentException>((long)this.GetHashCode(), "{0}: Using default working hours for {1} since we got an exception while constructing AttendeeWorkHours. The Exception is: {2}", TraceContext.Get(), freeBusyQuery.Email.Address, arg);
            }
            if (attendeeWorkHours == null)
            {
                attendeeWorkHours = new AttendeeWorkHours(null);
            }
            return(attendeeWorkHours);
        }
Exemplo n.º 7
0
        public override void EndProxyWebRequest(ProxyWebRequest proxyWebRequest, QueryList queryList, IService service, IAsyncResult asyncResult)
        {
            GetUserAvailabilityResponse getUserAvailabilityResponse = service.EndGetUserAvailability(asyncResult);

            FreeBusyResponse[] array = null;
            if (getUserAvailabilityResponse != null)
            {
                array = getUserAvailabilityResponse.FreeBusyResponseArray;
            }
            if (array == null)
            {
                Application.ProxyWebRequestTracer.TraceError((long)proxyWebRequest.GetHashCode(), "{0}: Proxy web request returned NULL FreeBusyResponseArray.", new object[]
                {
                    TraceContext.Get()
                });
            }
            for (int i = 0; i < queryList.Count; i++)
            {
                FreeBusyQuery    freeBusyQuery    = (FreeBusyQuery)queryList[i];
                FreeBusyResponse freeBusyResponse = null;
                if (array != null && i < array.Length)
                {
                    freeBusyResponse = array[i];
                    if (freeBusyResponse == null)
                    {
                        Application.ProxyWebRequestTracer.TraceDebug <object, EmailAddress>((long)proxyWebRequest.GetHashCode(), "{0}: Proxy web request returned NULL FreeBusyResponse for mailbox {1}.", TraceContext.Get(), freeBusyQuery.Email);
                    }
                }
                FreeBusyQueryResult resultOnFirstCall;
                if (freeBusyResponse == null)
                {
                    resultOnFirstCall = new FreeBusyQueryResult(new ProxyNoResultException(Strings.descProxyNoResultError(freeBusyQuery.Email.Address, service.Url), 60732U));
                }
                else
                {
                    resultOnFirstCall = FreeBusyApplication.CopyViewAndResponseToResult(service.Url, freeBusyResponse.FreeBusyView, freeBusyResponse.ResponseMessage, freeBusyQuery.Email);
                }
                freeBusyQuery.SetResultOnFirstCall(resultOnFirstCall);
            }
        }
Exemplo n.º 8
0
        private static bool IsAllowedByFreeBusyAccessScope(FreeBusyQuery freeBusyQuery, OrganizationRelationship organizationRelationship)
        {
            if (organizationRelationship.FreeBusyAccessScope == null)
            {
                FreeBusyPermission.SecurityTracer.TraceDebug <object, ADObjectId>(0L, "{0}: OrganizationRelationship {1} doesn't restrict any mailbox to share externally.", TraceContext.Get(), organizationRelationship.Id);
                return(true);
            }
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, organizationRelationship.Session.SessionSettings, 620, "IsAllowedByFreeBusyAccessScope", "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\Availability\\FreeBusyPermission.cs");
            ADGroup           adgroup = tenantOrRootOrgRecipientSession.Read(organizationRelationship.FreeBusyAccessScope) as ADGroup;

            if (adgroup == null)
            {
                FreeBusyPermission.SecurityTracer.TraceError <object, ADObjectId>(0L, "{0}: OrganizationRelationship.FreeBusyAccessScope is defined as {1}, but cannot be found in AD.", TraceContext.Get(), organizationRelationship.FreeBusyAccessScope);
                return(false);
            }
            if (!adgroup.ContainsMember(freeBusyQuery.RecipientData.Id, false))
            {
                FreeBusyPermission.SecurityTracer.TraceDebug <object, EmailAddress, ADObjectId>(0L, "{0}: mailbox {1} is not member of OrganizationRelationship.FreeBusyAccessScope {2}.", TraceContext.Get(), freeBusyQuery.Email, organizationRelationship.FreeBusyAccessScope);
                return(false);
            }
            return(true);
        }
Exemplo n.º 9
0
        public override BaseQuery CreateFromGroup(RecipientData recipientData, BaseQuery[] groupMembers, bool groupCapped)
        {
            bool flag  = (this.queryType & QueryType.FreeBusy) != (QueryType)0;
            bool flag2 = (this.queryType & QueryType.MeetingSuggestions) != (QueryType)0 && !groupCapped;

            FreeBusyQuery[] groupMembersForFreeBusy    = null;
            FreeBusyQuery[] groupMembersForSuggestions = null;
            if (flag)
            {
                if (groupCapped)
                {
                    Application.ProxyWebRequestTracer.TraceDebug <object, RecipientData>((long)this.GetHashCode(), "{0}:Not generating requests for members of group {1} because the group is larger than the allowed group size.", TraceContext.Get(), recipientData);
                    return(FreeBusyQuery.CreateFromGroup(recipientData, new FreeBusyDLLimitReachedException(Configuration.MaximumGroupMemberCount)));
                }
                groupMembersForFreeBusy = FreeBusyApplication.ConvertBaseToFreeBusyQuery(groupMembers);
            }
            if (flag2)
            {
                groupMembersForSuggestions = FreeBusyApplication.ConvertBaseToFreeBusyQuery(groupMembers);
            }
            return(FreeBusyQuery.CreateFromGroup(recipientData, groupMembersForFreeBusy, groupMembersForSuggestions));
        }
Exemplo n.º 10
0
        public static FreeBusyPermissionLevel DetermineAllowedAccess(ClientContext clientContext, MailboxSession session, CalendarFolder calendarFolder, FreeBusyQuery freeBusyQuery, bool defaultFreeBusyOnly)
        {
            RawSecurityDescriptor rawSecurityDescriptor = calendarFolder.TryGetProperty(CalendarFolderSchema.FreeBusySecurityDescriptor) as RawSecurityDescriptor;

            if (rawSecurityDescriptor == null)
            {
                FreeBusyPermission.SecurityTracer.TraceDebug <object, CalendarFolder>(0L, "{0}: Unable to retrieve FreeBusySecurityDescriptor from folder {1}. Using None as permission level.", TraceContext.Get(), calendarFolder);
                return(FreeBusyPermissionLevel.None);
            }
            if (FreeBusyPermission.SecurityTracer.IsTraceEnabled(TraceType.DebugTrace))
            {
                string sddlForm = rawSecurityDescriptor.GetSddlForm(AccessControlSections.All);
                FreeBusyPermission.SecurityTracer.TraceDebug <object, EmailAddress, string>(0L, "{0}: The SDDL form of calendar folder security descriptor of mailbox {1} is: {2}.", TraceContext.Get(), freeBusyQuery.Email, sddlForm);
            }
            if (defaultFreeBusyOnly)
            {
                FreeBusyPermission.SecurityTracer.TraceDebug(0L, "{0}: Using DefaultClientSecurityContext because of defaultFreeBusyOnly is set.", new object[]
                {
                    TraceContext.Get()
                });
                return(FreeBusyPermission.AccessCheck(rawSecurityDescriptor, ClientSecurityContext.FreeBusyPermissionDefaultClientSecurityContext));
            }
            InternalClientContext internalClientContext = clientContext as InternalClientContext;

            if (internalClientContext != null)
            {
                return(FreeBusyPermission.FromInternalClient(internalClientContext, rawSecurityDescriptor, freeBusyQuery));
            }
            ExternalClientContext externalClientContext = clientContext as ExternalClientContext;

            return(FreeBusyPermission.FromExternalClient(externalClientContext, session, rawSecurityDescriptor, freeBusyQuery));
        }
Exemplo n.º 11
0
        private static FreeBusyPermissionLevel FromExternalClient(ExternalClientContext externalClientContext, MailboxSession mailboxSession, RawSecurityDescriptor securityDescriptor, FreeBusyQuery freeBusyQuery)
        {
            FreeBusyPermissionLevel val  = FreeBusyPermission.FromExternalClientWithPersonalRelationship(externalClientContext, mailboxSession, securityDescriptor, freeBusyQuery);
            FreeBusyPermissionLevel val2 = FreeBusyPermission.FromExternalClientWithOrganizationalRelationship(externalClientContext, mailboxSession, securityDescriptor, freeBusyQuery);
            FreeBusyPermissionLevel freeBusyPermissionLevel = (FreeBusyPermissionLevel)Math.Max((int)val2, (int)val);

            FreeBusyPermission.SecurityTracer.TraceDebug <object, SmtpAddress, FreeBusyPermissionLevel>(0L, "{0}: permission level for {1} is {2}", TraceContext.Get(), externalClientContext.EmailAddress, freeBusyPermissionLevel);
            return(freeBusyPermissionLevel);
        }
Exemplo n.º 12
0
        private static FreeBusyPermissionLevel FromExternalClientWithOrganizationalRelationship(ExternalClientContext externalClientContext, MailboxSession mailboxSession, RawSecurityDescriptor securityDescriptor, FreeBusyQuery freeBusyQuery)
        {
            OrganizationRelationship organizationRelationship = FreeBusyPermission.GetOrganizationRelationship(mailboxSession.MailboxOwner.MailboxInfo.OrganizationId, externalClientContext.EmailAddress.Domain);

            if (organizationRelationship == null)
            {
                FreeBusyPermission.SecurityTracer.TraceDebug <object, SmtpAddress, string>(0L, "{0}: No organization relationship for {1} with organization id {2}", TraceContext.Get(), externalClientContext.EmailAddress, (mailboxSession.MailboxOwner.MailboxInfo.OrganizationId == null) ? "<null>" : mailboxSession.MailboxOwner.MailboxInfo.OrganizationId.ToString());
                return(FreeBusyPermissionLevel.None);
            }
            FreeBusyPermissionLevel freeBusyPermissionLevel = FreeBusyPermissionLevel.Detail;

            if (organizationRelationship != null)
            {
                freeBusyPermissionLevel = FreeBusyPermission.GetMaximumFreeBusyPermissionLevel(organizationRelationship);
                if (freeBusyPermissionLevel == FreeBusyPermissionLevel.None)
                {
                    FreeBusyPermission.SecurityTracer.TraceDebug <object, ADObjectId>(0L, "{0}: OrganizationRelationship {1} restricts permission level to None.", TraceContext.Get(), organizationRelationship.Id);
                    return(FreeBusyPermissionLevel.None);
                }
            }
            FreeBusyPermissionLevel freeBusyPermissionLevel2 = FreeBusyPermission.AccessCheck(securityDescriptor, ClientSecurityContext.FreeBusyPermissionDefaultClientSecurityContext);

            if (freeBusyPermissionLevel2 == FreeBusyPermissionLevel.None)
            {
                return(FreeBusyPermissionLevel.None);
            }
            if (freeBusyPermissionLevel2 > freeBusyPermissionLevel)
            {
                FreeBusyPermission.SecurityTracer.TraceDebug(0L, "{0}: OrganizationRelationship {1} restricts permission level to {2}. Lowering permission from {3}.", new object[]
                {
                    TraceContext.Get(),
                    organizationRelationship.Id,
                    freeBusyPermissionLevel,
                    freeBusyPermissionLevel2
                });
                freeBusyPermissionLevel2 = freeBusyPermissionLevel;
            }
            if (!FreeBusyPermission.IsAllowedByFreeBusyAccessScope(freeBusyQuery, organizationRelationship))
            {
                freeBusyPermissionLevel2 = FreeBusyPermissionLevel.None;
            }
            return(freeBusyPermissionLevel2);
        }
Exemplo n.º 13
0
        private void ExecuteMeetingSuggestionsQuery(AvailabilityQueryResult result)
        {
            AvailabilityQuery.MeetingSuggestionsTracer.TraceDebug((long)this.GetHashCode(), "{0}: Entering AvailabilityQuery.ExecuteMeetingSuggestionsQuery()", new object[]
            {
                TraceContext.Get()
            });
            base.RequestLogger.AppendToLog <int>("suggest", 1);
            try
            {
                MeetingSuggester meetingSuggester = new MeetingSuggester();
                meetingSuggester.SetOptionsFromSuggestionsViewOptions(this.desiredSuggestionsView, base.ClientContext.TimeZone);
                List <AttendeeData> list  = new List <AttendeeData>(this.mailboxArray.Length);
                List <int>[]        array = new List <int> [this.mailboxArray.Length];
                int num = 0;
                for (int i = 0; i < this.freeBusyQueryArray.Length; i++)
                {
                    MailboxData   mailboxData   = this.mailboxArray[i];
                    FreeBusyQuery freeBusyQuery = this.freeBusyQueryArray[i];
                    List <int>    list2         = new List <int>();
                    switch (freeBusyQuery.AttendeeKind)
                    {
                    case AttendeeKind.Individual:
                    case AttendeeKind.Unknown:
                        this.AddAttendeeDataToList(mailboxData, freeBusyQuery, list);
                        list2.Add(num);
                        num++;
                        break;

                    case AttendeeKind.Group:
                        if (freeBusyQuery.GroupMembersForSuggestions != null)
                        {
                            foreach (FreeBusyQuery freeBusyQuery2 in freeBusyQuery.GroupMembersForSuggestions)
                            {
                                this.AddAttendeeDataToList(mailboxData, freeBusyQuery2, list);
                                list2.Add(num);
                                num++;
                            }
                        }
                        else
                        {
                            this.AddAttendeeDataToList(mailboxData, freeBusyQuery, list);
                            list2.Add(num);
                            num++;
                        }
                        break;
                    }
                    array[i] = list2;
                }
                AttendeeData[] attendees = list.ToArray();
                Duration       detailedSuggestionsWindow = this.desiredSuggestionsView.DetailedSuggestionsWindow;
                result.DailyMeetingSuggestions = meetingSuggester.GetSuggestionsByDateRange(new ExDateTime(base.ClientContext.TimeZone, detailedSuggestionsWindow.StartTime), new ExDateTime(base.ClientContext.TimeZone, detailedSuggestionsWindow.EndTime), base.ClientContext.TimeZone, this.desiredSuggestionsView.MeetingDurationInMinutes, attendees);
                foreach (SuggestionDayResult suggestionDayResult in result.DailyMeetingSuggestions)
                {
                    foreach (Suggestion suggestion in suggestionDayResult.SuggestionArray)
                    {
                        AttendeeConflictData[] array2 = new AttendeeConflictData[this.mailboxArray.Length];
                        for (int m = 0; m < this.freeBusyQueryArray.Length; m++)
                        {
                            FreeBusyQuery freeBusyQuery3 = this.freeBusyQueryArray[m];
                            List <int>    list3          = array[m];
                            switch (freeBusyQuery3.AttendeeKind)
                            {
                            case AttendeeKind.Individual:
                            {
                                int num2 = list3[0];
                                array2[m] = suggestion.AttendeeConflictDataArray[num2];
                                break;
                            }

                            case AttendeeKind.Group:
                                if (freeBusyQuery3.GroupMembersForSuggestions != null)
                                {
                                    int num3 = 0;
                                    int num4 = 0;
                                    int num5 = 0;
                                    foreach (int num6 in list3)
                                    {
                                        IndividualAttendeeConflictData individualAttendeeConflictData = (IndividualAttendeeConflictData)suggestion.AttendeeConflictDataArray[num6];
                                        if (individualAttendeeConflictData.IsMissingFreeBusyData)
                                        {
                                            num4++;
                                        }
                                        else if (individualAttendeeConflictData.BusyType == BusyType.Free)
                                        {
                                            num5++;
                                        }
                                        else
                                        {
                                            num3++;
                                        }
                                    }
                                    array2[m] = GroupAttendeeConflictData.Create(list3.Count, num3, num5, num4);
                                }
                                else
                                {
                                    array2[m] = TooBigGroupAttendeeConflictData.Create();
                                }
                                break;

                            case AttendeeKind.Unknown:
                                array2[m] = UnknownAttendeeConflictData.Create();
                                break;
                            }
                        }
                        suggestion.AttendeeConflictDataArray = array2;
                    }
                }
            }
            catch (LocalizedException ex)
            {
                ErrorHandler.SetErrorCodeIfNecessary(ex, ErrorConstants.MeetingSuggestionGenerationFailed);
                result.MeetingSuggestionsException = ex;
            }
            AvailabilityQuery.MeetingSuggestionsTracer.TraceDebug((long)this.GetHashCode(), "{0}: Leaving AvailabilityQuery.ExecuteMeetingSuggestionsQuery()", new object[]
            {
                TraceContext.Get()
            });
        }
Exemplo n.º 14
0
 private static FreeBusyPermissionLevel GetPermissionLevel(ClientSecurityContext clientSecurityContext, FreeBusyQuery freeBusyQuery, RawSecurityDescriptor securityDescriptor)
 {
     if (FreeBusyPermission.CallerHasFullPermission(clientSecurityContext, freeBusyQuery))
     {
         FreeBusyPermission.SecurityTracer.TraceDebug <object, ClientSecurityContext, EmailAddress>(0L, "{0}: Caller {1} has owner access on mailbox {2}.", TraceContext.Get(), clientSecurityContext, freeBusyQuery.Email);
         return(FreeBusyPermissionLevel.Owner);
     }
     return(FreeBusyPermission.AccessCheck(securityDescriptor, clientSecurityContext));
 }
Exemplo n.º 15
0
        private static FreeBusyPermissionLevel FromInternalClient(InternalClientContext internalClientContext, RawSecurityDescriptor securityDescriptor, FreeBusyQuery freeBusyQuery)
        {
            if (internalClientContext.ClientSecurityContext == null)
            {
                FreeBusyPermission.SecurityTracer.TraceDebug <object, EmailAddress>(0L, "{0}: Caller {1} has no ClientSecurityContext, using default context as 'everyone'.", TraceContext.Get(), freeBusyQuery.Email);
                return(FreeBusyPermission.AccessCheck(securityDescriptor, ClientSecurityContext.FreeBusyPermissionDefaultClientSecurityContext));
            }
            if (!Configuration.UseDisabledAccount || VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled)
            {
                return(FreeBusyPermission.GetPermissionLevel(internalClientContext.ClientSecurityContext, freeBusyQuery, securityDescriptor));
            }
            FreeBusyPermission.SecurityTracer.TraceDebug <object, InternalClientContext>(0L, "{0}: Creating a munged security context for caller {1}.", TraceContext.Get(), internalClientContext);
            ClientSecurityContext clientSecurityContext = null;

            try
            {
                clientSecurityContext = new SlaveAccountTokenMunger().MungeToken(internalClientContext.ClientSecurityContext, OrganizationId.ForestWideOrgId);
                return(FreeBusyPermission.GetPermissionLevel(clientSecurityContext, freeBusyQuery, securityDescriptor));
            }
            catch (TokenMungingException arg)
            {
                FreeBusyPermission.SecurityTracer.TraceError <object, InternalClientContext, TokenMungingException>(0L, "{0}: Unable to get the munged token for Caller {1}, error {2}, using the client context supplied.", TraceContext.Get(), internalClientContext, arg);
            }
            finally
            {
                if (clientSecurityContext != null)
                {
                    clientSecurityContext.Dispose();
                }
            }
            return(FreeBusyPermission.GetPermissionLevel(internalClientContext.ClientSecurityContext, freeBusyQuery, securityDescriptor));
        }
Exemplo n.º 16
0
        private FreeBusyQueryResult InternalGetCalendarData(FreeBusyQuery freeBusyQuery, MailboxSession session)
        {
            FreeBusyViewType freeBusyViewType = FreeBusyViewType.None;

            CalendarEvent[] calendarEventArray = null;
            string          mergedFreeBusy     = null;
            WorkingHours    workingHours       = null;
            EmailAddress    email = freeBusyQuery.Email;
            StoreObjectId   associatedFolderId = freeBusyQuery.RecipientData.AssociatedFolderId;
            StoreObjectId   defaultFolderId    = session.GetDefaultFolderId(DefaultFolderType.Calendar);

            if (defaultFolderId == null)
            {
                return(this.HandleException(email, new NoCalendarException()));
            }
            if (associatedFolderId != null && !associatedFolderId.Equals(defaultFolderId))
            {
                return(this.HandleException(email, new NotDefaultCalendarException()));
            }
            session.ExTimeZone = this.clientContext.TimeZone;
            using (CalendarFolder calendarFolder = CalendarFolder.Bind(session, DefaultFolderType.Calendar, CalendarQuery.CalendarFolderQueryProps))
            {
                TimeSpan t = this.deadline - DateTime.UtcNow;
                if (t <= TimeSpan.Zero)
                {
                    return(this.HandleException(email, new TimeoutExpiredException("Determine-Allowed-Access")));
                }
                FreeBusyPermissionLevel freeBusyPermissionLevel = FreeBusyPermission.DetermineAllowedAccess(this.clientContext, session, calendarFolder, freeBusyQuery, this.defaultFreeBusyOnly);
                CalendarQuery.CalendarViewTracer.TraceDebug((long)this.GetHashCode(), "{0}: AccessCheck returned {1} for user {2} on mailbox {3}", new object[]
                {
                    TraceContext.Get(),
                    freeBusyPermissionLevel,
                    this.clientContext,
                    email
                });
                if (freeBusyPermissionLevel == FreeBusyPermissionLevel.None)
                {
                    CalendarQuery.CalendarViewTracer.TraceDebug <object, EmailAddress>((long)this.GetHashCode(), "{0}: No mailbox data will be returned for mailbox {1} since the granted access level to caller is None.", TraceContext.Get(), email);
                    return(new FreeBusyQueryResult(new NoFreeBusyAccessException(44348U)));
                }
                t = this.deadline - DateTime.UtcNow;
                if (t <= TimeSpan.Zero)
                {
                    return(this.HandleException(email, new TimeoutExpiredException("Get-Calendar-View")));
                }
                freeBusyViewType = CalendarQuery.GetReturnView(this.requestedFreeBusyView.RequestedView, freeBusyPermissionLevel);
                ExDateTime windowStart = new ExDateTime(this.clientContext.TimeZone, this.requestedFreeBusyView.TimeWindow.StartTime);
                ExDateTime windowEnd   = new ExDateTime(this.clientContext.TimeZone, this.requestedFreeBusyView.TimeWindow.EndTime);
                try
                {
                    calendarEventArray = InternalCalendarQuery.GetCalendarEvents(email, calendarFolder, windowStart, windowEnd, freeBusyViewType, freeBusyPermissionLevel == FreeBusyPermissionLevel.Owner, this.clientContext.RequestSchemaVersion);
                }
                catch (ResultSetTooBigException e)
                {
                    return(this.HandleException(email, e));
                }
                if (FreeBusyViewOptions.IsMerged(freeBusyViewType))
                {
                    t = this.deadline - DateTime.UtcNow;
                    if (t <= TimeSpan.Zero)
                    {
                        return(this.HandleException(email, new TimeoutExpiredException("Generate-Merged-FreeBusy")));
                    }
                    int mergedFreeBusyIntervalInMinutes = this.requestedFreeBusyView.MergedFreeBusyIntervalInMinutes;
                    mergedFreeBusy = MergedFreeBusy.GenerateMergedFreeBusyString(this.clientContext.TimeZone, mergedFreeBusyIntervalInMinutes, windowStart, windowEnd, calendarEventArray, false, null, this.clientContext.RequestSchemaVersion);
                }
                t = this.deadline - DateTime.UtcNow;
                if (t <= TimeSpan.Zero)
                {
                    return(this.HandleException(email, new TimeoutExpiredException("Getting-Work-Hours")));
                }
                workingHours = this.GetWorkingHours(email, session, calendarFolder);
            }
            return(new FreeBusyQueryResult(freeBusyViewType, calendarEventArray, mergedFreeBusy, workingHours));
        }
Exemplo n.º 17
0
        private static bool CallerHasFullPermission(ClientSecurityContext clientSecurityContext, FreeBusyQuery freeBusyQuery)
        {
            SecurityIdentifier sid = freeBusyQuery.RecipientData.Sid;
            SecurityIdentifier masterAccountSid = freeBusyQuery.RecipientData.MasterAccountSid;
            bool flag = (sid != null && sid.Equals(clientSecurityContext.UserSid)) || (masterAccountSid != null && masterAccountSid.Equals(clientSecurityContext.UserSid));

            if (flag)
            {
                FreeBusyPermission.SecurityTracer.TraceDebug(0L, "{0}: Caller {1} is owner of mailbox {2}, mailbox user SID {3}, master account SID {4}.", new object[]
                {
                    TraceContext.Get(),
                    clientSecurityContext,
                    freeBusyQuery.Email,
                    sid,
                    masterAccountSid
                });
                return(true);
            }
            RawSecurityDescriptor exchangeSecurityDescriptor = freeBusyQuery.RecipientData.ExchangeSecurityDescriptor;

            if (exchangeSecurityDescriptor != null)
            {
                if (FreeBusyPermission.SecurityTracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    string sddlForm = exchangeSecurityDescriptor.GetSddlForm(AccessControlSections.All);
                    FreeBusyPermission.SecurityTracer.TraceDebug <object, EmailAddress, string>(0L, "{0}: The SDDL form of mailbox security descriptor of mailbox {1} is: {2}.", TraceContext.Get(), freeBusyQuery.Email, sddlForm);
                }
                if (clientSecurityContext.GetGrantedAccess(exchangeSecurityDescriptor, AccessMask.CreateChild) == 1 || clientSecurityContext.GetGrantedAccess(exchangeSecurityDescriptor, AccessMask.List) == 4)
                {
                    FreeBusyPermission.SecurityTracer.TraceDebug <object, EmailAddress>(0L, "{0}: Caller does have 'owner' rights in mailbox {1}.", TraceContext.Get(), freeBusyQuery.Email);
                    return(true);
                }
            }
            else
            {
                FreeBusyPermission.SecurityTracer.TraceDebug <object, EmailAddress>(0L, "{0}: User does not have an ExchangeSecurityDescriptor.", TraceContext.Get(), freeBusyQuery.Email);
            }
            FreeBusyPermission.SecurityTracer.TraceDebug <object, EmailAddress>(0L, "{0}: Caller does NOT have 'owner' rights in mailbox {1}.", TraceContext.Get(), freeBusyQuery.Email);
            return(false);
        }
Exemplo n.º 18
0
 public override BaseQuery CreateFromIndividual(RecipientData recipientData)
 {
     return(FreeBusyQuery.CreateFromIndividual(recipientData));
 }
Exemplo n.º 19
0
        private static FreeBusyPermissionLevel FromExternalClientWithPersonalRelationship(ExternalClientContext externalClientContext, MailboxSession mailboxSession, RawSecurityDescriptor securityDescriptor, FreeBusyQuery freeBusyQuery)
        {
            string externalIdentity = FreeBusyPermission.GetExternalIdentity(externalClientContext, mailboxSession);

            if (externalIdentity == null)
            {
                FreeBusyPermission.SecurityTracer.TraceDebug <object, SmtpAddress, IExchangePrincipal>(0L, "{0}: No external identity for {1} in mailbox {2}.", TraceContext.Get(), externalClientContext.EmailAddress, mailboxSession.MailboxOwner);
                return(FreeBusyPermissionLevel.None);
            }
            ISecurityAccessToken securityAccessToken = new SecurityAccessToken
            {
                UserSid   = externalIdentity,
                GroupSids = ClientSecurityContext.DisabledEveryoneOnlySidStringAndAttributesArray
            };
            FreeBusyPermissionLevel result;

            using (ClientSecurityContext clientSecurityContext = new ClientSecurityContext(securityAccessToken, AuthzFlags.AuthzSkipTokenGroups))
            {
                result = FreeBusyPermission.AccessCheck(securityDescriptor, clientSecurityContext);
            }
            return(result);
        }
Exemplo n.º 20
0
 public override BaseQuery CreateFromIndividual(RecipientData recipientData, LocalizedException exception)
 {
     return(FreeBusyQuery.CreateFromIndividual(recipientData, exception));
 }