WSSecurityTokenSerializer クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
WS-Security、WS-Trust、および WS-SecureConversation セキュリティ仕様で定義されているセキュリティ トークン、セキュリティ キー識別子、およびセキュリティ キー識別句のシリアル化と逆シリアル化に使用されるクラス。
public ref class WSSecurityTokenSerializer : System::IdentityModel::Selectors::SecurityTokenSerializer
public class WSSecurityTokenSerializer : System.IdentityModel.Selectors.SecurityTokenSerializer
type WSSecurityTokenSerializer = class
inherit SecurityTokenSerializer
Public Class WSSecurityTokenSerializer
Inherits SecurityTokenSerializer
- 継承
例
次のコードは、このクラスのユーザーによるオーバーライドを示しています。
public class CreditCardSecurityTokenSerializer : WSSecurityTokenSerializer
{
public CreditCardSecurityTokenSerializer(SecurityTokenVersion version) : base() { }
protected override bool CanReadTokenCore(XmlReader reader)
{
XmlDictionaryReader localReader = XmlDictionaryReader.CreateDictionaryReader(reader);
if (reader == null)
{
throw new ArgumentNullException("reader");
}
if (reader.IsStartElement(Constants.CreditCardTokenName, Constants.CreditCardTokenNamespace))
{
return true;
}
return base.CanReadTokenCore(reader);
}
protected override SecurityToken ReadTokenCore(XmlReader reader, SecurityTokenResolver tokenResolver)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
if (reader.IsStartElement(Constants.CreditCardTokenName, Constants.CreditCardTokenNamespace))
{
string id = reader.GetAttribute(Constants.Id, Constants.WsUtilityNamespace);
reader.ReadStartElement();
// Read the credit card number.
string creditCardNumber = reader.ReadElementString(Constants.CreditCardNumberElementName, Constants.CreditCardTokenNamespace);
// Read the expiration date.
string expirationTimeString = reader.ReadElementString(Constants.CreditCardExpirationElementName, Constants.CreditCardTokenNamespace);
DateTime expirationTime = XmlConvert.ToDateTime(expirationTimeString, XmlDateTimeSerializationMode.Utc);
// Read the issuer of the credit card.
string creditCardIssuer = reader.ReadElementString(Constants.CreditCardIssuerElementName, Constants.CreditCardTokenNamespace);
reader.ReadEndElement();
CreditCardInfo cardInfo = new CreditCardInfo(creditCardNumber, creditCardIssuer, expirationTime);
return new CreditCardToken(cardInfo, id);
}
else
{
return WSSecurityTokenSerializer.DefaultInstance.ReadToken(reader, tokenResolver);
}
}
protected override bool CanWriteTokenCore(SecurityToken token)
{
if (token is CreditCardToken)
{
return true;
}
else
{
return base.CanWriteTokenCore(token);
}
}
protected override void WriteTokenCore(XmlWriter writer, SecurityToken token)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
if (token == null)
{
throw new ArgumentNullException("token");
}
CreditCardToken c = token as CreditCardToken;
if (c != null)
{
writer.WriteStartElement(Constants.CreditCardTokenPrefix, Constants.CreditCardTokenName, Constants.CreditCardTokenNamespace);
writer.WriteAttributeString(Constants.WsUtilityPrefix, Constants.Id, Constants.WsUtilityNamespace, token.Id);
writer.WriteElementString(Constants.CreditCardNumberElementName, Constants.CreditCardTokenNamespace, c.CardInfo.CardNumber);
writer.WriteElementString(Constants.CreditCardExpirationElementName, Constants.CreditCardTokenNamespace, XmlConvert.ToString(c.CardInfo.ExpirationDate, XmlDateTimeSerializationMode.Utc));
writer.WriteElementString(Constants.CreditCardIssuerElementName, Constants.CreditCardTokenNamespace, c.CardInfo.CardIssuer);
writer.WriteEndElement();
writer.Flush();
}
else
{
base.WriteTokenCore(writer, token);
}
}
}
Public Class CreditCardSecurityTokenSerializer
Inherits WSSecurityTokenSerializer
Public Sub New(ByVal version As SecurityTokenVersion)
MyBase.New()
End Sub
Protected Overrides Function CanReadTokenCore(ByVal reader As XmlReader) As Boolean
Dim localReader = XmlDictionaryReader.CreateDictionaryReader(reader)
If reader Is Nothing Then
Throw New ArgumentNullException("reader")
End If
If reader.IsStartElement(Constants.CreditCardTokenName, _
Constants.CreditCardTokenNamespace) Then
Return True
End If
Return MyBase.CanReadTokenCore(reader)
End Function
Protected Overrides Function ReadTokenCore(ByVal reader As XmlReader, _
ByVal tokenResolver As SecurityTokenResolver) As SecurityToken
If reader Is Nothing Then
Throw New ArgumentNullException("reader")
End If
If reader.IsStartElement(Constants.CreditCardTokenName, _
Constants.CreditCardTokenNamespace) Then
Dim id = reader.GetAttribute(Constants.Id, _
Constants.WsUtilityNamespace)
reader.ReadStartElement()
' Read the credit card number.
Dim creditCardNumber = reader.ReadElementString(Constants.CreditCardNumberElementName, _
Constants.CreditCardTokenNamespace)
' Read the expiration date.
Dim expirationTimeString = reader.ReadElementString(Constants.CreditCardExpirationElementName, _
Constants.CreditCardTokenNamespace)
Dim expirationTime As DateTime = XmlConvert.ToDateTime(expirationTimeString, _
XmlDateTimeSerializationMode.Utc)
' Read the issuer of the credit card.
Dim creditCardIssuer = reader.ReadElementString(Constants.CreditCardIssuerElementName, _
Constants.CreditCardTokenNamespace)
reader.ReadEndElement()
Dim cardInfo As New CreditCardInfo(creditCardNumber, _
creditCardIssuer, _
expirationTime)
Return New CreditCardToken(cardInfo, id)
Else
Return WSSecurityTokenSerializer.DefaultInstance.ReadToken(reader, _
tokenResolver)
End If
End Function
Protected Overrides Function CanWriteTokenCore(ByVal token As SecurityToken) As Boolean
If TypeOf token Is CreditCardToken Then
Return True
Else
Return MyBase.CanWriteTokenCore(token)
End If
End Function
Protected Overrides Sub WriteTokenCore(ByVal writer As XmlWriter, _
ByVal token As SecurityToken)
If writer Is Nothing Then
Throw New ArgumentNullException("writer")
End If
If token Is Nothing Then
Throw New ArgumentNullException("token")
End If
Dim c = TryCast(token, CreditCardToken)
If c IsNot Nothing Then
With writer
.WriteStartElement(Constants.CreditCardTokenPrefix, _
Constants.CreditCardTokenName, _
Constants.CreditCardTokenNamespace)
.WriteAttributeString(Constants.WsUtilityPrefix, _
Constants.Id, _
Constants.WsUtilityNamespace, _
token.Id)
.WriteElementString(Constants.CreditCardNumberElementName, _
Constants.CreditCardTokenNamespace, _
c.CardInfo.CardNumber)
.WriteElementString(Constants.CreditCardExpirationElementName, _
Constants.CreditCardTokenNamespace, _
XmlConvert.ToString(c.CardInfo.ExpirationDate, _
XmlDateTimeSerializationMode.Utc))
.WriteElementString(Constants.CreditCardIssuerElementName, _
Constants.CreditCardTokenNamespace, _
c.CardInfo.CardIssuer)
.WriteEndElement()
.Flush()
End With
Else
MyBase.WriteTokenCore(writer, token)
End If
End Sub
End Class
コンストラクター
プロパティ
DefaultInstance |
このクラスの既定のインスタンスを取得します。 |
EmitBspRequiredAttributes |
BSP の必須の属性を出力するかどうかを示す値を取得します。 |
MaximumKeyDerivationLabelLength |
キー派生最大ラベル長を取得します。 |
MaximumKeyDerivationNonceLength |
キー派生最大 nonce 長を取得します。 |
MaximumKeyDerivationOffset |
キー派生最大オフセットを取得します。 |
SecurityVersion |
セキュリティ バージョンを取得します。 |
メソッド
適用対象
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET