예제 #1
0
        private void EnsureValidMessageParts(IProtocolMessage message)
        {
            MessageDictionary  dictionary  = this.MessageDescriptions.GetAccessor(message);
            MessageDescription description = this.MessageDescriptions.Get(message);

            description.EnsureMessagePartsPassBasicValidation(dictionary);
        }
예제 #2
0
        /// <summary>
        /// Verifies that all required message parts are initialized to values
        /// prior to sending the message to a remote party.
        /// </summary>
        /// <param name="message">The message to verify.</param>
        /// <exception cref="ProtocolException">
        /// Thrown when any required message part does not have a value.
        /// </exception>
        private static void EnsureValidMessageParts(IProtocolMessage message)
        {
            Debug.Assert(message != null, "message == null");

            MessageDictionary  dictionary  = new MessageDictionary(message);
            MessageDescription description = MessageDescription.Get(message.GetType(), message.Version);

            description.EnsureMessagePartsPassBasicValidation(dictionary);
        }
        /// <summary>
        /// Gets the extensions on a message.
        /// </summary>
        /// <param name="message">The carrier of the extensions.</param>
        /// <param name="ignoreUnsigned">If set to <c>true</c> only signed extensions will be available.</param>
        /// <param name="extensionFilter">A optional filter that takes an extension type URI and
        /// returns a value indicating whether that extension should be deserialized and
        /// returned in the sequence.  May be null.</param>
        /// <returns>A sequence of extensions in the message.</returns>
        private IEnumerable <IOpenIdMessageExtension> GetExtensions(IProtocolMessageWithExtensions message, bool ignoreUnsigned, Func <string, bool> extensionFilter)
        {
            bool isAtProvider = message is SignedResponseRequest;

            // We have a helper class that will do all the heavy-lifting of organizing
            // all the extensions, their aliases, and their parameters.
            var extensionManager = ExtensionArgumentsManager.CreateIncomingExtensions(this.GetExtensionsDictionary(message, ignoreUnsigned));

            foreach (string typeUri in extensionManager.GetExtensionTypeUris())
            {
                // Our caller may have already obtained a signed version of this extension,
                // so skip it if they don't want this one.
                if (extensionFilter != null && !extensionFilter(typeUri))
                {
                    continue;
                }

                var extensionData = extensionManager.GetExtensionArguments(typeUri);

                // Initialize this particular extension.
                IOpenIdMessageExtension extension = this.ExtensionFactory.Create(typeUri, extensionData, message, isAtProvider);
                if (extension != null)
                {
                    try {
                        // Make sure the extension fulfills spec requirements before deserializing it.
                        MessageDescription messageDescription = this.Channel.MessageDescriptions.Get(extension);
                        messageDescription.EnsureMessagePartsPassBasicValidation(extensionData);

                        // Deserialize the extension.
                        MessageDictionary extensionDictionary = messageDescription.GetDictionary(extension);
                        foreach (var pair in extensionData)
                        {
                            extensionDictionary[pair.Key] = pair.Value;
                        }

                        // Give extensions that require custom serialization a chance to do their work.
                        var customSerializingExtension = extension as IMessageWithEvents;
                        if (customSerializingExtension != null)
                        {
                            customSerializingExtension.OnReceiving();
                        }
                    } catch (ProtocolException ex) {
                        Logger.OpenId.ErrorFormat(OpenIdStrings.BadExtension, extension.GetType(), ex);
                        extension = null;
                    }

                    if (extension != null)
                    {
                        yield return(extension);
                    }
                }
                else
                {
                    Logger.OpenId.DebugFormat("Extension with type URI '{0}' ignored because it is not a recognized extension.", typeUri);
                }
            }
        }