internal static bool RemoveInstanceIdFromMessage(Message message)
        {
            ContextMessageProperty contextProperties = null;

            bool found = ContextMessageProperty.TryGet(message, out contextProperties);

            if (found)
            {
                contextProperties.Context.Remove(ContextManager.InstanceIdKey);
            }
            return(found);
        }
        public static CorrelationContext CreateCorrelationContext(MessageProperties messageProperties)
        {
            ContextMessageProperty property;

            if (ContextMessageProperty.TryGet(messageProperties, out property))
            {
                IDictionary <string, string> context = property.Context;
                return(new CorrelationContext {
                    Context = context
                });
            }
            return(null);
        }
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            try
            {
                if (reply != null)
                {
                    ContextMessageProperty context = null;

                    if (sessionMode == SessionMode.NotAllowed || reply.Properties.ContainsKey(suppressContextOnReply))
                    {
                        if (ContextMessageProperty.TryGet(reply, out context))
                        {
                            context.Context.Clear();
                        }
                    }
                    else
                    {
                        string newInstanceId = correlationState as string;

                        if (newInstanceId != null)
                        {
                            if (!ContextMessageProperty.TryGet(reply, out context))
                            {
                                context = new ContextMessageProperty();
                                context.Context[WellKnownContextProperties.InstanceId] = newInstanceId;
                                context.AddOrReplaceInMessage(reply);
                            }
                            else
                            {
                                context.Context[WellKnownContextProperties.InstanceId] = newInstanceId;
                            }
                        }
                    }
                }
            }
            finally
            {
                DurableInstance durableInstance = OperationContext.Current.InstanceContext.Extensions.Find <DurableInstance>();

                if (durableInstance == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new InvalidOperationException(
                                  SR2.GetString(
                                      SR2.RequiredInstanceContextExtensionNotFound,
                                      typeof(DurableInstance).Name)));
                }
                //Decrement InstanceActivity Count
                durableInstance.DecrementActivityCount();
            }
        }
        internal static Guid GetInstanceIdFromMessage(Message message)
        {
            string instanceId = null;
            ContextMessageProperty contextProperties = null;

            if (ContextMessageProperty.TryGet(message, out contextProperties))
            {
                if (contextProperties.Context.TryGetValue(ContextManager.InstanceIdKey, out instanceId))
                {
                    return(new Guid(instanceId));
                }
            }
            return(Guid.Empty);
        }
        IDictionary <string, string> GetContextProperties()
        {
            Fx.Assert(OperationContext.Current != null, "Called from non service thread");

            ContextMessageProperty incomingContextProperties = null;

            if (OperationContext.Current.IncomingMessageProperties != null &&
                ContextMessageProperty.TryGet(OperationContext.Current.IncomingMessageProperties, out incomingContextProperties))
            {
                return(incomingContextProperties.Context);
            }
            else
            {
                return(SerializableReadOnlyDictionary <string, string> .Empty);
            }
        }
        internal static void UpdateLogicalChannelContext(LogicalChannel logicalChannel)
        {
            Fx.Assert(OperationContext.Current != null, "Can be called from valid OperationContextScope");

            WorkflowTrace.Host.TraceEvent(TraceEventType.Verbose, 0,
                                          "ChannelManagerService: updating context associated with logical channel {0}",
                                          logicalChannel.InstanceId);

            ContextMessageProperty contextMessageProperty;
            MessageProperties      properties = OperationContext.Current.IncomingMessageProperties;

            if (properties != null && ContextMessageProperty.TryGet(properties, out contextMessageProperty))
            {
                logicalChannel.Context = contextMessageProperty.Context;
            }
        }
        protected virtual Guid GetInstanceIdFromMessage(Message message)
        {
            if (!this.isPerCall)
            {
                ContextMessageProperty contextProperties = null;
                string instanceId = null;

                if (ContextMessageProperty.TryGet(message, out contextProperties))
                {
                    if (contextProperties.Context.TryGetValue(WellKnownContextProperties.InstanceId, out instanceId))
                    {
                        return(Fx.CreateGuid(instanceId));
                    }
                }
            }
            return(Guid.Empty);
        }
示例#8
0
        protected override Guid OnGetInstanceId(object[] inputs, OperationContext operationContext)
        {
            Fx.Assert(operationContext.IncomingMessageHeaders.Action == RaiseEventAction, "Message action is not RaiseEvent");
            Guid instanceId = Guid.Empty;
            ContextMessageProperty contextMessageProperty;

            if (ContextMessageProperty.TryGet(operationContext.IncomingMessageProperties, out contextMessageProperty))
            {
                string stringInstanceId = null;
                if (contextMessageProperty.Context.TryGetValue("instanceId", out stringInstanceId))
                {
                    Fx.TryCreateGuid(stringInstanceId, out instanceId);
                }
            }

            return(instanceId);
        }
        void PromoteContextProperties()
        {
            Fx.Assert(OperationContext.Current != null, "Called from non service thread");

            if (outgoingContextProperties != null)
            {
                ContextMessageProperty context;
                if (!ContextMessageProperty.TryGet(OperationContext.Current.OutgoingMessageProperties, out context))
                {
                    new ContextMessageProperty(this.outgoingContextProperties).AddOrReplaceInMessageProperties(OperationContext.Current.OutgoingMessageProperties);
                }
                else
                {
                    foreach (KeyValuePair <string, string> contextElement in this.outgoingContextProperties)
                    {
                        context.Context[contextElement.Key] = contextElement.Value;
                    }
                }
            }
        }
        internal static void SetInstanceIdInMessage(Message message, string instanceId)
        {
            ContextMessageProperty contextProperties = null;

            if (!ContextMessageProperty.TryGet(message, out contextProperties))
            {
                contextProperties = new ContextMessageProperty(ContextManager.CreateContext(ContextManager.InstanceIdKey, instanceId));
                message.Properties.Add(ContextMessageProperty.Name, contextProperties);
            }
            else
            {
                if (!contextProperties.Context.ContainsKey(ContextManager.InstanceIdKey))
                {
                    contextProperties.Context.Add(ContextManager.InstanceIdKey, instanceId);
                }
                else
                {
                    contextProperties.Context[ContextManager.InstanceIdKey] = instanceId;
                }
            }
        }
            private static bool HandleEndGetInstance(IAsyncResult result)
            {
                ControlOperationInvoker.ControlOperationAsyncResult asyncState = (ControlOperationInvoker.ControlOperationAsyncResult)result.AsyncState;
                bool shouldAbandon = true;

                try
                {
                    try
                    {
                        asyncState.workflowServiceInstance = asyncState.invoker.instanceManager.EndGetInstance(result);
                        shouldAbandon = false;
                    }
                    catch (InstanceLockedException exception)
                    {
                        RedirectionException exception2;
                        if (asyncState.TryCreateRedirectionException(exception, out exception2))
                        {
                            throw System.ServiceModel.Activities.FxTrace.Exception.AsError(exception2);
                        }
                        throw System.ServiceModel.Activities.FxTrace.Exception.AsError(CreateFaultException(exception));
                    }
                    catch (OperationCanceledException exception3)
                    {
                        asyncState.BufferReceiveHelper(ref shouldAbandon, true);
                        throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new RetryException(null, exception3));
                    }
                    catch (InstancePersistenceException exception4)
                    {
                        asyncState.BufferReceiveHelper(ref shouldAbandon, false);
                        if (exception4 is InstanceKeyNotReadyException)
                        {
                            asyncState.invoker.host.RaiseUnknownMessageReceived(asyncState.operationContext.IncomingMessage);
                        }
                        asyncState.invoker.host.FaultServiceHostIfNecessary(exception4);
                        throw System.ServiceModel.Activities.FxTrace.Exception.AsError(CreateFaultException(exception4));
                    }
                }
                catch (Exception exception5)
                {
                    if (Fx.IsFatal(exception5))
                    {
                        throw;
                    }
                    if (!shouldAbandon || !asyncState.ShouldAbandonReceiveContext())
                    {
                        throw;
                    }
                    return(asyncState.AbandonReceiveContext(exception5));
                }
                if (!asyncState.instanceKey.IsValid && (asyncState.instanceId == Guid.Empty))
                {
                    ContextMessageProperty contextMessageProperty = null;
                    if (!ContextMessageProperty.TryGet(asyncState.operationContext.OutgoingMessageProperties, out contextMessageProperty))
                    {
                        contextMessageProperty = new ContextMessageProperty();
                        contextMessageProperty.Context.Add("instanceId", Guid.NewGuid().ToString());
                        contextMessageProperty.AddOrReplaceInMessageProperties(asyncState.operationContext.OutgoingMessageProperties);
                    }
                    else
                    {
                        contextMessageProperty.Context["instanceId"] = Guid.NewGuid().ToString();
                    }
                }
                return(asyncState.PerformOperation());
            }
