Policy.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / Policy.cs / 1 / Policy.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------
//
// Presharp uses the c# pragma mechanism to supress its warnings. 
// These are not recognised by the base compiler so we need to explictly
// disable the following warnings. See http://winweb/cse/Tools/PREsharp/userguide/default.asp 
// for details. 
//
#pragma warning disable 1634, 1691      // unknown message, unknown pragma 



namespace Microsoft.InfoCards 
{
    using System; 
    using System.IO; 
    using System.Xml;
    using System.Text; 
    using System.Diagnostics;
    using System.ServiceModel;
    using System.Globalization;
    using System.Collections.Generic; 

    using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace; 
 
    internal class Policy
    { 

        string                      m_policyXml                 = String.Empty;                 // A copy of the incoming xml from which this Policy instance was parsed.
        string[]                    m_requiredClaimUris         = null;                         // Claims that should be in the security token as specified by the RP's security policy
        string[]                    m_optionalClaimUris         = null;                         // Claims that should be in the security token as specified by the RP's security policy, but are marked as Optional 

        UInt32                      m_keySize                   = 0;                            // The key size requested by the RP's security policy 
        bool                        m_keySizeSpecified          = false;                        // A bool that tracks if the RP's security policy specified a key size 
        bool                        m_keyTypeSpecified          = false;                        // A bool that tracks if the RP's security policy specified a key type
        // The key type specified by the RP's security policy. Set default key type to asymmetric ( it supports unscoped tokens ). 
        SecurityKeyTypeInternal     m_keyType                   = SecurityKeyTypeInternal.AsymmetricKey;

        string                      m_requestType               = null;                         // The type of request specified by the RP's security policy
        MemoryStream                m_unprocessedPolicyElements = null;                         // Holds all elements from the RP's security policy that are not explicitly read by the Cardspace code 
        OptionalRstParameters       m_optionalRstParams         = new OptionalRstParameters();  // Holds the optional parameters from the RP's security policy (eg Token type )
        EndpointAddress             m_policyAppliesToEpr        = null;                         // The applies to specified in RP's policy  /* SSS_WARNINGS_OFF */ 
        bool                        m_nonWhiteListElementFound  = false; 
        List                m_nonWhiteListElements      = new List();			/* SSS_WARNINGS_ON */
        ProtocolProfile             m_protocolProfile           = null; 

        private Policy()
        {
        } 

        public Policy( string originalPolicyXml, string rstPolicyXml ) 
        { 
            m_policyXml = originalPolicyXml;
            ParsePolicyXml( rstPolicyXml ); 
        }

        //
        // Constructor for creating a merged policy. 
        //
        public static Policy CreateMergedPolicy( string originalPolicyXml, Policy primary, Policy secondary ) 
        { 
            Policy merged = new Policy();
 
            merged.m_policyXml = originalPolicyXml;

            //
            // populate the merged policy with values from Primary whenever possible. 
            //
 
            // 
            // m_policyXml is the serialized string representation of this instance, hence we will need to
            // re-serialize this instance after all the other fields are populated. 
            //
            merged.m_requiredClaimUris = ( null != primary.m_requiredClaimUris ) ? primary.m_requiredClaimUris : secondary.m_requiredClaimUris;
            merged.m_optionalClaimUris = ( null != primary.m_optionalClaimUris ) ? primary.m_optionalClaimUris : secondary.m_optionalClaimUris;
            merged.m_requestType = ( !String.IsNullOrEmpty( primary.m_requestType ) ) ? primary.m_requestType : secondary.m_requestType; 

            // 
            // We always use the unprocessed policy elements from the primary policy. 
            //
            merged.m_unprocessedPolicyElements = primary.m_unprocessedPolicyElements; 
            merged.m_policyAppliesToEpr = ( null != primary.m_policyAppliesToEpr ) ? primary.m_policyAppliesToEpr : secondary.m_policyAppliesToEpr;

            merged.m_keySize = primary.m_keySizeSpecified ? primary.m_keySize : secondary.m_keySize;
            merged.m_keyType = primary.m_keyTypeSpecified ? primary.m_keyType : secondary.m_keyType;    /* SSS_WARNINGS_OFF */ 

            merged.m_nonWhiteListElements = new List(); 
 
            merged.m_nonWhiteListElementFound = primary.m_nonWhiteListElementFound || secondary.m_nonWhiteListElementFound;
 
            if( primary.m_nonWhiteListElementFound )
            {
                merged.m_nonWhiteListElements.AddRange( primary.m_nonWhiteListElements );
            } 

            if( secondary.m_nonWhiteListElementFound ) 
            { 
                merged.m_nonWhiteListElements.AddRange( secondary.m_nonWhiteListElements );
            }												/* SSS_WARNINGS_ON */ 

            //
            // Always use the protocol profile from the primary policy as this element is garaunteed to be populated.
            // 
            IDT.Assert( ( null != primary.m_protocolProfile ), "Received Null Protocol Profile in the Primary Policy" );
            merged.m_protocolProfile = primary.ProtocolVersionProfile; 
 
            //
            // Merged the values in the optional RST Params 
            //
            merged.m_optionalRstParams = OptionalRstParameters.CreateMergedParameters( primary.OptionalRstParams, secondary.OptionalRstParams );

            return merged; 
        }
 
        public string RequestType 
        {
            get { return m_requestType; } 
        }

        public string PolicyXml
        { 
            get { return m_policyXml; }
        } 
 
        public OptionalRstParameters OptionalRstParams
        { 
            get { return m_optionalRstParams; }
        }

        public string[] RequiredClaims 
        {
            get { return m_requiredClaimUris; } 
        } 
        public string[] OptionalClaims
        { 
            get { return m_optionalClaimUris; }
        }

        public SecurityKeyTypeInternal KeyType 
        {
            get 
            { 
                return m_keyType;
            } 
        }

        public bool KeyTypeSpecified
        { 
            get
            { 
                return m_keyTypeSpecified; 
            }
        } 

        public EndpointAddress PolicyAppliesTo
        {
            get 
            {
                return m_policyAppliesToEpr; 
            } 
        }
 
        public MemoryStream UnprocessedPolicyElements
        {
            get { return m_unprocessedPolicyElements; }
        } 

        public bool KeySizeSpecified 
        { 
            get
            { 
                return m_keySizeSpecified;
            }
        }
 
        public uint KeySize
        { 
            get { return m_keySize; } 
        }							/* SSS_WARNINGS_OFF */
 
        public bool NonWhiteListElementsFound
        {
            get { return m_nonWhiteListElementFound; }
        } 

        public List NonWhiteListElements 
        { 
            get { return m_nonWhiteListElements; }
        }							/* SSS_WARNINGS_ON */ 

        public ProtocolProfile ProtocolVersionProfile
        {
            get 
            {
                return m_protocolProfile; 
            } 
        }
 

        //
        // Summary:
        // Parses the XML of the m_policyXml in to the correct properties. 
        //
        // The following list is parsed 
        // 
        // wsp:AppliesTo
        // wst:SignatureAlgorithm 
        // wst:EncryptionAlgorithm
        // wst:CanonicalizationAlgorithm
        // wst:KeyType
        // wst:KeySize - for asymmetric keys only the size of 2048 is accepted 
        // wst:Claims
        // wst:SignWith 
        // wst:EncryptWith 
        // wst:RequestType
        // wst:TokenType 
        //
        public void ParsePolicyXml( string policyXml )
        {
            XmlReader reader = InfoCardSchemas.CreateReader( policyXml ); 

            try 
            { 
                //
                // If we've already read past the node that we were processing 
                // OR there is more stuff to read.
                // Worst case when we read past current element is wsp:policy end element
                // as we wrapped the incoming policy elements in that.
                // 
                m_protocolProfile = new ProtocolProfile( policyXml );
 
                bool isEmptyElement = reader.IsEmptyElement; 

                reader.ReadStartElement(); 

                if( !isEmptyElement )
                {
                    while( reader.IsStartElement() ) 
                    {
                        if( InfoCardConstants.DoesPolicyElementsToBeProcessedListContain( reader.NamespaceURI, reader.LocalName ) ) 
                        { 
                            bool bReadEndElement = false;
 
                            //
                            // WSTrust Elements
                            //
                            if( reader.IsStartElement( ProtocolVersionProfile.WSTrust.SignatureAlgorithm, ProtocolVersionProfile.WSTrust.Namespace ) ) 
                            {
                                ReadSignatureAlgorithm( reader ); 
                                bReadEndElement = true; 
                            }
                            else if( reader.IsStartElement( ProtocolVersionProfile.WSTrust.EncryptionAlgorithm, ProtocolVersionProfile.WSTrust.Namespace ) ) 
                            {
                                ReadEncryptionAlgorithm( reader );
                                bReadEndElement = true;
                            } 
                            else if( reader.IsStartElement( ProtocolVersionProfile.WSTrust.CanonicalizationAlgorithm, ProtocolVersionProfile.WSTrust.Namespace ) )
                            { 
                                ReadCanonicalizationAlgorithm( reader ); 
                                bReadEndElement = true;
                            } 
                            else if( reader.IsStartElement( ProtocolVersionProfile.WSTrust.SignWith, ProtocolVersionProfile.WSTrust.Namespace ) )
                            {
                                ReadSignWith( reader );
                                bReadEndElement = true; 
                            }
                            else if( reader.IsStartElement( ProtocolVersionProfile.WSTrust.ClaimsElement, ProtocolVersionProfile.WSTrust.Namespace ) ) 
                            { 
                                ReadClaims( reader );
                                bReadEndElement = true; 
                            }
                            else if( reader.IsStartElement( ProtocolVersionProfile.WSTrust.TokenType, ProtocolVersionProfile.WSTrust.Namespace ) )
                            {
                                ReadTokenType( reader ); 
                                bReadEndElement = true;
                            } 
                            else if( reader.IsStartElement( ProtocolVersionProfile.WSTrust.KeyType, ProtocolVersionProfile.WSTrust.Namespace ) ) 
                            {
                                ReadKeyType( reader ); 
                                bReadEndElement = true;
                            }
                            else if( reader.IsStartElement( ProtocolVersionProfile.WSTrust.KeySize, ProtocolVersionProfile.WSTrust.Namespace ) )
                            { 
                                ReadKeySize( reader );
                                bReadEndElement = true; 
                            } 
                            else if( reader.IsStartElement( ProtocolVersionProfile.WSTrust.EncryptWith, ProtocolVersionProfile.WSTrust.Namespace ) )
                            { 
                                ReadEncryptWith( reader );
                                bReadEndElement = true;
                            }
                            else if( reader.IsStartElement( ProtocolVersionProfile.WSTrust.RequestType, ProtocolVersionProfile.WSTrust.Namespace ) ) 
                            {
                                ReadRequestType( reader ); 
                                bReadEndElement = true; 
                            }
 
                            //
                            // WSTrust 1.3 specific elements.
                            //
                            else if( ( XmlNames.WSSpecificationVersion.WSTrustOasis2007 == ProtocolVersionProfile.WSTrust.Version ) && 
                                    reader.IsStartElement( ProtocolVersionProfile.WSTrust.SecondaryParameters, ProtocolVersionProfile.WSTrust.Namespace ) )
                            { 
                                // 
                                // The WSTrust 1.3 specification introduced this element as optional for an STS to consume for the purposes of verifying
                                // the claims originating from the RP vs. the client. 
                                //
                                ReadSecondaryParameters( reader );
                            }
                            else if( ( XmlNames.WSSpecificationVersion.WSTrustOasis2007 == ProtocolVersionProfile.WSTrust.Version ) && 
                                    reader.IsStartElement( ProtocolVersionProfile.WSTrust.KeyWrapAlgorithm, ProtocolVersionProfile.WSTrust.Namespace ) )
                            { 
                                ReadKeyWrapAlgorithm( reader ); 
                                bReadEndElement = true;
                            } 

                            //
                            // WSPolicy Elements
                            // 
                            else if( reader.IsStartElement( ProtocolVersionProfile.WSPolicy.AppliesTo, ProtocolVersionProfile.WSPolicy.Namespace ) )
                            { 
                                ReadAppliesTo( reader ); 
                                bReadEndElement = true;
                            } 
                            else
                            {
                                reader.Skip();
                            } 

                            if( bReadEndElement ) 
                            { 
                                reader.ReadEndElement();
                            } 
                        }

                        else					/* SSS_WARNINGS_OFF */
                        { 
                            if( !InfoCardConstants.DoesLocalTokenFactoryWhiteListContain( reader.NamespaceURI, reader.LocalName ) )
                            { 
                                m_nonWhiteListElementFound = true; 
                                m_nonWhiteListElements.Add( reader.LocalName );
                            } 
                            CopyUnprocessedPolicyElements( reader );
                        }

                    } 
                    reader.ReadEndElement();
                } 
            }							/* SSS_WARNINGS_ON */ 
            catch( FormatException fe )
            { 
                //
                // Encompasses UriFormatException as well.
                //
                throw IDT.ThrowHelperError( new PolicyValidationException( 
                    SR.GetString( SR.InvalidPolicySpecified ), fe ) );
 
            } 
            catch( XmlException xe )
            { 
                throw IDT.ThrowHelperError( new PolicyValidationException(
                    SR.GetString( SR.InvalidPolicySpecified ), xe ) );
            }
            catch( InvalidOperationException ioe ) 
            {
                throw IDT.ThrowHelperError( new PolicyValidationException( 
                    SR.GetString( SR.InvalidPolicySpecified ), ioe ) ); 
            }
        } 

        //
        // Summary:
        // Reads the required claims portion of policy. 
        //
        // Remarks: 
        // Expects to be called with an XmlReader positioned on the  element. 
        //
        private void ReadClaims(XmlReader reader) 
        {
            List requiredClaims = new List();
            List optionalClaims = new List();
 
            IDT.ThrowInvalidArgumentConditional(
                    ProtocolVersionProfile.WSTrust.ClaimsElement != reader.LocalName || 
                    ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI, 
                    reader.LocalName );
 
            if( XmlNodeType.Element != reader.NodeType )
            {
                return;
            } 

            if( reader.IsEmptyElement ) 
            { 
                throw IDT.ThrowHelperError( new PolicyValidationException( SR.GetString( SR.NoClaimsFoundInPolicy ) ) );
            } 

            //
            // We should already be at the claims element, so we will
            //   performing the next read should 
            //
            if( reader.IsStartElement( ProtocolVersionProfile.WSTrust.ClaimsElement, ProtocolVersionProfile.WSTrust.Namespace ) ) 
            { 
                if( reader.IsEmptyElement )
                { 
                    reader.Read(); //read end of claims element
                }
                else
                { 
                    reader.Read();
                    while( reader.IsStartElement() ) 
                    { 
                        if( reader.IsStartElement( XmlNames.WSIdentity.ClaimElement, XmlNames.WSIdentity.Namespace ) )
                        { 
                            if( XmlNodeType.EndElement == reader.NodeType )
                            {
                                break;
                            } 

                            // 
                            // Look for the qualified name. 
                            //
                            string attributeValue = reader.GetAttribute( 
                                                            XmlNames.WSIdentity.UriAttribute,
                                                            XmlNames.WSIdentity.Namespace );

                            // 
                            // Look for the unqualified name.
                            // 
                            if( String.IsNullOrEmpty( attributeValue ) ) 
                            {
                                attributeValue = reader.GetAttribute( XmlNames.WSIdentity.UriAttribute ); 
                            }

                            if( String.IsNullOrEmpty( attributeValue ) )
                            { 
                                throw IDT.ThrowHelperError( new PolicyValidationException( SR.GetString( SR.ServiceInvalidClaimUri ) ) );
                            } 
 
                            string optionalValue = reader.GetAttribute( XmlNames.WSIdentity.OptionalAttribute );
                            bool isOptional = false; 

                            if( !String.IsNullOrEmpty( optionalValue ) )
                            {
                                // 
                                // FYI: If it is anything other than 0, 1, true, or false,
                                // schema validation would have already failed. 
                                // 
                                isOptional = XmlConvert.ToBoolean( optionalValue );
                            } 

                            //
                            // Add the value.
                            // 

                            // 
                            // Check if the value already exists 
                            //
                            bool foundInOptional = false; 
                            bool found = false;
                            foreach( string clm in requiredClaims )
                            {
                                if( clm == attributeValue ) 
                                {
                                    found = true; 
                                    break; 
                                }
                            } 
                            foreach( string clm in optionalClaims )
                            {
                                if( clm == attributeValue )
                                { 
                                    foundInOptional = true;
                                    found = true; 
                                    break; 
                                }
                            } 

                            //
                            // If claim is 'optional' append to the optional claim list
                            // 
                            if( isOptional )
                            { 
                                if( !found ) 
                                {
                                    optionalClaims.Add( attributeValue ); 
                                }

                            }
                            // 
                            // If claim is 'required' append to the required claim list
                            // If the claim was declared to be 'optional' before and now 
                            // as 'required', we move it to the required claim list 
                            //
                            else 
                            {
                                if( !found )
                                {
                                    requiredClaims.Add( attributeValue ); 
                                }
                                else 
                                { 
                                    if( foundInOptional )
                                    { 
                                        optionalClaims.Remove( attributeValue );
                                        requiredClaims.Add( attributeValue );
                                    }
 
                                }
                            } 
 

                            if( reader.IsEmptyElement ) 
                            {
                                reader.Read();
                            }
                            else 
                            {
                                reader.Read(); 
                                reader.ReadEndElement(); 
                            }
                        } 
                        else
                        {
                            reader.Skip();
                        } 
                    }
                } 
 
                //
                // Check to ensure we are reading the closing of the claims element. 
                //
                IDT.ThrowInvalidArgumentConditional( XmlNodeType.EndElement != reader.NodeType
                                                                , reader.NodeType.ToString() );
 
                m_requiredClaimUris = requiredClaims.ToArray();
                m_optionalClaimUris = optionalClaims.ToArray(); 
            } 
        }
 
        private void ReadTokenType(XmlReader reader)
        {
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSTrust.TokenType != reader.LocalName
                                                || ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI, 
                                                reader.LocalName );
 
            m_optionalRstParams.TokenType = reader.ReadString(); 

        } 

        //
        // Summary:
        //   http://some.website.com:8042/one/two 
        //   Scheme=http
        //   Host=some.website.com 
        //   Port=8042 
        //   Authority=some.website.com:8042
        //   Path=one/two 
        //
        //  1) Recipient.Uri and AppliesTo.Epr.Uri
        //     a) Must have same scheme, host, and port
        //     b) If appliesTo has a path: 
        //       i) recipient has NO path --> there is no way for it to be scoped --> throw
        //       ii) recipent has path --> appliesTo must be a prefix of the recipient [Ordinal Ignore Case] 
        // 
        //  2) AppliesTo must ONLY contain a single endpoint address element [of the addressing version WSAddress10 or WSAddressing2004]
        // 
        // Remarks: This reads the end element as well, so need special handling if you are using this function.
        //
        //
        public void ReadAppliesTo(XmlReader reader) 
        {
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSPolicy.AppliesTo != reader.LocalName 
                                    || ProtocolVersionProfile.WSPolicy.Namespace != reader.NamespaceURI, 
                                    reader.LocalName );
 
            if( reader.IsEmptyElement )
            {
                throw IDT.ThrowHelperError(
                            new PolicyValidationException( 
                                SR.GetString(
                                    SR.InvalidAppliesToInPolicy, 
                                    SR.GetString( SR.AppliesToMustOnlyHaveEndpointAddress ) ) ) ); 
            }
 
            reader.Read();

            EndpointAddress epr = null;
            // 
            // If we ended up on an end element, there was only whitespace
            //  in the appliesTo.  So we just skip over it. 
            // 
            if( XmlNodeType.EndElement != reader.NodeType )
            { 
                try
                {
                    epr = EndpointAddress.ReadFrom( XmlDictionaryReader.CreateDictionaryReader( reader.ReadSubtree() ) );
                    reader.ReadEndElement(); 
                }
                catch( Exception e ) 
                { 
                    if( IDT.IsFatal( e ) )
                    { 
                        throw;
                    }
                    throw IDT.ThrowHelperError(
                                new PolicyValidationException( 
                                    SR.GetString(
                                        SR.InvalidAppliesToInPolicy, 
                                        SR.GetString( SR.AppliesToMustOnlyHaveEndpointAddress ) ), 
                                e ) );
                } 

                //
                // If we have gotten to this point, and there are other children of the appliesTo other
                //  than the valid EPR, we will throw. 
                //
                if( reader.IsStartElement() ) 
                { 
                    throw IDT.ThrowHelperError(
                                new PolicyValidationException( 
                                    SR.GetString(
                                        SR.InvalidAppliesToInPolicy,
                                        SR.GetString( SR.AppliesToMustOnlyHaveEndpointAddress ) ) ) );
                } 

            } 
 
