コード例 #1
0
        void SetClaimsPrincipalToOperationContext(MessageRpc rpc)
        {
            // TODO: Reenable this code

            //ServiceSecurityContext securityContext = rpc.SecurityContext;
            //if (!rpc.HasSecurityContext)
            //{
            //    SecurityMessageProperty securityContextProperty = rpc.Request.Properties.Security;
            //    if (securityContextProperty != null)
            //    {
            //        securityContext = securityContextProperty.ServiceSecurityContext;
            //    }
            //}

            //if (securityContext != null)
            //{
            //    object principal;
            //    if (securityContext.AuthorizationContext.Properties.TryGetValue(AuthorizationPolicy.ClaimsPrincipalKey, out principal))
            //    {
            //        ClaimsPrincipal claimsPrincipal = principal as ClaimsPrincipal;
            //        if (claimsPrincipal != null)
            //        {
            //            //
            //            // Always set ClaimsPrincipal to OperationContext.Current if identityModel pipeline is used.
            //            //
            //            OperationContext.Current.ClaimsPrincipal = claimsPrincipal;
            //        }
            //        else
            //        {
            //            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.NoPrincipalSpecifiedInAuthorizationContext));
            //        }
            //    }
            //}
        }
コード例 #2
0
 void InspectInputs(ref MessageRpc rpc)
 {
     if (ParameterInspectors.Length > 0)
     {
         InspectInputsCore(ref rpc);
     }
 }
コード例 #3
0
        private async Task ProcessError(MessageRpc rpc)
        {
            try
            {
                _error.ProvideMessageFault(rpc);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                _error.HandleError(e);
            }

            PrepareReply(rpc);

            if (rpc.CanSendReply)
            {
                rpc.ReplyTimeoutHelper = new TimeoutHelper(rpc.Channel.OperationTimeout);
                //if (rpc.Reply != null)
                //{
                //    TraceUtility.MessageFlowAtMessageSent(rpc.Reply, rpc.EventTraceActivity);
                //}

                await ReplyAsync(rpc);
            }

            ProcessMessageCleanup(rpc);
        }
コード例 #4
0
        //        void EndFinalizeCorrelation(ref MessageRpc rpc)
        //        {
        //            try
        //            {
        //                rpc.Reply = rpc.CorrelationCallback.EndFinalizeCorrelation(rpc.AsyncResult);
        //            }
        //            catch (Exception e)
        //            {
        //                if (Fx.IsFatal(e))
        //                {
        //                    throw;
        //                }

        //                if (!this.error.HandleError(e))
        //                {
        //                    rpc.CanSendReply = false;
        //                }
        //            }
        //        }

        bool EndReply(ref MessageRpc rpc)
        {
            bool success = false;

            try
            {
                rpc.TaskResult.GetAwaiter().GetResult();
                rpc.RequestContextThrewOnReply = false;
                success = true;

                //if (TD.DispatchMessageStopIsEnabled())
                //{
                //    TD.DispatchMessageStop(rpc.EventTraceActivity);
                //}
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                error.HandleError(e);
            }

            return(success);
        }
コード例 #5
0
        private ServiceSecurityContext GetAndCacheSecurityContext(MessageRpc rpc)
        {
            ServiceSecurityContext securityContext = rpc.SecurityContext;

            if (!rpc.HasSecurityContext)
            {
                SecurityMessageProperty securityContextProperty = rpc.Request.Properties.Security;
                if (securityContextProperty == null)
                {
                    securityContext = null; // SecurityContext.Anonymous
                }
                else
                {
                    securityContext = securityContextProperty.ServiceSecurityContext;
                    if (securityContext == null)
                    {
                        throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SecurityContextMissing, rpc.Operation.Name)), rpc.Request);
                    }
                }

                rpc.SecurityContext    = securityContext;
                rpc.HasSecurityContext = true;
            }

            return(securityContext);
        }
コード例 #6
0
 internal void AfterReply(ref MessageRpc rpc)
 {
     if (rpc.Operation.IsTerminating && rpc.Channel.HasSession)
     {
         Timer timer = new Timer(new TimerCallback(AbortChannel), rpc.Channel.Binder.Channel, rpc.Channel.CloseTimeout, TimeSpan.FromMilliseconds(-1));
     }
 }
