protected SecurityTokenAuthenticator CreateSecureConversationTokenAuthenticator(RecipientServiceModelSecurityTokenRequirement recipientRequirement, bool preserveBootstrapTokens, out SecurityTokenResolver sctResolver)
 {
     SecurityBindingElement securityBindingElement = recipientRequirement.SecurityBindingElement;
     if (securityBindingElement == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(System.ServiceModel.SR.GetString("TokenAuthenticatorRequiresSecurityBindingElement", new object[] { recipientRequirement }));
     }
     bool flag = !recipientRequirement.SupportSecurityContextCancellation;
     LocalServiceSecuritySettings localServiceSettings = securityBindingElement.LocalServiceSettings;
     IMessageFilterTable<EndpointAddress> propertyOrDefault = recipientRequirement.GetPropertyOrDefault<IMessageFilterTable<EndpointAddress>>(ServiceModelSecurityTokenRequirement.EndpointFilterTableProperty, null);
     if (!flag)
     {
         sctResolver = new SecurityContextSecurityTokenResolver(0x7fffffff, false);
         return new SecuritySessionSecurityTokenAuthenticator { BootstrapSecurityBindingElement = System.ServiceModel.Security.SecurityUtils.GetIssuerSecurityBindingElement(recipientRequirement), IssuedSecurityTokenParameters = recipientRequirement.GetProperty<SecurityTokenParameters>(ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty), IssuedTokenCache = (ISecurityContextSecurityTokenCache) sctResolver, IssuerBindingContext = recipientRequirement.GetProperty<BindingContext>(ServiceModelSecurityTokenRequirement.IssuerBindingContextProperty), KeyEntropyMode = securityBindingElement.KeyEntropyMode, ListenUri = recipientRequirement.ListenUri, SecurityAlgorithmSuite = recipientRequirement.SecurityAlgorithmSuite, SessionTokenLifetime = TimeSpan.MaxValue, KeyRenewalInterval = securityBindingElement.LocalServiceSettings.SessionKeyRenewalInterval, StandardsManager = System.ServiceModel.Security.SecurityUtils.CreateSecurityStandardsManager(recipientRequirement, this), EndpointFilterTable = propertyOrDefault, MaximumConcurrentNegotiations = localServiceSettings.MaxStatefulNegotiations, NegotiationTimeout = localServiceSettings.NegotiationTimeout, PreserveBootstrapTokens = preserveBootstrapTokens };
     }
     sctResolver = new SecurityContextSecurityTokenResolver(localServiceSettings.MaxCachedCookies, true, localServiceSettings.MaxClockSkew);
     return new AcceleratedTokenAuthenticator { 
         BootstrapSecurityBindingElement = System.ServiceModel.Security.SecurityUtils.GetIssuerSecurityBindingElement(recipientRequirement), KeyEntropyMode = securityBindingElement.KeyEntropyMode, EncryptStateInServiceToken = true, IssuedSecurityTokenParameters = recipientRequirement.GetProperty<SecurityTokenParameters>(ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty), IssuedTokenCache = (ISecurityContextSecurityTokenCache) sctResolver, IssuerBindingContext = recipientRequirement.GetProperty<BindingContext>(ServiceModelSecurityTokenRequirement.IssuerBindingContextProperty), ListenUri = recipientRequirement.ListenUri, SecurityAlgorithmSuite = recipientRequirement.SecurityAlgorithmSuite, StandardsManager = System.ServiceModel.Security.SecurityUtils.CreateSecurityStandardsManager(recipientRequirement, this), SecurityStateEncoder = this.parent.SecureConversationAuthentication.SecurityStateEncoder, KnownTypes = this.parent.SecureConversationAuthentication.SecurityContextClaimTypes, PreserveBootstrapTokens = preserveBootstrapTokens, MaximumCachedNegotiationState = localServiceSettings.MaxStatefulNegotiations, NegotiationTimeout = localServiceSettings.NegotiationTimeout, ServiceTokenLifetime = localServiceSettings.IssuedCookieLifetime, MaximumConcurrentNegotiations = localServiceSettings.MaxStatefulNegotiations, 
         AuditLogLocation = recipientRequirement.AuditLogLocation, SuppressAuditFailure = recipientRequirement.SuppressAuditFailure, MessageAuthenticationAuditLevel = recipientRequirement.MessageAuthenticationAuditLevel, EndpointFilterTable = propertyOrDefault
      };
 }
        protected SecurityTokenAuthenticator CreateSecureConversationTokenAuthenticator(RecipientServiceModelSecurityTokenRequirement recipientRequirement, bool preserveBootstrapTokens, out SecurityTokenResolver sctResolver)
        {
            SecurityBindingElement securityBindingElement = recipientRequirement.SecurityBindingElement;
            if (securityBindingElement == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.TokenAuthenticatorRequiresSecurityBindingElement, recipientRequirement));
            }
            bool isCookieMode = !recipientRequirement.SupportSecurityContextCancellation;
            LocalServiceSecuritySettings localServiceSettings = securityBindingElement.LocalServiceSettings;
            IMessageFilterTable<EndpointAddress> endpointFilterTable = recipientRequirement.GetPropertyOrDefault<IMessageFilterTable<EndpointAddress>>(ServiceModelSecurityTokenRequirement.EndpointFilterTableProperty, null);

            if (!isCookieMode)
            {
                sctResolver = new SecurityContextSecurityTokenResolver(Int32.MaxValue, false);

                // remember this authenticator for future reference
                SecuritySessionSecurityTokenAuthenticator authenticator = new SecuritySessionSecurityTokenAuthenticator();
                authenticator.BootstrapSecurityBindingElement = SecurityUtils.GetIssuerSecurityBindingElement(recipientRequirement);
                authenticator.IssuedSecurityTokenParameters = recipientRequirement.GetProperty<SecurityTokenParameters>(ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty);
                authenticator.IssuedTokenCache = (ISecurityContextSecurityTokenCache)sctResolver;
                authenticator.IssuerBindingContext = recipientRequirement.GetProperty<BindingContext>(ServiceModelSecurityTokenRequirement.IssuerBindingContextProperty);
                authenticator.KeyEntropyMode = securityBindingElement.KeyEntropyMode;
                authenticator.ListenUri = recipientRequirement.ListenUri;
                authenticator.SecurityAlgorithmSuite = recipientRequirement.SecurityAlgorithmSuite;
                authenticator.SessionTokenLifetime = TimeSpan.MaxValue;
                authenticator.KeyRenewalInterval = securityBindingElement.LocalServiceSettings.SessionKeyRenewalInterval;
                authenticator.StandardsManager = SecurityUtils.CreateSecurityStandardsManager(recipientRequirement, this);
                authenticator.EndpointFilterTable = endpointFilterTable;
                authenticator.MaximumConcurrentNegotiations = localServiceSettings.MaxStatefulNegotiations;
                authenticator.NegotiationTimeout = localServiceSettings.NegotiationTimeout;
                authenticator.PreserveBootstrapTokens = preserveBootstrapTokens;
                return authenticator;
            }
            else
            {
                sctResolver = new SecurityContextSecurityTokenResolver(localServiceSettings.MaxCachedCookies, true, localServiceSettings.MaxClockSkew);

                AcceleratedTokenAuthenticator authenticator = new AcceleratedTokenAuthenticator();
                authenticator.BootstrapSecurityBindingElement = SecurityUtils.GetIssuerSecurityBindingElement(recipientRequirement);
                authenticator.KeyEntropyMode = securityBindingElement.KeyEntropyMode;
                authenticator.EncryptStateInServiceToken = true;
                authenticator.IssuedSecurityTokenParameters = recipientRequirement.GetProperty<SecurityTokenParameters>(ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty);
                authenticator.IssuedTokenCache = (ISecurityContextSecurityTokenCache)sctResolver;
                authenticator.IssuerBindingContext = recipientRequirement.GetProperty<BindingContext>(ServiceModelSecurityTokenRequirement.IssuerBindingContextProperty);
                authenticator.ListenUri = recipientRequirement.ListenUri;
                authenticator.SecurityAlgorithmSuite = recipientRequirement.SecurityAlgorithmSuite;
                authenticator.StandardsManager = SecurityUtils.CreateSecurityStandardsManager(recipientRequirement, this);
                authenticator.SecurityStateEncoder = parent.SecureConversationAuthentication.SecurityStateEncoder;
                authenticator.KnownTypes = parent.SecureConversationAuthentication.SecurityContextClaimTypes;
                authenticator.PreserveBootstrapTokens = preserveBootstrapTokens;

                // local security quotas
                authenticator.MaximumCachedNegotiationState = localServiceSettings.MaxStatefulNegotiations;
                authenticator.NegotiationTimeout = localServiceSettings.NegotiationTimeout;
                authenticator.ServiceTokenLifetime = localServiceSettings.IssuedCookieLifetime;
                authenticator.MaximumConcurrentNegotiations = localServiceSettings.MaxStatefulNegotiations;

                // audit settings
                authenticator.AuditLogLocation = recipientRequirement.AuditLogLocation;
                authenticator.SuppressAuditFailure = recipientRequirement.SuppressAuditFailure;
                authenticator.MessageAuthenticationAuditLevel = recipientRequirement.MessageAuthenticationAuditLevel;
                authenticator.EndpointFilterTable = endpointFilterTable;
                return authenticator;
            }
        }