Example #1
0
        /// <summary>
        /// Deletes matching cache entries from the MruCache.
        /// </summary>
        /// <param name="endpointId">Specifies the endpointId for the entries to be deleted.</param>
        /// <param name="contextId">Specifies the contextId for the entries to be deleted.</param>
        public override void RemoveAll(string endpointId, System.Xml.UniqueId contextId)
        {
            if (null == contextId || string.IsNullOrEmpty(endpointId))
            {
                return;
            }

            Dictionary <SessionSecurityTokenCacheKey, CacheEntry> entriesToDelete = new Dictionary <SessionSecurityTokenCacheKey, CacheEntry>();
            SessionSecurityTokenCacheKey key = new SessionSecurityTokenCacheKey(endpointId, contextId, null);

            key.IgnoreKeyGeneration = true;
            lock (this._syncRoot)
            {
                foreach (SessionSecurityTokenCacheKey itemKey in this._items.Keys)
                {
                    if (itemKey.Equals(key))
                    {
                        entriesToDelete.Add(itemKey, this._items[itemKey]);
                    }
                }

                foreach (SessionSecurityTokenCacheKey itemKey in entriesToDelete.Keys)
                {
                    this._items.Remove(itemKey);
                    CacheEntry entry = entriesToDelete[itemKey];
                    this._mruList.Remove(entry.Node);
                    if (object.ReferenceEquals(this.mruEntry.Node, entry.Node))
                    {
                        this.mruEntry.Value = null;
                        this.mruEntry.Node  = null;
                    }
                }
            }
        }
        /// <summary>
        /// Creates an instance of <see cref="SessionSecurityTokenCacheKey"/> which
        /// is used as an index while caching <see cref="SessionSecurityToken"/>.
        /// </summary>
        /// <param name="endpointId">The endpoint Id to which the <see cref="SessionSecurityToken"/> is scoped.</param>
        /// <param name="contextId">UniqueId of the <see cref="SessionSecurityToken"/>.</param>
        /// <param name="keyGeneration">UniqueId which is available when the <see cref="SessionSecurityToken"/> is renewed. Will be
        /// null when caching a new <see cref="SessionSecurityToken"/>.</param>
        public SessionSecurityTokenCacheKey(string endpointId, System.Xml.UniqueId contextId, System.Xml.UniqueId keyGeneration)
        {
            if (endpointId == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointId");
            }

            if (contextId == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contextId");
            }
            
            this.endpointId = endpointId;
            this.contextId = contextId;
            this.keyGeneration = keyGeneration;
        }
Example #3
0
        public SecurityContextSecurityToken GetContext(System.Xml.UniqueId contextId, System.Xml.UniqueId generation)
        {
            SessionSecurityToken         token = null;
            SessionSecurityTokenCacheKey key   = new SessionSecurityTokenCacheKey(_claimsHandler.EndpointId, contextId, generation);

            token = _tokenCache.Get(key);

            SecurityContextSecurityToken sctToken = null;

            if (token != null && token.IsSecurityContextSecurityTokenWrapper)
            {
                sctToken = SecurityContextSecurityTokenHelper.ConvertSessionTokenToSecurityContextSecurityToken(token);
            }

            return(sctToken);
        }
        /// <summary>
        /// Creates an instance of <see cref="SessionSecurityTokenCacheKey"/> which
        /// is used as an index while caching <see cref="SessionSecurityToken"/>.
        /// </summary>
        /// <param name="endpointId">The endpoint Id to which the <see cref="SessionSecurityToken"/> is scoped.</param>
        /// <param name="contextId">UniqueId of the <see cref="SessionSecurityToken"/>.</param>
        /// <param name="keyGeneration">UniqueId which is available when the <see cref="SessionSecurityToken"/> is renewed. Will be
        /// null when caching a new <see cref="SessionSecurityToken"/>.</param>
        public SessionSecurityTokenCacheKey(string endpointId, System.Xml.UniqueId contextId, System.Xml.UniqueId keyGeneration)
        {
            if (endpointId == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointId");
            }

            if (contextId == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contextId");
            }

            this.endpointId    = endpointId;
            this.contextId     = contextId;
            this.keyGeneration = keyGeneration;
        }
Example #5
0
        /// <summary>
        /// Called to retrieve all tokens that match a particular contextId. WCF will call this
        /// </summary>
        /// <param name="contextId"></param>
        /// <returns></returns>
        public Collection <SecurityContextSecurityToken> GetAllContexts(System.Xml.UniqueId contextId)
        {
            Collection <SecurityContextSecurityToken> tokens = new Collection <SecurityContextSecurityToken>();

            IEnumerable <SessionSecurityToken> cachedTokens = _tokenCache.GetAll(_claimsHandler.EndpointId, contextId);

            if (cachedTokens != null)
            {
                foreach (SessionSecurityToken sessionSct in cachedTokens)
                {
                    if (sessionSct != null && sessionSct.IsSecurityContextSecurityTokenWrapper)
                    {
                        SecurityContextSecurityToken sctToken = SecurityContextSecurityTokenHelper.ConvertSessionTokenToSecurityContextSecurityToken(sessionSct);
                        tokens.Add(sctToken);
                    }
                }
            }

            return(tokens);
        }
Example #6
0
        /// <summary>
        /// Returns all the entries that match the given key.
        /// </summary>
        /// <param name="endpointId">The endpoint id for the entries to be retrieved.</param>
        /// <param name="contextId">The context id for the entries to be retrieved.</param>
        /// <returns>A collection of all the matching entries, an empty collection of no match found.</returns>
        public override IEnumerable <SessionSecurityToken> GetAll(string endpointId, System.Xml.UniqueId contextId)
        {
            Collection <SessionSecurityToken> tokens = new Collection <SessionSecurityToken>();

            if (null == contextId || string.IsNullOrEmpty(endpointId))
            {
                return(tokens);
            }

            CacheEntry entry;
            SessionSecurityTokenCacheKey key = new SessionSecurityTokenCacheKey(endpointId, contextId, null);

            key.IgnoreKeyGeneration = true;

            lock (this._syncRoot)
            {
                foreach (SessionSecurityTokenCacheKey itemKey in this._items.Keys)
                {
                    if (itemKey.Equals(key))
                    {
                        entry = this._items[itemKey];

                        // Move the node to the head of the MRU list if it's not already there
                        if (this._mruList.Count > 1 && !object.ReferenceEquals(this._mruList.First, entry.Node))
                        {
                            this._mruList.Remove(entry.Node);
                            this._mruList.AddFirst(entry.Node);
                            this.mruEntry = entry;
                        }

                        tokens.Add(entry.Value);
                    }
                }
            }

            return(tokens);
        }
 public SecurityContextSecurityToken(System.Xml.UniqueId contextId, string id, byte[] key, DateTime validFrom, DateTime validTo, System.Collections.ObjectModel.ReadOnlyCollection <System.IdentityModel.Policy.IAuthorizationPolicy> authorizationPolicies)
 {
 }
 public SecurityContextSecurityToken(System.Xml.UniqueId contextId, string id, byte[] key, DateTime validFrom, DateTime validTo)
 {
 }
 public override void RemoveAll(string endpointId, System.Xml.UniqueId contextId)
 {
     throw new NotImplementedException("PassiveRepositorySessionSecurityTokenCache.RemoveAll");
 }
        public static System.ServiceModel.Security.Tokens.SecurityContextSecurityToken CreateCookieSecurityContextToken(System.Xml.UniqueId contextId, string id, byte[] key, DateTime validFrom, DateTime validTo, System.Collections.ObjectModel.ReadOnlyCollection <System.IdentityModel.Policy.IAuthorizationPolicy> authorizationPolicies, System.ServiceModel.Security.SecurityStateEncoder securityStateEncoder)
        {
            Contract.Ensures(Contract.Result <System.ServiceModel.Security.Tokens.SecurityContextSecurityToken>() != null);

            return(default(System.ServiceModel.Security.Tokens.SecurityContextSecurityToken));
        }
 public SecurityContextKeyIdentifierClause(System.Xml.UniqueId contextId) : base(default(string))
 {
 }
 public override IEnumerable <SessionSecurityToken> GetAll(
     string endpointId, System.Xml.UniqueId contextId)
 {
     throw new NotImplementedException("PassiveRepositorySessionSecurityTokenCache.GetAll");
 }
Example #13
0
        public void RemoveContext(System.Xml.UniqueId contextId, System.Xml.UniqueId generation)
        {
            SessionSecurityTokenCacheKey key = new SessionSecurityTokenCacheKey(_claimsHandler.EndpointId, contextId, generation);

            _tokenCache.Remove(key);
        }
 public SecurityContextKeyIdentifierClause(System.Xml.UniqueId contextId, System.Xml.UniqueId generation, byte[] derivationNonce, int derivationLength) : base(default(string))
 {
 }
 public bool Matches(System.Xml.UniqueId contextId, System.Xml.UniqueId generation)
 {
     return(default(bool));
 }
 public System.Collections.ObjectModel.Collection <SecurityContextSecurityToken> GetAllContexts(System.Xml.UniqueId contextId)
 {
     return(default(System.Collections.ObjectModel.Collection <SecurityContextSecurityToken>));
 }
 public SecurityContextSecurityToken GetContext(System.Xml.UniqueId contextId, System.Xml.UniqueId generation)
 {
     return(default(SecurityContextSecurityToken));
 }
 public void RemoveContext(System.Xml.UniqueId contextId, System.Xml.UniqueId generation)
 {
 }
 public void RemoveAllContexts(System.Xml.UniqueId contextId)
 {
 }
 public virtual void WriteValue(System.Xml.UniqueId value)
 {
 }
Example #21
0
 /// <summary>
 /// Removes all the tokens that match the contextId.
 /// </summary>
 /// <param name="contextId">The context id.</param>
 /// <remarks>
 /// When WCF renews a token, its context id is the same as the issuedToken. The only
 /// difference is in the generationId. When WCF closes the session channel, all the tokens that
 /// were issued need to be removed that match the contextId.
 /// </remarks>
 public void RemoveAllContexts(System.Xml.UniqueId contextId)
 {
     _tokenCache.RemoveAll(_claimsHandler.EndpointId, contextId);
 }