WSSecurityTokenSerializer.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 / WSSecurityTokenSerializer.cs / 1 / WSSecurityTokenSerializer.cs

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

namespace System.ServiceModel.Security 
{
    using System.Collections.Generic; 
    using System.ServiceModel; 
    using System.ServiceModel.Security.Tokens;
    using System.IdentityModel.Selectors; 
    using System.IdentityModel.Tokens;
    using System.Runtime.Serialization;
    using System.Xml;
 
    public class WSSecurityTokenSerializer : SecurityTokenSerializer
    { 
        const int DefaultMaximumKeyDerivationOffset = 64; // bytes 
        const int DefaultMaximumKeyDerivationLabelLength = 128; // bytes
        const int DefaultMaximumKeyDerivationNonceLength = 128; // bytes 

        static WSSecurityTokenSerializer instance;
        readonly bool emitBspRequiredAttributes;
        readonly SecurityVersion securityVersion; 
        readonly List keyIdentifierEntries;
        readonly List keyIdentifierClauseEntries; 
        readonly List serializerEntries; 
        WSSecureConversation secureConversation;
        readonly List tokenEntries; 
        int maximumKeyDerivationOffset;
        int maximumKeyDerivationLabelLength;
        int maximumKeyDerivationNonceLength;
 
        public WSSecurityTokenSerializer()
            : this(SecurityVersion.WSSecurity11) 
        { 
        }
 
        public WSSecurityTokenSerializer(bool emitBspRequiredAttributes)
            : this(SecurityVersion.WSSecurity11, emitBspRequiredAttributes)
        {
        } 

        public WSSecurityTokenSerializer(SecurityVersion securityVersion) 
            : this(securityVersion, false) 
        {
        } 

        public WSSecurityTokenSerializer(SecurityVersion securityVersion, bool emitBspRequiredAttributes)
            : this(securityVersion, emitBspRequiredAttributes, null)
        { 
        }
 
        public WSSecurityTokenSerializer(SecurityVersion securityVersion, bool emitBspRequiredAttributes, SamlSerializer samlSerializer) 
            :this(securityVersion, emitBspRequiredAttributes, samlSerializer, null, null)
        { 
        }

        public WSSecurityTokenSerializer(SecurityVersion securityVersion, bool emitBspRequiredAttributes, SamlSerializer samlSerializer, SecurityStateEncoder securityStateEncoder, IEnumerable knownTypes)
            : this(securityVersion, emitBspRequiredAttributes, samlSerializer, securityStateEncoder, knownTypes, DefaultMaximumKeyDerivationOffset, DefaultMaximumKeyDerivationLabelLength, DefaultMaximumKeyDerivationNonceLength) 
        {
        } 
 
        public WSSecurityTokenSerializer(SecurityVersion securityVersion, TrustVersion trustVersion, SecureConversationVersion secureConversationVersion, bool emitBspRequiredAttributes, SamlSerializer samlSerializer, SecurityStateEncoder securityStateEncoder, IEnumerable knownTypes)
            : this(securityVersion, trustVersion, secureConversationVersion, emitBspRequiredAttributes, samlSerializer, securityStateEncoder, knownTypes, DefaultMaximumKeyDerivationOffset, DefaultMaximumKeyDerivationLabelLength, DefaultMaximumKeyDerivationNonceLength) 
        {
        }

        public WSSecurityTokenSerializer(SecurityVersion securityVersion, bool emitBspRequiredAttributes, SamlSerializer samlSerializer, SecurityStateEncoder securityStateEncoder, IEnumerable knownTypes, 
            int maximumKeyDerivationOffset, int maximumKeyDerivationLabelLength, int maximumKeyDerivationNonceLength)
            : this(securityVersion, TrustVersion.Default, SecureConversationVersion.Default, emitBspRequiredAttributes, samlSerializer, securityStateEncoder, knownTypes, maximumKeyDerivationOffset, maximumKeyDerivationLabelLength, maximumKeyDerivationNonceLength) 
        { 
        }
 
        public WSSecurityTokenSerializer(SecurityVersion securityVersion, TrustVersion trustVersion, SecureConversationVersion secureConversationVersion, bool emitBspRequiredAttributes, SamlSerializer samlSerializer, SecurityStateEncoder securityStateEncoder, IEnumerable knownTypes,
            int maximumKeyDerivationOffset, int maximumKeyDerivationLabelLength, int maximumKeyDerivationNonceLength)
        {
            if (securityVersion == null) 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("securityVersion"));
 
            if (maximumKeyDerivationOffset < 0) 
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("maximumKeyDerivationOffset", SR.GetString(SR.ValueMustBeNonNegative))); 
            }
            if (maximumKeyDerivationLabelLength < 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("maximumKeyDerivationLabelLength", SR.GetString(SR.ValueMustBeNonNegative))); 
            }
            if (maximumKeyDerivationNonceLength <= 0) 
            { 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("maximumKeyDerivationNonceLength", SR.GetString(SR.ValueMustBeGreaterThanZero)));
            } 

            this.securityVersion = securityVersion;
            this.emitBspRequiredAttributes = emitBspRequiredAttributes;
            this.maximumKeyDerivationOffset = maximumKeyDerivationOffset; 
            this.maximumKeyDerivationNonceLength = maximumKeyDerivationNonceLength;
            this.maximumKeyDerivationLabelLength = maximumKeyDerivationLabelLength; 
 
            this.serializerEntries = new List();
 
            if (secureConversationVersion == SecureConversationVersion.WSSecureConversationFeb2005)
            {
                this.secureConversation = new WSSecureConversationFeb2005(this, securityStateEncoder, knownTypes, maximumKeyDerivationOffset, maximumKeyDerivationLabelLength, maximumKeyDerivationNonceLength);
            } 
            else if (secureConversationVersion == SecureConversationVersion.WSSecureConversation13)
            { 
                this.secureConversation = new WSSecureConversationDec2005(this, securityStateEncoder, knownTypes, maximumKeyDerivationOffset, maximumKeyDerivationLabelLength, maximumKeyDerivationNonceLength); 
            }
            else 
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
            }
 
            this.serializerEntries.Add(new XmlDsigSep2000(this));
            this.serializerEntries.Add(new XmlEncApr2001(this)); 
 
            if (securityVersion == SecurityVersion.WSSecurity10)
            { 
                this.serializerEntries.Add(new WSSecurityJan2004(this, samlSerializer));
            }
            else if (securityVersion == SecurityVersion.WSSecurity11)
            { 
                this.serializerEntries.Add(new WSSecurityXXX2005(this, samlSerializer));
            } 
            else 
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("securityVersion", SR.GetString(SR.MessageSecurityVersionOutOfRange))); 
            }
            this.serializerEntries.Add(this.secureConversation);
            if (trustVersion == TrustVersion.WSTrustFeb2005)
            { 
                this.serializerEntries.Add(new WSTrustFeb2005(this));
            } 
            else if (trustVersion == TrustVersion.WSTrust13) 
            {
                this.serializerEntries.Add(new WSTrustDec2005(this)); 
            }
            else
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); 
            }
 
            this.tokenEntries = new List(); 
            this.keyIdentifierEntries = new List();
            this.keyIdentifierClauseEntries = new List(); 

            for (int i = 0; i < this.serializerEntries.Count; ++i)
            {
                SerializerEntries serializerEntry = this.serializerEntries[i]; 
                serializerEntry.PopulateTokenEntries(this.tokenEntries);
                serializerEntry.PopulateKeyIdentifierEntries(this.keyIdentifierEntries); 
                serializerEntry.PopulateKeyIdentifierClauseEntries(this.keyIdentifierClauseEntries); 
            }
        } 

        public static WSSecurityTokenSerializer DefaultInstance
        {
            get 
            {
                if (instance == null) 
                    instance = new WSSecurityTokenSerializer(); 
                return instance;
            } 
        }

        public bool EmitBspRequiredAttributes
        { 
            get { return this.emitBspRequiredAttributes; }
        } 
 
        public SecurityVersion SecurityVersion
        { 
            get { return this.securityVersion; }
        }

        public int MaximumKeyDerivationOffset 
        {
            get { return this.maximumKeyDerivationOffset; } 
        } 

        public int MaximumKeyDerivationLabelLength 
        {
            get { return this.maximumKeyDerivationLabelLength; }
        }
 
        public int MaximumKeyDerivationNonceLength
        { 
            get { return this.maximumKeyDerivationNonceLength; } 
        }
 
        internal WSSecureConversation SecureConversation
        {
            get { return this.secureConversation; }
        } 

        bool ShouldWrapException(Exception e) 
        { 
            if (DiagnosticUtility.IsFatal(e))
            { 
                return false;
            }
            return ((e is ArgumentException) || (e is FormatException) || (e is InvalidOperationException));
        } 

        protected override bool CanReadTokenCore(XmlReader reader) 
        { 
            XmlDictionaryReader localReader = XmlDictionaryReader.CreateDictionaryReader(reader);
            for (int i = 0; i < this.tokenEntries.Count; i++) 
            {
                TokenEntry tokenEntry = this.tokenEntries[i];
                if (tokenEntry.CanReadTokenCore(localReader))
                    return true; 
            }
            return false; 
        } 

        protected override SecurityToken ReadTokenCore(XmlReader reader, SecurityTokenResolver tokenResolver) 
        {
            XmlDictionaryReader localReader = XmlDictionaryReader.CreateDictionaryReader(reader);
            for (int i = 0; i < this.tokenEntries.Count; i++)
            { 
                TokenEntry tokenEntry = this.tokenEntries[i];
                if (tokenEntry.CanReadTokenCore(localReader)) 
                { 
                    try
                    { 
                        return tokenEntry.ReadTokenCore(localReader, tokenResolver);
                    }
#pragma warning suppress 56500 // covered by FxCOP
                    catch (Exception e) 
                    {
                        if (!ShouldWrapException(e)) 
                        { 
                            throw;
                        } 
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.ErrorDeserializingTokenXml), e));
                    }
                }
            } 
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.CannotReadToken, reader.LocalName, reader.NamespaceURI, localReader.GetAttribute(XD.SecurityJan2004Dictionary.ValueType, null))));
        } 
 
        protected override bool CanWriteTokenCore(SecurityToken token)
        { 
            for (int i = 0; i < this.tokenEntries.Count; i++)
            {
                TokenEntry tokenEntry = this.tokenEntries[i];
                if (tokenEntry.SupportsCore(token.GetType())) 
                    return true;
            } 
            return false; 
        }
 
        protected override void WriteTokenCore(XmlWriter writer, SecurityToken token)
        {
            bool wroteToken = false;
            XmlDictionaryWriter localWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer); 
            for (int i = 0; i < this.tokenEntries.Count; i++)
            { 
                TokenEntry tokenEntry = this.tokenEntries[i]; 
                if (tokenEntry.SupportsCore(token.GetType()))
                { 
                    try
                    {
                        tokenEntry.WriteTokenCore(localWriter, token);
                    } 
#pragma warning suppress 56500 // covered by FxCOP
                    catch (Exception e) 
                    { 
                        if (!ShouldWrapException(e))
                        { 
                            throw;
                        }
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.ErrorSerializingSecurityToken), e));
                    } 
                    wroteToken = true;
                    break; 
                } 
            }
 
            if (!wroteToken)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.StandardsManagerCannotWriteObject, token.GetType())));

            localWriter.Flush(); 
        }
 
        protected override bool CanReadKeyIdentifierCore(XmlReader reader) 
        {
            XmlDictionaryReader localReader = XmlDictionaryReader.CreateDictionaryReader(reader); 
            for (int i = 0; i < this.keyIdentifierEntries.Count; i++)
            {
                KeyIdentifierEntry keyIdentifierEntry = this.keyIdentifierEntries[i];
                if (keyIdentifierEntry.CanReadKeyIdentifierCore(localReader)) 
                    return true;
            } 
            return false; 
        }
 
        protected override SecurityKeyIdentifier ReadKeyIdentifierCore(XmlReader reader)
        {
            XmlDictionaryReader localReader = XmlDictionaryReader.CreateDictionaryReader(reader);
            for (int i = 0; i < this.keyIdentifierEntries.Count; i++) 
            {
                KeyIdentifierEntry keyIdentifierEntry = this.keyIdentifierEntries[i]; 
                if (keyIdentifierEntry.CanReadKeyIdentifierCore(localReader)) 
                {
                    try 
                    {
                        return keyIdentifierEntry.ReadKeyIdentifierCore(localReader);
                    }
#pragma warning suppress 56500 // covered by FxCOP 
                    catch (Exception e)
                    { 
                        if (!ShouldWrapException(e)) 
                        {
                            throw; 
                        }
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.ErrorDeserializingKeyIdentifier), e));
                    }
                } 
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.CannotReadKeyIdentifier, reader.LocalName, reader.NamespaceURI))); 
        } 

        protected override bool CanWriteKeyIdentifierCore(SecurityKeyIdentifier keyIdentifier) 
        {
            for (int i = 0; i < this.keyIdentifierEntries.Count; ++i)
            {
                KeyIdentifierEntry keyIdentifierEntry = this.keyIdentifierEntries[i]; 
                if (keyIdentifierEntry.SupportsCore(keyIdentifier))
                    return true; 
            } 
            return false;
        } 

        protected override void WriteKeyIdentifierCore(XmlWriter writer, SecurityKeyIdentifier keyIdentifier)
        {
            bool wroteKeyIdentifier = false; 
            XmlDictionaryWriter localWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer);
            for (int i = 0; i < this.keyIdentifierEntries.Count; ++i) 
            { 
                KeyIdentifierEntry keyIdentifierEntry = this.keyIdentifierEntries[i];
                if (keyIdentifierEntry.SupportsCore(keyIdentifier)) 
                {
                    try
                    {
                        keyIdentifierEntry.WriteKeyIdentifierCore(localWriter, keyIdentifier); 
                    }
#pragma warning suppress 56500 // covered by FxCOP 
                    catch (Exception e) 
                    {
                        if (!ShouldWrapException(e)) 
                        {
                            throw;
                        }
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.ErrorSerializingKeyIdentifier), e)); 
                    }
                    wroteKeyIdentifier = true; 
                    break; 
                }
            } 

            if (!wroteKeyIdentifier)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.StandardsManagerCannotWriteObject, keyIdentifier.GetType())));
 
            localWriter.Flush();
        } 
 
        protected override bool CanReadKeyIdentifierClauseCore(XmlReader reader)
        { 
            XmlDictionaryReader localReader = XmlDictionaryReader.CreateDictionaryReader(reader);
            for (int i = 0; i < this.keyIdentifierClauseEntries.Count; i++)
            {
                KeyIdentifierClauseEntry keyIdentifierClauseEntry = this.keyIdentifierClauseEntries[i]; 
                if (keyIdentifierClauseEntry.CanReadKeyIdentifierClauseCore(localReader))
                    return true; 
            } 
            return false;
        } 

        protected override SecurityKeyIdentifierClause ReadKeyIdentifierClauseCore(XmlReader reader)
        {
            XmlDictionaryReader localReader = XmlDictionaryReader.CreateDictionaryReader(reader); 
            for (int i = 0; i < this.keyIdentifierClauseEntries.Count; i++)
            { 
                KeyIdentifierClauseEntry keyIdentifierClauseEntry = this.keyIdentifierClauseEntries[i]; 
                if (keyIdentifierClauseEntry.CanReadKeyIdentifierClauseCore(localReader))
                { 
                    try
                    {
                        return keyIdentifierClauseEntry.ReadKeyIdentifierClauseCore(localReader);
                    } 
#pragma warning suppress 56500 // covered by FxCOP
                    catch (Exception e) 
                    { 
                        if (!ShouldWrapException(e))
                        { 
                            throw;
                        }
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.ErrorDeserializingKeyIdentifierClause), e));
                    } 
                }
            } 
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.CannotReadKeyIdentifierClause, reader.LocalName, reader.NamespaceURI))); 
        }
 
        protected override bool CanWriteKeyIdentifierClauseCore(SecurityKeyIdentifierClause keyIdentifierClause)
        {
            for (int i = 0; i < this.keyIdentifierClauseEntries.Count; ++i)
            { 
                KeyIdentifierClauseEntry keyIdentifierClauseEntry = this.keyIdentifierClauseEntries[i];
                if (keyIdentifierClauseEntry.SupportsCore(keyIdentifierClause)) 
                    return true; 
            }
            return false; 
        }

        protected override void WriteKeyIdentifierClauseCore(XmlWriter writer, SecurityKeyIdentifierClause keyIdentifierClause)
        { 
            bool wroteKeyIdentifierClause = false;
            XmlDictionaryWriter localWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer); 
            for (int i = 0; i < this.keyIdentifierClauseEntries.Count; ++i) 
            {
                KeyIdentifierClauseEntry keyIdentifierClauseEntry = this.keyIdentifierClauseEntries[i]; 
                if (keyIdentifierClauseEntry.SupportsCore(keyIdentifierClause))
                {
                    try
                    { 
                        keyIdentifierClauseEntry.WriteKeyIdentifierClauseCore(localWriter, keyIdentifierClause);
                    } 
#pragma warning suppress 56500 // covered by FxCOP 
                    catch (Exception e)
                    { 
                        if (!ShouldWrapException(e))
                        {
                            throw;
                        } 
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.ErrorSerializingKeyIdentifierClause), e));
                    } 
                    wroteKeyIdentifierClause = true; 
                    break;
                } 
            }

            if (!wroteKeyIdentifierClause)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.StandardsManagerCannotWriteObject, keyIdentifierClause.GetType()))); 

            localWriter.Flush(); 
        } 

        internal void PopulateStrEntries(IList strEntries) 
        {
            foreach (SerializerEntries serializerEntry in serializerEntries)
            {
                serializerEntry.PopulateStrEntries(strEntries); 
            }
        } 
 
        internal Type[] GetTokenTypes(string tokenTypeUri)
        { 
            if (tokenTypeUri != null)
            {
                for (int i = 0; i < this.tokenEntries.Count; i++)
                { 
                    TokenEntry tokenEntry = this.tokenEntries[i];
 
                    if (tokenEntry.SupportsTokenTypeUri(tokenTypeUri)) 
                    {
                        return tokenEntry.GetTokenTypes(); 
                    }
                }
            }
            return null; 
        }
 
        protected internal virtual string GetTokenTypeUri(Type tokenType) 
        {
            if (tokenType != null) 
            {
                for (int i = 0; i < this.tokenEntries.Count; i++)
                {
                    TokenEntry tokenEntry = this.tokenEntries[i]; 

                    if (tokenEntry.SupportsCore(tokenType)) 
                    { 
                        return tokenEntry.TokenTypeUri;
                    } 
                }
            }
            return null;
        } 

        public virtual SecurityKeyIdentifierClause CreateKeyIdentifierClauseFromTokenXml(XmlElement element, SecurityTokenReferenceStyle tokenReferenceStyle) 
        { 
            if (element == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element"); 

            for (int i = 0; i < this.tokenEntries.Count; i++)
            {
                TokenEntry tokenEntry = this.tokenEntries[i]; 
                if (tokenEntry.CanReadTokenCore(element))
                { 
                    try 
                    {
                        return tokenEntry.CreateKeyIdentifierClauseFromTokenXmlCore(element, tokenReferenceStyle); 
                    }
#pragma warning suppress 56500 // covered by FxCOP
                    catch (Exception e)
                    { 
                        if (!ShouldWrapException(e))
                        { 
                            throw; 
                        }
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.ErrorDeserializingKeyIdentifierClauseFromTokenXml), e)); 
                    }
                }
            }
 
            // PreSharp Bug: Parameter 'element' to this public method must be validated: A null-dereference can occur here.
#pragma warning suppress 56506 
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.CannotReadToken, element.LocalName, element.NamespaceURI, element.GetAttribute(SecurityJan2004Strings.ValueType, null)))); 
        }
 
        internal abstract class TokenEntry
        {
            Type[] tokenTypes = null;
            public virtual IAsyncResult BeginReadTokenCore(XmlDictionaryReader reader, 
                SecurityTokenResolver tokenResolver, AsyncCallback callback, object state)
            { 
                SecurityToken result = this.ReadTokenCore(reader, tokenResolver); 
                return new TypedCompletedAsyncResult(result, callback, state);
            } 

            protected abstract XmlDictionaryString LocalName { get; }
            protected abstract XmlDictionaryString NamespaceUri { get; }
            public Type TokenType { get { return GetTokenTypes()[0]; } } 
            public abstract string TokenTypeUri { get; }
            protected abstract string ValueTypeUri { get; } 
 
            protected abstract Type[] GetTokenTypesCore();
 
            public Type[] GetTokenTypes()
            {
                if (this.tokenTypes == null)
                    this.tokenTypes = GetTokenTypesCore(); 
                return this.tokenTypes;
            } 
 
            public bool SupportsCore(Type tokenType)
            { 
                Type[] tokenTypes = GetTokenTypes();
                for (int i = 0; i < tokenTypes.Length; ++i)
                {
                    if (tokenTypes[i].IsAssignableFrom(tokenType)) 
                        return true;
                } 
                return false; 
            }
 
            public virtual bool SupportsTokenTypeUri(string tokenTypeUri)
            {
                return (this.TokenTypeUri == tokenTypeUri);
            } 

            protected static SecurityKeyIdentifierClause CreateDirectReference(XmlElement issuedTokenXml, string idAttributeLocalName, string idAttributeNamespace, Type tokenType) 
            { 
                string id = issuedTokenXml.GetAttribute(idAttributeLocalName, idAttributeNamespace);
                if (id == null) 
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.RequiredAttributeMissing, idAttributeLocalName, issuedTokenXml.LocalName)));
                }
                return new LocalIdKeyIdentifierClause(id, tokenType); 
            }
 
            public virtual bool CanReadTokenCore(XmlElement element) 
            {
                string valueTypeUri = null; 

                if (element.HasAttribute(SecurityJan2004Strings.ValueType, null))
                {
                    valueTypeUri = element.GetAttribute(SecurityJan2004Strings.ValueType, null); 
                }
 
                return element.LocalName == LocalName.Value && element.NamespaceURI == NamespaceUri.Value && valueTypeUri == this.ValueTypeUri; 
            }
 
            public virtual bool CanReadTokenCore(XmlDictionaryReader reader)
            {
                return reader.IsStartElement(this.LocalName, this.NamespaceUri) &&
                       reader.GetAttribute(XD.SecurityJan2004Dictionary.ValueType, null) == this.ValueTypeUri; 
            }
 
            public virtual SecurityToken EndReadTokenCore(IAsyncResult result) 
            {
                return TypedCompletedAsyncResult.End(result); 
            }

            public abstract SecurityKeyIdentifierClause CreateKeyIdentifierClauseFromTokenXmlCore(XmlElement issuedTokenXml, SecurityTokenReferenceStyle tokenReferenceStyle);
 
            public abstract SecurityToken ReadTokenCore(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver);
 
            public abstract void WriteTokenCore(XmlDictionaryWriter writer, SecurityToken token); 
        }
 
        internal abstract class KeyIdentifierEntry
        {
            protected abstract XmlDictionaryString LocalName { get; }
            protected abstract XmlDictionaryString NamespaceUri { get; } 

            public virtual bool CanReadKeyIdentifierCore(XmlDictionaryReader reader) 
            { 
                return reader.IsStartElement(this.LocalName, this.NamespaceUri);
            } 

            public abstract SecurityKeyIdentifier ReadKeyIdentifierCore(XmlDictionaryReader reader);

            public abstract bool SupportsCore(SecurityKeyIdentifier keyIdentifier); 

            public abstract void WriteKeyIdentifierCore(XmlDictionaryWriter writer, SecurityKeyIdentifier keyIdentifier); 
        } 

        internal abstract class KeyIdentifierClauseEntry 
        {

            protected abstract XmlDictionaryString LocalName { get; }
            protected abstract XmlDictionaryString NamespaceUri { get; } 

            public virtual bool CanReadKeyIdentifierClauseCore(XmlDictionaryReader reader) 
            { 
                return reader.IsStartElement(this.LocalName, this.NamespaceUri);
            } 

            public abstract SecurityKeyIdentifierClause ReadKeyIdentifierClauseCore(XmlDictionaryReader reader);

            public abstract bool SupportsCore(SecurityKeyIdentifierClause keyIdentifierClause); 

            public abstract void WriteKeyIdentifierClauseCore(XmlDictionaryWriter writer, SecurityKeyIdentifierClause keyIdentifierClause); 
        } 

        internal abstract class StrEntry 
        {
            public abstract Type GetTokenType(SecurityKeyIdentifierClause clause);
            public abstract bool CanReadClause(XmlDictionaryReader reader, string tokenType);
            public abstract SecurityKeyIdentifierClause ReadClause(XmlDictionaryReader reader, byte[] derivationNonce, int derivationLength, string tokenType); 
            public abstract bool SupportsCore(SecurityKeyIdentifierClause clause);
            public abstract void WriteContent(XmlDictionaryWriter writer, SecurityKeyIdentifierClause clause); 
        } 

        internal abstract class SerializerEntries 
        {
            public virtual void PopulateTokenEntries(IList tokenEntries) { }
            public virtual void PopulateKeyIdentifierEntries(IList keyIdentifierEntries) { }
            public virtual void PopulateKeyIdentifierClauseEntries(IList keyIdentifierClauseEntries) { } 
            public virtual void PopulateStrEntries(IList strEntries) { }
        } 
 
    }
} 

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