//----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------- namespace System.IdentityModel.Protocols.WSTrust { using System.Xml; /// /// Base class for support of versions of WS-Trust request messages. /// public abstract class WSTrustRequestSerializer { /// /// When overriden in the derived class deserializes the RST from the XmlReader to a RequestSecurityToken object. /// /// XML reader over the RST /// Current Serialization context. /// RequestSecurityToken object if the deserialization was successful public abstract RequestSecurityToken ReadXml(XmlReader reader, WSTrustSerializationContext context); /// /// When overridden in the derived class reads a child element inside RST. /// /// Reader pointing at an element to read inside the RST. /// The RequestSecurityToken element that is being populated from the reader. /// Current Serialization context. public abstract void ReadXmlElement(XmlReader reader, RequestSecurityToken requestSecurityToken, WSTrustSerializationContext context); /// /// When overriden in the derived classs writes out the supported elements on the request object. /// /// The request instance /// The writer to write to /// Current Serialization context. public abstract void WriteKnownRequestElement(RequestSecurityToken requestSecurityToken, XmlWriter writer, WSTrustSerializationContext context); /// /// When overriden in the derived class serializes the given RequestSecurityToken into the XmlWriter /// /// RequestSecurityToken object to be serialized /// XML writer to serialize into /// Current Serialization context. public abstract void WriteXml(RequestSecurityToken request, XmlWriter writer, WSTrustSerializationContext context); /// /// When overridden in the derived class writes a child element inside the RST. /// /// Writer to which the RST is serialized. /// The Local name of the element to be written. /// The value of the element. /// The entire RST object that is being serialized. /// Current Serialization context. public abstract void WriteXmlElement(XmlWriter writer, string elementName, object elementValue, RequestSecurityToken requestSecurityToken, WSTrustSerializationContext context); /// /// Creates an instance of the RequestSecurityToken object that this class can Serialize or Deserialize. /// /// Instance of RequestSecurityToken object public virtual RequestSecurityToken CreateRequestSecurityToken() { return new RequestSecurityToken(); } /// /// Validates the RequestSecurityToken object that has been deserialized. /// /// The RequestSecurityToken object to Validate. /// An Issue Request for an Asymmetric Key did not specify UseKey. public virtual void Validate(RequestSecurityToken requestSecurityToken) { if (requestSecurityToken == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rst"); } // Validate the RequestSecurityToken required parameters. if ((StringComparer.Ordinal.Equals(requestSecurityToken.RequestType, RequestTypes.Issue) || requestSecurityToken.RequestType == null) && StringComparer.Ordinal.Equals(requestSecurityToken.KeyType, KeyTypes.Asymmetric) && ((requestSecurityToken.UseKey == null) || (requestSecurityToken.UseKey.SecurityKeyIdentifier == null && requestSecurityToken.UseKey.Token == null))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ID3091))); } } /// /// When implemented in the derived class checks if the given reader is positioned at a RequestSecurityToken element. /// /// The reader to read from. /// 'True' if the reader is positioned at an RST element that this serializer can read. public abstract bool CanRead(XmlReader reader); /// /// When overriden in the derived classs reads a custom element. /// /// The reader on the current element. /// Current Serialization context. protected virtual void ReadCustomElement(XmlReader reader, WSTrustSerializationContext context) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.ID2072, reader.LocalName))); } } }