示例#1
0
        /// <summary>
        /// For the request, determine if the requestor's IP address is valid.
        /// </summary>
        /// <param name="auth">An authentication configuration instance.</param>
        /// <param name="authModule">The authentication module instance to use to authenticate the user for the operation.</param>
        /// <param name="operation">The operation that is being requested.</param>
        /// <param name="opContext">The OperationContext for the request (note: this is not the WebOperationContext used for other calls).</param>
        /// <returns>An errordetail instance holding any error that was encountered, or null if no errors were encountered.</returns>
        private static errordetail AuthorizeIPAddressForUser(AuthenticationConfig auth, OttaMattaAuthentication authModule, string operation, System.ServiceModel.OperationContext opContext)
        {
            errordetail  result = null;
            const string endpointPropertyName = "System.ServiceModel.Channels.RemoteEndpointMessageProperty";
            bool         failIfNoIP           = false;

            System.ServiceModel.Channels.MessageProperties properties = opContext.IncomingMessageProperties;
            if (properties.ContainsKey(endpointPropertyName))
            {
                RemoteEndpointMessageProperty endpoint = properties[endpointPropertyName] as RemoteEndpointMessageProperty;

                //
                // Note: on local dev machines this is the IPv6 address, like "fe80::c513:967d:1b57:8c33%11".
                //
                string ipAddress = endpoint.Address;

                //
                // We have an IP address.  Let's see if it's authorized for this user.
                //
                if (authModule != null && auth.UserAllowedIps.ContainsKey(authModule.Username))
                {
                    bool ipOK = auth.UserAllowedIps[authModule.Username].Contains(ipAddress);

                    if (!ipOK)
                    {
                        result = new errordetail(string.Format("The IP address \"{0}\" is not authorized for user account \"{1}\"", ipAddress, authModule.Username), HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    //
                    // There are no IP address restrictions for this account.
                    //
                }
            }
            else
            {
                //
                // Can't get the remote IP from the system.  We can assume that something has changed in the WCF .NET codebase, and allow it for now.
                // Or, we can fail the request.
                //
                if (failIfNoIP)
                {
                    result = new errordetail("Unable to determine request IP address", HttpStatusCode.InternalServerError);
                }
            }

            return(result);
        }
        public static bool TryGet(MessageProperties properties, out CorrelationMessageProperty property)
        {
            if (properties == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
            }
            object obj2 = null;

            if (properties.TryGetValue("CorrelationMessageProperty", out obj2))
            {
                property = obj2 as CorrelationMessageProperty;
            }
            else
            {
                property = null;
            }
            return(property != null);
        }
示例#3
0
        public static bool TryGet(MessageProperties properties, out CallbackContextMessageProperty contextMessageProperty)
        {
            if (properties == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
            }
            object obj2 = null;

            if (properties.TryGetValue("CallbackContextMessageProperty", out obj2))
            {
                contextMessageProperty = obj2 as CallbackContextMessageProperty;
            }
            else
            {
                contextMessageProperty = null;
            }
            return(contextMessageProperty != null);
        }
        public static bool TryGet(MessageProperties properties, out ChannelBindingMessageProperty property)
        {
            if (properties == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
            }

            property = null;
            object value;

            if (properties.TryGetValue(ChannelBindingMessageProperty.Name, out value))
            {
                property = value as ChannelBindingMessageProperty;
                return(property != null);
            }

            return(false);
        }
示例#5
0
        private static void CopyProperties(MessageProperties messageProperties, IDictionary <string, object> properties)
        {
            Contract.Assert(messageProperties != null, "The 'messageProperties' parameter should not be null.");
            Contract.Assert(properties != null, "The 'properties' parameter should not be null.");

            foreach (KeyValuePair <string, object> property in messageProperties)
            {
                object value = property.Value;
                string key   = property.Key;

                if ((value is HttpRequestMessageProperty && string.Equals(key, HttpRequestMessageProperty.Name, StringComparison.OrdinalIgnoreCase)) ||
                    (value is HttpResponseMessageProperty && string.Equals(key, HttpResponseMessageProperty.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    continue;
                }

                properties[key] = value;
            }
        }
        public static bool TryGet(MessageProperties properties, out NetworkInterfaceMessageProperty property)
        {
            if (properties == null)
            {
                throw FxTrace.Exception.ArgumentNull("properties");
            }

            object value = null;

            if (properties.TryGetValue(PropertyName, out value))
            {
                property = value as NetworkInterfaceMessageProperty;
            }
            else
            {
                property = null;
            }
            return(property != null);
        }
示例#7
0
        public static bool TryGet(MessageProperties properties, out CorrelationCallbackMessageProperty property)
        {
            if (properties == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
            }

            object value = null;

            if (properties.TryGetValue(PropertyName, out value))
            {
                property = value as CorrelationCallbackMessageProperty;
            }
            else
            {
                property = null;
            }
            return(property != null);
        }
示例#8
0
 public override void Close()
 {
     lock (ThisLock)
     {
         if (!closed)
         {
             closed       = true;
             this.headers = null;
             if (properties != null)
             {
                 properties.Dispose();
                 properties = null;
             }
             this.messageData.Close();
             this.messageData = null;
             this.quotas      = null;
         }
     }
 }
示例#9
0
        internal void MergeProperties(MessageProperties properties)
        {
            // MergeProperties behavior should be equivalent to the behavior
            // of CopyProperties except that Merge supports property values that
            // implement the IMergeEnabledMessageProperty.  Any changes to CopyProperties
            // should be reflected in MergeProperties as well.
            if (properties == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
            }

            if (_disposed)
            {
                ThrowDisposed();
            }

            if (properties._properties != null)
            {
                for (int i = 0; i < properties._properties.Length; i++)
                {
                    if (properties._properties[i].Name == null)
                    {
                        break;
                    }

                    Property property = properties._properties[i];

                    IMergeEnabledMessageProperty currentValue;
                    if (!this.TryGetValue(property.Name, out currentValue) ||
                        !currentValue.TryMergeWithProperty(property.Value))
                    {
                        // Merge wasn't possible so copy
                        // this[string] will call CreateCopyOfPropertyValue, so we don't need to repeat that here
                        this[property.Name] = property.Value;
                    }
                }
            }

            this.Via = properties.Via;
            this.AllowOutputBatching = properties.AllowOutputBatching;
            this.Security            = (properties.Security != null) ? (SecurityMessageProperty)properties.Security.CreateCopy() : null;
            this.Encoder             = properties.Encoder;
        }
示例#10
0
        public void CopyProperties(MessageProperties properties)
        {
            // CopyProperties behavior should be equivalent to the behavior
            // of MergeProperties except that Merge supports property values that
            // implement the IMergeEnabledMessageProperty.  Any changes to CopyProperties
            // should be reflected in MergeProperties as well.
            if (properties == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(properties));
            }

            if (_disposed)
            {
                ThrowDisposed();
            }

            if (properties._properties != null)
            {
                for (int i = 0; i < properties._properties.Length; i++)
                {
                    if (properties._properties[i].Name == null)
                    {
                        break;
                    }

                    Property property = properties._properties[i];

                    // this[string] will call CreateCopyOfPropertyValue, so we don't need to repeat that here
                    this[property.Name] = property.Value;
                }
            }

            Via = properties.Via;
            AllowOutputBatching = properties.AllowOutputBatching;
            Security            = (properties.Security != null) ? (SecurityMessageProperty)properties.Security.CreateCopy() : null;
            Encoder             = properties.Encoder;
        }
 public MessageProperties(MessageProperties properties)
 {
     this.CopyProperties(properties);
 }
示例#12
0
 internal DefaultMessageBuffer(MessageHeaders headers, MessageProperties properties, AttributeCollection attributes)
     : this(0, headers, properties, null, false, attributes)
 {
 }
示例#13
0
 public XPathMessageBuffer(IXPathNavigable source, MessageVersion version, int maxSizeOfHeaders, MessageProperties properties, AttributeCollection attributes)
 {
     this.source          = source;
     this.version         = version;
     this.max_header_size = maxSizeOfHeaders;
     this.properties      = properties;
     this.attributes      = attributes;
 }
        public static bool TryGet(MessageProperties properties, out System.ServiceModel.Channels.ReceiveContext property)
        {
            property = default(System.ServiceModel.Channels.ReceiveContext);

            return(default(bool));
        }
 public void AddOrReplaceInMessageProperties(MessageProperties properties)
 {
 }
示例#16
0
 internal DefaultMessageBuffer(MessageHeaders headers, MessageProperties properties)
     : this(0, headers, properties, null, false)
 {
 }
示例#17
0
 public MessageProperties(MessageProperties properties)
 {
     list = new List <Pair> ();
     CopyProperties(properties);
 }
示例#18
0
        public BufferedMessage(IBufferedMessageData messageData, System.ServiceModel.Channels.RecycledMessageState recycledMessageState, bool[] understoodHeaders, bool understoodHeadersModified)
        {
            bool flag = true;

            try
            {
                this.recycledMessageState = recycledMessageState;
                this.messageData          = messageData;
                this.properties           = recycledMessageState.TakeProperties();
                if (this.properties == null)
                {
                    this.properties = new MessageProperties();
                }
                XmlDictionaryReader messageReader  = messageData.GetMessageReader();
                MessageVersion      messageVersion = messageData.MessageEncoder.MessageVersion;
                if (messageVersion.Envelope == EnvelopeVersion.None)
                {
                    this.reader  = messageReader;
                    this.headers = new MessageHeaders(messageVersion);
                }
                else
                {
                    EnvelopeVersion envelopeVersion = ReceivedMessage.ReadStartEnvelope(messageReader);
                    if (messageVersion.Envelope != envelopeVersion)
                    {
                        Exception innerException = new ArgumentException(System.ServiceModel.SR.GetString("EncoderEnvelopeVersionMismatch", new object[] { envelopeVersion, messageVersion.Envelope }), "reader");
                        throw TraceUtility.ThrowHelperError(new CommunicationException(innerException.Message, innerException), this);
                    }
                    if (ReceivedMessage.HasHeaderElement(messageReader, envelopeVersion))
                    {
                        this.headers = recycledMessageState.TakeHeaders();
                        if (this.headers == null)
                        {
                            this.headers = new MessageHeaders(messageVersion, messageReader, messageData, recycledMessageState, understoodHeaders, understoodHeadersModified);
                        }
                        else
                        {
                            this.headers.Init(messageVersion, messageReader, messageData, recycledMessageState, understoodHeaders, understoodHeadersModified);
                        }
                    }
                    else
                    {
                        this.headers = new MessageHeaders(messageVersion);
                    }
                    ReceivedMessage.VerifyStartBody(messageReader, envelopeVersion);
                    int maxSizeOfHeaders = 0x7fffffff;
                    this.bodyAttributes = XmlAttributeHolder.ReadAttributes(messageReader, ref maxSizeOfHeaders);
                    if (maxSizeOfHeaders < 0x7fffefff)
                    {
                        this.bodyAttributes = null;
                    }
                    if (base.ReadStartBody(messageReader))
                    {
                        this.reader = messageReader;
                    }
                    else
                    {
                        messageReader.Close();
                    }
                }
                flag = false;
            }
            finally
            {
                if (flag && MessageLogger.LoggingEnabled)
                {
                    MessageLogger.LogMessage(messageData.Buffer, MessageLoggingSource.Malformed);
                }
            }
        }
 public override void UpdateMessageProperties(MessageProperties inboundMessageProperties)
 {
     this.channel.webSocketMessageSource.UpdateOpenNotificationMessageProperties(inboundMessageProperties);
 }
示例#20
0
 public void CopyProperties(MessageProperties properties)
 {
     list.AddRange(properties.list);
 }
示例#21
0
 InternalByteStreamMessage(ByteStreamBufferedMessageData messageData, MessageHeaders headers, MessageProperties properties, XmlDictionaryReaderQuotas quotas, bool moveBodyReaderToContent)
 {
     this.headers    = new MessageHeaders(headers);
     this.properties = new MessageProperties(properties);
     this.bodyWriter = new BufferedBodyWriter(messageData);
     this.reader     = new XmlBufferedByteStreamReader(messageData, quotas);
     this.moveBodyReaderToContent = moveBodyReaderToContent;
 }
示例#22
0
                public ByteStreamMessageBuffer(ByteStreamBufferedMessageData messageData, MessageHeaders headers, MessageProperties properties, XmlDictionaryReaderQuotas quotas, bool moveBodyReaderToContent)
                    : base()
                {
                    this.messageData = messageData;
                    this.headers     = new MessageHeaders(headers);
                    this.properties  = new MessageProperties(properties);
                    this.quotas      = new XmlDictionaryReaderQuotas();
                    quotas.CopyTo(this.quotas);
                    this.moveBodyReaderToContent = moveBodyReaderToContent;

                    this.messageData.Open();
                }
示例#23
0
 public BodyWriterMessage(MessageHeaders headers, KeyValuePair <string, object>[] properties, System.ServiceModel.Channels.BodyWriter bodyWriter) : this(bodyWriter)
 {
     this.headers    = new MessageHeaders(headers);
     this.properties = new MessageProperties(properties);
 }