Exemplo n.º 1
0
        internal async Task <IList <SupportingTokenSpecification> > TryGetSupportingTokensAsync(SecurityProtocolFactory factory, EndpointAddress target, Uri via, Message message, TimeSpan timeout)
        {
            IList <SupportingTokenSpecification> supportingTokens = null;

            if (!factory.ActAsInitiator)
            {
                return(null);
            }

            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
            }

            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            IList <SupportingTokenProviderSpecification> supportingTokenProviders = GetSupportingTokenProviders(message.Headers.Action);

            if (supportingTokenProviders != null && supportingTokenProviders.Count > 0)
            {
                supportingTokens = new Collection <SupportingTokenSpecification>();
                for (int i = 0; i < supportingTokenProviders.Count; ++i)
                {
                    SupportingTokenProviderSpecification spec = supportingTokenProviders[i];
                    SecurityToken supportingToken;
                    supportingToken = await spec.TokenProvider.GetTokenAsync(timeoutHelper.RemainingTime());

                    supportingTokens.Add(new SupportingTokenSpecification(supportingToken, EmptyReadOnlyCollection <IAuthorizationPolicy> .Instance, spec.SecurityTokenAttachmentMode, spec.TokenParameters));
                }
            }

            // add any runtime supporting tokens
            AddMessageSupportingTokens(message, ref supportingTokens);
            return(supportingTokens);
        }
            private void AddSupportingToken(IAsyncResult result)
            {
                SupportingTokenProviderSpecification specification = this.supportingTokenProviders[this.currentTokenProviderIndex];

                if (result is SecurityTokenProvider.SecurityTokenAsyncResult)
                {
                    this.supportingTokens.Add(new SupportingTokenSpecification(SecurityTokenProvider.SecurityTokenAsyncResult.End(result), EmptyReadOnlyCollection <IAuthorizationPolicy> .Instance, specification.SecurityTokenAttachmentMode, specification.TokenParameters));
                }
                else
                {
                    this.supportingTokens.Add(new SupportingTokenSpecification(specification.TokenProvider.EndGetToken(result), EmptyReadOnlyCollection <IAuthorizationPolicy> .Instance, specification.SecurityTokenAttachmentMode, specification.TokenParameters));
                }
                this.currentTokenProviderIndex++;
            }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
            void AddSupportingToken(IAsyncResult result)
            {
                SupportingTokenProviderSpecification spec = supportingTokenProviders[this.currentTokenProviderIndex];

                SecurityTokenProvider.SecurityTokenAsyncResult securityTokenAsyncResult = result as SecurityTokenProvider.SecurityTokenAsyncResult;
                if (securityTokenAsyncResult != null)
                {
                    this.supportingTokens.Add(new SupportingTokenSpecification(SecurityTokenProvider.SecurityTokenAsyncResult.End(result), EmptyReadOnlyCollection <IAuthorizationPolicy> .Instance, spec.SecurityTokenAttachmentMode, spec.TokenParameters));
                }
                else
                {
                    this.supportingTokens.Add(new SupportingTokenSpecification(spec.TokenProvider.EndGetToken(result), EmptyReadOnlyCollection <IAuthorizationPolicy> .Instance, spec.SecurityTokenAttachmentMode, spec.TokenParameters));
                }

                ++this.currentTokenProviderIndex;
            }
        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);
        }
 private bool AddSupportingTokens()
 {
     while (this.currentTokenProviderIndex < this.supportingTokenProviders.Count)
     {
         SupportingTokenProviderSpecification specification = this.supportingTokenProviders[this.currentTokenProviderIndex];
         IAsyncResult result = null;
         if ((this.binding is TransportSecurityProtocol) && (specification.TokenParameters is KerberosSecurityTokenParameters))
         {
             result = new SecurityTokenProvider.SecurityTokenAsyncResult(new ProviderBackedSecurityToken(specification.TokenProvider, this.timeoutHelper.RemainingTime()), null, this);
         }
         else
         {
             result = specification.TokenProvider.BeginGetToken(this.timeoutHelper.RemainingTime(), getSupportingTokensCallback, this);
         }
         if (!result.CompletedSynchronously)
         {
             return(false);
         }
         this.AddSupportingToken(result);
     }
     this.binding.AddMessageSupportingTokens(this.message, ref this.supportingTokens);
     return(this.OnGetSupportingTokensDone(this.timeoutHelper.RemainingTime()));
 }
 void AddSupportingTokenProviders(SupportingTokenParameters supportingTokenParameters, bool isOptional, IList<SupportingTokenProviderSpecification> providerSpecList)
 {
     for (int i = 0; i < supportingTokenParameters.Endorsing.Count; ++i)
     {
         SecurityTokenRequirement requirement = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.Endorsing[i], SecurityTokenAttachmentMode.Endorsing);
         try
         {
             if (isOptional)
             {
                 requirement.IsOptionalToken = true;
             }
             System.IdentityModel.Selectors.SecurityTokenProvider provider = this.factory.SecurityTokenManager.CreateSecurityTokenProvider(requirement);
             if (provider == null)
             {
                 continue;
             }
             SupportingTokenProviderSpecification providerSpec = new SupportingTokenProviderSpecification(provider, SecurityTokenAttachmentMode.Endorsing, supportingTokenParameters.Endorsing[i]);
             providerSpecList.Add(providerSpec);
         }
         catch (Exception e)
         {
             if (!isOptional || Fx.IsFatal(e))
             {
                 throw;
             }
         }
     }
     for (int i = 0; i < supportingTokenParameters.SignedEndorsing.Count; ++i)
     {
         SecurityTokenRequirement requirement = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.SignedEndorsing[i], SecurityTokenAttachmentMode.SignedEndorsing);
         try
         {
             if (isOptional)
             {
                 requirement.IsOptionalToken = true;
             }
             System.IdentityModel.Selectors.SecurityTokenProvider provider = this.factory.SecurityTokenManager.CreateSecurityTokenProvider(requirement);
             if (provider == null)
             {
                 continue;
             }
             SupportingTokenProviderSpecification providerSpec = new SupportingTokenProviderSpecification(provider, SecurityTokenAttachmentMode.SignedEndorsing, supportingTokenParameters.SignedEndorsing[i]);
             providerSpecList.Add(providerSpec);
         }
         catch (Exception e)
         {
             if (!isOptional || Fx.IsFatal(e))
             {
                 throw;
             }
         }
     }
     for (int i = 0; i < supportingTokenParameters.SignedEncrypted.Count; ++i)
     {
         SecurityTokenRequirement requirement = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.SignedEncrypted[i], SecurityTokenAttachmentMode.SignedEncrypted);
         try
         {
             if (isOptional)
             {
                 requirement.IsOptionalToken = true;
             }
             System.IdentityModel.Selectors.SecurityTokenProvider provider = this.factory.SecurityTokenManager.CreateSecurityTokenProvider(requirement);
             if (provider == null)
             {
                 continue;
             }
             SupportingTokenProviderSpecification providerSpec = new SupportingTokenProviderSpecification(provider, SecurityTokenAttachmentMode.SignedEncrypted, supportingTokenParameters.SignedEncrypted[i]);
             providerSpecList.Add(providerSpec);
         }
         catch (Exception e)
         {
             if (!isOptional || Fx.IsFatal(e))
             {
                 throw;
             }
         }
     }
     for (int i = 0; i < supportingTokenParameters.Signed.Count; ++i)
     {
         SecurityTokenRequirement requirement = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.Signed[i], SecurityTokenAttachmentMode.Signed);
         try
         {
             if (isOptional)
             {
                 requirement.IsOptionalToken = true;
             }
             System.IdentityModel.Selectors.SecurityTokenProvider provider = this.factory.SecurityTokenManager.CreateSecurityTokenProvider(requirement);
             if (provider == null)
             {
                 continue;
             }
             SupportingTokenProviderSpecification providerSpec = new SupportingTokenProviderSpecification(provider, SecurityTokenAttachmentMode.Signed, supportingTokenParameters.Signed[i]);
             providerSpecList.Add(providerSpec);
         }
         catch (Exception e)
         {
             if (!isOptional || Fx.IsFatal(e))
             {
                 throw;
             }
         }
     }
 }
Exemplo n.º 8
0
        private void AddSupportingTokenProviders(SupportingTokenParameters supportingTokenParameters, bool isOptional, IList <SupportingTokenProviderSpecification> providerSpecList)
        {
            for (int i = 0; i < supportingTokenParameters.Endorsing.Count; ++i)
            {
                SecurityTokenRequirement requirement = CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.Endorsing[i], SecurityTokenAttachmentMode.Endorsing);
                try
                {
                    if (isOptional)
                    {
                        requirement.IsOptionalToken = true;
                    }
                    SecurityTokenProvider provider = SecurityProtocolFactory.SecurityTokenManager.CreateSecurityTokenProvider(requirement);
                    if (provider == null)
                    {
                        continue;
                    }
                    SupportingTokenProviderSpecification providerSpec = new SupportingTokenProviderSpecification(provider, SecurityTokenAttachmentMode.Endorsing, supportingTokenParameters.Endorsing[i]);
                    providerSpecList.Add(providerSpec);
                }
                catch (Exception e)
                {
                    if (!isOptional || Fx.IsFatal(e))
                    {
                        throw;
                    }
                }
            }

            for (int i = 0; i < supportingTokenParameters.SignedEndorsing.Count; ++i)
            {
                SecurityTokenRequirement requirement = CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.SignedEndorsing[i], SecurityTokenAttachmentMode.SignedEndorsing);
                try
                {
                    if (isOptional)
                    {
                        requirement.IsOptionalToken = true;
                    }
                    SecurityTokenProvider provider = SecurityProtocolFactory.SecurityTokenManager.CreateSecurityTokenProvider(requirement);
                    if (provider == null)
                    {
                        continue;
                    }
                    SupportingTokenProviderSpecification providerSpec = new SupportingTokenProviderSpecification(provider, SecurityTokenAttachmentMode.SignedEndorsing, supportingTokenParameters.SignedEndorsing[i]);
                    providerSpecList.Add(providerSpec);
                }
                catch (Exception e)
                {
                    if (!isOptional || Fx.IsFatal(e))
                    {
                        throw;
                    }
                }
            }

            for (int i = 0; i < supportingTokenParameters.SignedEncrypted.Count; ++i)
            {
                SecurityTokenRequirement requirement = CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.SignedEncrypted[i], SecurityTokenAttachmentMode.SignedEncrypted);
                try
                {
                    if (isOptional)
                    {
                        requirement.IsOptionalToken = true;
                    }
                    SecurityTokenProvider provider = SecurityProtocolFactory.SecurityTokenManager.CreateSecurityTokenProvider(requirement);
                    if (provider == null)
                    {
                        continue;
                    }
                    SupportingTokenProviderSpecification providerSpec = new SupportingTokenProviderSpecification(provider, SecurityTokenAttachmentMode.SignedEncrypted, supportingTokenParameters.SignedEncrypted[i]);
                    providerSpecList.Add(providerSpec);
                }
                catch (Exception e)
                {
                    if (!isOptional || Fx.IsFatal(e))
                    {
                        throw;
                    }
                }
            }

            for (int i = 0; i < supportingTokenParameters.Signed.Count; ++i)
            {
                SecurityTokenRequirement requirement = CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.Signed[i], SecurityTokenAttachmentMode.Signed);
                try
                {
                    if (isOptional)
                    {
                        requirement.IsOptionalToken = true;
                    }
                    SecurityTokenProvider provider = SecurityProtocolFactory.SecurityTokenManager.CreateSecurityTokenProvider(requirement);
                    if (provider == null)
                    {
                        continue;
                    }
                    SupportingTokenProviderSpecification providerSpec = new SupportingTokenProviderSpecification(provider, SecurityTokenAttachmentMode.Signed, supportingTokenParameters.Signed[i]);
                    providerSpecList.Add(providerSpec);
                }
                catch (Exception e)
                {
                    if (!isOptional || Fx.IsFatal(e))
                    {
                        throw;
                    }
                }
            }
        }
 private void AddSupportingTokenProviders(SupportingTokenParameters supportingTokenParameters, bool isOptional, IList<SupportingTokenProviderSpecification> providerSpecList)
 {
     for (int i = 0; i < supportingTokenParameters.Endorsing.Count; i++)
     {
         SecurityTokenRequirement tokenRequirement = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.Endorsing[i], SecurityTokenAttachmentMode.Endorsing);
         try
         {
             SupportingTokenProviderSpecification item = new SupportingTokenProviderSpecification(this.factory.SecurityTokenManager.CreateSecurityTokenProvider(tokenRequirement), SecurityTokenAttachmentMode.Endorsing, supportingTokenParameters.Endorsing[i]);
             providerSpecList.Add(item);
         }
         catch (Exception exception)
         {
             if (!isOptional || Fx.IsFatal(exception))
             {
                 throw;
             }
         }
     }
     for (int j = 0; j < supportingTokenParameters.SignedEndorsing.Count; j++)
     {
         SecurityTokenRequirement requirement2 = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.SignedEndorsing[j], SecurityTokenAttachmentMode.SignedEndorsing);
         try
         {
             SupportingTokenProviderSpecification specification2 = new SupportingTokenProviderSpecification(this.factory.SecurityTokenManager.CreateSecurityTokenProvider(requirement2), SecurityTokenAttachmentMode.SignedEndorsing, supportingTokenParameters.SignedEndorsing[j]);
             providerSpecList.Add(specification2);
         }
         catch (Exception exception2)
         {
             if (!isOptional || Fx.IsFatal(exception2))
             {
                 throw;
             }
         }
     }
     for (int k = 0; k < supportingTokenParameters.SignedEncrypted.Count; k++)
     {
         SecurityTokenRequirement requirement3 = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.SignedEncrypted[k], SecurityTokenAttachmentMode.SignedEncrypted);
         try
         {
             SupportingTokenProviderSpecification specification3 = new SupportingTokenProviderSpecification(this.factory.SecurityTokenManager.CreateSecurityTokenProvider(requirement3), SecurityTokenAttachmentMode.SignedEncrypted, supportingTokenParameters.SignedEncrypted[k]);
             providerSpecList.Add(specification3);
         }
         catch (Exception exception3)
         {
             if (!isOptional || Fx.IsFatal(exception3))
             {
                 throw;
             }
         }
     }
     for (int m = 0; m < supportingTokenParameters.Signed.Count; m++)
     {
         SecurityTokenRequirement requirement4 = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.Signed[m], SecurityTokenAttachmentMode.Signed);
         try
         {
             SupportingTokenProviderSpecification specification4 = new SupportingTokenProviderSpecification(this.factory.SecurityTokenManager.CreateSecurityTokenProvider(requirement4), SecurityTokenAttachmentMode.Signed, supportingTokenParameters.Signed[m]);
             providerSpecList.Add(specification4);
         }
         catch (Exception exception4)
         {
             if (!isOptional || Fx.IsFatal(exception4))
             {
                 throw;
             }
         }
     }
 }
 private void AddSupportingTokenProviders(SupportingTokenParameters supportingTokenParameters, bool isOptional, IList <SupportingTokenProviderSpecification> providerSpecList)
 {
     for (int i = 0; i < supportingTokenParameters.Endorsing.Count; i++)
     {
         SecurityTokenRequirement tokenRequirement = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.Endorsing[i], SecurityTokenAttachmentMode.Endorsing);
         try
         {
             SupportingTokenProviderSpecification item = new SupportingTokenProviderSpecification(this.factory.SecurityTokenManager.CreateSecurityTokenProvider(tokenRequirement), SecurityTokenAttachmentMode.Endorsing, supportingTokenParameters.Endorsing[i]);
             providerSpecList.Add(item);
         }
         catch (Exception exception)
         {
             if (!isOptional || Fx.IsFatal(exception))
             {
                 throw;
             }
         }
     }
     for (int j = 0; j < supportingTokenParameters.SignedEndorsing.Count; j++)
     {
         SecurityTokenRequirement requirement2 = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.SignedEndorsing[j], SecurityTokenAttachmentMode.SignedEndorsing);
         try
         {
             SupportingTokenProviderSpecification specification2 = new SupportingTokenProviderSpecification(this.factory.SecurityTokenManager.CreateSecurityTokenProvider(requirement2), SecurityTokenAttachmentMode.SignedEndorsing, supportingTokenParameters.SignedEndorsing[j]);
             providerSpecList.Add(specification2);
         }
         catch (Exception exception2)
         {
             if (!isOptional || Fx.IsFatal(exception2))
             {
                 throw;
             }
         }
     }
     for (int k = 0; k < supportingTokenParameters.SignedEncrypted.Count; k++)
     {
         SecurityTokenRequirement requirement3 = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.SignedEncrypted[k], SecurityTokenAttachmentMode.SignedEncrypted);
         try
         {
             SupportingTokenProviderSpecification specification3 = new SupportingTokenProviderSpecification(this.factory.SecurityTokenManager.CreateSecurityTokenProvider(requirement3), SecurityTokenAttachmentMode.SignedEncrypted, supportingTokenParameters.SignedEncrypted[k]);
             providerSpecList.Add(specification3);
         }
         catch (Exception exception3)
         {
             if (!isOptional || Fx.IsFatal(exception3))
             {
                 throw;
             }
         }
     }
     for (int m = 0; m < supportingTokenParameters.Signed.Count; m++)
     {
         SecurityTokenRequirement requirement4 = this.CreateInitiatorSecurityTokenRequirement(supportingTokenParameters.Signed[m], SecurityTokenAttachmentMode.Signed);
         try
         {
             SupportingTokenProviderSpecification specification4 = new SupportingTokenProviderSpecification(this.factory.SecurityTokenManager.CreateSecurityTokenProvider(requirement4), SecurityTokenAttachmentMode.Signed, supportingTokenParameters.Signed[m]);
             providerSpecList.Add(specification4);
         }
         catch (Exception exception4)
         {
             if (!isOptional || Fx.IsFatal(exception4))
             {
                 throw;
             }
         }
     }
 }