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에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET