Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,332 @@
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// <OWNER>[....]</OWNER>
//
//
// Claim.cs
//
namespace System.Security.Claims
{
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
/// <summary>
/// A Claim is a statement about an entity by an Issuer.
/// A Claim consists of a Value, a Subject and an Issuer.
/// Additional properties, Type, ValueType, Properties and OriginalIssuer
/// help understand the claim when making decisions.
/// </summary>
[Serializable]
public class Claim
{
string m_issuer;
string m_originalIssuer;
string m_type;
string m_value;
string m_valueType;
Dictionary<string, string> m_properties;
[NonSerialized]
object m_propertyLock = new object();
[NonSerialized]
ClaimsIdentity m_subject;
#region Claim Constructors
/// <summary>
/// Creates a <see cref="Claim"/> with the specified type and value.
/// </summary>
/// <param name="type">The claim type.</param>
/// <param name="value">The claim value.</param>
/// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="value"/> is null.</exception>
/// <remarks>
/// <see cref="Claim.Issuer"/> is set to <see cref="ClaimsIdentity.DefaultIssuer"/>,
/// <see cref="Claim.ValueType"/> is set to <see cref="ClaimValueTypes.String"/>,
/// <see cref="Claim.OriginalIssuer"/> is set to <see cref="ClaimsIdentity.DefaultIssuer"/>, and
/// <see cref="Claim.Subject"/> is set to null.
/// </remarks>
/// <seealso cref="ClaimsIdentity"/>
/// <seealso cref="ClaimTypes"/>
/// <seealso cref="ClaimValueTypes"/>
public Claim(string type, string value)
: this(type, value, ClaimValueTypes.String, ClaimsIdentity.DefaultIssuer, ClaimsIdentity.DefaultIssuer, (ClaimsIdentity)null)
{
}
/// <summary>
/// Creates a <see cref="Claim"/> with the specified type, value, and value type.
/// </summary>
/// <param name="type">The claim type.</param>
/// <param name="value">The claim value.</param>
/// <param name="valueType">The claim value type.</param>
/// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="value"/> is null.</exception>
/// <remarks>
/// <see cref="Claim.Issuer"/> is set to <see cref="ClaimsIdentity.DefaultIssuer"/>,
/// <see cref="Claim.OriginalIssuer"/> is set to <see cref="ClaimsIdentity.DefaultIssuer"/>,
/// and <see cref="Claim.Subject"/> is set to null.
/// </remarks>
/// <seealso cref="ClaimsIdentity"/>
/// <seealso cref="ClaimTypes"/>
/// <seealso cref="ClaimValueTypes"/>
public Claim(string type, string value, string valueType)
: this(type, value, valueType, ClaimsIdentity.DefaultIssuer, ClaimsIdentity.DefaultIssuer, (ClaimsIdentity)null)
{
}
/// <summary>
/// Creates a <see cref="Claim"/> with the specified type, value, value type, and issuer.
/// </summary>
/// <param name="type">The claim type.</param>
/// <param name="value">The claim value.</param>
/// <param name="valueType">The claim value type. If this parameter is empty or null, then <see cref="ClaimValueTypes.String"/> is used.</param>
/// <param name="issuer">The claim issuer. If this parameter is empty or null, then <see cref="ClaimsIdentity.DefaultIssuer"/> is used.</param>
/// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="value"/> is null.</exception>
/// <remarks>
/// <see cref="Claim.OriginalIssuer"/> is set to value of the <paramref name="issuer"/> parameter,
/// <see cref="Claim.Subject"/> is set to null.
/// </remarks>
/// <seealso cref="ClaimsIdentity"/>
/// <seealso cref="ClaimTypes"/>
/// <seealso cref="ClaimValueTypes"/>
public Claim(string type, string value, string valueType, string issuer)
: this(type, value, valueType, issuer, issuer, (ClaimsIdentity)null)
{
}
/// <summary>
/// Creates a <see cref="Claim"/> with the specified type, value, value type, issuer and original issuer.
/// </summary>
/// <param name="type">The claim type.</param>
/// <param name="value">The claim value.</param>
/// <param name="valueType">The claim value type. If this parameter is null, then <see cref="ClaimValueTypes.String"/> is used.</param>
/// <param name="issuer">The claim issuer. If this parameter is empty or null, then <see cref="ClaimsIdentity.DefaultIssuer"/> is used.</param>
/// <param name="originalIssuer">The original issuer of this claim. If this parameter is empty or null, then orignalIssuer == issuer.</param>
/// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="value"/> is null.</exception>
/// <remarks>
/// <see cref="Claim.Subject"/> is set to null.
/// </remarks>
/// <seealso cref="ClaimsIdentity"/>
/// <seealso cref="ClaimTypes"/>
/// <seealso cref="ClaimValueTypes"/>
public Claim(string type, string value, string valueType, string issuer, string originalIssuer)
: this(type, value, valueType, issuer, originalIssuer, (ClaimsIdentity)null)
{
}
/// <summary>
/// Creates a <see cref="Claim"/> with the specified type, value, value type, issuer and original issuer.
/// </summary>
/// <param name="type">The claim type.</param>
/// <param name="value">The claim value.</param>
/// <param name="valueType">The claim value type. If this parameter is null, then <see cref="ClaimValueTypes.String"/> is used.</param>
/// <param name="issuer">The claim issuer. If this parameter is empty or null, then <see cref="ClaimsIdentity.DefaultIssuer"/> is used.</param>
/// <param name="originalIssuer">The original issuer of this claim. If this parameter is empty or null, then orignalIssuer == issuer.</param>
/// <param name="subject">The subject that this claim describes.</param>
/// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="value"/> is null.</exception>
/// <seealso cref="ClaimsIdentity"/>
/// <seealso cref="ClaimTypes"/>
/// <seealso cref="ClaimValueTypes"/>
public Claim(string type, string value, string valueType, string issuer, string originalIssuer, ClaimsIdentity subject)
: this( type, value, valueType, issuer, originalIssuer, subject, null, null )
{
}
/// <summary>
/// This internal constructor was added as a performance boost when adding claims that are found in the NTToken.
/// We need to add a property value to distinguish DeviceClaims from UserClaims.
/// </summary>
/// <param name="propertyKey">This allows adding a property when adding a Claim.</param>
/// <param name="propertyValue">The value associcated with the property.</param>
internal Claim(string type, string value, string valueType, string issuer, string originalIssuer, ClaimsIdentity subject, string propertyKey, string propertyValue)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
if (value == null)
{
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
m_type = type;
m_value = value;
if (String.IsNullOrEmpty(valueType))
{
m_valueType = ClaimValueTypes.String;
}
else
{
m_valueType = valueType;
}
if (String.IsNullOrEmpty(issuer))
{
m_issuer = ClaimsIdentity.DefaultIssuer;
}
else
{
m_issuer = issuer;
}
if (String.IsNullOrEmpty(originalIssuer))
{
m_originalIssuer = m_issuer;
}
else
{
m_originalIssuer = originalIssuer;
}
m_subject = subject;
if (propertyKey != null)
{
Properties.Add(propertyKey, propertyValue);
}
}
#endregion
/// <summary>
/// Gets the issuer of the <see cref="Claim"/>.
/// </summary>
public string Issuer
{
get { return m_issuer; }
}
[OnDeserialized()]
private void OnDeserializedMethod(StreamingContext context)
{
m_propertyLock = new object();
}
/// <summary>
/// Gets the original issuer of the <see cref="Claim"/>.
/// </summary>
/// <remarks>
/// When the <see cref="OriginalIssuer"/> differs from the <see cref="Issuer"/>, it means
/// that the claim was issued by the <see cref="OriginalIssuer"/> and was re-issued
/// by the <see cref="Issuer"/>.
/// </remarks>
public string OriginalIssuer
{
get { return m_originalIssuer; }
}
/// <summary>
/// Gets the collection of Properties associated with the <see cref="Claim"/>.
/// </summary>
public IDictionary<string, string> Properties
{
get
{
if (m_properties == null)
{
lock (m_propertyLock)
{
if (m_properties == null)
{
m_properties = new Dictionary<string, string>();
}
}
}
return m_properties;
}
}
/// <summary>
/// Gets the subject of the <see cref="Claim"/>.
/// </summary>
public ClaimsIdentity Subject
{
get { return m_subject; }
internal set { m_subject = value; }
}
/// <summary>
/// Gets the claim type of the <see cref="Claim"/>.
/// </summary>
public string Type
{
get { return m_type; }
}
/// <summary>
/// Gets the value of the <see cref="Claim"/>.
/// </summary>
public string Value
{
get { return m_value; }
}
/// <summary>
/// Gets the value type of the <see cref="Claim"/>.
/// </summary>
public string ValueType
{
get { return m_valueType; }
}
/// <summary>
/// Returns a new <see cref="Claim"/> object copied from this object. The subject of the new claim object is set to null.
/// </summary>
/// <returns>A new <see cref="Claim"/> object copied from this object.</returns>
/// <remarks>This is a shallow copy operation.</remarks>
public virtual Claim Clone()
{
return Clone((ClaimsIdentity)null);
}
/// <summary>
/// Returns a new <see cref="Claim"/> object copied from this object. The subject of the new claim object is set to identity.
/// </summary>
/// <param name="identity">The <see cref="ClaimsIdentity"/> that this <see cref="Claim"/> is associated with.</param>
/// <returns>A new <see cref="Claim"/> object copied from this object.</returns>
/// <remarks>This is a shallow copy operation.</remarks>
public virtual Claim Clone(ClaimsIdentity identity)
{
Claim newClaim = new Claim(m_type, m_value, m_valueType, m_issuer, m_originalIssuer, identity);
if (m_properties != null)
{
foreach (string key in m_properties.Keys)
{
newClaim.Properties[key] = m_properties[key];
}
}
return newClaim;
}
/// <summary>
/// Returns a string representation of the <see cref="Claim"/> object.
/// </summary>
/// <remarks>
/// The returned string contains the values of the <see cref="Type"/> and <see cref="Value"/> properties.
/// </remarks>
/// <returns>The string representation of the <see cref="Claim"/> object.</returns>
public override string ToString()
{
return String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}: {1}", m_type, m_value);
}
}
}

View File

@@ -0,0 +1,94 @@
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// <OWNER>[....]</OWNER>
//
//
// ClaimTypes.cs
//
namespace System.Security.Claims
{
using System.Runtime.InteropServices;
/// <summary>
/// Defines the claim types that are supported by the framework.
/// </summary>
[ComVisible(false)]
public static class ClaimTypes
{
internal const string ClaimTypeNamespace = "http://schemas.microsoft.com/ws/2008/06/identity/claims";
public const string AuthenticationInstant = ClaimTypeNamespace + "/authenticationinstant";
public const string AuthenticationMethod = ClaimTypeNamespace + "/authenticationmethod";
public const string CookiePath = ClaimTypeNamespace + "/cookiepath";
public const string DenyOnlyPrimarySid = ClaimTypeNamespace + "/denyonlyprimarysid";
public const string DenyOnlyPrimaryGroupSid = ClaimTypeNamespace + "/denyonlyprimarygroupsid";
public const string DenyOnlyWindowsDeviceGroup = ClaimTypeNamespace + "/denyonlywindowsdevicegroup";
public const string Dsa = ClaimTypeNamespace + "/dsa";
public const string Expiration = ClaimTypeNamespace + "/expiration";
public const string Expired = ClaimTypeNamespace + "/expired";
public const string GroupSid = ClaimTypeNamespace + "/groupsid";
public const string IsPersistent = ClaimTypeNamespace + "/ispersistent";
public const string PrimaryGroupSid = ClaimTypeNamespace + "/primarygroupsid";
public const string PrimarySid = ClaimTypeNamespace + "/primarysid";
public const string Role = ClaimTypeNamespace + "/role";
public const string SerialNumber = ClaimTypeNamespace + "/serialnumber";
public const string UserData = ClaimTypeNamespace + "/userdata";
public const string Version = ClaimTypeNamespace + "/version";
public const string WindowsAccountName = ClaimTypeNamespace + "/windowsaccountname";
public const string WindowsDeviceClaim = ClaimTypeNamespace + "/windowsdeviceclaim";
public const string WindowsDeviceGroup = ClaimTypeNamespace + "/windowsdevicegroup";
public const string WindowsUserClaim = ClaimTypeNamespace + "/windowsuserclaim";
public const string WindowsFqbnVersion = ClaimTypeNamespace + "/windowsfqbnversion";
public const string WindowsSubAuthority = ClaimTypeNamespace + "/windowssubauthority";
//
// From System.IdentityModel.Claims
//
internal const string ClaimType2005Namespace = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims";
public const string Anonymous = ClaimType2005Namespace + "/anonymous";
public const string Authentication = ClaimType2005Namespace + "/authentication";
public const string AuthorizationDecision = ClaimType2005Namespace + "/authorizationdecision";
public const string Country = ClaimType2005Namespace + "/country";
public const string DateOfBirth = ClaimType2005Namespace + "/dateofbirth";
public const string Dns = ClaimType2005Namespace + "/dns";
public const string DenyOnlySid = ClaimType2005Namespace + "/denyonlysid"; // NOTE: shown as 'Deny only group SID' on the ADFSv2 UI!
public const string Email = ClaimType2005Namespace + "/emailaddress";
public const string Gender = ClaimType2005Namespace + "/gender";
public const string GivenName = ClaimType2005Namespace + "/givenname";
public const string Hash = ClaimType2005Namespace + "/hash";
public const string HomePhone = ClaimType2005Namespace + "/homephone";
public const string Locality = ClaimType2005Namespace + "/locality";
public const string MobilePhone = ClaimType2005Namespace + "/mobilephone";
public const string Name = ClaimType2005Namespace + "/name";
public const string NameIdentifier = ClaimType2005Namespace + "/nameidentifier";
public const string OtherPhone = ClaimType2005Namespace + "/otherphone";
public const string PostalCode = ClaimType2005Namespace + "/postalcode";
public const string Rsa = ClaimType2005Namespace + "/rsa";
public const string Sid = ClaimType2005Namespace + "/sid";
public const string Spn = ClaimType2005Namespace + "/spn";
public const string StateOrProvince = ClaimType2005Namespace + "/stateorprovince";
public const string StreetAddress = ClaimType2005Namespace + "/streetaddress";
public const string Surname = ClaimType2005Namespace + "/surname";
public const string System = ClaimType2005Namespace + "/system";
public const string Thumbprint = ClaimType2005Namespace + "/thumbprint";
public const string Upn = ClaimType2005Namespace + "/upn";
public const string Uri = ClaimType2005Namespace + "/uri";
public const string Webpage = ClaimType2005Namespace + "/webpage";
public const string X500DistinguishedName = ClaimType2005Namespace + "/x500distinguishedname";
internal const string ClaimType2009Namespace = "http://schemas.xmlsoap.org/ws/2009/09/identity/claims";
public const string Actor = ClaimType2009Namespace + "/actor";
}
}

