System.Security.Claims.ClaimsIdentity.ClaimsIdentity C# (CSharp) Method

ClaimsIdentity() public method

Initializes an instance of ClaimsIdentity.
If 'identity' is a ClaimsIdentity, then there are potentially multiple sources for AuthenticationType, NameClaimType, RoleClaimType.

Priority is given to the parameters: authenticationType, nameClaimType, roleClaimType.

All Claims are copied into this instance in a List{Claim}. Each Claim is examined and if Claim.Subject != this, then Claim.Clone(this) is called before the claim is added.

Any 'External' claims are ignored.

if 'identity' is a and results in a circular refrence back to 'this'.
public ClaimsIdentity ( IIdentity identity, IEnumerable claims, string authenticationType, string nameType, string roleType ) : System.Collections.Generic
identity IIdentity supplies the and .
claims IEnumerable associated with this instance.
authenticationType string The type of authentication used.
nameType string The used when obtaining the value of .
roleType string The used when performing logic for .
return System.Collections.Generic
        public ClaimsIdentity(IIdentity identity, IEnumerable<Claim> claims, string authenticationType, string nameType, string roleType)
        {
            // TODO - brentsch, should we have another constructor that takes ClaimsIdentity thereby bypassing the cast below?
            ClaimsIdentity claimsIdentity = identity as ClaimsIdentity;

            _authenticationType = !string.IsNullOrWhiteSpace(authenticationType) ? authenticationType : (identity != null ? identity.AuthenticationType : null);
            _nameClaimType = !string.IsNullOrEmpty(nameType) ? nameType : (claimsIdentity != null ? claimsIdentity._nameClaimType : DefaultNameClaimType);
            _roleClaimType = !string.IsNullOrEmpty(roleType) ? roleType : (claimsIdentity != null ? claimsIdentity._roleClaimType : DefaultRoleClaimType);

            if (claimsIdentity != null)
            {
                _label = claimsIdentity._label;
                _bootstrapContext = claimsIdentity._bootstrapContext;

                if (claimsIdentity.Actor != null)
                {
                    //
                    // Check if the Actor is circular before copying. That check is done while setting
                    // the Actor property and so not really needed here. But checking just for sanity sake
                    //
                    if (!IsCircular(claimsIdentity.Actor))
                    {
                        _actor = claimsIdentity.Actor;
                    }
                    else
                    {
                        throw new InvalidOperationException(SR.GetResourceString("InvalidOperationException_ActorGraphCircular", "Actor cannot be set so that circular directed graph will exist chaining the subjects together."));
                    }
                }
                SafeAddClaims(claimsIdentity._instanceClaims);
            }
            else
            {
                if (identity != null && !string.IsNullOrEmpty(identity.Name))
                {
                    SafeAddClaim(new Claim(_nameClaimType, identity.Name, ClaimValueTypes.String, DefaultIssuer, DefaultIssuer, this));
                }
            }

            if (claims != null)
            {
                SafeAddClaims(claims);
            }
        }

Same methods

ClaimsIdentity::ClaimsIdentity ( )
ClaimsIdentity::ClaimsIdentity ( System reader )
ClaimsIdentity::ClaimsIdentity ( System info, System context )
ClaimsIdentity::ClaimsIdentity ( System identity, System claims )
ClaimsIdentity::ClaimsIdentity ( System identity, System claims, string authenticationType, string nameType, string roleType )
ClaimsIdentity::ClaimsIdentity ( System claims )
ClaimsIdentity::ClaimsIdentity ( System claims, string authenticationType )
ClaimsIdentity::ClaimsIdentity ( System claims, string authenticationType, string nameType, string roleType )
ClaimsIdentity::ClaimsIdentity ( string authenticationType )
ClaimsIdentity::ClaimsIdentity ( string authenticationType, string nameType, string roleType )
ClaimsIdentity::ClaimsIdentity ( ) : System.Collections.Generic
ClaimsIdentity::ClaimsIdentity ( BinaryReader reader ) : System.Collections.Generic
ClaimsIdentity::ClaimsIdentity ( ClaimsIdentity other ) : System.Collections.Generic
ClaimsIdentity::ClaimsIdentity ( IEnumerable claims ) : System.Collections.Generic
ClaimsIdentity::ClaimsIdentity ( IEnumerable claims, string authenticationType ) : System.Collections.Generic
ClaimsIdentity::ClaimsIdentity ( IEnumerable claims, string authenticationType, string nameType, string roleType ) : System.Collections.Generic
ClaimsIdentity::ClaimsIdentity ( IIdentity identity ) : System.Collections.Generic
ClaimsIdentity::ClaimsIdentity ( IIdentity identity, IEnumerable claims ) : System.Collections.Generic
ClaimsIdentity::ClaimsIdentity ( SerializationInfo info ) : System.Collections.Generic
ClaimsIdentity::ClaimsIdentity ( SerializationInfo info, StreamingContext context ) : System.Collections.Generic
ClaimsIdentity::ClaimsIdentity ( string authenticationType ) : System.Collections.Generic
ClaimsIdentity::ClaimsIdentity ( string authenticationType, string nameType, string roleType ) : System.Collections.Generic