Example #1
0
        internal bool TryGetSupportingTokens(SecurityProtocolFactory factory, EndpointAddress target, Uri via, Message message, TimeSpan timeout, bool isBlockingCall, out IList <SupportingTokenSpecification> supportingTokens)
        {
            if (!factory.ActAsInitiator)
            {
                supportingTokens = null;
                return(true);
            }
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            supportingTokens = null;
            IList <SupportingTokenProviderSpecification> supportingTokenProviders = this.GetSupportingTokenProviders(message.Headers.Action);

            if (supportingTokenProviders != null && supportingTokenProviders.Count > 0)
            {
                // dont do anything if blocking is not allowed
                if (!isBlockingCall)
                {
                    return(false);
                }

                supportingTokens = new Collection <SupportingTokenSpecification>();
                for (int i = 0; i < supportingTokenProviders.Count; ++i)
                {
                    SupportingTokenProviderSpecification spec = supportingTokenProviders[i];
                    SecurityToken supportingToken;
                    // The ProviderBackedSecurityToken was added in Win7 to allow KerberosRequestorSecurity
                    // to pass a channel binding to InitializeSecurityContext.
                    if ((this is TransportSecurityProtocol) && (spec.TokenParameters is KerberosSecurityTokenParameters))
                    {
                        supportingToken = new ProviderBackedSecurityToken(spec.TokenProvider, timeoutHelper.RemainingTime());
                    }
                    else
                    {
                        supportingToken = spec.TokenProvider.GetToken(timeoutHelper.RemainingTime());
                    }

                    supportingTokens.Add(new SupportingTokenSpecification(supportingToken, EmptyReadOnlyCollection <IAuthorizationPolicy> .Instance, spec.SecurityTokenAttachmentMode, spec.TokenParameters));
                }
            }
            // add any runtime supporting tokens
            AddMessageSupportingTokens(message, ref supportingTokens);

            return(true);
        }
Example #2
0
        private void AttachChannelBindingTokenIfFound()
        {
            ChannelBindingMessageProperty property = null;

            ChannelBindingMessageProperty.TryGet(base.InnerMessage, out property);
            if (((property != null) && (this.securityHeader.ElementContainer != null)) && (this.securityHeader.ElementContainer.EndorsingSupportingTokens != null))
            {
                foreach (SecurityToken token in this.securityHeader.ElementContainer.EndorsingSupportingTokens)
                {
                    ProviderBackedSecurityToken token2 = token as ProviderBackedSecurityToken;
                    if (token2 != null)
                    {
                        token2.ChannelBinding = property.ChannelBinding;
                    }
                }
            }
        }
        internal bool TryGetSupportingTokens(System.ServiceModel.Security.SecurityProtocolFactory factory, EndpointAddress target, Uri via, Message message, TimeSpan timeout, bool isBlockingCall, out IList <SupportingTokenSpecification> supportingTokens)
        {
            if (!factory.ActAsInitiator)
            {
                supportingTokens = null;
                return(true);
            }
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            TimeoutHelper helper = new TimeoutHelper(timeout);

            supportingTokens = null;
            IList <SupportingTokenProviderSpecification> supportingTokenProviders = this.GetSupportingTokenProviders(message.Headers.Action);

            if ((supportingTokenProviders != null) && (supportingTokenProviders.Count > 0))
            {
                if (!isBlockingCall)
                {
                    return(false);
                }
                supportingTokens = new Collection <SupportingTokenSpecification>();
                for (int i = 0; i < supportingTokenProviders.Count; i++)
                {
                    SecurityToken token;
                    SupportingTokenProviderSpecification specification = supportingTokenProviders[i];
                    if ((this is TransportSecurityProtocol) && (specification.TokenParameters is KerberosSecurityTokenParameters))
                    {
                        token = new ProviderBackedSecurityToken(specification.TokenProvider, helper.RemainingTime());
                    }
                    else
                    {
                        token = specification.TokenProvider.GetToken(helper.RemainingTime());
                    }
                    supportingTokens.Add(new SupportingTokenSpecification(token, EmptyReadOnlyCollection <IAuthorizationPolicy> .Instance, specification.SecurityTokenAttachmentMode, specification.TokenParameters));
                }
            }
            this.AddMessageSupportingTokens(message, ref supportingTokens);
            return(true);
        }
Example #4
0
        private void AttachChannelBindingTokenIfFound()
        {
            ChannelBindingMessageProperty cbmp = null;

            ChannelBindingMessageProperty.TryGet(this.InnerMessage, out cbmp);

            if (cbmp != null)
            {
                if (this.securityHeader.ElementContainer != null && this.securityHeader.ElementContainer.EndorsingSupportingTokens != null)
                {
                    foreach (SecurityToken token in this.securityHeader.ElementContainer.EndorsingSupportingTokens)
                    {
                        ProviderBackedSecurityToken pbst = token as ProviderBackedSecurityToken;
                        if (pbst != null)
                        {
                            pbst.ChannelBinding = cbmp.ChannelBinding;
                        }
                    }
                }
            }
        }