View File

@@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// <OWNER>[....]</OWNER>
//
//
// ClaimValueTypes.cs
//
using System.Runtime.InteropServices;
namespace System.Security.Claims
{
/// <summary>
/// Defines the claim value types of the framework.
/// </summary>
[ComVisible(false)]
public static class ClaimValueTypes
{
const string XmlSchemaNamespace = "http://www.w3.org/2001/XMLSchema";
// the schema needs to be checked for all these types to ensure they allowed
public const string Base64Binary = XmlSchemaNamespace + "#base64Binary";
public const string Base64Octet = XmlSchemaNamespace + "#base64Octet";
public const string Boolean = XmlSchemaNamespace + "#boolean";
public const string Date = XmlSchemaNamespace + "#date";
public const string DateTime = XmlSchemaNamespace + "#dateTime";
public const string Double = XmlSchemaNamespace + "#double";
public const string Fqbn = XmlSchemaNamespace + "#fqbn";
public const string HexBinary = XmlSchemaNamespace + "#hexBinary";
public const string Integer = XmlSchemaNamespace + "#integer";
public const string Integer32 = XmlSchemaNamespace + "#integer32";
public const string Integer64 = XmlSchemaNamespace + "#integer64";
public const string Sid = XmlSchemaNamespace + "#sid";
public const string String = XmlSchemaNamespace + "#string";
public const string Time = XmlSchemaNamespace + "#time";
public const string UInteger32 = XmlSchemaNamespace + "#uinteger32";
public const string UInteger64 = XmlSchemaNamespace + "#uinteger64";
const string SoapSchemaNamespace = "http://schemas.xmlsoap.org/";
public const string DnsName = SoapSchemaNamespace + "claims/dns";
public const string Email = SoapSchemaNamespace + "ws/2005/05/identity/claims/emailaddress";
public const string Rsa = SoapSchemaNamespace + "ws/2005/05/identity/claims/rsa";
public const string UpnName = SoapSchemaNamespace + "claims/UPN";
const string XmlSignatureConstantsNamespace = "http://www.w3.org/2000/09/xmldsig#";
public const string DsaKeyValue = XmlSignatureConstantsNamespace + "DSAKeyValue";
public const string KeyInfo = XmlSignatureConstantsNamespace + "KeyInfo";
public const string RsaKeyValue = XmlSignatureConstantsNamespace + "RSAKeyValue";
const string XQueryOperatorsNameSpace = "http://www.w3.org/TR/2002/WD-xquery-operators-20020816";
public const string DaytimeDuration = XQueryOperatorsNameSpace + "#dayTimeDuration";
public const string YearMonthDuration = XQueryOperatorsNameSpace + "#yearMonthDuration";
const string Xacml10Namespace = "urn:oasis:names:tc:xacml:1.0";
public const string Rfc822Name = Xacml10Namespace + ":data-type:rfc822Name";
public const string X500Name = Xacml10Namespace + ":data-type:x500Name";
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,51 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// <OWNER>[....]</OWNER>
//
//
// RoleClaimProvider.cs
//
namespace System.Security.Claims
{
using System.Collections.Generic;
/// <summary>
/// This internal class is used to wrap role claims that can be set on GenericPrincipal. They need to be kept distinct from other claims.
/// ClaimsIdentity has a property the holds this type. Since it is internal, few checks are
/// made on parameters.
/// </summary>
[System.Runtime.InteropServices.ComVisible(false)]
internal class RoleClaimProvider
{
string m_issuer;
string[] m_roles;
ClaimsIdentity m_subject;
public RoleClaimProvider(string issuer, string[] roles, ClaimsIdentity subject)
{
m_issuer = issuer;
m_roles = roles;
m_subject = subject;
}
public IEnumerable<Claim> Claims
{
get
{
for (int i = 0; i < m_roles.Length; i++)
{
if (m_roles[i] != null)
{
yield return new Claim(m_subject.RoleClaimType, m_roles[i], ClaimValueTypes.String, m_issuer, m_issuer, m_subject);
}
}
}
}
}
}