//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.RelyingParty {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
///
/// An authentication request comparer that judges equality solely on the OP endpoint hostname.
///
internal class DuplicateRequestedHostsComparer : IEqualityComparer {
///
/// The singleton instance of this comparer.
///
private static IEqualityComparer instance = new DuplicateRequestedHostsComparer();
///
/// Prevents a default instance of the class from being created.
///
private DuplicateRequestedHostsComparer() {
}
///
/// Gets the singleton instance of this comparer.
///
internal static IEqualityComparer Instance {
get { return instance; }
}
#region IEqualityComparer Members
///
/// Determines whether the specified objects are equal.
///
/// The first object to compare.
/// The second object to compare.
///
/// true if the specified objects are equal; otherwise, false.
///
public bool Equals(IAuthenticationRequest x, IAuthenticationRequest y) {
if (x == null && y == null) {
return true;
}
if (x == null || y == null) {
return false;
}
// We'll distinguish based on the host name only, which
// admittedly is only a heuristic, but if we remove one that really wasn't a duplicate, well,
// this multiple OP attempt thing was just a convenience feature anyway.
return string.Equals(x.Provider.Uri.Host, y.Provider.Uri.Host, StringComparison.OrdinalIgnoreCase);
}
///
/// Returns a hash code for the specified object.
///
/// The for which a hash code is to be returned.
/// A hash code for the specified object.
///
/// The type of is a reference type and is null.
///
public int GetHashCode(IAuthenticationRequest obj) {
return obj.Provider.Uri.Host.GetHashCode();
}
#endregion
}
}