Пример #1
0
 protected override bool CheckAccessCore(OperationContext operationContext)
 {
     if (RbacAuthorizationManager.NewAuthZMethodEnabled.Value)
     {
         if (HttpContext.Current.Items.Contains(RbacAuthorizationManager.DataServiceExceptionKey))
         {
             throw (DataServiceException)HttpContext.Current.Items[RbacAuthorizationManager.DataServiceExceptionKey];
         }
         operationContext.SetRbacPrincipal((RbacPrincipal)HttpContext.Current.User);
         return(base.CheckAccessCore(operationContext));
     }
     else
     {
         RbacPrincipal rbacPrincipal = null;
         ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.RbacPrincipalAcquireLatency, delegate
         {
             rbacPrincipal = RbacPrincipalManager.Instance.AcquireRbacPrincipal(HttpContext.Current);
         });
         if (rbacPrincipal == null)
         {
             return(false);
         }
         HttpContext.Current.User = rbacPrincipal;
         rbacPrincipal.SetCurrentThreadPrincipal();
         if (OperationContext.Current != null)
         {
             OperationContext.Current.SetRbacPrincipal(rbacPrincipal);
         }
         return(base.CheckAccessCore(operationContext));
     }
 }
Пример #2
0
        private void OnAuthorizeRequest(object sender, EventArgs e)
        {
            ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "ReportingModule.OnAuthorizeRequest");
            HttpApplication   httpApplication   = (HttpApplication)sender;
            HttpContext       context           = httpApplication.Context;
            RequestStatistics requestStatistics = context.Items[RequestStatistics.RequestStatsKey] as RequestStatistics;

            if (context.Request.IsAuthenticated)
            {
                requestStatistics.AddExtendedStatisticsDataPoint("AuthN", "True");
                try
                {
                    RbacPrincipal rbacPrincipal = RbacPrincipalManager.Instance.AcquireRbacPrincipalWrapper(context);
                    if (rbacPrincipal != null)
                    {
                        ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "[OnAuthorizeRequest] RbacPrincipal != null");
                        context.User = rbacPrincipal;
                        rbacPrincipal.SetCurrentThreadPrincipal();
                        requestStatistics.AddExtendedStatisticsDataPoint("AuthZ", "True");
                    }
                    else
                    {
                        ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "[OnAuthorizeRequest] RbacPrincipal == null");
                        context.Response.StatusCode = 401;
                        httpApplication.CompleteRequest();
                        requestStatistics.AddExtendedStatisticsDataPoint("AuthZ", "False");
                    }
                    goto IL_138;
                }
                catch (DataServiceException value)
                {
                    ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "[OnAuthorizeRequest] DataServiceException got");
                    context.Items.Add(RbacAuthorizationManager.DataServiceExceptionKey, value);
                    requestStatistics.AddExtendedStatisticsDataPoint("AuthZ", "False");
                    goto IL_138;
                }
            }
            requestStatistics.AddExtendedStatisticsDataPoint("AuthN", "False");
            requestStatistics.AddExtendedStatisticsDataPoint("AuthZ", "False");
IL_138:
            ExTraceGlobals.ReportingWebServiceTracer.TraceDebug((long)this.GetHashCode(), "ReportingModule.OnAuthorizeRequest - End");
        }