Ejemplo n.º 1
0
        /// <summary>
        /// Returns a filtered and sorted list of the available OP endpoints for a discovered Identifier.
        /// </summary>
        /// <param name="endpoints">The endpoints.</param>
        /// <param name="relyingParty">The relying party.</param>
        /// <returns>A filtered and sorted list of endpoints; may be empty if the input was empty or the filter removed all endpoints.</returns>
        private static List <IdentifierDiscoveryResult> FilterAndSortEndpoints(IEnumerable <IdentifierDiscoveryResult> endpoints, OpenIdRelyingParty relyingParty)
        {
            Requires.NotNull(endpoints, "endpoints");
            Requires.NotNull(relyingParty, "relyingParty");

            bool anyFilteredOut    = false;
            var  filteredEndpoints = new List <IdentifierDiscoveryResult>();

            foreach (var endpoint in endpoints)
            {
                if (relyingParty.FilterEndpoint(endpoint))
                {
                    filteredEndpoints.Add(endpoint);
                }
                else
                {
                    anyFilteredOut = true;
                }
            }

            // Sort endpoints so that the first one in the list is the most preferred one.
            filteredEndpoints.OrderBy(ep => ep, relyingParty.EndpointOrder);

            var endpointList = new List <IdentifierDiscoveryResult>(filteredEndpoints.Count);

            foreach (var endpoint in filteredEndpoints)
            {
                endpointList.Add(endpoint);
            }

            if (anyFilteredOut)
            {
                Logger.Yadis.DebugFormat("Some endpoints were filtered out.  Total endpoints remaining: {0}", filteredEndpoints.Count);
            }
            if (Logger.Yadis.IsDebugEnabled)
            {
                if (MessagingUtilities.AreEquivalent(endpoints, endpointList))
                {
                    Logger.Yadis.Debug("Filtering and sorting of endpoints did not affect the list.");
                }
                else
                {
                    Logger.Yadis.Debug("After filtering and sorting service endpoints, this is the new prioritized list:");
                    Logger.Yadis.Debug(Util.ToStringDeferred(filteredEndpoints, true));
                }
            }

            return(endpointList);
        }
		/// <summary>
		/// Returns a filtered and sorted list of the available OP endpoints for a discovered Identifier.
		/// </summary>
		/// <param name="endpoints">The endpoints.</param>
		/// <param name="relyingParty">The relying party.</param>
		/// <returns>A filtered and sorted list of endpoints; may be empty if the input was empty or the filter removed all endpoints.</returns>
		private static List<IdentifierDiscoveryResult> FilterAndSortEndpoints(IEnumerable<IdentifierDiscoveryResult> endpoints, OpenIdRelyingParty relyingParty) {
			Requires.NotNull(endpoints, "endpoints");
			Requires.NotNull(relyingParty, "relyingParty");

			bool anyFilteredOut = false;
			var filteredEndpoints = new List<IdentifierDiscoveryResult>();
			foreach (var endpoint in endpoints) {
				if (relyingParty.FilterEndpoint(endpoint)) {
					filteredEndpoints.Add(endpoint);
				} else {
					anyFilteredOut = true;
				}
			}

			// Sort endpoints so that the first one in the list is the most preferred one.
			filteredEndpoints.OrderBy(ep => ep, relyingParty.EndpointOrder);

			var endpointList = new List<IdentifierDiscoveryResult>(filteredEndpoints.Count);
			foreach (var endpoint in filteredEndpoints) {
				endpointList.Add(endpoint);
			}

			if (anyFilteredOut) {
				Logger.Yadis.DebugFormat("Some endpoints were filtered out.  Total endpoints remaining: {0}", filteredEndpoints.Count);
			}
			if (Logger.Yadis.IsDebugEnabled) {
				if (MessagingUtilities.AreEquivalent(endpoints, endpointList)) {
					Logger.Yadis.Debug("Filtering and sorting of endpoints did not affect the list.");
				} else {
					Logger.Yadis.Debug("After filtering and sorting service endpoints, this is the new prioritized list:");
					Logger.Yadis.Debug(Util.ToStringDeferred(filteredEndpoints, true));
				}
			}

			return endpointList;
		}