Share via


SamlAttribute 類別

定義

表示與 SamlAttributeStatement 之主體關聯的屬性。

public ref class SamlAttribute
public class SamlAttribute
type SamlAttribute = class
Public Class SamlAttribute
繼承
SamlAttribute

範例

protected override Collection<SamlAttribute> GetIssuedClaims(RequestSecurityToken RST)
{
    EndpointAddress rstAppliesTo = RST.AppliesTo;

    if (rstAppliesTo == null)
    {
        throw new InvalidOperationException("No AppliesTo EndpointAddress in RequestSecurityToken");
    }

    string bookName = rstAppliesTo.Headers.FindHeader(Constants.BookNameHeaderName, Constants.BookNameHeaderNamespace).GetValue<string>();
    if (string.IsNullOrEmpty(bookName))
        throw new FaultException("The book name was not specified in the RequestSecurityToken");

    EnsurePurchaseLimitSufficient(bookName);

    Collection<SamlAttribute> samlAttributes = new Collection<SamlAttribute>();

    foreach (ClaimSet claimSet in ServiceSecurityContext.Current.AuthorizationContext.ClaimSets)
    {
        // Copy Name claims from the incoming credentials into the set of claims to be issued.
        IEnumerable<Claim> nameClaims = claimSet.FindClaims(ClaimTypes.Name, Rights.PossessProperty);
        if (nameClaims != null)
        {
            foreach (Claim nameClaim in nameClaims)
            {
                samlAttributes.Add(new SamlAttribute(nameClaim));
            }
        }
    }
    // Add a purchase authorized claim.
    samlAttributes.Add(new SamlAttribute(new Claim(Constants.PurchaseAuthorizedClaim, bookName, Rights.PossessProperty)));
    return samlAttributes;
}
Protected Overrides Function GetIssuedClaims(ByVal RST As RequestSecurityToken) As Collection(Of SamlAttribute)

    Dim rstAppliesTo As EndpointAddress = RST.AppliesTo

    If rstAppliesTo Is Nothing Then
        Throw New InvalidOperationException("No AppliesTo EndpointAddress in RequestSecurityToken")
    End If

    Dim bookName As String = rstAppliesTo.Headers.FindHeader(Constants.BookNameHeaderName, Constants.BookNameHeaderNamespace).GetValue(Of String)()

    If String.IsNullOrEmpty(bookName) Then
        Throw New FaultException("The book name was not specified in the RequestSecurityToken")
    End If
    EnsurePurchaseLimitSufficient(bookName)

    Dim samlAttributes As New Collection(Of SamlAttribute)()

    Dim claimSet As ClaimSet
    For Each claimSet In ServiceSecurityContext.Current.AuthorizationContext.ClaimSets
        ' Copy Name claims from the incoming credentials into the set of claims we're going to issue
        Dim nameClaims As IEnumerable(Of Claim) = claimSet.FindClaims(ClaimTypes.Name, Rights.PossessProperty)
        If Not (nameClaims Is Nothing) Then
            Dim nameClaim As Claim
            For Each nameClaim In nameClaims
                samlAttributes.Add(New SamlAttribute(nameClaim))
            Next nameClaim
        End If
    Next claimSet
    ' add a purchase authorized claim
    samlAttributes.Add(New SamlAttribute(New Claim(Constants.PurchaseAuthorizedClaim, bookName, Rights.PossessProperty)))
    Return samlAttributes

End Function

備註

SamlAttribute 類別會對應到已在 OASIS SAML 1.1 規格中定義之 <saml:Attribute> XML 項目。

執行個體會包含 之主體的 宣告。 例如,SamlAttribute 可能會包含 Over21 宣告,這個宣告的型別會指定於 Namespace 屬性中,而宣告的資源會指定成為在 AttributeValues 屬性中之集合的一個成員。 當呼叫 CreatePolicy 方法時,這個 Over21 宣告會加入 SamlAttributeStatement 傳回的授權原則中。 當 AttributeValues 屬性包含多個項目時,則每個項目都會傳回一個宣告。

SamlAttribute SAML 物件階層中的位置為:

SamlSecurityToken

SamlAssertion

SamlAttributeStatement

SamlAttribute

建構函式

SamlAttribute()

初始化 SamlAttribute 類別的新執行個體。

SamlAttribute(Claim)

使用指定的宣告,初始化 SamlAttribute 類別的新執行個體。

SamlAttribute(String, String, IEnumerable<String>)

使用指定的屬性名稱、XML 命名空間 (Namespace) 以及屬性值,初始化 SamlAttribute 類別的新執行個體。

屬性

AttributeValues

取得 SAML 屬性的屬性值集合。

AttributeValueXsiType

取得或設定 SAML 屬性中所包含值的 xsi:type。

IsReadOnly

取得值,這個值會指出這個執行個體的屬性是否是唯讀的。

Name

取得或設定 SAML 屬性的名稱。

Namespace

取得或設定其中定義了 SAML 屬性名稱的 XML 命名空間。

OriginalIssuer

取得或設定表示 SAML 屬性之 OriginalIssuer 的字串。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
ExtractClaims()

取得這個 SAML 屬性所表示的宣告集合。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MakeReadOnly()

使得這個執行個體成為唯讀的。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ReadXml(XmlDictionaryReader, SamlSerializer, SecurityTokenSerializer, SecurityTokenResolver)

從指定的 XML 讀取器讀取 SAML 屬性。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
WriteXml(XmlDictionaryWriter, SamlSerializer, SecurityTokenSerializer)

將 SAML 屬性寫入至指定的 XML 序列化程式。

適用於