/// <summary> /// Checks whether a given claim exists /// </summary> /// <param name="principal">The principal.</param> /// <param name="claimType">Type of the claim.</param> /// <returns>true/false</returns> public static bool ClaimExists(this IClaimsPrincipal principal, string claimType) { Contract.Requires(principal != null); Contract.Requires(!String.IsNullOrEmpty(claimType)); return principal.ClaimExists(c => c.ClaimType.Equals(claimType, StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// Checks whether a given claim exists /// </summary> /// <param name="identity">The identity.</param> /// <param name="claimType">Type of the claim.</param> /// <returns>true/false</returns> public static bool ClaimExists(this IClaimsIdentity identity, string claimType) { Contract.Requires(identity != null); Contract.Requires(identity.Claims != null); Contract.Requires(!String.IsNullOrEmpty(claimType)); return identity.ClaimExists(c => c.ClaimType.Equals(claimType, StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// Demands a specific claim. /// </summary> /// <param name="identity">The principal.</param> /// <param name="predicate">The search predicate.</param> public static void DemandClaim(this IClaimsIdentity identity, Predicate<Claim> predicate) { Contract.Requires(identity != null); Contract.Requires(identity.Claims != null); Contract.Requires(predicate != null); if (!identity.ClaimExists(predicate)) { throw new SecurityException("Demand for Claim failed"); } }