Esempio n. 1
0
        /// <summary>
        /// Override of the base class that reads a child element inside the RST
        /// </summary>
        /// <param name="reader">Reader pointing at an element to read inside the RST.</param>
        /// <param name="rst">The RequestSecurityToken element that is being populated from the reader.</param>
        /// <param name="context">Current Serialization context.</param>
        /// <exception cref="ArgumentNullException">Either reader or rst or context parameter is null.</exception>
        /// <exception cref="WSTrustSerializationException">Unable to deserialize the current parameter.</exception>
        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");
            }

            // special case SecondaryParameters, they cannot be embeded as per WS-Trust 1.3
            if (reader.IsStartElement(WSTrust13Constants.ElementNames.SecondaryParameters, WSTrust13Constants.NamespaceURI))
            {
                rst.SecondaryParameters = this.ReadSecondaryParameters(reader, context);
                return;
            }

            if (reader.IsStartElement(WSTrust13Constants.ElementNames.KeyWrapAlgorithm, WSTrust13Constants.NamespaceURI))
            {
                rst.KeyWrapAlgorithm = reader.ReadElementContentAsString();
                if (!UriUtil.CanCreateValidUri(rst.KeyWrapAlgorithm, UriKind.Absolute))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WSTrustSerializationException(SR.GetString(SR.ID3135, WSTrust13Constants.ElementNames.KeyWrapAlgorithm, WSTrust13Constants.NamespaceURI, rst.KeyWrapAlgorithm)));
                }

                return;
            }

            if (reader.IsStartElement(WSTrust13Constants.ElementNames.ValidateTarget, WSTrust13Constants.NamespaceURI))
            {
                if (!reader.IsEmptyElement)
                {
                    rst.ValidateTarget = new SecurityTokenElement(WSTrustSerializationHelper.ReadInnerXml(reader), context.SecurityTokenHandlers);
                }

                if (rst.ValidateTarget == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WSTrustSerializationException(SR.GetString(SR.ID3221)));
                }

                return;
            }

            WSTrustSerializationHelper.ReadRSTXml(reader, rst, context, WSTrustConstantsAdapter.Trust13);
        }
Esempio n. 2
0
        /// <summary>
        /// Special case for reading SecondaryParameters inside a WS-Trust 1.3 RST.  The specification states that a SecondaryParameters element
        /// cannot be inside a SecondaryParameters element.  Override this method to provide custom processing.
        /// </summary>
        /// <param name="reader">Reader pointing at the SecondaryParameters element inside the RST.</param>
        /// <param name="context">Current Serialization context.</param>
        /// <exception cref="ArgumentNullException">Either reader or context parameter is null.</exception>
        /// <exception cref="WSTrustSerializationException">An inner 'SecondaryParameter' element was found while processing the outer 'SecondaryParameter'.</exception>
        /// <returns>RequestSecurityToken that contains the SecondaryParameters found in the RST</returns>
        protected virtual RequestSecurityToken ReadSecondaryParameters(
            XmlReader reader,
            WSTrustSerializationContext context)
        {
            RequestSecurityToken secondaryParameters = CreateRequestSecurityToken();

            if (reader.IsEmptyElement)
            {
                reader.Read();
                reader.MoveToContent();
                return(secondaryParameters);
            }

            reader.ReadStartElement();
            while (reader.IsStartElement())
            {
                if (reader.IsStartElement(
                        WSTrust13Constants.ElementNames.KeyWrapAlgorithm, WSTrust13Constants.NamespaceURI))
                {
                    secondaryParameters.KeyWrapAlgorithm = reader.ReadElementContentAsString();
                    if (!UriUtil.CanCreateValidUri(secondaryParameters.KeyWrapAlgorithm, UriKind.Absolute))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                  new WSTrustSerializationException(
                                      SR.GetString(
                                          SR.ID3135,
                                          WSTrust13Constants.ElementNames.KeyWrapAlgorithm,
                                          WSTrust13Constants.NamespaceURI,
                                          secondaryParameters.KeyWrapAlgorithm)));
                    }
                }
                else if (reader.IsStartElement(
                             WSTrust13Constants.ElementNames.SecondaryParameters, WSTrust13Constants.NamespaceURI))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new WSTrustSerializationException(SR.GetString(SR.ID3130)));
                }
                else
                {
                    WSTrustSerializationHelper.ReadRSTXml(
                        reader,
                        secondaryParameters,
                        context,
                        WSTrustConstantsAdapter.GetConstantsAdapter(reader.NamespaceURI) ?? WSTrustConstantsAdapter.TrustFeb2005);
                }
            }

            reader.ReadEndElement();

            return(secondaryParameters);
        }
Esempio n. 3
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="rst">The request instance</param>
        /// <param name="writer">The writer to write to</param>
        /// <param name="context">Current Serialization context.</param>
        /// <exception cref="ArgumentNullException">Either rst or writer or context parameter is null.</exception>
        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");
            }

            // Write out the exisiting ones
            WSTrustSerializationHelper.WriteKnownRequestElement(rst, writer, context, this, WSTrustConstantsAdapter.Trust13);

            // Specific to WS-Trust 13
            if (!string.IsNullOrEmpty(rst.KeyWrapAlgorithm))
            {
                if (!UriUtil.CanCreateValidUri(rst.KeyWrapAlgorithm, UriKind.Absolute))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WSTrustSerializationException(SR.GetString(SR.ID3135, WSTrust13Constants.ElementNames.KeyWrapAlgorithm, WSTrust13Constants.NamespaceURI, rst.KeyWrapAlgorithm)));
                }

                this.WriteXmlElement(writer, WSTrust13Constants.ElementNames.KeyWrapAlgorithm, rst.KeyWrapAlgorithm, rst, context);
            }

            if (rst.SecondaryParameters != null)
            {
                this.WriteXmlElement(writer, WSTrust13Constants.ElementNames.SecondaryParameters, rst.SecondaryParameters, rst, context);
            }

            if (rst.ValidateTarget != null)
            {
                this.WriteXmlElement(writer, WSTrust13Constants.ElementNames.ValidateTarget, rst.ValidateTarget, rst, context);
            }
        }