ClaimsIdentity 类

定义

表示基于声明的标识。Represents a claims-based identity.

public ref class ClaimsIdentity : System::Security::Principal::IIdentity
public class ClaimsIdentity : System.Security.Principal.IIdentity
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class ClaimsIdentity : System.Security.Principal.IIdentity
type ClaimsIdentity = class
    interface IIdentity
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type ClaimsIdentity = class
    interface IIdentity
Public Class ClaimsIdentity
Implements IIdentity
继承
ClaimsIdentity
派生
属性
实现

注解

ClaimsIdentity类是基于声明的标识的具体实现; 即,声明集合描述的标识。The ClaimsIdentity class is a concrete implementation of a claims-based identity; that is, an identity described by a collection of claims. 声明是有关由颁发者创建的实体的声明,该实体描述了该实体的属性、权限或其他质量。A claim is a statement about an entity made by an issuer that describes a property, right, or some other quality of that entity. 此类实体称为声明的使用者。Such an entity is said to be the subject of the claim. 声明由 Claim 类表示。A claim is represented by the Claim class. 中包含的声明 ClaimsIdentity 描述对应标识表示的实体,并可用于做出授权和身份验证决定。The claims contained in a ClaimsIdentity describe the entity that the corresponding identity represents, and can be used to make authorization and authentication decisions. 基于声明的访问模型具有比专用于角色的更传统访问模型更多的优势。A claims-based access model has many advantages over more traditional access models that rely exclusively on roles. 例如,声明可以提供有关其所表示的标识的更丰富的信息,并且可以通过更具体的方式评估授权或身份验证。For example, claims can provide much richer information about the identity they represent and can be evaluated for authorization or authentication in a far more specific manner.

从 .NET Framework 4.5 开始,Windows Identity Foundation (WIF) 和基于声明的标识已完全集成到 .NET Framework 中。Beginning with .NET Framework 4.5, Windows Identity Foundation (WIF) and claims-based identity have been fully integrated into the .NET Framework. 这意味着,在 .NET Framework 中表示标识的许多类现在派生自 ClaimsIdentity ,并通过声明的集合描述其属性。This means that many classes that represent an identity in the .NET Framework now derive from ClaimsIdentity and describe their properties through a collection of claims. 这不同于以前版本的 .NET Framework,在这种情况下,这些类 IIdentity 直接实现接口。This is different from previous versions of the .NET Framework, in which, these classes implemented the IIdentity interface directly. 描述标识的声明集合可通过属性进行访问 ClaimsThe collection of claims that describe the identity can be accessed through the Claims property. ClaimsIdentity类提供多种方法用于查找和修改声明,并完全支持 (LINQ) 的语言集成查询。The ClaimsIdentity class provides several methods for finding and modifying claims and fully supports language integrated queries (LINQ). 在应用程序代码中, ClaimsIdentity 通常通过 ClaimsPrincipal 对象(例如返回的主体)访问对象 Thread.CurrentPrincipalIn application code, ClaimsIdentity objects are typically accessed through ClaimsPrincipal objects; for example, the principal returned by Thread.CurrentPrincipal.

备注

ClaimsPrincipalClaims 还具有属性。The ClaimsPrincipal class has a Claims property as well. 在大多数情况下,你应该通过 ClaimsPrincipal.Claims 集合而不是通过集合来访问用户的声明 ClaimsIn the majority of cases you should access the user's claims through the ClaimsPrincipal.Claims collection rather than through the Claims collection. ClaimsIdentity仅当主体包含多个 ClaimsIdentity ,并且需要评估或修改特定标识时,才需要访问单个的声明。You will need to access the claims of an individual ClaimsIdentity only in the cases where the principal contains more than one ClaimsIdentity and you need to evaluate or modify a specific identity.

重要

若要在集合中添加或删除声明 Claims ,调用方必须具有完全信任。To add or remove claims from the Claims collection, a caller must have full trust.