コード例 #7
0
        internal async Task LockInstanceAsync(MessageRpc rpc)
        {
            if (concurrencyMode != ConcurrencyMode.Multiple)
            {
                ConcurrencyInstanceContextFacet resource = rpc.InstanceContext.Concurrency;
                bool needToWait = false;
                lock (rpc.InstanceContext.ThisLock)
                {
                    if (!resource.Locked)
                    {
                        resource.Locked = true;
                    }
                    else
                    {
                        needToWait = true;
                    }
                }

                if (needToWait)
                {
                    await resource.EnqueueNewMessage();
                }

                // TODO: Throw this on setup
                if (concurrencyMode == ConcurrencyMode.Reentrant)
                {
                    throw new NotSupportedException(nameof(ConcurrencyMode.Reentrant));
                }
            }
        }
コード例 #8
0
        public void Authenticate(ref MessageRpc rpc)
        {
            SecurityMessageProperty security = SecurityMessageProperty.GetOrCreate(rpc.Request);
            ReadOnlyCollection <IAuthorizationPolicy> authPolicy = security.ServiceSecurityContext.AuthorizationPolicies;

            try
            {
                authPolicy = _serviceAuthenticationManager.Authenticate(security.ServiceSecurityContext.AuthorizationPolicies, rpc.Channel.ListenUri, ref rpc.Request);
                if (authPolicy == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.AuthenticationManagerShouldNotReturnNull));
                }
            }
            catch (Exception ex)
            {
                if (Fx.IsFatal(ex))
                {
                    throw;
                }

                // TODO: PerformanceCounters
                // TODO: Decide if we want Auditing and add back
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateFailedAuthenticationFaultException());
            }

            rpc.Request.Properties.Security.ServiceSecurityContext.AuthorizationPolicies = authPolicy;
        }
