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> /// Deserializes the SecurityToken from the given XmlReader. /// </summary> /// <param name="reader">Reader to a Security token.</param> /// <param name="tokenResolver">Instance of SecurityTokenResolver.</param> /// <returns>'True' if the serializer can read the given Security Token.</returns> /// <exception cref="ArgumentNullException">The input parameter 'reader' is null.</exception> protected override SecurityToken ReadTokenCore(XmlReader reader, SecurityTokenResolver tokenResolver) { if (reader == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } try { foreach (SecurityTokenHandler securityTokenHandler in _securityTokenHandlers) { if (securityTokenHandler.CanReadToken(reader)) { SecurityToken token = securityTokenHandler.ReadToken(reader, tokenResolver); SessionSecurityToken sessionToken = token as SessionSecurityToken; if (sessionToken != null) { if (sessionToken.SecureConversationVersion.AbsoluteUri != _scVersion.Namespace.Value) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID4053, sessionToken.SecureConversationVersion, _scVersion)); } return(SecurityContextSecurityTokenHelper.ConvertSessionTokenToSecurityContextSecurityToken(sessionToken)); } else { return(token); } } } return(base.ReadTokenCore(reader, tokenResolver)); } catch (Exception ex) { if (!(MapExceptionsToSoapFaults && _exceptionMapper.HandleSecurityTokenProcessingException(ex))) { throw; } Fx.Assert(false, "ExceptionMapper did not handle an exception correctly."); // This should never happen. ExceptionMapper will handle the exception, in which case, // a fault exception is thrown or the original exception gets thrown. } return(null); }
/// <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); }