Ejemplo n.º 1
0
 /// <summary>
 /// Adds an extension to the response to send to the relying party.
 /// </summary>
 /// <param name="extension">The extension to add to the response message.</param>
 public void AddResponseExtension(IOpenIdMessageExtension extension)
 {
     // Because the derived AuthenticationRequest class can swap out
     // one response message for another (auth vs. no-auth), and because
     // some response messages support extensions while others don't,
     // we just add the extensions to a collection here and add them
     // to the response on the way out.
     this.responseExtensions.Add(extension);
 }
        /// <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);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds an extension to the response to send to the relying party.
        /// </summary>
        /// <param name="extension">The extension to add to the response message.</param>
        public void AddResponseExtension(IOpenIdMessageExtension extension)
        {
            ErrorUtilities.VerifyArgumentNotNull(extension, "extension");

            // Because the derived AuthenticationRequest class can swap out
            // one response message for another (auth vs. no-auth), and because
            // some response messages support extensions while others don't,
            // we just add the extensions to a collection here and add them
            // to the response on the way out.
            this.responseExtensions.Add(extension);
            this.ResetUserAgentResponse();
        }
        /// <summary>
        /// Creates a new instance of some extension based on the received extension parameters.
        /// </summary>
        /// <param name="typeUri">The type URI of the extension.</param>
        /// <param name="data">The parameters associated specifically with this extension.</param>
        /// <param name="baseMessage">The OpenID message carrying this extension.</param>
        /// <param name="isProviderRole">A value indicating whether this extension is being received at the OpenID Provider.</param>
        /// <returns>
        /// An instance of <see cref="IOpenIdMessageExtension"/> if the factory recognizes
        /// the extension described in the input parameters; <c>null</c> otherwise.
        /// </returns>
        /// <remarks>
        /// This factory method need only initialize properties in the instantiated extension object
        /// that are not bound using <see cref="MessagePartAttribute"/>.
        /// </remarks>
        public IOpenIdMessageExtension Create(string typeUri, IDictionary <string, string> data, IProtocolMessageWithExtensions baseMessage, bool isProviderRole)
        {
            foreach (var factory in this.factories)
            {
                IOpenIdMessageExtension result = factory.Create(typeUri, data, baseMessage, isProviderRole);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new instance of some extension based on the received extension parameters.
        /// </summary>
        /// <param name="typeUri">The type URI of the extension.</param>
        /// <param name="data">The parameters associated specifically with this extension.</param>
        /// <param name="baseMessage">The OpenID message carrying this extension.</param>
        /// <returns>
        /// An instance of <see cref="IOpenIdMessageExtension"/> if the factory recognizes
        /// the extension described in the input parameters; <c>null</c> otherwise.
        /// </returns>
        /// <remarks>
        /// This factory method need only initialize properties in the instantiated extension object
        /// that are not bound using <see cref="MessagePartAttribute"/>.
        /// </remarks>
        public IOpenIdMessageExtension Create(string typeUri, IDictionary <string, string> data, IProtocolMessageWithExtensions baseMessage)
        {
            foreach (var factoryMethod in this.registeredExtensions)
            {
                IOpenIdMessageExtension result = factoryMethod(typeUri, data, baseMessage);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
        /// <summary>
        /// Performs any transformation on an incoming message that may be necessary and/or
        /// validates an incoming message based on the rules of this channel binding element.
        /// </summary>
        /// <param name="message">The incoming message to process.</param>
        /// <returns>
        /// True if the <paramref name="message"/> applied to this binding element
        /// and the operation was successful.  False if the operation did not apply to this message.
        /// </returns>
        /// <exception cref="ProtocolException">
        /// Thrown when the binding element rules indicate that this message is invalid and should
        /// NOT be processed.
        /// </exception>
        /// <remarks>
        /// Implementations that provide message protection must honor the
        /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
        /// </remarks>
        public bool PrepareMessageForReceiving(IProtocolMessage message)
        {
            var extendableMessage = message as IProtocolMessageWithExtensions;

            if (extendableMessage != null)
            {
                // 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));
                foreach (string typeUri in extensionManager.GetExtensionTypeUris())
                {
                    var extensionData = extensionManager.GetExtensionArguments(typeUri);

                    // Initialize this particular extension.
                    IOpenIdMessageExtension extension = this.ExtensionFactory.Create(typeUri, extensionData, extendableMessage);
                    if (extension != null)
                    {
                        MessageDictionary extensionDictionary = new MessageDictionary(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();
                        }

                        extendableMessage.Extensions.Add(extension);
                    }
                    else
                    {
                        Logger.WarnFormat("Extension with type URI '{0}' ignored because it is not a recognized extension.", typeUri);
                    }
                }

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Determines whether a given extension is supported by this endpoint.
        /// </summary>
        /// <param name="extension">An instance of the extension to check support for.</param>
        /// <returns>
        /// 	<c>true</c> if the extension is supported by this endpoint; otherwise, <c>false</c>.
        /// </returns>
        public bool IsExtensionSupported(IOpenIdMessageExtension extension)
        {
            // Consider the primary case.
            if (this.IsTypeUriPresent(extension.TypeUri))
            {
                return true;
            }

            // Consider the secondary cases.
            if (extension.AdditionalSupportedTypeUris != null)
            {
                if (extension.AdditionalSupportedTypeUris.Any(typeUri => this.IsTypeUriPresent(typeUri)))
                {
                    return true;
                }
            }

            return false;
        }
        /// <summary>
        /// Determines whether a given extension is supported by this endpoint.
        /// </summary>
        /// <param name="extension">An instance of the extension to check support for.</param>
        /// <returns>
        ///     <c>true</c> if the extension is supported by this endpoint; otherwise, <c>false</c>.
        /// </returns>
        public bool IsExtensionSupported(IOpenIdMessageExtension extension)
        {
            Contract.Requires <ArgumentNullException>(extension != null);

            // Consider the primary case.
            if (this.IsTypeUriPresent(extension.TypeUri))
            {
                return(true);
            }

            // Consider the secondary cases.
            if (extension.AdditionalSupportedTypeUris != null)
            {
                if (extension.AdditionalSupportedTypeUris.Any(typeUri => this.IsTypeUriPresent(typeUri)))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Determines whether a given extension is supported by this endpoint.
        /// </summary>
        /// <param name="extension">An instance of the extension to check support for.</param>
        /// <returns>
        ///     <c>true</c> if the extension is supported by this endpoint; otherwise, <c>false</c>.
        /// </returns>
        public bool IsExtensionSupported(IOpenIdMessageExtension extension)
        {
            ErrorUtilities.VerifyArgumentNotNull(extension, "extension");

            // Consider the primary case.
            if (this.IsExtensionSupported(extension.TypeUri))
            {
                return(true);
            }

            // Consider the secondary cases.
            if (extension.AdditionalSupportedTypeUris != null)
            {
                if (extension.AdditionalSupportedTypeUris.Any(typeUri => this.IsExtensionSupported(typeUri)))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 10
0
 void IAuthenticationRequest.AddExtension(IOpenIdMessageExtension extension)
 {
     Requires.NotNull(extension, "extension");
     throw new NotImplementedException();
 }
 /// <summary>
 /// Adds an OpenID extension to the request directed at the OpenID provider.
 /// </summary>
 /// <param name="extension">The initialized extension to add to the request.</param>
 public void AddExtension(IOpenIdMessageExtension extension)
 {
     ErrorUtilities.VerifyArgumentNotNull(extension, "extension");
     this.extensions.Add(extension);
 }
		/// <summary>
		/// Adds an OpenID extension to the request directed at the OpenID provider.
		/// </summary>
		/// <param name="extension">The initialized extension to add to the request.</param>
		public void AddExtension(IOpenIdMessageExtension extension) {
			this.extensions.Add(extension);
		}
Ejemplo n.º 13
0
 /// <summary>
 /// Adds an OpenID extension to the request directed at the OpenID provider.
 /// </summary>
 /// <param name="extension">The initialized extension to add to the request.</param>
 public void AddExtension(IOpenIdMessageExtension extension)
 {
     this.extensions.Add(extension);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Adds an OpenID extension to the request directed at the OpenID provider.
 /// </summary>
 /// <param name="extension">The initialized extension to add to the request.</param>
 public void AddExtension(IOpenIdMessageExtension extension)
 {
     ErrorUtilities.VerifyArgumentNotNull(extension, "extension");
     this.extensions.Add(extension);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Adds an extension to the response to send to the relying party.
 /// </summary>
 /// <param name="extension">The extension to add to the response message.</param>
 void IRequest.AddResponseExtension(IOpenIdMessageExtension extension)
 {
     Contract.Requires <ArgumentNullException>(extension != null);
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Adds an extension to the response to send to the relying party.
 /// </summary>
 /// <param name="extension">The extension to add to the response message.</param>
 void IRequest.AddResponseExtension(IOpenIdMessageExtension extension)
 {
     Requires.NotNull(extension, "extension");
     throw new NotImplementedException();
 }