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

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Security.Tokens
{ 
    using System.Xml;
    using System.ServiceModel; 
    using System.Collections.ObjectModel; 
    using System.IdentityModel.Selectors;
    using System.IdentityModel.Tokens; 

    public class SecurityContextSecurityTokenResolver : SecurityTokenResolver, ISecurityContextSecurityTokenCache
    {
        SecurityContextTokenCache tokenCache; 
        bool removeOldestTokensOnCacheFull;
        int capacity; 
 
        public SecurityContextSecurityTokenResolver(int securityContextCacheCapacity, bool removeOldestTokensOnCacheFull)
        { 
            if (securityContextCacheCapacity <= 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("securityContextCacheCapacity", SR.GetString(SR.ValueMustBeGreaterThanZero)));
            } 
            this.capacity = securityContextCacheCapacity;
            this.removeOldestTokensOnCacheFull = removeOldestTokensOnCacheFull; 
            this.tokenCache = new SecurityContextTokenCache(this.capacity, this.removeOldestTokensOnCacheFull); 
        }
 
        public int SecurityContextTokenCacheCapacity
        {
            get
            { 
                return this.capacity;
            } 
        } 

        public bool RemoveOldestTokensOnCacheFull 
        {
            get
            {
                return this.removeOldestTokensOnCacheFull; 
            }
        } 
 
        public void AddContext(SecurityContextSecurityToken token)
        { 
            this.tokenCache.AddContext(token);
        }

        public bool TryAddContext(SecurityContextSecurityToken token) 
        {
            return this.tokenCache.TryAddContext(token); 
        } 

 
        public void ClearContexts()
        {
            this.tokenCache.ClearContexts();
        } 

        public void RemoveContext(UniqueId contextId, UniqueId generation) 
        { 
            this.tokenCache.RemoveContext(contextId, generation, false);
        } 

        public void RemoveAllContexts(UniqueId contextId)
        {
            this.tokenCache.RemoveAllContexts(contextId); 
        }
 
        public SecurityContextSecurityToken GetContext(UniqueId contextId, UniqueId generation) 
        {
            return this.tokenCache.GetContext(contextId, generation); 
        }

        public Collection GetAllContexts(UniqueId contextId)
        { 
            return this.tokenCache.GetAllContexts(contextId);
        } 
 
        public void UpdateContextCachingTime(SecurityContextSecurityToken context, DateTime expirationTime)
        { 
            this.tokenCache.UpdateContextCachingTime(context, expirationTime);
        }

        protected override bool TryResolveTokenCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityToken token) 
        {
            SecurityContextKeyIdentifierClause sctSkiClause = keyIdentifierClause as SecurityContextKeyIdentifierClause; 
            if (sctSkiClause != null) 
            {
                token = this.tokenCache.GetContext(sctSkiClause.ContextId, sctSkiClause.Generation); 
            }
            else
            {
                token = null; 
            }
            return (token != null); 
        } 

        protected override bool TryResolveSecurityKeyCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityKey key) 
        {
            SecurityToken sct;
            if (TryResolveTokenCore(keyIdentifierClause, out sct))
            { 
                key = ((SecurityContextSecurityToken)sct).SecurityKeys[0];
                return true; 
            } 
            else
            { 
                key = null;
                return false;
            }
        } 

        protected override bool TryResolveTokenCore(SecurityKeyIdentifier keyIdentifier, out SecurityToken token) 
        { 
            SecurityContextKeyIdentifierClause sctSkiClause;
            if (keyIdentifier.TryFind(out sctSkiClause)) 
            {
                return TryResolveToken(sctSkiClause, out token);
            }
            else 
            {
                token = null; 
                return false; 
            }
        } 
    }
}

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