//----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------- namespace System.IdentityModel.Protocols.WSTrust { using System.Xml; /// /// Class for deserializing a WS-Trust Feb 2005 RequestSecurityToken from an XmlReader /// public class WSTrustFeb2005RequestSerializer : WSTrustRequestSerializer { /// /// 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 /// The reader or context parameter is null /// There was an error parsing the RST public override RequestSecurityToken ReadXml(XmlReader reader, WSTrustSerializationContext context) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } return WSTrustSerializationHelper.CreateRequest(reader, context, this, WSTrustConstantsAdapter.TrustFeb2005); } /// /// Override of the base class that reads a child element inside the RST /// /// Reader pointing at an element to read inside the RST. /// The RequestSecurityToken element that is being populated from the reader. /// Current Serialization context. /// Either reader or rst or context parameter is null. /// Unable to deserialize the current parameter. public override void ReadXmlElement(XmlReader reader, RequestSecurityToken rst, WSTrustSerializationContext context) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } if (rst == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rst"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } WSTrustSerializationHelper.ReadRSTXml(reader, rst, context, WSTrustConstantsAdapter.TrustFeb2005); } /// /// Writes out the supported elements on the request object. Override this method if someone /// has sub-class the RequestSecurityToken class and added more property to it. /// /// The request instance /// The writer to write to /// Current Serialization context. /// Either rst or writer or context parameter is null. public override void WriteKnownRequestElement(RequestSecurityToken rst, XmlWriter writer, WSTrustSerializationContext context) { if (rst == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rst"); } if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } WSTrustSerializationHelper.WriteKnownRequestElement(rst, writer, context, this, WSTrustConstantsAdapter.TrustFeb2005); } /// /// Serializes the given RequestSecurityToken into the XmlWriter /// /// RequestSecurityToken object to be serialized /// XML writer to serialize into /// Current Serialization context. /// The request or writer or context parameter is null. public override void WriteXml(RequestSecurityToken request, XmlWriter writer, WSTrustSerializationContext context) { if (request == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("request"); } if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } WSTrustSerializationHelper.WriteRequest(request, writer, context, this, WSTrustConstantsAdapter.TrustFeb2005); } /// /// Override of the Base class method that writes a specific RST parameter to the outgoing stream. /// /// 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. /// Either writer or rst or context is null. /// elementName is null or an empty string. public override void WriteXmlElement(XmlWriter writer, string elementName, object elementValue, RequestSecurityToken rst, WSTrustSerializationContext context) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } if (string.IsNullOrEmpty(elementName)) { throw DiagnosticUtility.ThrowHelperArgumentNullOrEmptyString("elementName"); } if (rst == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rst"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } WSTrustSerializationHelper.WriteRSTXml(writer, elementName, elementValue, context, WSTrustConstantsAdapter.TrustFeb2005); } /// /// Checks if the given reader is positioned at a RequestSecurityToken element with namespace /// 'http://schemas.xmlsoap.org/ws/2005/02/trust' /// /// The reader to read from /// /// 'True' if the reader is positioned at a RequestSecurityToken element with namespace /// 'http://schemas.xmlsoap.org/ws/2005/02/trust'. /// /// The input argument is null. public override bool CanRead(XmlReader reader) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } return reader.IsStartElement(WSTrustFeb2005Constants.ElementNames.RequestSecurityToken, WSTrustFeb2005Constants.NamespaceURI); } } }