在基于声明的模型中, IIdentity.Name IPrincipal.IsInRole(String) 通过计算标识中包含的声明来实现属性和方法。In the claims-based model, the IIdentity.Name property and the IPrincipal.IsInRole(String) method are implemented by evaluating the claims contained by an identity. 基于声明的模型中的基本实现由 ClaimsIdentity.Name 属性和 ClaimsPrincipal.IsInRole 方法提供。The base implementations in the claims-based model are provided by the ClaimsIdentity.Name property and the ClaimsPrincipal.IsInRole method. 使用 NameClaimTypeRoleClaimType 属性可以指定在执行这些操作时应该用于评估标识所包含的声明的声明类型。The NameClaimType and RoleClaimType properties enable you to specify a claim type that should be used to evaluate the claims contained by the identity when performing these operations.

委托方案通过 Actor 和属性进行支持 BootstrapContextDelegation scenarios are supported through the Actor and BootstrapContext properties.

构造函数

ClaimsIdentity()

用空声称集合初始化 ClaimsIdentity 类的新实例。Initializes a new instance of the ClaimsIdentity class with an empty claims collection.

ClaimsIdentity(BinaryReader)

用指定的 BinaryReader 初始化 ClaimsIdentity 的实例。Initializes an instance of ClaimsIdentity with the specified BinaryReader.

ClaimsIdentity(ClaimsIdentity)

从现有 ClaimsIdentity 实例初始化 ClaimsIdentity 类的新实例。Initializes a new instance of the ClaimsIdentity class from an existing ClaimsIdentity instance.

ClaimsIdentity(IEnumerable<Claim>)

使用枚举集合 ClaimsIdentity 对象的初始化 Claim 类的新实例。Initializes a new instance of the ClaimsIdentity class using an enumerated collection of Claim objects.

ClaimsIdentity(IEnumerable<Claim>, String)

用指定的声称和身份验证类型初始化 ClaimsIdentity 类的新实例。Initializes a new instance of the ClaimsIdentity class with the specified claims and authentication type.

ClaimsIdentity(IEnumerable<Claim>, String, String, String)

用指定的声明、身份验证类型、名称声明类型、角色声明类型初始化 ClaimsIdentity 类的新实例。Initializes a new instance of the ClaimsIdentity class with the specified claims, authentication type, name claim type, and role claim type.

ClaimsIdentity(IIdentity)

初始化 ClaimsIdentity 类的新实例,该类表示具有指定的 IIdentity 用户。Initializes a new instance of the ClaimsIdentity class using the name and authentication type from the specified IIdentity.

ClaimsIdentity(IIdentity, IEnumerable<Claim>)

使用指定的 ClaimsIdentity 和类型提供程序初始化 IIdentity 类的新实例。Initializes a new instance of the ClaimsIdentity class using the specified claims and the specified IIdentity.

ClaimsIdentity(IIdentity, IEnumerable<Claim>, String, String, String)

从指定的 ClaimsIdentity 用指定的声明、身份验证的类型、名称声明类型、角色声明类型来初始化 IIdentity 类的新实例。Initializes a new instance of the ClaimsIdentity class from the specified IIdentity using the specified claims, authentication type, name claim type, and role claim type.

ClaimsIdentity(SerializationInfo)

从使用 ISerializable 创建的序列化流初始化 ClaimsIdentity 类的新实例。Initializes a new instance of the ClaimsIdentity class from a serialized stream created by using ISerializable.

ClaimsIdentity(SerializationInfo, StreamingContext)

从使用 ISerializable 创建的序列化流初始化 ClaimsIdentity 类的新实例。Initializes a new instance of the ClaimsIdentity class from a serialized stream created by using ISerializable.

ClaimsIdentity(String)

用空的声明集合和指定的身份验证类型初始化 ClaimsIdentity 类的新实例。Initializes a new instance of the ClaimsIdentity class with an empty claims collection and the specified authentication type.

