//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy {
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
///
/// Utility methods for use by the PAPE extension.
///
internal static class PapeUtilities {
///
/// Looks at the incoming fields and figures out what the aliases and name spaces for auth level types are.
///
/// The incoming message data in which to discover TypeURIs and aliases.
/// The initialized with the given data.
internal static AliasManager FindIncomingAliases(IDictionary fields) {
AliasManager aliasManager = new AliasManager();
foreach (var pair in fields) {
if (!pair.Key.StartsWith(Constants.AuthLevelNamespaceDeclarationPrefix, StringComparison.Ordinal)) {
continue;
}
string alias = pair.Key.Substring(Constants.AuthLevelNamespaceDeclarationPrefix.Length);
aliasManager.SetAlias(alias, pair.Value);
}
aliasManager.SetPreferredAliasesWhereNotSet(Constants.AssuranceLevels.PreferredTypeUriToAliasMap);
return aliasManager;
}
///
/// Concatenates a sequence of strings using a space as a separator.
///
/// The elements to concatenate together..
/// The concatenated string of elements.
/// Thrown if any element in the sequence includes a space.
internal static string ConcatenateListOfElements(IEnumerable values) {
Requires.NotNull(values, "values");
StringBuilder valuesList = new StringBuilder();
foreach (string value in values.Distinct()) {
if (value.Contains(" ")) {
throw new FormatException(string.Format(CultureInfo.CurrentCulture, OpenIdStrings.InvalidUri, value));
}
valuesList.Append(value);
valuesList.Append(" ");
}
if (valuesList.Length > 0) {
valuesList.Length -= 1; // remove trailing space
}
return valuesList.ToString();
}
}
}