From 5fd13d80a87c9015b8691bb35145371f50b06e39 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Tue, 7 Jan 2020 14:51:14 -0800 Subject: [PATCH 1/6] Annotate System.Security.Claims for nullable --- .../ref/System.Security.Claims.cs | 92 +++++++------- .../ref/System.Security.Claims.csproj | 1 + .../src/System.Security.Claims.csproj | 1 + .../src/System/Security/Claims/Claim.cs | 54 ++++----- .../System/Security/Claims/ClaimsIdentity.cs | 114 +++++++++--------- .../System/Security/Claims/ClaimsPrincipal.cs | 40 +++--- .../System/Security/Claims/GenericIdentity.cs | 6 +- .../Security/Claims/GenericPrincipal.cs | 10 +- 8 files changed, 160 insertions(+), 158 deletions(-) diff --git a/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs b/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs index 54ab521ae75ccc..781c9899845d7c 100644 --- a/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs +++ b/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs @@ -10,27 +10,27 @@ namespace System.Security.Claims public partial class Claim { public Claim(System.IO.BinaryReader reader) { } - public Claim(System.IO.BinaryReader reader, System.Security.Claims.ClaimsIdentity subject) { } + public Claim(System.IO.BinaryReader reader, System.Security.Claims.ClaimsIdentity? subject) { } protected Claim(System.Security.Claims.Claim other) { } - protected Claim(System.Security.Claims.Claim other, System.Security.Claims.ClaimsIdentity subject) { } + protected Claim(System.Security.Claims.Claim other, System.Security.Claims.ClaimsIdentity? subject) { } public Claim(string type, string value) { } - public Claim(string type, string value, string valueType) { } - public Claim(string type, string value, string valueType, string issuer) { } - public Claim(string type, string value, string valueType, string issuer, string originalIssuer) { } - public Claim(string type, string value, string valueType, string issuer, string originalIssuer, System.Security.Claims.ClaimsIdentity subject) { } - protected virtual byte[] CustomSerializationData { get { throw null; } } + public Claim(string type, string value, string? valueType) { } + public Claim(string type, string value, string? valueType, string? issuer) { } + public Claim(string type, string value, string? valueType, string? issuer, string? originalIssuer) { } + public Claim(string type, string value, string? valueType, string? issuer, string? originalIssuer, System.Security.Claims.ClaimsIdentity? subject) { } + protected virtual byte[]? CustomSerializationData { get { throw null; } } public string Issuer { get { throw null; } } public string OriginalIssuer { get { throw null; } } - public System.Collections.Generic.IDictionary Properties { get { throw null; } } - public System.Security.Claims.ClaimsIdentity Subject { get { throw null; } } + public System.Collections.Generic.IDictionary Properties { get { throw null; } } + public System.Security.Claims.ClaimsIdentity? Subject { get { throw null; } } public string Type { get { throw null; } } public string Value { get { throw null; } } public string ValueType { get { throw null; } } public virtual System.Security.Claims.Claim Clone() { throw null; } - public virtual System.Security.Claims.Claim Clone(System.Security.Claims.ClaimsIdentity identity) { throw null; } + public virtual System.Security.Claims.Claim Clone(System.Security.Claims.ClaimsIdentity? identity) { throw null; } public override string ToString() { throw null; } public virtual void WriteTo(System.IO.BinaryWriter writer) { } - protected virtual void WriteTo(System.IO.BinaryWriter writer, byte[] userData) { } + protected virtual void WriteTo(System.IO.BinaryWriter writer, byte[]? userData) { } } public partial class ClaimsIdentity : System.Security.Principal.IIdentity { @@ -38,43 +38,43 @@ public partial class ClaimsIdentity : System.Security.Principal.IIdentity public const string DefaultNameClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"; public const string DefaultRoleClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"; public ClaimsIdentity() { } - public ClaimsIdentity(System.Collections.Generic.IEnumerable claims) { } - public ClaimsIdentity(System.Collections.Generic.IEnumerable claims, string authenticationType) { } - public ClaimsIdentity(System.Collections.Generic.IEnumerable claims, string authenticationType, string nameType, string roleType) { } + public ClaimsIdentity(System.Collections.Generic.IEnumerable? claims) { } + public ClaimsIdentity(System.Collections.Generic.IEnumerable? claims, string? authenticationType) { } + public ClaimsIdentity(System.Collections.Generic.IEnumerable? claims, string? authenticationType, string? nameType, string? roleType) { } public ClaimsIdentity(System.IO.BinaryReader reader) { } protected ClaimsIdentity(System.Runtime.Serialization.SerializationInfo info) { } protected ClaimsIdentity(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } protected ClaimsIdentity(System.Security.Claims.ClaimsIdentity other) { } - public ClaimsIdentity(System.Security.Principal.IIdentity identity) { } - public ClaimsIdentity(System.Security.Principal.IIdentity identity, System.Collections.Generic.IEnumerable claims) { } - public ClaimsIdentity(System.Security.Principal.IIdentity identity, System.Collections.Generic.IEnumerable claims, string authenticationType, string nameType, string roleType) { } - public ClaimsIdentity(string authenticationType) { } - public ClaimsIdentity(string authenticationType, string nameType, string roleType) { } - public System.Security.Claims.ClaimsIdentity Actor { get { throw null; } set { } } - public virtual string AuthenticationType { get { throw null; } } - public object BootstrapContext { get { throw null; } set { } } - public virtual System.Collections.Generic.IEnumerable Claims { get { throw null; } } - protected virtual byte[] CustomSerializationData { get { throw null; } } + public ClaimsIdentity(System.Security.Principal.IIdentity? identity) { } + public ClaimsIdentity(System.Security.Principal.IIdentity? identity, System.Collections.Generic.IEnumerable? claims) { } + public ClaimsIdentity(System.Security.Principal.IIdentity? identity, System.Collections.Generic.IEnumerable? claims, string? authenticationType, string? nameType, string? roleType) { } + public ClaimsIdentity(string? authenticationType) { } + public ClaimsIdentity(string? authenticationType, string? nameType, string? roleType) { } + public System.Security.Claims.ClaimsIdentity? Actor { get { throw null; } set { } } + public virtual string? AuthenticationType { get { throw null; } } + public object? BootstrapContext { get { throw null; } set { } } + public virtual System.Collections.Generic.IEnumerable Claims { get { throw null; } } + protected virtual byte[]? CustomSerializationData { get { throw null; } } public virtual bool IsAuthenticated { get { throw null; } } - public string Label { get { throw null; } set { } } - public virtual string Name { get { throw null; } } + public string? Label { get { throw null; } set { } } + public virtual string? Name { get { throw null; } } public string NameClaimType { get { throw null; } } public string RoleClaimType { get { throw null; } } public virtual void AddClaim(System.Security.Claims.Claim claim) { } public virtual void AddClaims(System.Collections.Generic.IEnumerable claims) { } public virtual System.Security.Claims.ClaimsIdentity Clone() { throw null; } protected virtual System.Security.Claims.Claim CreateClaim(System.IO.BinaryReader reader) { throw null; } - public virtual System.Collections.Generic.IEnumerable FindAll(System.Predicate match) { throw null; } + public virtual System.Collections.Generic.IEnumerable FindAll(System.Predicate match) { throw null; } public virtual System.Collections.Generic.IEnumerable FindAll(string type) { throw null; } - public virtual System.Security.Claims.Claim FindFirst(System.Predicate match) { throw null; } - public virtual System.Security.Claims.Claim FindFirst(string type) { throw null; } + public virtual System.Security.Claims.Claim? FindFirst(System.Predicate match) { throw null; } + public virtual System.Security.Claims.Claim? FindFirst(string type) { throw null; } protected virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public virtual bool HasClaim(System.Predicate match) { throw null; } + public virtual bool HasClaim(System.Predicate match) { throw null; } public virtual bool HasClaim(string type, string value) { throw null; } - public virtual void RemoveClaim(System.Security.Claims.Claim claim) { } - public virtual bool TryRemoveClaim(System.Security.Claims.Claim claim) { throw null; } + public virtual void RemoveClaim(System.Security.Claims.Claim? claim) { } + public virtual bool TryRemoveClaim(System.Security.Claims.Claim? claim) { throw null; } public virtual void WriteTo(System.IO.BinaryWriter writer) { } - protected virtual void WriteTo(System.IO.BinaryWriter writer, byte[] userData) { } + protected virtual void WriteTo(System.IO.BinaryWriter writer, byte[]? userData) { } } public partial class ClaimsPrincipal : System.Security.Principal.IPrincipal { @@ -84,27 +84,27 @@ public ClaimsPrincipal(System.IO.BinaryReader reader) { } protected ClaimsPrincipal(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public ClaimsPrincipal(System.Security.Principal.IIdentity identity) { } public ClaimsPrincipal(System.Security.Principal.IPrincipal principal) { } - public virtual System.Collections.Generic.IEnumerable Claims { get { throw null; } } + public virtual System.Collections.Generic.IEnumerable Claims { get { throw null; } } public static System.Func ClaimsPrincipalSelector { get { throw null; } set { } } - public static System.Security.Claims.ClaimsPrincipal Current { get { throw null; } } - protected virtual byte[] CustomSerializationData { get { throw null; } } + public static System.Security.Claims.ClaimsPrincipal? Current { get { throw null; } } + protected virtual byte[]? CustomSerializationData { get { throw null; } } public virtual System.Collections.Generic.IEnumerable Identities { get { throw null; } } - public virtual System.Security.Principal.IIdentity Identity { get { throw null; } } - public static System.Func, System.Security.Claims.ClaimsIdentity> PrimaryIdentitySelector { get { throw null; } set { } } + public virtual System.Security.Principal.IIdentity? Identity { get { throw null; } } + public static System.Func, System.Security.Claims.ClaimsIdentity?> PrimaryIdentitySelector { get { throw null; } set { } } public virtual void AddIdentities(System.Collections.Generic.IEnumerable identities) { } public virtual void AddIdentity(System.Security.Claims.ClaimsIdentity identity) { } public virtual System.Security.Claims.ClaimsPrincipal Clone() { throw null; } protected virtual System.Security.Claims.ClaimsIdentity CreateClaimsIdentity(System.IO.BinaryReader reader) { throw null; } - public virtual System.Collections.Generic.IEnumerable FindAll(System.Predicate match) { throw null; } + public virtual System.Collections.Generic.IEnumerable FindAll(System.Predicate match) { throw null; } public virtual System.Collections.Generic.IEnumerable FindAll(string type) { throw null; } - public virtual System.Security.Claims.Claim FindFirst(System.Predicate match) { throw null; } - public virtual System.Security.Claims.Claim FindFirst(string type) { throw null; } + public virtual System.Security.Claims.Claim? FindFirst(System.Predicate match) { throw null; } + public virtual System.Security.Claims.Claim? FindFirst(string type) { throw null; } protected virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public virtual bool HasClaim(System.Predicate match) { throw null; } + public virtual bool HasClaim(System.Predicate match) { throw null; } public virtual bool HasClaim(string type, string value) { throw null; } public virtual bool IsInRole(string role) { throw null; } public virtual void WriteTo(System.IO.BinaryWriter writer) { } - protected virtual void WriteTo(System.IO.BinaryWriter writer, byte[] userData) { } + protected virtual void WriteTo(System.IO.BinaryWriter writer, byte[]? userData) { } } public static partial class ClaimTypes { @@ -202,15 +202,15 @@ protected GenericIdentity(System.Security.Principal.GenericIdentity identity) { public GenericIdentity(string name) { } public GenericIdentity(string name, string type) { } public override string AuthenticationType { get { throw null; } } - public override System.Collections.Generic.IEnumerable Claims { get { throw null; } } + public override System.Collections.Generic.IEnumerable Claims { get { throw null; } } public override bool IsAuthenticated { get { throw null; } } public override string Name { get { throw null; } } public override System.Security.Claims.ClaimsIdentity Clone() { throw null; } } public partial class GenericPrincipal : System.Security.Claims.ClaimsPrincipal { - public GenericPrincipal(System.Security.Principal.IIdentity identity, string[] roles) { } + public GenericPrincipal(System.Security.Principal.IIdentity identity, string[]? roles) { } public override System.Security.Principal.IIdentity Identity { get { throw null; } } - public override bool IsInRole(string role) { throw null; } + public override bool IsInRole(string? role) { throw null; } } } diff --git a/src/libraries/System.Security.Claims/ref/System.Security.Claims.csproj b/src/libraries/System.Security.Claims/ref/System.Security.Claims.csproj index f50b03583ce946..644919c10192bd 100644 --- a/src/libraries/System.Security.Claims/ref/System.Security.Claims.csproj +++ b/src/libraries/System.Security.Claims/ref/System.Security.Claims.csproj @@ -1,6 +1,7 @@ $(NetCoreAppCurrent)-Debug;$(NetCoreAppCurrent)-Release + enable diff --git a/src/libraries/System.Security.Claims/src/System.Security.Claims.csproj b/src/libraries/System.Security.Claims/src/System.Security.Claims.csproj index 1158601bc31e31..12c7885a9f2c6b 100644 --- a/src/libraries/System.Security.Claims/src/System.Security.Claims.csproj +++ b/src/libraries/System.Security.Claims/src/System.Security.Claims.csproj @@ -2,6 +2,7 @@ System.Security.Claims $(NetCoreAppCurrent)-Debug;$(NetCoreAppCurrent)-Release + enable diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/Claim.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/Claim.cs index 785383437176bf..7a64b9dcf4d130 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/Claim.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/Claim.cs @@ -27,13 +27,13 @@ private enum SerializationMask UserData = 128, } - private readonly byte[] _userSerializationData; + private readonly byte[]? _userSerializationData; private readonly string _issuer; private readonly string _originalIssuer; - private Dictionary _properties; + private Dictionary? _properties; - private readonly ClaimsIdentity _subject; + private readonly ClaimsIdentity? _subject; private readonly string _type; private readonly string _value; private readonly string _valueType; @@ -56,7 +56,7 @@ public Claim(BinaryReader reader) /// a pointing to a . /// the value for , which is the that has these claims. /// if 'reader' is null. - public Claim(BinaryReader reader, ClaimsIdentity subject) + public Claim(BinaryReader reader, ClaimsIdentity? subject) { if (reader == null) { @@ -157,7 +157,7 @@ public Claim(BinaryReader reader, ClaimsIdentity subject) /// /// public Claim(string type, string value) - : this(type, value, ClaimValueTypes.String, ClaimsIdentity.DefaultIssuer, ClaimsIdentity.DefaultIssuer, (ClaimsIdentity)null) + : this(type, value, ClaimValueTypes.String, ClaimsIdentity.DefaultIssuer, ClaimsIdentity.DefaultIssuer, (ClaimsIdentity?)null) { } @@ -176,8 +176,8 @@ public Claim(string type, string value) /// /// /// - public Claim(string type, string value, string valueType) - : this(type, value, valueType, ClaimsIdentity.DefaultIssuer, ClaimsIdentity.DefaultIssuer, (ClaimsIdentity)null) + public Claim(string type, string value, string? valueType) + : this(type, value, valueType, ClaimsIdentity.DefaultIssuer, ClaimsIdentity.DefaultIssuer, (ClaimsIdentity?)null) { } @@ -196,8 +196,8 @@ public Claim(string type, string value, string valueType) /// /// /// - public Claim(string type, string value, string valueType, string issuer) - : this(type, value, valueType, issuer, issuer, (ClaimsIdentity)null) + public Claim(string type, string value, string? valueType, string? issuer) + : this(type, value, valueType, issuer, issuer, (ClaimsIdentity?)null) { } @@ -216,8 +216,8 @@ public Claim(string type, string value, string valueType, string issuer) /// /// /// - public Claim(string type, string value, string valueType, string issuer, string originalIssuer) - : this(type, value, valueType, issuer, originalIssuer, (ClaimsIdentity)null) + public Claim(string type, string value, string? valueType, string? issuer, string? originalIssuer) + : this(type, value, valueType, issuer, originalIssuer, (ClaimsIdentity?)null) { } @@ -234,7 +234,7 @@ public Claim(string type, string value, string valueType, string issuer, string /// /// /// - public Claim(string type, string value, string valueType, string issuer, string originalIssuer, ClaimsIdentity subject) + public Claim(string type, string value, string? valueType, string? issuer, string? originalIssuer, ClaimsIdentity? subject) : this(type, value, valueType, issuer, originalIssuer, subject, null, null) { } @@ -251,7 +251,7 @@ public Claim(string type, string value, string valueType, string issuer, string /// The subject that this claim describes. /// This allows adding a property when adding a Claim. /// The value associated with the property. - internal Claim(string type, string value, string valueType, string issuer, string originalIssuer, ClaimsIdentity subject, string propertyKey, string propertyValue) + internal Claim(string type, string value, string? valueType, string? issuer, string? originalIssuer, ClaimsIdentity? subject, string? propertyKey, string? propertyValue) { if (type == null) { @@ -272,7 +272,7 @@ internal Claim(string type, string value, string valueType, string issuer, strin if (propertyKey != null) { - _properties = new Dictionary(); + _properties = new Dictionary(); _properties[propertyKey] = propertyValue; } } @@ -284,7 +284,7 @@ internal Claim(string type, string value, string valueType, string issuer, strin /// will be set to 'null'. /// if 'other' is null. protected Claim(Claim other) - : this(other, (other == null ? (ClaimsIdentity)null : other._subject)) + : this(other, (other == null ? (ClaimsIdentity?)null : other._subject)) { } @@ -295,7 +295,7 @@ protected Claim(Claim other) /// the to assign to . /// will be set to 'subject'. /// if 'other' is null. - protected Claim(Claim other, ClaimsIdentity subject) + protected Claim(Claim other, ClaimsIdentity? subject) { if (other == null) throw new ArgumentNullException(nameof(other)); @@ -308,7 +308,7 @@ protected Claim(Claim other, ClaimsIdentity subject) _valueType = other._valueType; if (other._properties != null) { - _properties = new Dictionary(other._properties); + _properties = new Dictionary(other._properties); } if (other._userSerializationData != null) @@ -320,7 +320,7 @@ protected Claim(Claim other, ClaimsIdentity subject) /// /// Contains any additional data provided by a derived type, typically set when calling . /// - protected virtual byte[] CustomSerializationData + protected virtual byte[]? CustomSerializationData { get { @@ -352,13 +352,13 @@ public string OriginalIssuer /// /// Gets the collection of Properties associated with the . /// - public IDictionary Properties + public IDictionary Properties { get { if (_properties == null) { - _properties = new Dictionary(); + _properties = new Dictionary(); } return _properties; } @@ -367,7 +367,7 @@ public IDictionary Properties /// /// Gets the subject of the . /// - public ClaimsIdentity Subject + public ClaimsIdentity? Subject { get { return _subject; } } @@ -403,7 +403,7 @@ public string ValueType /// public virtual Claim Clone() { - return Clone((ClaimsIdentity)null); + return Clone((ClaimsIdentity?)null); } /// @@ -411,7 +411,7 @@ public virtual Claim Clone() /// /// the value for , which is the that has these claims. /// will be set to 'identity'. - public virtual Claim Clone(ClaimsIdentity identity) + public virtual Claim Clone(ClaimsIdentity? identity) { return new Claim(this, identity); } @@ -432,7 +432,7 @@ public virtual void WriteTo(BinaryWriter writer) /// the to use for data storage. /// additional data provided by derived type. /// if 'writer' is null. - protected virtual void WriteTo(BinaryWriter writer, byte[] userData) + protected virtual void WriteTo(BinaryWriter writer, byte[]? userData) { if (writer == null) { @@ -514,17 +514,17 @@ protected virtual void WriteTo(BinaryWriter writer, byte[] userData) if ((mask & SerializationMask.HasProperties) == SerializationMask.HasProperties) { - writer.Write(_properties.Count); + writer.Write(_properties!.Count); foreach (var kvp in _properties) { writer.Write(kvp.Key); - writer.Write(kvp.Value); + writer.Write(kvp.Value!); } } if ((mask & SerializationMask.UserData) == SerializationMask.UserData) { - writer.Write(userData.Length); + writer.Write(userData!.Length); writer.Write(userData); } diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs index 93c67bd66fe009..4924e51df48f9e 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs @@ -27,13 +27,13 @@ private enum SerializationMask UserData = 128, } - private byte[] _userSerializationData; - private ClaimsIdentity _actor; - private string _authenticationType; - private object _bootstrapContext; - private List> _externalClaims; - private string _label; - private readonly List _instanceClaims = new List(); + private byte[]? _userSerializationData; + private ClaimsIdentity? _actor; + private string? _authenticationType; + private object? _bootstrapContext; + private List>? _externalClaims; + private string? _label; + private readonly List _instanceClaims = new List(); private string _nameClaimType = DefaultNameClaimType; private string _roleClaimType = DefaultRoleClaimType; @@ -50,7 +50,7 @@ private enum SerializationMask /// Initializes an instance of . /// public ClaimsIdentity() - : this((IIdentity)null, (IEnumerable)null, (string)null, (string)null, (string)null) + : this((IIdentity?)null, (IEnumerable?)null, (string?)null, (string?)null, (string?)null) { } @@ -59,8 +59,8 @@ public ClaimsIdentity() /// /// supplies the and . /// for details on how internal values are set. - public ClaimsIdentity(IIdentity identity) - : this(identity, (IEnumerable)null, (string)null, (string)null, (string)null) + public ClaimsIdentity(IIdentity? identity) + : this(identity, (IEnumerable?)null, (string?)null, (string?)null, (string?)null) { } @@ -71,8 +71,8 @@ public ClaimsIdentity(IIdentity identity) /// /// for details on how internal values are set. /// - public ClaimsIdentity(IEnumerable claims) - : this((IIdentity)null, claims, (string)null, (string)null, (string)null) + public ClaimsIdentity(IEnumerable? claims) + : this((IIdentity?)null, claims, (string?)null, (string?)null, (string?)null) { } @@ -80,8 +80,8 @@ public ClaimsIdentity(IEnumerable claims) /// Initializes an instance of . /// /// The authentication method used to establish this identity. - public ClaimsIdentity(string authenticationType) - : this((IIdentity)null, (IEnumerable)null, authenticationType, (string)null, (string)null) + public ClaimsIdentity(string? authenticationType) + : this((IIdentity?)null, (IEnumerable?)null, authenticationType, (string?)null, (string?)null) { } @@ -91,8 +91,8 @@ public ClaimsIdentity(string authenticationType) /// associated with this instance. /// The authentication method used to establish this identity. /// for details on how internal values are set. - public ClaimsIdentity(IEnumerable claims, string authenticationType) - : this((IIdentity)null, claims, authenticationType, (string)null, (string)null) + public ClaimsIdentity(IEnumerable? claims, string? authenticationType) + : this((IIdentity?)null, claims, authenticationType, (string?)null, (string?)null) { } @@ -102,8 +102,8 @@ public ClaimsIdentity(IEnumerable claims, string authenticationType) /// supplies the and . /// associated with this instance. /// for details on how internal values are set. - public ClaimsIdentity(IIdentity identity, IEnumerable claims) - : this(identity, claims, (string)null, (string)null, (string)null) + public ClaimsIdentity(IIdentity? identity, IEnumerable? claims) + : this(identity, claims, (string?)null, (string?)null, (string?)null) { } @@ -114,8 +114,8 @@ public ClaimsIdentity(IIdentity identity, IEnumerable claims) /// The used when obtaining the value of . /// The used when performing logic for . /// for details on how internal values are set. - public ClaimsIdentity(string authenticationType, string nameType, string roleType) - : this((IIdentity)null, (IEnumerable)null, authenticationType, nameType, roleType) + public ClaimsIdentity(string? authenticationType, string? nameType, string? roleType) + : this((IIdentity?)null, (IEnumerable?)null, authenticationType, nameType, roleType) { } @@ -127,8 +127,8 @@ public ClaimsIdentity(string authenticationType, string nameType, string roleTyp /// The used when obtaining the value of . /// The used when performing logic for . /// for details on how internal values are set. - public ClaimsIdentity(IEnumerable claims, string authenticationType, string nameType, string roleType) - : this((IIdentity)null, claims, authenticationType, nameType, roleType) + public ClaimsIdentity(IEnumerable? claims, string? authenticationType, string? nameType, string? roleType) + : this((IIdentity?)null, claims, authenticationType, nameType, roleType) { } @@ -146,9 +146,9 @@ public ClaimsIdentity(IEnumerable claims, string authenticationType, stri /// Any 'External' claims are ignored. /// /// if 'identity' is a and results in a circular reference back to 'this'. - public ClaimsIdentity(IIdentity identity, IEnumerable claims, string authenticationType, string nameType, string roleType) + public ClaimsIdentity(IIdentity? identity, IEnumerable? claims, string? authenticationType, string? nameType, string? roleType) { - ClaimsIdentity claimsIdentity = identity as ClaimsIdentity; + ClaimsIdentity? claimsIdentity = identity as ClaimsIdentity; _authenticationType = (identity != null && string.IsNullOrEmpty(authenticationType)) ? identity.AuthenticationType : authenticationType; _nameClaimType = !string.IsNullOrEmpty(nameType) ? nameType : (claimsIdentity != null ? claimsIdentity._nameClaimType : DefaultNameClaimType); @@ -255,7 +255,7 @@ protected ClaimsIdentity(SerializationInfo info) /// /// Gets the authentication type that can be used to determine how this authenticated to an authority. /// - public virtual string AuthenticationType + public virtual string? AuthenticationType { get { return _authenticationType; } } @@ -272,7 +272,7 @@ public virtual bool IsAuthenticated /// Gets or sets a that was granted delegation rights. /// /// if 'value' results in a circular reference back to 'this'. - public ClaimsIdentity Actor + public ClaimsIdentity? Actor { get { return _actor; } set @@ -291,7 +291,7 @@ public ClaimsIdentity Actor /// /// Gets or sets a context that was used to create this . /// - public object BootstrapContext + public object? BootstrapContext { get { return _bootstrapContext; } set { _bootstrapContext = value; } @@ -301,7 +301,7 @@ public object BootstrapContext /// Gets the claims as , associated with this . /// /// May contain nulls. - public virtual IEnumerable Claims + public virtual IEnumerable Claims { get { @@ -314,14 +314,14 @@ public virtual IEnumerable Claims } } - private IEnumerable CombinedClaimsIterator() + private IEnumerable CombinedClaimsIterator() { for (int i = 0; i < _instanceClaims.Count; i++) { yield return _instanceClaims[i]; } - for (int j = 0; j < _externalClaims.Count; j++) + for (int j = 0; j < _externalClaims!.Count; j++) { if (_externalClaims[j] != null) { @@ -336,7 +336,7 @@ private IEnumerable CombinedClaimsIterator() /// /// Contains any additional data provided by a derived type, typically set when calling . /// - protected virtual byte[] CustomSerializationData + protected virtual byte[]? CustomSerializationData { get { @@ -363,7 +363,7 @@ internal List> ExternalClaims /// /// Gets or sets the label for this /// - public string Label + public string? Label { get { return _label; } set { _label = value; } @@ -373,12 +373,12 @@ public string Label /// Gets the Name of this . /// /// Calls where string == NameClaimType, if found, returns otherwise null. - public virtual string Name + public virtual string? Name { // just an accessor for getting the name claim get { - Claim claim = FindFirst(_nameClaimType); + Claim? claim = FindFirst(_nameClaimType); if (claim != null) { return claim.Value; @@ -473,7 +473,7 @@ public virtual void AddClaims(IEnumerable claims) /// It is possible that a returned from cannot be removed. This would be the case for 'External' claims that are provided by reference. /// object.ReferenceEquals is used to 'match'. /// - public virtual bool TryRemoveClaim(Claim claim) + public virtual bool TryRemoveClaim(Claim? claim) { if (claim == null) { @@ -502,7 +502,7 @@ public virtual bool TryRemoveClaim(Claim claim) /// object.ReferenceEquals is used to 'match'. /// /// if 'claim' cannot be removed. - public virtual void RemoveClaim(Claim claim) + public virtual void RemoveClaim(Claim? claim) { if (!TryRemoveClaim(claim)) { @@ -515,9 +515,9 @@ public virtual void RemoveClaim(Claim claim) /// /// a to add to /// private only call from constructor, adds to internal list. - private void SafeAddClaims(IEnumerable claims) + private void SafeAddClaims(IEnumerable claims) { - foreach (Claim claim in claims) + foreach (Claim? claim in claims) { if (claim == null) continue; @@ -537,7 +537,7 @@ private void SafeAddClaims(IEnumerable claims) /// Adds claim to internal list. Calling Claim.Clone if Claim.Subject != this. /// /// private only call from constructor, adds to internal list. - private void SafeAddClaim(Claim claim) + private void SafeAddClaim(Claim? claim) { if (claim == null) return; @@ -558,14 +558,14 @@ private void SafeAddClaim(Claim claim) /// The function that performs the matching logic. /// A of matched claims. /// if 'match' is null. - public virtual IEnumerable FindAll(Predicate match) + public virtual IEnumerable FindAll(Predicate match) { if (match == null) { throw new ArgumentNullException(nameof(match)); } - foreach (Claim claim in Claims) + foreach (Claim? claim in Claims) { if (match(claim)) { @@ -588,7 +588,7 @@ public virtual IEnumerable FindAll(string type) throw new ArgumentNullException(nameof(type)); } - foreach (Claim claim in Claims) + foreach (Claim? claim in Claims) { if (claim != null) { @@ -606,14 +606,14 @@ public virtual IEnumerable FindAll(string type) /// The function that performs the matching logic. /// A , null if nothing matches. /// if 'match' is null. - public virtual Claim FindFirst(Predicate match) + public virtual Claim? FindFirst(Predicate match) { if (match == null) { throw new ArgumentNullException(nameof(match)); } - foreach (Claim claim in Claims) + foreach (Claim? claim in Claims) { if (match(claim)) { @@ -631,14 +631,14 @@ public virtual Claim FindFirst(Predicate match) /// A , null if nothing matches. /// Comparison is: StringComparison.OrdinalIgnoreCase. /// if 'type' is null. - public virtual Claim FindFirst(string type) + public virtual Claim? FindFirst(string type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } - foreach (Claim claim in Claims) + foreach (Claim? claim in Claims) { if (claim != null) { @@ -658,14 +658,14 @@ public virtual Claim FindFirst(string type) /// The function that performs the matching logic. /// true if a claim is found, false otherwise. /// if 'match' is null. - public virtual bool HasClaim(Predicate match) + public virtual bool HasClaim(Predicate match) { if (match == null) { throw new ArgumentNullException(nameof(match)); } - foreach (Claim claim in Claims) + foreach (Claim? claim in Claims) { if (match(claim)) { @@ -697,7 +697,7 @@ public virtual bool HasClaim(string type, string value) throw new ArgumentNullException(nameof(value)); } - foreach (Claim claim in Claims) + foreach (Claim? claim in Claims) { if (claim != null && string.Equals(claim.Type, type, StringComparison.OrdinalIgnoreCase) @@ -825,7 +825,7 @@ public virtual void WriteTo(BinaryWriter writer) /// the to use for data storage. /// additional data provided by derived type. /// if 'writer' is null. - protected virtual void WriteTo(BinaryWriter writer, byte[] userData) + protected virtual void WriteTo(BinaryWriter writer, byte[]? userData) { if (writer == null) { @@ -842,7 +842,7 @@ protected virtual void WriteTo(BinaryWriter writer, byte[] userData) if (_bootstrapContext != null) { - string rawData = _bootstrapContext as string; + string? rawData = _bootstrapContext as string; if (rawData != null) { mask |= SerializationMask.BootstrapConext; @@ -890,12 +890,12 @@ protected virtual void WriteTo(BinaryWriter writer, byte[] userData) writer.Write(numberOfPropertiesWritten); if ((mask & SerializationMask.AuthenticationType) == SerializationMask.AuthenticationType) { - writer.Write(_authenticationType); + writer.Write(_authenticationType!); } if ((mask & SerializationMask.BootstrapConext) == SerializationMask.BootstrapConext) { - writer.Write(_bootstrapContext as string); + writer.Write((_bootstrapContext as string)!); } if ((mask & SerializationMask.NameClaimType) == SerializationMask.NameClaimType) @@ -910,7 +910,7 @@ protected virtual void WriteTo(BinaryWriter writer, byte[] userData) if ((mask & SerializationMask.HasLabel) == SerializationMask.HasLabel) { - writer.Write(_label); + writer.Write(_label!); } if ((mask & SerializationMask.HasClaims) == SerializationMask.HasClaims) @@ -918,18 +918,18 @@ protected virtual void WriteTo(BinaryWriter writer, byte[] userData) writer.Write(_instanceClaims.Count); foreach (var claim in _instanceClaims) { - claim.WriteTo(writer); + claim!.WriteTo(writer); } } if ((mask & SerializationMask.Actor) == SerializationMask.Actor) { - _actor.WriteTo(writer); + _actor!.WriteTo(writer); } if ((mask & SerializationMask.UserData) == SerializationMask.UserData) { - writer.Write(userData.Length); + writer.Write(userData!.Length); writer.Write(userData); } diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs index 6bc0b19f13cbf3..db48fec299d7ad 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs @@ -22,9 +22,9 @@ private enum SerializationMask } private readonly List _identities = new List(); - private readonly byte[] _userSerializationData; + private readonly byte[]? _userSerializationData; - private static Func, ClaimsIdentity> s_identitySelector = SelectPrimaryIdentity; + private static Func, ClaimsIdentity?> s_identitySelector = SelectPrimaryIdentity; private static Func s_principalSelector = ClaimsPrincipalSelector; protected ClaimsPrincipal(SerializationInfo info, StreamingContext context) @@ -35,7 +35,7 @@ protected ClaimsPrincipal(SerializationInfo info, StreamingContext context) /// /// This method iterates through the collection of ClaimsIdentities and chooses an identity as the primary. /// - private static ClaimsIdentity SelectPrimaryIdentity(IEnumerable identities) + private static ClaimsIdentity? SelectPrimaryIdentity(IEnumerable identities) { if (identities == null) { @@ -53,7 +53,7 @@ private static ClaimsIdentity SelectPrimaryIdentity(IEnumerable return null; } - public static Func, ClaimsIdentity> PrimaryIdentitySelector + public static Func, ClaimsIdentity?> PrimaryIdentitySelector { get { @@ -111,7 +111,7 @@ public ClaimsPrincipal(IIdentity identity) throw new ArgumentNullException(nameof(identity)); } - ClaimsIdentity ci = identity as ClaimsIdentity; + ClaimsIdentity? ci = identity as ClaimsIdentity; if (ci != null) { _identities.Add(ci); @@ -138,7 +138,7 @@ public ClaimsPrincipal(IPrincipal principal) // If IPrincipal is a ClaimsPrincipal add all of the identities // If IPrincipal is not a ClaimsPrincipal, create a new identity from IPrincipal.Identity // - ClaimsPrincipal cp = principal as ClaimsPrincipal; + ClaimsPrincipal? cp = principal as ClaimsPrincipal; if (null == cp) { _identities.Add(new ClaimsIdentity(principal.Identity)); @@ -225,13 +225,13 @@ public virtual void AddIdentities(IEnumerable identities) /// /// Gets the claims as , associated with this by enumerating all . /// - public virtual IEnumerable Claims + public virtual IEnumerable Claims { get { foreach (ClaimsIdentity identity in Identities) { - foreach (Claim claim in identity.Claims) + foreach (Claim? claim in identity.Claims) { yield return claim; } @@ -242,7 +242,7 @@ public virtual IEnumerable Claims /// /// Contains any additional data provided by derived type, typically set when calling . /// - protected virtual byte[] CustomSerializationData + protected virtual byte[]? CustomSerializationData { get { @@ -277,7 +277,7 @@ protected virtual ClaimsIdentity CreateClaimsIdentity(BinaryReader reader) /// /// Returns the Current Principal by calling a delegate. Users may specify the delegate. /// - public static ClaimsPrincipal Current + public static ClaimsPrincipal? Current { // just accesses the current selected principal selector, doesn't set get @@ -298,7 +298,7 @@ public static ClaimsPrincipal Current /// A of matched claims. /// Each is called. . /// if 'match' is null. - public virtual IEnumerable FindAll(Predicate match) + public virtual IEnumerable FindAll(Predicate match) { if (match == null) { @@ -309,7 +309,7 @@ public virtual IEnumerable FindAll(Predicate match) { if (identity != null) { - foreach (Claim claim in identity.FindAll(match)) + foreach (Claim? claim in identity.FindAll(match)) { yield return claim; } @@ -350,14 +350,14 @@ public virtual IEnumerable FindAll(string type) /// A , null if nothing matches. /// Each is called. . /// if 'match' is null. - public virtual Claim FindFirst(Predicate match) + public virtual Claim? FindFirst(Predicate match) { if (match == null) { throw new ArgumentNullException(nameof(match)); } - Claim claim = null; + Claim? claim = null; foreach (ClaimsIdentity identity in Identities) { @@ -381,14 +381,14 @@ public virtual Claim FindFirst(Predicate match) /// A , null if nothing matches. /// Each is called. . /// if 'type' is null. - public virtual Claim FindFirst(string type) + public virtual Claim? FindFirst(string type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } - Claim claim = null; + Claim? claim = null; for (int i = 0; i < _identities.Count; i++) { @@ -412,7 +412,7 @@ public virtual Claim FindFirst(string type) /// true if a claim is found, false otherwise. /// Each is called. . /// if 'match' is null. - public virtual bool HasClaim(Predicate match) + public virtual bool HasClaim(Predicate match) { if (match == null) { @@ -482,7 +482,7 @@ public virtual IEnumerable Identities /// /// Gets the identity of the current principal. /// - public virtual System.Security.Principal.IIdentity Identity + public virtual System.Security.Principal.IIdentity? Identity { get { @@ -535,7 +535,7 @@ public virtual void WriteTo(BinaryWriter writer) /// the to use for data storage. /// additional data provided by derived type. /// if 'writer' is null. - protected virtual void WriteTo(BinaryWriter writer, byte[] userData) + protected virtual void WriteTo(BinaryWriter writer, byte[]? userData) { if (writer == null) { @@ -569,7 +569,7 @@ protected virtual void WriteTo(BinaryWriter writer, byte[] userData) if ((mask & SerializationMask.UserData) == SerializationMask.UserData) { - writer.Write(userData.Length); + writer.Write(userData!.Length); writer.Write(userData); } diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs index 1fb721b228c505..40d6a2345b2879 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs @@ -9,8 +9,8 @@ namespace System.Security.Principal { public class GenericIdentity : ClaimsIdentity { - private readonly string m_name; - private readonly string m_type; + private readonly string m_name = null!; // Init-ed in parameterized constructors + private readonly string m_type = null!; public GenericIdentity(string name) { @@ -56,7 +56,7 @@ public override ClaimsIdentity Clone() return new GenericIdentity(this); } - public override IEnumerable Claims + public override IEnumerable Claims { get { diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs index aac4c43c5b68d7..b20959418b3640 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs @@ -10,9 +10,9 @@ namespace System.Security.Principal public class GenericPrincipal : ClaimsPrincipal { private readonly IIdentity m_identity; - private readonly string[] m_roles; + private readonly string[]? m_roles; - public GenericPrincipal(IIdentity identity, string[] roles) + public GenericPrincipal(IIdentity identity, string[]? roles) { if (identity == null) throw new ArgumentNullException(nameof(identity)); @@ -33,9 +33,9 @@ public GenericPrincipal(IIdentity identity, string[] roles) /// /// helper method to add roles /// - private void AddIdentityWithRoles(IIdentity identity, string[] roles) + private void AddIdentityWithRoles(IIdentity identity, string[]? roles) { - ClaimsIdentity claimsIdentity = identity as ClaimsIdentity; + ClaimsIdentity? claimsIdentity = identity as ClaimsIdentity; if (claimsIdentity != null) { @@ -70,7 +70,7 @@ public override IIdentity Identity get { return m_identity; } } - public override bool IsInRole(string role) + public override bool IsInRole(string? role) { if (role == null || m_roles == null) return false; From a972883f073d67106a1cd19155b40ba163390708 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Tue, 7 Jan 2020 16:30:49 -0800 Subject: [PATCH 2/6] Some update --- .../ref/System.Security.Claims.cs | 14 +++++----- .../System/Security/Claims/ClaimsIdentity.cs | 28 +++++++++---------- .../System/Security/Claims/ClaimsPrincipal.cs | 12 ++++---- .../System/Security/Claims/GenericIdentity.cs | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs b/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs index 781c9899845d7c..17fe4f57a8fe65 100644 --- a/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs +++ b/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs @@ -64,9 +64,9 @@ public virtual void AddClaim(System.Security.Claims.Claim claim) { } public virtual void AddClaims(System.Collections.Generic.IEnumerable claims) { } public virtual System.Security.Claims.ClaimsIdentity Clone() { throw null; } protected virtual System.Security.Claims.Claim CreateClaim(System.IO.BinaryReader reader) { throw null; } - public virtual System.Collections.Generic.IEnumerable FindAll(System.Predicate match) { throw null; } + public virtual System.Collections.Generic.IEnumerable FindAll(System.Predicate match) { throw null; } public virtual System.Collections.Generic.IEnumerable FindAll(string type) { throw null; } - public virtual System.Security.Claims.Claim? FindFirst(System.Predicate match) { throw null; } + public virtual System.Security.Claims.Claim? FindFirst(System.Predicate match) { throw null; } public virtual System.Security.Claims.Claim? FindFirst(string type) { throw null; } protected virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public virtual bool HasClaim(System.Predicate match) { throw null; } @@ -84,7 +84,7 @@ public ClaimsPrincipal(System.IO.BinaryReader reader) { } protected ClaimsPrincipal(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public ClaimsPrincipal(System.Security.Principal.IIdentity identity) { } public ClaimsPrincipal(System.Security.Principal.IPrincipal principal) { } - public virtual System.Collections.Generic.IEnumerable Claims { get { throw null; } } + public virtual System.Collections.Generic.IEnumerable Claims { get { throw null; } } public static System.Func ClaimsPrincipalSelector { get { throw null; } set { } } public static System.Security.Claims.ClaimsPrincipal? Current { get { throw null; } } protected virtual byte[]? CustomSerializationData { get { throw null; } } @@ -95,12 +95,12 @@ public virtual void AddIdentities(System.Collections.Generic.IEnumerable FindAll(System.Predicate match) { throw null; } + public virtual System.Collections.Generic.IEnumerable FindAll(System.Predicate match) { throw null; } public virtual System.Collections.Generic.IEnumerable FindAll(string type) { throw null; } - public virtual System.Security.Claims.Claim? FindFirst(System.Predicate match) { throw null; } + public virtual System.Security.Claims.Claim? FindFirst(System.Predicate match) { throw null; } public virtual System.Security.Claims.Claim? FindFirst(string type) { throw null; } protected virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public virtual bool HasClaim(System.Predicate match) { throw null; } + public virtual bool HasClaim(System.Predicate match) { throw null; } public virtual bool HasClaim(string type, string value) { throw null; } public virtual bool IsInRole(string role) { throw null; } public virtual void WriteTo(System.IO.BinaryWriter writer) { } @@ -202,7 +202,7 @@ protected GenericIdentity(System.Security.Principal.GenericIdentity identity) { public GenericIdentity(string name) { } public GenericIdentity(string name, string type) { } public override string AuthenticationType { get { throw null; } } - public override System.Collections.Generic.IEnumerable Claims { get { throw null; } } + public override System.Collections.Generic.IEnumerable Claims { get { throw null; } } public override bool IsAuthenticated { get { throw null; } } public override string Name { get { throw null; } } public override System.Security.Claims.ClaimsIdentity Clone() { throw null; } diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs index 4924e51df48f9e..d052dd636943df 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs @@ -33,7 +33,7 @@ private enum SerializationMask private object? _bootstrapContext; private List>? _externalClaims; private string? _label; - private readonly List _instanceClaims = new List(); + private readonly List _instanceClaims = new List(); private string _nameClaimType = DefaultNameClaimType; private string _roleClaimType = DefaultRoleClaimType; @@ -301,7 +301,7 @@ public object? BootstrapContext /// Gets the claims as , associated with this . /// /// May contain nulls. - public virtual IEnumerable Claims + public virtual IEnumerable Claims { get { @@ -314,7 +314,7 @@ public virtual IEnumerable Claims } } - private IEnumerable CombinedClaimsIterator() + private IEnumerable CombinedClaimsIterator() { for (int i = 0; i < _instanceClaims.Count; i++) { @@ -441,14 +441,14 @@ public virtual void AddClaim(Claim claim) /// Enumeration of claims to add. /// Each claim is examined and if != this, then Claim.Clone(this) is called before the claim is added. /// if 'claims' is null. - public virtual void AddClaims(IEnumerable claims) + public virtual void AddClaims(IEnumerable claims) { if (claims == null) { throw new ArgumentNullException(nameof(claims)); } - foreach (Claim claim in claims) + foreach (Claim? claim in claims) { if (claim == null) { @@ -558,14 +558,14 @@ private void SafeAddClaim(Claim? claim) /// The function that performs the matching logic. /// A of matched claims. /// if 'match' is null. - public virtual IEnumerable FindAll(Predicate match) + public virtual IEnumerable FindAll(Predicate match) { if (match == null) { throw new ArgumentNullException(nameof(match)); } - foreach (Claim? claim in Claims) + foreach (Claim claim in Claims) { if (match(claim)) { @@ -588,7 +588,7 @@ public virtual IEnumerable FindAll(string type) throw new ArgumentNullException(nameof(type)); } - foreach (Claim? claim in Claims) + foreach (Claim claim in Claims) { if (claim != null) { @@ -606,14 +606,14 @@ public virtual IEnumerable FindAll(string type) /// The function that performs the matching logic. /// A , null if nothing matches. /// if 'match' is null. - public virtual Claim? FindFirst(Predicate match) + public virtual Claim? FindFirst(Predicate match) { if (match == null) { throw new ArgumentNullException(nameof(match)); } - foreach (Claim? claim in Claims) + foreach (Claim claim in Claims) { if (match(claim)) { @@ -638,7 +638,7 @@ public virtual IEnumerable FindAll(string type) throw new ArgumentNullException(nameof(type)); } - foreach (Claim? claim in Claims) + foreach (Claim claim in Claims) { if (claim != null) { @@ -658,14 +658,14 @@ public virtual IEnumerable FindAll(string type) /// The function that performs the matching logic. /// true if a claim is found, false otherwise. /// if 'match' is null. - public virtual bool HasClaim(Predicate match) + public virtual bool HasClaim(Predicate match) { if (match == null) { throw new ArgumentNullException(nameof(match)); } - foreach (Claim? claim in Claims) + foreach (Claim claim in Claims) { if (match(claim)) { @@ -697,7 +697,7 @@ public virtual bool HasClaim(string type, string value) throw new ArgumentNullException(nameof(value)); } - foreach (Claim? claim in Claims) + foreach (Claim claim in Claims) { if (claim != null && string.Equals(claim.Type, type, StringComparison.OrdinalIgnoreCase) diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs index db48fec299d7ad..abeff195d78b9d 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs @@ -225,13 +225,13 @@ public virtual void AddIdentities(IEnumerable identities) /// /// Gets the claims as , associated with this by enumerating all . /// - public virtual IEnumerable Claims + public virtual IEnumerable Claims { get { foreach (ClaimsIdentity identity in Identities) { - foreach (Claim? claim in identity.Claims) + foreach (Claim claim in identity.Claims) { yield return claim; } @@ -298,7 +298,7 @@ public static ClaimsPrincipal? Current /// A of matched claims. /// Each is called. . /// if 'match' is null. - public virtual IEnumerable FindAll(Predicate match) + public virtual IEnumerable FindAll(Predicate match) { if (match == null) { @@ -309,7 +309,7 @@ public static ClaimsPrincipal? Current { if (identity != null) { - foreach (Claim? claim in identity.FindAll(match)) + foreach (Claim claim in identity.FindAll(match)) { yield return claim; } @@ -350,7 +350,7 @@ public virtual IEnumerable FindAll(string type) /// A , null if nothing matches. /// Each is called. . /// if 'match' is null. - public virtual Claim? FindFirst(Predicate match) + public virtual Claim? FindFirst(Predicate match) { if (match == null) { @@ -412,7 +412,7 @@ public virtual IEnumerable FindAll(string type) /// true if a claim is found, false otherwise. /// Each is called. . /// if 'match' is null. - public virtual bool HasClaim(Predicate match) + public virtual bool HasClaim(Predicate match) { if (match == null) { diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs index 40d6a2345b2879..3bc44c3514c9a0 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs @@ -56,7 +56,7 @@ public override ClaimsIdentity Clone() return new GenericIdentity(this); } - public override IEnumerable Claims + public override IEnumerable Claims { get { From f67362e6957bfd1dd670b06c316f6a64ec89f0c8 Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Tue, 7 Jan 2020 16:35:43 -0800 Subject: [PATCH 3/6] Ref update --- .../System.Security.Claims/ref/System.Security.Claims.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs b/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs index 17fe4f57a8fe65..03cc48db5077e8 100644 --- a/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs +++ b/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs @@ -53,7 +53,7 @@ public ClaimsIdentity(string? authenticationType, string? nameType, string? role public System.Security.Claims.ClaimsIdentity? Actor { get { throw null; } set { } } public virtual string? AuthenticationType { get { throw null; } } public object? BootstrapContext { get { throw null; } set { } } - public virtual System.Collections.Generic.IEnumerable Claims { get { throw null; } } + public virtual System.Collections.Generic.IEnumerable Claims { get { throw null; } } protected virtual byte[]? CustomSerializationData { get { throw null; } } public virtual bool IsAuthenticated { get { throw null; } } public string? Label { get { throw null; } set { } } @@ -61,7 +61,7 @@ public ClaimsIdentity(string? authenticationType, string? nameType, string? role public string NameClaimType { get { throw null; } } public string RoleClaimType { get { throw null; } } public virtual void AddClaim(System.Security.Claims.Claim claim) { } - public virtual void AddClaims(System.Collections.Generic.IEnumerable claims) { } + public virtual void AddClaims(System.Collections.Generic.IEnumerable claims) { } public virtual System.Security.Claims.ClaimsIdentity Clone() { throw null; } protected virtual System.Security.Claims.Claim CreateClaim(System.IO.BinaryReader reader) { throw null; } public virtual System.Collections.Generic.IEnumerable FindAll(System.Predicate match) { throw null; } @@ -69,7 +69,7 @@ public virtual void AddClaims(System.Collections.Generic.IEnumerable match) { throw null; } public virtual System.Security.Claims.Claim? FindFirst(string type) { throw null; } protected virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } - public virtual bool HasClaim(System.Predicate match) { throw null; } + public virtual bool HasClaim(System.Predicate match) { throw null; } public virtual bool HasClaim(string type, string value) { throw null; } public virtual void RemoveClaim(System.Security.Claims.Claim? claim) { } public virtual bool TryRemoveClaim(System.Security.Claims.Claim? claim) { throw null; } From 606026ba81ed4e857a13a0d35d70f74f2a0139ff Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Wed, 8 Jan 2020 15:30:54 -0800 Subject: [PATCH 4/6] Addressing feedback --- .../src/System/Security/Claims/GenericIdentity.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs index 3bc44c3514c9a0..a3c161cfd56bd6 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs @@ -9,7 +9,7 @@ namespace System.Security.Principal { public class GenericIdentity : ClaimsIdentity { - private readonly string m_name = null!; // Init-ed in parameterized constructors + private readonly string m_name = null!; // Initialized in parameterized constructors private readonly string m_type = null!; public GenericIdentity(string name) From 148638ca5be8acbc865ecefb988be990bf85bc7e Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Thu, 9 Jan 2020 15:43:22 -0800 Subject: [PATCH 5/6] as => is updates --- .../src/System/Security/Claims/ClaimsIdentity.cs | 3 +-- .../src/System/Security/Claims/ClaimsPrincipal.cs | 3 +-- .../src/System/Security/Claims/GenericPrincipal.cs | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs index d052dd636943df..346a34bd1e2655 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs @@ -842,8 +842,7 @@ protected virtual void WriteTo(BinaryWriter writer, byte[]? userData) if (_bootstrapContext != null) { - string? rawData = _bootstrapContext as string; - if (rawData != null) + if (_bootstrapContext is string rawData) { mask |= SerializationMask.BootstrapConext; numberOfPropertiesWritten++; diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs index abeff195d78b9d..bc7dab0a78ee22 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs @@ -111,8 +111,7 @@ public ClaimsPrincipal(IIdentity identity) throw new ArgumentNullException(nameof(identity)); } - ClaimsIdentity? ci = identity as ClaimsIdentity; - if (ci != null) + if (identity is ClaimsIdentity ci) { _identities.Add(ci); } diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs index b20959418b3640..8b4c9a56840926 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs @@ -35,9 +35,7 @@ public GenericPrincipal(IIdentity identity, string[]? roles) /// private void AddIdentityWithRoles(IIdentity identity, string[]? roles) { - ClaimsIdentity? claimsIdentity = identity as ClaimsIdentity; - - if (claimsIdentity != null) + if (identity is ClaimsIdentity claimsIdentity) { claimsIdentity = claimsIdentity.Clone(); } From d0733285c729d68ee235c1658f5de52d4020119c Mon Sep 17 00:00:00 2001 From: Buyaa Namnan Date: Fri, 10 Jan 2020 15:30:48 -0800 Subject: [PATCH 6/6] Applying feedback --- .../src/System/Security/Claims/Claim.cs | 15 ++++++++------- .../src/System/Security/Claims/ClaimsIdentity.cs | 4 ++-- .../src/System/Security/Claims/GenericIdentity.cs | 9 ++------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/Claim.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/Claim.cs index 7a64b9dcf4d130..d48914daf00cdc 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/Claim.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/Claim.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; +using System.Diagnostics; using System.IO; namespace System.Security.Claims @@ -31,7 +32,7 @@ private enum SerializationMask private readonly string _issuer; private readonly string _originalIssuer; - private Dictionary? _properties; + private Dictionary? _properties; private readonly ClaimsIdentity? _subject; private readonly string _type; @@ -272,8 +273,8 @@ internal Claim(string type, string value, string? valueType, string? issuer, str if (propertyKey != null) { - _properties = new Dictionary(); - _properties[propertyKey] = propertyValue; + _properties = new Dictionary(); + _properties[propertyKey] = propertyValue!; } } @@ -308,7 +309,7 @@ protected Claim(Claim other, ClaimsIdentity? subject) _valueType = other._valueType; if (other._properties != null) { - _properties = new Dictionary(other._properties); + _properties = new Dictionary(other._properties); } if (other._userSerializationData != null) @@ -352,13 +353,13 @@ public string OriginalIssuer /// /// Gets the collection of Properties associated with the . /// - public IDictionary Properties + public IDictionary Properties { get { if (_properties == null) { - _properties = new Dictionary(); + _properties = new Dictionary(); } return _properties; } @@ -518,7 +519,7 @@ protected virtual void WriteTo(BinaryWriter writer, byte[]? userData) foreach (var kvp in _properties) { writer.Write(kvp.Key); - writer.Write(kvp.Value!); + writer.Write(kvp.Value); } } diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs index 346a34bd1e2655..d1507e2314835e 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsIdentity.cs @@ -894,7 +894,7 @@ protected virtual void WriteTo(BinaryWriter writer, byte[]? userData) if ((mask & SerializationMask.BootstrapConext) == SerializationMask.BootstrapConext) { - writer.Write((_bootstrapContext as string)!); + writer.Write((string)_bootstrapContext!); } if ((mask & SerializationMask.NameClaimType) == SerializationMask.NameClaimType) @@ -917,7 +917,7 @@ protected virtual void WriteTo(BinaryWriter writer, byte[]? userData) writer.Write(_instanceClaims.Count); foreach (var claim in _instanceClaims) { - claim!.WriteTo(writer); + claim.WriteTo(writer); } } diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs index a3c161cfd56bd6..4f0cc83fecfd6d 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericIdentity.cs @@ -9,8 +9,8 @@ namespace System.Security.Principal { public class GenericIdentity : ClaimsIdentity { - private readonly string m_name = null!; // Initialized in parameterized constructors - private readonly string m_type = null!; + private readonly string m_name; + private readonly string m_type; public GenericIdentity(string name) { @@ -36,11 +36,6 @@ public GenericIdentity(string name, string type) AddNameClaim(); } - private GenericIdentity() - : base() - { } - - protected GenericIdentity(GenericIdentity identity) : base(identity) {