            m_policyAppliesToEpr = epr;
 
        }


        private void ReadKeyType(XmlReader reader) 
        {
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSTrust.KeyType != reader.LocalName 
                                                || ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI, 
                                                reader.LocalName );
 

            Uri keyTypeUri = new Uri( reader.ReadString() );

            if( ProtocolVersionProfile.WSTrust.KeyTypeSymmetric.Equals( keyTypeUri ) ) 
            {
                m_keyType = SecurityKeyTypeInternal.SymmetricKey; 
            } 
            else if( ProtocolVersionProfile.WSTrust.KeyTypeAsymmetric.Equals( keyTypeUri ) )
            { 
                m_keyType = SecurityKeyTypeInternal.AsymmetricKey;
            }
            else if( ProtocolVersionProfile.WSTrust.KeyTypeBearer.Equals( keyTypeUri ) )
            { 
                m_keyType = SecurityKeyTypeInternal.NoKey;
            } 
            else 
            {
                throw IDT.ThrowHelperError( new PolicyValidationException( SR.GetString( SR.KeyTypeNotRecognized, keyTypeUri.ToString() ) ) ); 
            }

            m_keyTypeSpecified = true;
        } 

 
        private void ReadKeySize(XmlReader reader) 
        {
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSTrust.KeySize != reader.LocalName 
                                                || ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI,
                                                reader.LocalName );

            try 
            {
                m_keySize = Convert.ToUInt32( reader.ReadString(), CultureInfo.InvariantCulture ); 
            } 
            catch( FormatException e )
            { 
                throw IDT.ThrowHelperError( new PolicyValidationException( SR.GetString( SR.ServiceBadKeySizeInPolicy ), e ) );
            }
            catch( OverflowException e )
            { 
                throw IDT.ThrowHelperError( new PolicyValidationException( SR.GetString( SR.ServiceBadKeySizeInPolicy ), e ) );
            } 
 
            m_keySizeSpecified = true;
 
        }


        private void ReadSignatureAlgorithm(XmlReader reader) 
        {
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSTrust.SignatureAlgorithm != reader.LocalName 
                                                || ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI, 
                                                reader.LocalName );
 

            m_optionalRstParams.SignatureAlgorithm = reader.ReadString();

        } 

 
 
        private void ReadEncryptionAlgorithm(XmlReader reader)
        { 
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSTrust.EncryptionAlgorithm != reader.LocalName
                                                || ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI,
                                                reader.LocalName );
 

            m_optionalRstParams.EncryptionAlgorithm = reader.ReadString(); 
 
        }
 
        private void ReadCanonicalizationAlgorithm(XmlReader reader)
        {
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSTrust.CanonicalizationAlgorithm != reader.LocalName
                                                || ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI, 
                                                reader.LocalName );
 
 
            m_optionalRstParams.CanonicalizationAlgorithm = reader.ReadString();
 
        }


        private void ReadEncryptWith(XmlReader reader) 
        {
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSTrust.EncryptWith != reader.LocalName 
                                                || ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI, 
                                                reader.LocalName );
 
            m_optionalRstParams.EncryptWith = reader.ReadString();


        } 

        private void ReadSignWith(XmlReader reader) 
        { 
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSTrust.SignWith != reader.LocalName
                                                || ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI, 
                                                reader.LocalName );

            m_optionalRstParams.SignWith = reader.ReadString();
 
        }
 
 
        private void ReadRequestType(XmlReader reader)
        { 
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSTrust.RequestType != reader.LocalName
                                                || ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI,
                                                reader.LocalName );
 
            m_requestType = reader.ReadString();
        } 
 
        private void ReadSecondaryParameters( XmlReader reader )
        { 
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSTrust.SecondaryParameters != reader.LocalName
                                                || ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI,
                                                reader.LocalName );
 
            while( reader.IsStartElement() )
            { 
                reader.Skip(); 
            }
        } 

        private void ReadKeyWrapAlgorithm( XmlReader reader )
        {
            IDT.ThrowInvalidArgumentConditional( ProtocolVersionProfile.WSTrust.KeyWrapAlgorithm != reader.LocalName 
                                                || ProtocolVersionProfile.WSTrust.Namespace != reader.NamespaceURI,
                                                reader.LocalName ); 
 
            m_optionalRstParams.KeyWrapAlgorithm = reader.ReadString();
 
        }

        //
        // Summary 
        //  Copies extra policy elements into the MemoryStream
        // 
        // Paramters 
        //   reader - the XmlReader from which the policy element should be read.
        // 
        private void CopyUnprocessedPolicyElements( XmlReader reader )
        {
            if( null == m_unprocessedPolicyElements )
            { 
                m_unprocessedPolicyElements = new MemoryStream();
            } 
 
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.OmitXmlDeclaration = true; 
            XmlWriter xmlWriter = XmlWriter.Create( m_unprocessedPolicyElements, settings );
            xmlWriter.WriteNode( reader, true );
            xmlWriter.Flush();
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK