internal static VariantConfigurationSnapshot GetSnapshotForCurrentUser(out bool isGlobal) { RbacPrincipal current = RbacPrincipal.GetCurrent(false); if (current != null && current.RbacConfiguration != null && current.RbacConfiguration.ConfigurationSettings != null && current.RbacConfiguration.ConfigurationSettings.VariantConfigurationSnapshot != null) { isGlobal = false; return(current.RbacConfiguration.ConfigurationSettings.VariantConfigurationSnapshot); } isGlobal = true; return(EacFlightUtility.EacGlobalSnapshot); }
internal static string GetPeriodicKeyPerUser() { RbacPrincipal current = RbacPrincipal.GetCurrent(false); if (current != null) { return(current.NameForEventLog); } if (HttpContext.Current.Request.IsAuthenticated) { return(HttpContext.Current.User.Identity.GetSafeName(true)); } return(null); }
protected override ICollection <KeyValuePair <string, object> > GetComponentSpecificData(IActivityScope activityScope, string eventId) { Dictionary <string, object> dictionary = null; if (activityScope != null) { HttpContext httpContext = HttpContext.Current; if (httpContext != null) { string sourceCafeServer = CafeHelper.GetSourceCafeServer(httpContext.Request); if (!string.IsNullOrEmpty(sourceCafeServer)) { activityScope.SetProperty(ActivityContextLoggerMetaData.FrontEndServer, sourceCafeServer); } string requestUrlForLog = httpContext.GetRequestUrlForLog(); activityScope.SetProperty(ActivityContextLoggerMetaData.Url, requestUrlForLog); } RbacPrincipal current = RbacPrincipal.GetCurrent(false); if (current != null) { string value; if (current.RbacConfiguration.DelegatedPrincipal != null) { value = current.RbacConfiguration.DelegatedPrincipal.UserId; } else { SmtpAddress executingUserPrimarySmtpAddress = current.RbacConfiguration.ExecutingUserPrimarySmtpAddress; value = (executingUserPrimarySmtpAddress.IsValidAddress ? executingUserPrimarySmtpAddress.ToString() : current.RbacConfiguration.ExecutingUserPrincipalName); } if (!string.IsNullOrEmpty(value)) { activityScope.SetProperty(ActivityContextLoggerMetaData.PrimarySmtpAddress, value); } OrganizationId organizationId = current.RbacConfiguration.OrganizationId; if (organizationId != null && organizationId.OrganizationalUnit != null) { string name = organizationId.OrganizationalUnit.Name; activityScope.SetProperty(ActivityContextLoggerMetaData.Organization, name); } } dictionary = new Dictionary <string, object>(ActivityContextLogger.EnumToShortKeyMapping.Count); ExtensibleLogger.CopyPIIProperty(activityScope, dictionary, ActivityContextLoggerMetaData.PrimarySmtpAddress, ActivityContextLogger.PrimarySmtpAddressKey); ExtensibleLogger.CopyProperties(activityScope, dictionary, ActivityContextLogger.EnumToShortKeyMapping); } return(dictionary); }
internal ClientLogEvent(Datapoint datapoint) { this.datapoint = datapoint; LocalSession localSession = RbacPrincipal.GetCurrent(false) as LocalSession; string value = (localSession == null) ? string.Empty : localSession.LogonTypeFlag; this.datapointProperties = new Dictionary <string, object> { { "TIME", this.datapoint.Time }, { "SID", HttpContext.Current.GetSessionID() }, { "USID", (HttpContext.Current.User is RbacSession) ? HttpContext.Current.GetCachedUserUniqueKey() : string.Empty }, { "SRC", this.datapoint.Src }, { "REQID", this.datapoint.ReqId }, { "IP", this.GetClientIP() }, { "UA", HttpUtility.UrlEncode(HttpContext.Current.Request.UserAgent) }, { "BLD", ExchangeSetupContext.InstalledVersion.ToString() }, { "LTYPE", value } }; }
private void OnPostAuthenticateRequest(object sender, EventArgs e) { HttpApplication applicationInstance = HttpContext.Current.ApplicationInstance; HttpContext httpContext = HttpContext.Current; HttpRequest request = httpContext.Request; if (request.IsAuthenticated && RbacPrincipal.GetCurrent(false) != null && ClientAccessRulesModule.ShouldBlockConnection(httpContext, RbacPrincipal.Current.RbacConfiguration)) { if (httpContext.IsWebServiceRequest() || httpContext.IsUploadRequest()) { ClientAccessRulesModule.SendAjaxErrorToClient(httpContext); } else { httpContext.Response.Redirect(string.Format("{0}logoff.owa?reason=6", EcpUrl.OwaVDir)); } applicationInstance.CompleteRequest(); } }
internal static string GetUserNameToLog() { string result = Strings.UserUnauthenticated; RbacPrincipal current = RbacPrincipal.GetCurrent(false); if (current != null) { result = current.NameForEventLog; } else if (HttpContext.Current.Request.IsAuthenticated) { result = HttpContext.Current.User.Identity.GetSafeName(true); } else if (HttpContext.Current.User == null) { result = Strings.UserNotSet; } return(result); }
public void AppendToIisLog() { if (!string.IsNullOrEmpty(HttpContext.Current.GetSessionID())) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("&perfRecord="); stringBuilder.Append(this.ToString().Replace("&", "%26")); stringBuilder.Append("&sessionId="); using (StringWriter stringWriter = new StringWriter(stringBuilder)) { HttpContext.Current.Server.UrlEncode(HttpContext.Current.GetSessionID(), stringWriter); } LocalSession localSession = RbacPrincipal.GetCurrent(false) as LocalSession; if (localSession != null) { stringBuilder.Append("&logonType="); stringBuilder.Append(localSession.LogonTypeFlag); } HttpContext.Current.Response.AppendToLog(stringBuilder.ToString()); } }
private static void Application_Error(object sender, EventArgs e) { HttpContext httpContext = HttpContext.Current; Exception ex = httpContext.GetError(); ExTraceGlobals.EventLogTracer.TraceError <EcpTraceFormatter <Exception> >(0, 0L, "Application Error: {0}", ex.GetTraceFormatter()); DDIHelper.Trace("Application Error: {0}", new object[] { ex.GetTraceFormatter() }); EcpPerfCounters.AspNetErrors.Increment(); EcpEventLogConstants.Tuple_RequestFailed.LogPeriodicFailure(EcpEventLogExtensions.GetUserNameToLog(), httpContext.GetRequestUrlForLog(), ex, EcpEventLogExtensions.GetFlightInfoForLog()); RbacPrincipal current = RbacPrincipal.GetCurrent(false); string tenantName = string.Empty; if (current != null) { OrganizationId organizationId = current.RbacConfiguration.OrganizationId; if (organizationId != null && organizationId.OrganizationalUnit != null) { tenantName = organizationId.OrganizationalUnit.Name; } } ActivityContextLogger.Instance.LogEvent(new PeriodicFailureEvent(ActivityContext.ActivityId.FormatForLog(), tenantName, httpContext.GetRequestUrlForLog(), ex, EcpEventLogExtensions.GetFlightInfoForLog())); ActivityContextManager.CleanupActivityContext(httpContext); if (ex is DelegatedSecurityTokenExpiredException) { ErrorHandlingModule.HandleDelegatedSecurityTokenExpire(httpContext); return; } if (httpContext.IsWebServiceRequest()) { string errorCause = DiagnosticsBehavior.GetErrorCause(ex); ErrorHandlingUtil.SendReportForCriticalException(httpContext, ex); ErrorHandlingModule.SendJsonError(httpContext, ex, errorCause); return; } if (httpContext.IsUploadRequest()) { ErrorHandlingUtil.SendReportForCriticalException(httpContext, ex); ErrorHandlingModule.SendJsonErrorForUpload(httpContext, ex); return; } if (ex is HttpException && ex.InnerException != null) { ex = ex.InnerException; } httpContext.Request.ServerVariables["X-ECP-ERROR"] = ex.GetType().FullName; string text = null; string text2 = null; if (ex is OverBudgetException) { text = "overbudget"; } else if (ex is IdentityNotMappedException || ex is TransientException) { text = "transientserviceerror"; } else if (ex is ObjectNotFoundException) { if (ex.InnerException is NonUniqueRecipientException) { text = "nonuniquerecipient"; } else { text = "nonmailbox"; } } else if (ex is ServerNotInSiteException || ex is LowVersionUserDeniedException) { text = "lowversion"; } else if (ex is CmdletAccessDeniedException || ex is DelegatedAccessDeniedException) { text = "noroles"; } else if (ex is UrlNotFoundOrNoAccessException) { text = "urlnotfoundornoaccess"; } else if (ex is BadRequestException) { text = "badrequest"; } else if (ex is BadQueryParameterException) { text = "badqueryparameter"; } else if (ex is ProxyFailureException) { text = "transientserviceerror"; } else if (ex is ProxyCantFindCasServerException) { text = "proxy"; } else if (ex is CasServerNotSupportEsoException) { text = "noeso"; } else if (ex is RegionalSettingsNotConfiguredException) { text = "regionalsettingsnotconfigured"; } else if (ex is SecurityException || (ErrorHandlingUtil.KnownReflectedExceptions.Value.ContainsKey("Microsoft.Exchange.Hygiene.Security.Authorization.NoValidRolesAssociatedToUserException, Microsoft.Exchange.Hygiene.Security.Authorization") && ex.GetType() == ErrorHandlingUtil.KnownReflectedExceptions.Value["Microsoft.Exchange.Hygiene.Security.Authorization.NoValidRolesAssociatedToUserException, Microsoft.Exchange.Hygiene.Security.Authorization"])) { text = "noroles"; } else if (ex is ExchangeConfigurationException) { text = "anonymousauthenticationdisabled"; } else if (ex is CannotAccessOptionsWithBEParamOrCookieException) { text = "cannotaccessoptionswithbeparamorcookie"; } else if (ex.IsMaxRequestLengthExceededException()) { EcpPerfCounters.RedirectToError.Increment(); text2 = httpContext.Request.AppRelativeCurrentExecutionFilePath; } else { ErrorHandlingUtil.SendReportForCriticalException(httpContext, ex); if (!ErrorHandlingUtil.ShowIisNativeErrorPage && !ex.IsInterestingHttpException()) { text = "unexpected"; } } if (text2 != null) { httpContext.Server.Transfer(text2, true); return; } if (text != null) { ErrorHandlingModule.TransferToErrorPage(text, ErrorHandlingUtil.CanShowDebugInfo(ex)); } }
private static PowerShellResults InvokeAsyncCore(Func <PowerShellResults> callback, Action <PowerShellResults> onCompleted, string uniqueUserIdentity, AsyncServiceManager.AsyncTaskBudgetManager asyncTaskBudget, string commandStringForTrace, ThrottlingType throttlingType) { if (string.IsNullOrEmpty(uniqueUserIdentity)) { throw new ArgumentNullException("uniqueUserIdentity cannot be null."); } AsyncServiceManager.AsyncTaskThrottlingStatus asyncTaskThrottlingStatus = asyncTaskBudget.RegisterAsyncTask(uniqueUserIdentity, commandStringForTrace, throttlingType); if (asyncTaskThrottlingStatus != AsyncServiceManager.AsyncTaskThrottlingStatus.None) { LocalizedString value = (asyncTaskThrottlingStatus == AsyncServiceManager.AsyncTaskThrottlingStatus.PerAppThrottlingHit) ? Strings.LongRunPerAppThrottlingHit : Strings.LongRunPerUserThrottlingHit; asyncTaskBudget.UnregisterAsyncTask(uniqueUserIdentity, throttlingType); return(new PowerShellResults { ErrorRecords = new ErrorRecord[] { new ErrorRecord(new InvalidOperationException(value)) } }); } AsyncServiceManager.WorkItem workItem = new AsyncServiceManager.WorkItem(Guid.NewGuid().ToString()); AsyncServiceManager.workItems[workItem.Id] = workItem; CultureInfo currentCulture = CultureInfo.CurrentCulture; IPrincipal currentPrincipal = Thread.CurrentPrincipal; OperationContext currentOperationContext = OperationContext.Current; HttpContext currentHttpContext = HttpContext.Current; commandStringForTrace = ((commandStringForTrace == null) ? string.Empty : commandStringForTrace); RbacPrincipal rbacSession = RbacPrincipal.GetCurrent(false); ThreadPool.QueueUserWorkItem(delegate(object state) { int managedThreadId = Thread.CurrentThread.ManagedThreadId; AsyncServiceManager.WorkItem workItem; AsyncServiceManager.workerThreads[managedThreadId] = workItem; CultureInfo currentCulture = CultureInfo.CurrentCulture; IPrincipal currentPrincipal = Thread.CurrentPrincipal; OperationContext value2 = OperationContext.Current; HttpContext value3 = HttpContext.Current; Thread.CurrentThread.CurrentCulture = (Thread.CurrentThread.CurrentUICulture = currentCulture); Thread.CurrentPrincipal = currentPrincipal; OperationContext.Current = currentOperationContext; HttpContext.Current = AsyncServiceManager.CloneHttpContextForLongRunningThread(currentHttpContext); ActivityContextManager.InitializeActivityContext(HttpContext.Current, ActivityContextLoggerId.LongRunning); PowerShellResults powerShellResults = null; try { EcpEventLogConstants.Tuple_AsyncWebRequestStarted.LogEvent(new object[] { uniqueUserIdentity, managedThreadId, commandStringForTrace }); powerShellResults = callback(); object obj = AsyncServiceManager.workerThreads[managedThreadId]; } catch (Exception exception) { powerShellResults = new PowerShellResults(); powerShellResults.ErrorRecords = new ErrorRecord[] { new ErrorRecord(exception) }; EcpEventLogConstants.Tuple_AsyncWebRequestFailed.LogEvent(new object[] { uniqueUserIdentity, managedThreadId, exception.GetTraceFormatter(), commandStringForTrace }); ErrorHandlingUtil.SendReportForCriticalException(currentHttpContext, exception); DDIHelper.Trace("Async work item {0}, Error: {1}", new object[] { workItem.Id, exception.GetTraceFormatter() }); } finally { AsyncServiceManager.workerThreads.Remove(managedThreadId); lock (workItem) { workItem.Results = powerShellResults; ProgressRecord progressRecord = workItem.LegacyProgressRecord ?? ((workItem.ProgressCalculator == null) ? new ProgressRecord() : workItem.ProgressCalculator.ProgressRecord); powerShellResults.ProgressRecord = progressRecord; progressRecord.HasCompleted = true; progressRecord.IsCancelled = workItem.Cancelled; workItem.FinishedEvent.Set(); } asyncTaskBudget.UnregisterAsyncTask(uniqueUserIdentity, throttlingType); if (onCompleted != null) { onCompleted(powerShellResults); } EcpEventLogConstants.Tuple_AsyncWebRequestEnded.LogEvent(new object[] { uniqueUserIdentity, managedThreadId, commandStringForTrace }); ActivityContextManager.CleanupActivityContext(HttpContext.Current); Thread.CurrentThread.CurrentCulture = (Thread.CurrentThread.CurrentUICulture = currentCulture); Thread.CurrentPrincipal = currentPrincipal; OperationContext.Current = value2; HttpContext.Current = value3; GC.KeepAlive(rbacSession); } }); return(new PowerShellResults { ProgressId = workItem.Id }); }