示例#12
0
        public bool Put(RmResourceChanges transaction, bool useAlternateEndpoint, out PutResponse response, SecurityToken token, ContextMessageProperty context)
        {
            response = null;
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }

            if (!useAlternateEndpoint)
            {
                PutRequest resourceEPrequest = this.requestFactory.CreatePutRequest(transaction);
                try {
                    this.wsTransferClient.Put(resourceEPrequest, out response);
                }
                //catch AuthN Fault here so we have the original transaction so we can re-submit later
                catch (System.ServiceModel.FaultException <Microsoft.ResourceManagement.Client.Faults.AuthenticationRequiredFault> authNFault) {
                    String STSEndpoinAddresst = authNFault.Detail.SecurityTokenServiceAddress;
                    ContextMessageProperty responseContext;
                    //TODO: Add AuthNLogicHere. For now, only support QA gates on the Authernate Endpoint
                }

                if (response == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                //TODO:Verify that the ObjectID is in the form Domain\User.
                PutRequest alternateEPrequest = this.requestFactory.CreatePutRequest(transaction);
                response = null;

                try {
                    this.alternateClient.Put(alternateEPrequest, out response, token, context);
                } catch (System.ServiceModel.FaultException <Microsoft.ResourceManagement.Client.Faults.AuthenticationRequiredFault> authNFault) {
                    String STSEndpointAddress = authNFault.Detail.SecurityTokenServiceAddress;
                    ContextMessageProperty responseContext;

                    if (ContextMessageProperty.TryGet(response.Message, out responseContext))
                    {
                        ContextualSecurityToken userToken = HandleAuthNFault(STSEndpointAddress, responseContext);
                        Put(transaction, true, out response, userToken, responseContext);
                    }
                    else
                    {
                        throw new Exception("Could not get security context from Put.");
                    }
                }

                if (response == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
示例#13
0
        public static void OTPReset(string domain, string username, ContextualSecurityToken authNSecurityToken, ContextMessageProperty contextMessageProperty)
        {
            // Create Anonymouse RmPerson and set ObjectID to Domain\User
            // The ObjectID attribute will become ResourceReferenceProperty in the message header
            RmPerson    user = new RmPerson();
            RmReference domainAndUsernameReference = new RmReference();

            domainAndUsernameReference.DomainAndUserNameValue = domain + '\\' + username;
            user.ObjectID = domainAndUsernameReference;
            PutResponse putResponse;

            putResponse = new PutResponse();
            string STSEndpoint = String.Empty;
            bool   putSuccess  = false; //This should always stay false with these calls unless no password reset workflow or qa authn workflow is attached.

            var          alternateClient = new AlternateClient();
            var          mexClient       = new MexClient();
            XmlSchemaSet metadata        = mexClient.Get();
            var          requestFactory  = new RmRequestFactory(metadata);

            // Set ResetPassword to true
            // Need a transaction to watch changes to the user
            using (RmResourceChanges transaction = new RmResourceChanges(user))
            {
                transaction.BeginChanges();

                user.ResetPassword = "******";

                try
                {
                    if (transaction.RmObject.ObjectID.Value.Split('\\').Length != 2)
                    {
                        throw new ArgumentException("User Identity must be specified by netbios domain in this format: Domain name\\user name.");
                    }

                    PutRequest alternateEPrequest = requestFactory.CreatePutRequest(transaction);

                    try
                    {
                        alternateClient.Put(alternateEPrequest, out putResponse, authNSecurityToken, contextMessageProperty);
                        putSuccess = true;
                    }
                    catch (System.ServiceModel.FaultException <Microsoft.ResourceManagement.Client.Faults.AuthenticationRequiredFault> authNFault)
                    {
                        Microsoft.ResourceManagement.WebServices.WSResourceManagement.AuthenticationRequiredFault msAuthNFault =
                            new Microsoft.ResourceManagement.WebServices.WSResourceManagement.AuthenticationRequiredFault(authNFault.Detail.SecurityTokenServiceAddress,
                                                                                                                          authNFault.Detail.UserRegistered.GetValueOrDefault(),
                                                                                                                          authNFault.Detail.UserLockedOut.GetValueOrDefault());

                        ContextMessageProperty responseContext;

                        if (ContextMessageProperty.TryGet(putResponse.Message, out responseContext) == false)
                        {
                            throw new InvalidOperationException("Could not retrieve security context message property even though we received an AuthN Fault. Something is fundamentally broken. Ensure assembly versions are correct and upgrades did not change protocol.");
                        }

                        throw new AuthenticationRequiredException(authNFault.Reason.ToString(),
                                                                  msAuthNFault,
                                                                  responseContext);
                    }
                }
                finally
                {
                    if (putSuccess == true)
                    {
                        transaction.AcceptChanges();
                    }
                    else
                    {
                        transaction.DiscardChanges();
                    }
                }
            }
        }