ClaimsIdentity(String, String, String)

用指定的声明、身份验证的类型、名称声明类型、角色声明类型来初始化 ClaimsIdentity 类的新实例。Initializes a new instance of the ClaimsIdentity class with the specified authentication type, name claim type, and role claim type.

字段

DefaultIssuer

默认颁发者,“地方当局”。The default issuer; "LOCAL AUTHORITY".

DefaultNameClaimType

默认名称声明类型;NameThe default name claim type; Name.

DefaultRoleClaimType

默认角色声明类型;RoleThe default role claim type; Role.

属性

Actor

获取或设置被授予委派权利的调用方的标识。Gets or sets the identity of the calling party that was granted delegation rights.

AuthenticationType

获取身份验证类型。Gets the authentication type.

BootstrapContext

获取或设置用于创建此声明标识的令牌。Gets or sets the token that was used to create this claims identity.

Claims

获取与此声明标识关联的声明。Gets the claims associated with this claims identity.

CustomSerializationData

包含派生类型提供的任何其他数据。Contains any additional data provided by a derived type. 通常在调用 WriteTo(BinaryWriter, Byte[]) 时设置。Typically set when calling WriteTo(BinaryWriter, Byte[]).

IsAuthenticated

获取一个值,该值指示是否验证了标识。Gets a value that indicates whether the identity has been authenticated.

Label

获取或设置此声明标识的标签。Gets or sets the label for this claims identity.

Name

获取此声明标识的名称。Gets the name of this claims identity.

NameClaimType

获取用于确定为此声明标识的 Name 属性提供值的声明的声明类型。Gets the claim type that is used to determine which claims provide the value for the Name property of this claims identity.

RoleClaimType

获取将解释为此声明标识中声明的 .NET 角色的声明类型。Gets the claim type that will be interpreted as a .NET role among the claims in this claims identity.

方法

AddClaim(Claim)

添加单个声明到此声明标识。Adds a single claim to this claims identity.

AddClaims(IEnumerable<Claim>)

添加声明列表到此声明标识。Adds a list of claims to this claims identity.

Clone()

返回从此声明标识中复制的新 ClaimsIdentityReturns a new ClaimsIdentity copied from this claims identity.

CreateClaim(BinaryReader)

为派生类型提供扩展点以创建自定义 ClaimProvides an extensibility point for derived types to create a custom Claim.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FindAll(Predicate<Claim>)

检索所有与指定谓词相匹配的声明。Retrieves all of the claims that are matched by the specified predicate.

FindAll(String)

检索所有有指定声明类型的声明。Retrieves all of the claims that have the specified claim type.

FindFirst(Predicate<Claim>)

检所由指定谓词匹配的第一个声明。Retrieves the first claim that is matched by the specified predicate.

FindFirst(String)

检索有指定声明类型的第一个声明。Retrieves the first claim with the specified claim type.

GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetObjectData(SerializationInfo, StreamingContext)

用序列化当前SerializationInfo 对象所需的数据来填充 ClaimsIdentityPopulates the SerializationInfo with data needed to serialize the current ClaimsIdentity object.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
HasClaim(Predicate<Claim>)

确定该声明标识是否拥有与指定条件相匹配的声明。Determines whether this claims identity has a claim that is matched by the specified predicate.

HasClaim(String, String)

确定该声明标识是否具备指定声明类型和值。Determines whether this claims identity has a claim with the specified claim type and value.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
RemoveClaim(Claim)

尝试从声明标识中移除一个声明。Attempts to remove a claim from the claims identity.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
TryRemoveClaim(Claim)

尝试从声明标识中移除一个声明。Attempts to remove a claim from the claims identity.

WriteTo(BinaryWriter)

使用 BinaryWriter 序列化。Serializes using a BinaryWriter.

WriteTo(BinaryWriter, Byte[])

使用 BinaryWriter 序列化。Serializes using a BinaryWriter.

适用于

另请参阅