コード例 #9
0
        void InitializeCallContextCore(MessageRpc rpc)
        {
            IClientChannel channel = rpc.Channel.Proxy as IClientChannel;
            int            offset  = Parent.CallContextCorrelationOffset;

            try
            {
                for (int i = 0; i < rpc.Operation.CallContextInitializers.Length; i++)
                {
                    ICallContextInitializer initializer = CallContextInitializers[i];
                    rpc.Correlation[offset + i] = initializer.BeforeInvoke(rpc.InstanceContext, channel, rpc.Request);
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowExceptionAsIs(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }
        }
コード例 #10
0
 void BeforeSendReply(MessageRpc rpc, ref Exception exception, ref bool thereIsAnUnhandledException)
 {
     if (_messageInspectors.Length > 0)
     {
         BeforeSendReplyCore(rpc, ref exception, ref thereIsAnUnhandledException);
     }
 }
コード例 #11
0
 internal void AfterReceiveRequestCore(ref MessageRpc rpc)
 {
     try
     {
         for (int i = 0; i < _messageInspectors.Length; i++)
         {
             rpc.Correlation[i] = _messageInspectors[i].AfterReceiveRequest(ref rpc.Request, (IClientChannel)rpc.Channel.Proxy, rpc.InstanceContext);
             //if (TD.MessageInspectorAfterReceiveInvokedIsEnabled())
             //{
             //    TD.MessageInspectorAfterReceiveInvoked(rpc.EventTraceActivity, this.messageInspectors[i].GetType().FullName);
             //}
         }
     }
     catch (Exception e)
     {
         if (Fx.IsFatal(e))
         {
             throw;
         }
         if (ErrorBehavior.ShouldRethrowExceptionAsIs(e))
         {
             throw;
         }
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
     }
 }
コード例 #12
0
 private void InitializeCallContext(MessageRpc rpc)
 {
     if (CallContextInitializers.Length > 0)
     {
         InitializeCallContextCore(rpc);
     }
 }
コード例 #13
0
ファイル: InstanceBehavior.cs プロジェクト: zheng1748/CoreWCF
        internal async Task EnsureInstanceContextAsync(MessageRpc rpc)
        {
            if (rpc.InstanceContext == null)
            {
                rpc.InstanceContext = new InstanceContext(rpc.Host, false);
                rpc.InstanceContext.ServiceThrottle       = rpc.channelHandler.InstanceContextServiceThrottle;
                rpc.MessageRpcOwnsInstanceContextThrottle = false;
            }

            rpc.OperationContext.SetInstanceContext(rpc.InstanceContext);
            rpc.InstanceContext.Behavior = this;

            if (rpc.InstanceContext.State == CommunicationState.Created)
            {
                Task openTask = null;
                lock (rpc.InstanceContext.ThisLock)
                {
                    if (rpc.InstanceContext.State == CommunicationState.Created)
                    {
                        var helper = new TimeoutHelper(rpc.Channel.CloseTimeout);
                        // awaiting the task outside the lock is safe as OpenAsync will transition the state away from Created before
                        // it returns an uncompleted Task.
                        openTask = rpc.InstanceContext.OpenAsync(helper.GetCancellationToken());
                        Fx.Assert(rpc.InstanceContext.State != CommunicationState.Created, "InstanceContext.OpenAsync should transition away from Created before returning a Task");
                    }
                }

                await openTask;
            }

            rpc.InstanceContext.BindRpc(rpc);
        }
コード例 #14
0
 void InspectOutputs(MessageRpc rpc)
 {
     if (ParameterInspectors.Length > 0)
     {
         InspectOutputsCore(rpc);
     }
 }
コード例 #15
0
ファイル: ThreadBehavior.cs プロジェクト: pentp/CoreWCF
        internal SynchronizationContext GetSyncContext(MessageRpc rpc)
        {
            Fx.Assert(rpc.InstanceContext != null, "instanceContext is null !");
            SynchronizationContext syncContext = rpc.InstanceContext.SynchronizationContext ?? context;

            return(syncContext);
        }
コード例 #16
0
 internal void AfterReceiveRequest(ref MessageRpc rpc)
 {
     if (_messageInspectors.Length > 0)
     {
         AfterReceiveRequestCore(ref rpc);
     }
 }
コード例 #17
0
 internal void ProvideMessageFault(MessageRpc rpc)
 {
     if (rpc.Error != null)
     {
         ProvideMessageFaultCore(rpc);
     }
 }
コード例 #18
0
 internal void HandleError(MessageRpc rpc)
 {
     if (rpc.Error != null)
     {
         HandleErrorCore(rpc);
     }
 }
コード例 #19
0
        internal async Task <MessageRpc> InvokeAsync(MessageRpc rpc)
        {
            if (rpc.Error == null)
            {
                try
                {
                    InitializeCallContext(rpc);
                    object target = rpc.Instance;
                    DeserializeInputs(rpc);
                    InspectInputs(rpc);
                    ValidateMustUnderstand(rpc);
                    ValidateAuthorizedClaims(rpc);

                    if (Parent.RequireClaimsPrincipalOnOperationContext)
                    {
                        SetClaimsPrincipalToOperationContext(rpc);
                    }

                    if (Parent.SecurityImpersonation != null)
                    {
                        await Parent.SecurityImpersonation.RunImpersonated(rpc, async() =>
                        {
                            (rpc.ReturnParameter, rpc.OutputParameters) = await Invoker.InvokeAsync(target, rpc.InputParameters);
                        });
                    }
                    else
                    {
                        (rpc.ReturnParameter, rpc.OutputParameters) = await Invoker.InvokeAsync(target, rpc.InputParameters);
                    }

                    InspectOutputs(rpc);
                    SerializeOutputs(rpc);
                }
コード例 #20
0
 internal void UnlockInstance(ref MessageRpc rpc)
 {
     if (concurrencyMode != ConcurrencyMode.Multiple)
     {
         ConcurrencyBehavior.UnlockInstance(rpc.InstanceContext);
     }
 }
コード例 #21
0
 void UninitializeCallContext(MessageRpc rpc)
 {
     if (CallContextInitializers.Length > 0)
     {
         UninitializeCallContextCore(rpc);
     }
 }
コード例 #22
0
        bool PrepareAndAddressReply(ref MessageRpc rpc)
        {
            bool canSendReply = true;

            if (!_manualAddressing)
            {
                if (!object.ReferenceEquals(rpc.RequestID, null))
                {
                    RequestReplyCorrelator.PrepareReply(rpc.Reply, rpc.RequestID);
                }

                if (!rpc.Channel.HasSession)
                {
                    canSendReply = RequestReplyCorrelator.AddressReply(rpc.Reply, rpc.ReplyToInfo);
                }
            }

            AddMessageProperties(rpc.Reply, rpc.OperationContext, rpc.Channel);
            //if (FxTrace.Trace.IsEnd2EndActivityTracingEnabled && rpc.EventTraceActivity != null)
            //{
            //    rpc.Reply.Properties[EventTraceActivity.Name] = rpc.EventTraceActivity;
            //}

            return(canSendReply);
        }
コード例 #23
0
 void SetActivityIdOnThread(MessageRpc rpc)
 {
     //if (FxTrace.Trace.IsEnd2EndActivityTracingEnabled && rpc.EventTraceActivity != null)
     //{
     //    // Propogate the ActivityId to the service operation
     //    EventTraceActivityHelper.SetOnThread(rpc.EventTraceActivity);
     //}
 }
コード例 #24
0
        void HandleErrorCore(MessageRpc rpc)
        {
            bool handled = HandleErrorCommon(rpc.Error, ref rpc.FaultInfo);

            if (handled)
            {
                rpc.Error = null;
            }
        }
コード例 #25
0
        void ProvideMessageFaultCoreCoda(MessageRpc rpc)
        {
            if (rpc.FaultInfo.Fault.Headers.Action == null)
            {
                rpc.FaultInfo.Fault.Headers.Action = rpc.RequestVersion.Addressing.DefaultFaultAction;
            }

            rpc.Reply = rpc.FaultInfo.Fault;
        }
コード例 #26
0
        internal Task <MessageRpc> DispatchAsync(MessageRpc rpc, bool isOperationContextSet)
        {
            rpc.ErrorProcessor = ProcessError;
            rpc.AsyncProcessor = ProcessMessageAsync;
            var task = rpc.ProcessAsync(isOperationContextSet);

            rpc._processCallReturned = true;
            return(task);
        }
コード例 #27
0
 Task AcquireDynamicInstanceContextAsync(MessageRpc rpc)
 {
     if (rpc.InstanceContext.QuotaThrottle != null)
     {
         return(AcquireDynamicInstanceContextCoreAsync(rpc));
     }
     else
     {
         return(Task.CompletedTask);
     }
 }
コード例 #28
0
 bool AcquireDynamicInstanceContext(ref MessageRpc rpc)
 {
     //if (rpc.InstanceContext.QuotaThrottle != null)
     //{
     //    return AcquireDynamicInstanceContextCore(ref rpc);
     //}
     //else
     //{
     return(true);
     //}
 }
コード例 #29
0
 void ValidateMustUnderstand(ref MessageRpc rpc)
 {
     if (parent.ValidateMustUnderstand)
     {
         rpc.NotUnderstoodHeaders = rpc.Request.Headers.GetHeadersNotUnderstood();
         if (rpc.NotUnderstoodHeaders != null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                       new MustUnderstandSoapException(rpc.NotUnderstoodHeaders, rpc.Request.Version.Envelope));
         }
     }
 }
コード例 #30
0
        void ProvideMessageFaultCore(MessageRpc rpc)
        {
            if (messageVersion != rpc.RequestVersion)
            {
                Fx.Assert("CoreWCF.Dispatcher.ErrorBehavior.ProvideMessageFaultCore(): (this.messageVersion != rpc.RequestVersion)");
            }

            InitializeFault(rpc);

            ProvideFault(rpc.Error, rpc.Channel.GetProperty <FaultConverter>(), ref rpc.FaultInfo);

            ProvideMessageFaultCoreCoda(rpc);
        }