public override PSPrimitiveDictionary GetApplicationPrivateData(PSSenderInfo senderInfo) { if (!Constants.IsPowerShellWebService) { ExchangeAuthorizationPlugin.InitializeAuthZPluginForRemotePS(senderInfo.ConnectionString); } ExchangeAuthorizationPlugin.EnsureSettingOverrideSyncIsStarted(); return(AuthZLogHelper.StartAndEndLoging <PSPrimitiveDictionary>("GetApplicationPrivateData", () => AuthZLogHelper.ExecuteWSManPluginAPI <PSPrimitiveDictionary>("GetApplicationPrivateData", true, true, null, delegate() { InitialSessionState initialSessionStateCore = this.GetInitialSessionStateCore(senderInfo); if (!Constants.IsPowerShellWebService) { this.CheckSessionOverBudget(); } this.currentUserISS.Target = initialSessionStateCore; int value = InitialSessionStateBuilder.CalculateHashForImplicitRemoting(initialSessionStateCore); PSPrimitiveDictionary psprimitiveDictionary = new PSPrimitiveDictionary(); psprimitiveDictionary.Add("ImplicitRemoting", new PSPrimitiveDictionary { { "Hash", value } }); if (!Constants.IsPowerShellWebService) { psprimitiveDictionary.Add("SupportedVersions", this.ExpandVersions(senderInfo.ConnectionString)); } this.LogCommonValues(); return psprimitiveDictionary; }))); }
// Token: 0x060012DC RID: 4828 RVA: 0x0003D450 File Offset: 0x0003B650 internal static void ExecuteWSManPluginAPI(string funcName, bool throwException, bool trackLatency, Action action) { AuthZLogHelper.ExecuteWSManPluginAPI <bool>(funcName, throwException, trackLatency, false, delegate() { action(); return(false); }); }
// Token: 0x060012DA RID: 4826 RVA: 0x0003D3BC File Offset: 0x0003B5BC internal static void StartAndEndLoging(string funcName, Action action) { AuthZLogHelper.StartAndEndLoging <bool>(funcName, delegate() { action(); return(true); }); }
// Token: 0x060012EA RID: 4842 RVA: 0x0003D9DC File Offset: 0x0003BBDC private static T HandleExceptionAndRetry <T>(string methodName, Func <T> func, bool throwException, T defaultReturnValue) { for (int i = 0; i < 2; i++) { try { Microsoft.Exchange.Diagnostics.Components.Authorization.ExTraceGlobals.PublicPluginAPITracer.TraceDebug <string, int>(0L, "Retry function {0} the {1} times.", methodName, i); return(func()); } catch (Exception ex) { bool flag = ex is TransientException; bool flag2 = AuthZPluginHelper.IsFatalException(ex); bool flag3 = flag2 || AuthZLogHelper.ExceptionNoNeedToRetry(ex); Microsoft.Exchange.Diagnostics.Components.Authorization.ExTraceGlobals.PublicPluginAPITracer.TraceDebug(0L, "{0} caught Exception {1}. IsTransientException = {2}. IsFatalException = {3}. NoNeedToRetry = {4}.", new object[] { methodName, ex, flag, flag2, flag3 }); ExEventLog.EventTuple eventInfo = Microsoft.Exchange.Configuration.ObjectModel.EventLog.TaskEventLogConstants.Tuple_RBACUnavailable_UnknownError; if (flag) { eventInfo = Microsoft.Exchange.Configuration.ObjectModel.EventLog.TaskEventLogConstants.Tuple_RBACUnavailable_TransientError; } else if (flag2) { eventInfo = Microsoft.Exchange.Configuration.ObjectModel.EventLog.TaskEventLogConstants.Tuple_RBACUnavailable_FatalError; } TaskLogger.LogRbacEvent(eventInfo, null, new object[] { methodName, ex }); if (flag3 || i == 1) { if (!(ex is ADTransientException) && (flag2 || throwException)) { throw; } AuthZLogHelper.LogException(ex, methodName, false); break; } else { AuthZLogger.SafeAppendGenericInfo(methodName + "-" + ex.GetType().Name + "-Retried", ex.Message); } } } Microsoft.Exchange.Diagnostics.Components.Authorization.ExTraceGlobals.PublicPluginAPITracer.TraceError <string, T>(0L, "{0} returns default value {1}.", methodName, defaultReturnValue); return(defaultReturnValue); }
protected override void Dispose(bool isDisposing) { AuthZLogHelper.StartAndEndLoging("Dispose", delegate() { AuthZLogHelper.ExecuteWSManPluginAPI("Dispose", false, false, delegate() { if (isDisposing) { this.OnDispose(); } this.< > n__FabricatedMethode(isDisposing); }); }); }
public override InitialSessionState GetInitialSessionState(PSSenderInfo senderInfo) { return(AuthZLogHelper.StartAndEndLoging <InitialSessionState>("GetInitialSessionState", () => AuthZLogHelper.ExecuteWSManPluginAPI <InitialSessionState>("GetInitialSessionState", true, true, null, delegate() { if (senderInfo == null || senderInfo.UserInfo == null || senderInfo.UserInfo.Identity == null || senderInfo.UserInfo.Identity.Name == null) { throw new ArgumentException("senderInfo"); } ExTraceGlobals.PublicPluginAPITracer.TraceDebug((long)this.GetHashCode(), "[EAP.GetInitialSessionState] Enter."); this.PreGetInitialSessionState(senderInfo); InitialSessionState initialSessionState = this.currentUserISS.Target as InitialSessionState; this.currentUserISS.Target = null; if (initialSessionState == null) { initialSessionState = this.GetInitialSessionStateCore(senderInfo); } this.PostGetInitialSessionState(senderInfo); return initialSessionState; }))); }
// Token: 0x060012E1 RID: 4833 RVA: 0x0003D75C File Offset: 0x0003B95C internal static void EndLogging(bool shouldCommit) { Microsoft.Exchange.Diagnostics.Components.Configuration.Core.ExTraceGlobals.InstrumentationTracer.TraceDebug(0L, "[AuthZLogHelper.EndLogging] End logging."); try { if (AuthZLogHelper.latencyTracker != null) { long num = Diagnostics.ExecuteAndLog <long>("AuthZLogHelper.StopLatencyTracker", false, null, Constants.CoreEventLogger, Microsoft.Exchange.Configuration.Core.EventLog.TaskEventLogConstants.Tuple_NonCrashingException, Microsoft.Exchange.Diagnostics.Components.Configuration.Core.ExTraceGlobals.InstrumentationTracer, null, delegate(Exception ex) { AuthZLogHelper.LogException(ex, "AuthZLogHelper.StopLatencyTracker", false); }, -1L, new Func <long>(AuthZLogHelper.StopLatencyTracker)); AuthZLogger.SafeSetLogger(ConfigurationCoreMetadata.TotalTime, num); AuthZLogHelper.latencyTracker.PushLatencyDetailsToLog(AuthZLogHelper.funcNameToLogMetadataDic, new Action <Enum, double>(AuthZLogger.UpdateLatency), delegate(string funcName, string totalLatency) { AuthZLogger.SafeAppendColumn(RpsCommonMetadata.GenericLatency, funcName, totalLatency); }); } else { AuthZLogger.SafeAppendColumn(RpsCommonMetadata.GenericLatency, "LatencyMissed", "AuthZLogHelper.latencyTracker is null"); } } finally { try { if (shouldCommit) { AuthZLogger.AsyncCommit(true); } } finally { AuthZLogHelper.latencyTracker = null; } } }
// Token: 0x060012DD RID: 4829 RVA: 0x0003D4C8 File Offset: 0x0003B6C8 internal static T ExecuteWSManPluginAPI <T>(string funcName, bool throwException, bool trackLatency, T defaultReturnValue, Func <T> func) { ExWatson.IsExceptionInteresting isExceptionInteresting = null; T result; try { AuthZLogger.SafeAppendColumn(RpsCommonMetadata.GenericLatency, funcName, DateTime.UtcNow.ToString()); string funcName2 = funcName; bool throwException2 = throwException; LatencyTracker latencyTracker = trackLatency ? AuthZLogHelper.latencyTracker : null; ExEventLog rbacEventLogger = AuthZLogHelper.RbacEventLogger; ExEventLog.EventTuple tuple_RemotePSPublicAPIFailed = Microsoft.Exchange.Configuration.ObjectModel.EventLog.TaskEventLogConstants.Tuple_RemotePSPublicAPIFailed; Trace publicPluginAPITracer = Microsoft.Exchange.Diagnostics.Components.Authorization.ExTraceGlobals.PublicPluginAPITracer; if (isExceptionInteresting == null) { isExceptionInteresting = ((object ex) => AuthZPluginHelper.IsFatalException(ex as Exception)); } result = Diagnostics.ExecuteAndLog <T>(funcName2, throwException2, latencyTracker, rbacEventLogger, tuple_RemotePSPublicAPIFailed, publicPluginAPITracer, isExceptionInteresting, delegate(Exception ex) { AuthZLogHelper.LogException(ex, funcName, throwException); }, defaultReturnValue, () => AuthZLogHelper.HandleExceptionAndRetry <T>(funcName, func, throwException, defaultReturnValue)); } catch (Exception ex) { string arg = (AuthZLogger.ActivityScope != null) ? AuthZLogger.ActivityScope.ActivityId.ToString() : null; AuthZLogHelper.EndLogging(true); Exception ex3; string str = string.Format("[FailureCategory={0}] ", FailureCategory.AuthZ + "-" + ex3.GetType().Name); string str2 = string.Format("[AuthZRequestId={0}]", arg); LocalizedString message = new LocalizedString(str2 + str + ex3.Message); AuthorizationException ex2 = new AuthorizationException(message, ex3); throw ex2; } return(result); }
// Token: 0x060012DB RID: 4827 RVA: 0x0003D3EC File Offset: 0x0003B5EC internal static T StartAndEndLoging <T>(string funcName, Func <T> func) { bool flag = false; bool flag2 = false; T result; try { flag2 = AuthZLogHelper.StartLogging(funcName, out flag); result = func(); } finally { if (flag2) { AuthZLogHelper.EndLogging(true); } else if (flag) { AuthZLogHelper.EndLogging(false); } } return(result); }
// Token: 0x060012DF RID: 4831 RVA: 0x0003D670 File Offset: 0x0003B870 internal static bool StartLogging(string funcName, out bool latencyTrackerStartedByMe) { AuthZLogger.SafeAppendColumn(RpsCommonMetadata.GenericLatency, funcName, DateTime.UtcNow.ToString()); latencyTrackerStartedByMe = false; if (AuthZLogHelper.latencyTracker == null) { Diagnostics.ExecuteAndLog("AuthZLogHelper.StartLatencyTracker", false, null, Constants.CoreEventLogger, Microsoft.Exchange.Configuration.Core.EventLog.TaskEventLogConstants.Tuple_NonCrashingException, Microsoft.Exchange.Diagnostics.Components.Configuration.Core.ExTraceGlobals.InstrumentationTracer, null, delegate(Exception ex) { AuthZLogHelper.LogException(ex, "AuthZLogHelper.StartLatencyTracker", false); }, delegate() { AuthZLogHelper.StartLatencyTracker(funcName); }); latencyTrackerStartedByMe = (AuthZLogHelper.latencyTracker != null); } if (AuthZLogger.LoggerNotDisposed) { return(false); } InitializeLoggerSettingsHelper.InitLoggerSettings(); AuthZLogger.InitializeRequestLogger(); AuthZLogger.SafeSetLogger(RpsAuthZMetadata.Function, funcName); return(true); }
// Token: 0x06001244 RID: 4676 RVA: 0x00039740 File Offset: 0x00037940 public override WindowsIdentity AuthorizeUser(SenderInfo senderInfo, out UserQuota userQuota) { ExTraceGlobals.PublicPluginAPITracer.TraceDebug((long)this.GetHashCode(), "[PswsAuthorization.AuthorizeUser] Enter."); WindowsIdentity current; try { if (this.IsBlockedPswsDirectInvocation()) { AuthZLogger.SafeAppendGenericError("PswsAuthorization.AuthorizeUser", "UnAuthorized. Blocked Psws direct invocation", false); throw new InvalidOperationException(Strings.InvalidPswsDirectInvocationBlocked); } CultureInfo cultureInfo = null; if (PswsAuthZHelper.TryParseCultureInfo(HttpContext.Current.Request.Headers, out cultureInfo)) { ExTraceGlobals.PublicPluginAPITracer.TraceDebug <string>((long)this.GetHashCode(), "[PswsAuthorization.AuthorizeUser] Set thread culture to be {0}", cultureInfo.Name); Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; } IThrottlingPolicy throttlingPolicy = null; PswsAuthZUserToken authZUserToken = null; AuthZLogHelper.ExecuteWSManPluginAPI("PswsAuthorization.AuthorizeUser", false, true, delegate() { UserToken userToken = HttpContext.Current.CurrentUserToken(); authZUserToken = PswsAuthZHelper.GetAuthZPluginUserToken(userToken); if (authZUserToken != null) { throttlingPolicy = authZUserToken.GetThrottlingPolicy(); } }); ExAssert.RetailAssert(authZUserToken != null, "UnAuthorized. The user token is invalid (null)."); ExAssert.RetailAssert(throttlingPolicy != null, "UnAuthorized. Unable to get the user quota."); PswsBudgetManager.Instance.HeartBeat(authZUserToken); AuthZLogger.SafeSetLogger(RpsAuthZMetadata.ServerActiveRunspaces, PswsBudgetManager.Instance.TotalActiveRunspaces); AuthZLogger.SafeSetLogger(RpsAuthZMetadata.ServerActiveUsers, PswsBudgetManager.Instance.TotalActiveUsers); AuthZLogger.SafeSetLogger(RpsAuthZMetadata.UserBudgetOnStart, PswsBudgetManager.Instance.GetWSManBudgetUsage(authZUserToken)); userQuota = new UserQuota((int)(throttlingPolicy.PswsMaxConcurrency.IsUnlimited ? 2147483647U : throttlingPolicy.PswsMaxConcurrency.Value), (int)(throttlingPolicy.PswsMaxRequest.IsUnlimited ? 2147483647U : throttlingPolicy.PswsMaxRequest.Value), (int)(throttlingPolicy.PswsMaxRequestTimePeriod.IsUnlimited ? 2147483647U : throttlingPolicy.PswsMaxRequestTimePeriod.Value)); ExTraceGlobals.PublicPluginAPITracer.TraceDebug <Unlimited <uint>, Unlimited <uint>, Unlimited <uint> >((long)this.GetHashCode(), "[PswsAuthorization.AuthorizeUser] User quota: PswsMaxConcurrenty={0}, PswsMaxRequest={1}, PswsMaxRequestTimePeriod={2}.", throttlingPolicy.PswsMaxConcurrency, throttlingPolicy.PswsMaxRequest, throttlingPolicy.PswsMaxRequestTimePeriod); AuthZLogger.SafeSetLogger(RpsAuthZMetadata.IsAuthorized, true); AuthZLogger.SafeSetLogger(RpsAuthZMetadata.AuthorizeUser, authZUserToken.UserNameForLogging); AuthZLogger.SafeSetLogger(RpsAuthZMetadata.GetQuota, string.Format("PswsMaxConcurrenty={0};PswsMaxRequest={1};PswsMaxRequestTimePeriod={2}", throttlingPolicy.PswsMaxConcurrency, throttlingPolicy.PswsMaxRequest, throttlingPolicy.PswsMaxRequestTimePeriod)); string ruleName = null; if (this.ConnectionBlockedByClientAccessRules(authZUserToken, out ruleName)) { throw new ClientAccessRulesBlockedConnectionException(ruleName); } current = WindowsIdentity.GetCurrent(); } catch (Exception ex) { ExTraceGlobals.PublicPluginAPITracer.TraceError <Exception>((long)this.GetHashCode(), "[PswsAuthorization.AuthorizeUser] Exception: {0}", ex); AuthZLogger.SafeAppendGenericError("PswsAuthorization.AuthorizeUser", ex, new Func <Exception, bool>(KnownException.IsUnhandledException)); TaskLogger.LogRbacEvent(TaskEventLogConstants.Tuple_PswsPublicAPIFailed, null, new object[] { "PswsAuthorization.AuthorizeUser", ex.ToString() }); AuthZLogger.SafeSetLogger(RpsAuthZMetadata.IsAuthorized, false); PswsErrorHandling.SendErrorToClient((ex is ClientAccessRulesBlockedConnectionException) ? PswsErrorCode.ClientAccessRuleBlock : PswsErrorCode.AuthZUserError, ex, null); throw; } finally { ExTraceGlobals.PublicPluginAPITracer.TraceDebug((long)this.GetHashCode(), "[PswsAuthorization.AuthorizeUser] Exit."); } return(current); }
private void LogCommonValues() { AuthZLogger.SafeSetLogger(RpsCommonMetadata.SessionId, this.sessionId); AuthZLogger.SafeAppendGenericInfo("FirstRequestId", this.firstRequestId); AuthZLogHelper.LogAuthZUserToken(this.currentAuthZUserToken); }
// Token: 0x060012E0 RID: 4832 RVA: 0x0003D736 File Offset: 0x0003B936 internal static void EndLogging() { AuthZLogHelper.EndLogging(true); }
// Token: 0x060012DE RID: 4830 RVA: 0x0003D634 File Offset: 0x0003B834 internal static bool StartLogging(string funcName) { bool flag = false; return(AuthZLogHelper.StartLogging(funcName, out flag)); }