WSSecureConversationDec2005.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 / ServiceModel / System / ServiceModel / Security / WSSecureConversationDec2005.cs / 1 / WSSecureConversationDec2005.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------

namespace System.ServiceModel.Security 
{
    using System; 
    using System.ServiceModel; 
    using System.Collections;
    using System.Collections.Generic; 
    using System.Diagnostics;
    using System.Globalization;
    using System.IO;
    using System.Text; 
    using System.Threading;
    using System.Xml; 
    using System.IdentityModel.Claims; 
    using System.IdentityModel.Policy;
    using System.IdentityModel.Tokens; 
    using System.Security.Cryptography.X509Certificates;
    using HexBinary = System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary;
    using System.ServiceModel.Channels;
    using System.ServiceModel.Security; 
    using System.ServiceModel.Security.Tokens;
    using System.Runtime.Serialization; 
    using KeyIdentifierEntry = WSSecurityTokenSerializer.KeyIdentifierEntry; 
    using KeyIdentifierClauseEntry = WSSecurityTokenSerializer.KeyIdentifierClauseEntry;
    using StrEntry = WSSecurityTokenSerializer.StrEntry; 
    using TokenEntry = WSSecurityTokenSerializer.TokenEntry;

    class WSSecureConversationDec2005 : WSSecureConversation
    { 
        SecurityStateEncoder securityStateEncoder;
        IList knownClaimTypes; 
 
        public WSSecureConversationDec2005(WSSecurityTokenSerializer tokenSerializer, SecurityStateEncoder securityStateEncoder, IEnumerable knownTypes,
            int maxKeyDerivationOffset, int maxKeyDerivationLabelLength, int maxKeyDerivationNonceLength) 
            : base(tokenSerializer, maxKeyDerivationOffset, maxKeyDerivationLabelLength, maxKeyDerivationNonceLength)
        {
            if (securityStateEncoder != null)
            { 
                this.securityStateEncoder = securityStateEncoder;
            } 
            else 
            {
                this.securityStateEncoder = new DataProtectionSecurityStateEncoder(); 
            }

            this.knownClaimTypes = new List();
            if (knownTypes != null) 
            {
                // Clone this collection. 
                foreach (Type knownType in knownTypes) 
                {
                    this.knownClaimTypes.Add(knownType); 
                }
            }
        }
 
        public override SecureConversationDictionary SerializerDictionary
        { 
            get { return DXD.SecureConversationDec2005Dictionary; } 
        }
 
        public override void PopulateStrEntries(IList strEntries)
        {
            strEntries.Add(new SctStrEntryDec2005(this));
        } 

        public override void PopulateTokenEntries(IList tokenEntryList) 
        { 
            base.PopulateTokenEntries(tokenEntryList);
            tokenEntryList.Add(new SecurityContextTokenEntryDec2005(this, this.securityStateEncoder, this.knownClaimTypes)); 
        }

        public override string DerivationAlgorithm
        { 
            get
            { 
                return SecurityAlgorithms.Psha1KeyDerivationDec2005; 
            }
        } 

        class SecurityContextTokenEntryDec2005 : SecurityContextTokenEntry
        {
            public SecurityContextTokenEntryDec2005(WSSecureConversationDec2005 parent, SecurityStateEncoder securityStateEncoder, IList knownClaimTypes) 
                : base(parent, securityStateEncoder, knownClaimTypes)
            { 
            } 

            protected override bool CanReadGeneration(XmlDictionaryReader reader) 
            {
                return reader.IsStartElement(DXD.SecureConversationDec2005Dictionary.Instance, DXD.SecureConversationDec2005Dictionary.Namespace);
            }
 
            protected override bool CanReadGeneration(XmlElement element)
            { 
                return (element.LocalName == DXD.SecureConversationDec2005Dictionary.Instance.Value && 
                    element.NamespaceURI == DXD.SecureConversationDec2005Dictionary.Namespace.Value);
            } 

            protected override UniqueId ReadGeneration(XmlDictionaryReader reader)
            {
                return reader.ReadElementContentAsUniqueId(); 
            }
 
            protected override UniqueId ReadGeneration(XmlElement element) 
            {
                return XmlHelper.ReadTextElementAsUniqueId(element); 
            }

            protected override void WriteGeneration(XmlDictionaryWriter writer, SecurityContextSecurityToken sct)
            { 
                // serialize the generation
                if (sct.KeyGeneration != null) 
                { 
                    writer.WriteStartElement(DXD.SecureConversationDec2005Dictionary.Prefix.Value,
                        DXD.SecureConversationDec2005Dictionary.Instance, 
                        DXD.SecureConversationDec2005Dictionary.Namespace);
                    XmlHelper.WriteStringAsUniqueId(writer, sct.KeyGeneration);
                    writer.WriteEndElement();
                } 
            }
        } 
 
        class SctStrEntryDec2005 : SctStrEntry
        { 
            public SctStrEntryDec2005(WSSecureConversationDec2005 parent)
                : base(parent)
            {
            } 

            protected override UniqueId ReadGeneration(XmlDictionaryReader reader) 
            { 
                return XmlHelper.GetAttributeAsUniqueId(reader, DXD.SecureConversationDec2005Dictionary.Instance,
                    DXD.SecureConversationDec2005Dictionary.Namespace); 
            }

            protected override void WriteGeneration(XmlDictionaryWriter writer, SecurityContextKeyIdentifierClause clause)
            { 
                // serialize the generation
                if (clause.Generation != null) 
                { 
                    XmlHelper.WriteAttributeStringAsUniqueId(writer, DXD.SecureConversationDec2005Dictionary.Prefix.Value,
                        DXD.SecureConversationDec2005Dictionary.Instance, DXD.SecureConversationDec2005Dictionary.Namespace, 
                        clause.Generation);
                }
            }
        } 

        public class DriverDec2005 : Driver 
        { 
            public DriverDec2005()
            { 
            }

            protected override SecureConversationDictionary DriverDictionary
            { 
                get { return DXD.SecureConversationDec2005Dictionary; }
            } 
 
            public override XmlDictionaryString CloseAction
            { 
                get { return DXD.SecureConversationDec2005Dictionary.RequestSecurityContextClose; }
            }

            public override XmlDictionaryString CloseResponseAction 
            {
                get { return DXD.SecureConversationDec2005Dictionary.RequestSecurityContextCloseResponse; } 
            } 

            public override bool IsSessionSupported 
            {
                get { return true; }
            }
 
            public override XmlDictionaryString RenewAction
            { 
                get { return DXD.SecureConversationDec2005Dictionary.RequestSecurityContextRenew; } 
            }
 
            public override XmlDictionaryString RenewResponseAction
            {
                get { return DXD.SecureConversationDec2005Dictionary.RequestSecurityContextRenewResponse; }
            } 

            public override XmlDictionaryString Namespace 
            { 
                get { return DXD.SecureConversationDec2005Dictionary.Namespace; }
            } 

            public override string TokenTypeUri
            {
                get { return DXD.SecureConversationDec2005Dictionary.SecurityContextTokenType.Value; } 
            }
        } 
    } 
}
 

// 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