public MsmqOutputSessionChannel(MsmqChannelFactory<IOutputSessionChannel> factory, EndpointAddress to, Uri via, bool manualAddressing)
     : base(factory, to, via, manualAddressing, factory.MessageVersion)
 {
     this.factory = factory;
     this.encoder = this.factory.MessageEncoderFactory.CreateSessionEncoder();
     this.buffers = new List<ArraySegment<byte>>();
     this.buffers.Add(EncodeSessionPreamble());
     if (factory.IsMsmqX509SecurityConfigured)
     {
         this.certificateTokenProvider = factory.CreateX509TokenProvider(to, via);
     }
     this.session = new OutputSession();
 }
Exemple #2
0
        public static Task<NetworkCredential> GetCredentialAsync(AuthenticationSchemes authenticationScheme, SecurityTokenProviderContainer credentialProvider,
            OutWrapper<TokenImpersonationLevel> impersonationLevelWrapper, OutWrapper<AuthenticationLevel> authenticationLevelWrapper,
            CancellationToken cancellationToken)
        {
            impersonationLevelWrapper.Value = TokenImpersonationLevel.None;
            authenticationLevelWrapper.Value = AuthenticationLevel.None;

            if (authenticationScheme == AuthenticationSchemes.Anonymous)
            {
                return Task.FromResult((NetworkCredential)null);
            }

            return GetCredentialCoreAsync(authenticationScheme, credentialProvider, impersonationLevelWrapper,
                    authenticationLevelWrapper, cancellationToken);
        }
 public MsmqOutputChannel(MsmqChannelFactory<IOutputChannel> factory, EndpointAddress to, Uri via, bool manualAddressing) : base(factory, to, via, manualAddressing, factory.MessageVersion)
 {
     byte[] modeBytes = ClientSingletonSizedEncoder.ModeBytes;
     EncodedVia via2 = new EncodedVia(this.Via.AbsoluteUri);
     EncodedContentType contentType = EncodedContentType.Create(factory.MessageEncoderFactory.Encoder.ContentType);
     this.preamble = DiagnosticUtility.Utility.AllocateByteArray(modeBytes.Length + ClientSingletonSizedEncoder.CalcStartSize(via2, contentType));
     Buffer.BlockCopy(modeBytes, 0, this.preamble, 0, modeBytes.Length);
     ClientSingletonSizedEncoder.EncodeStart(this.preamble, modeBytes.Length, via2, contentType);
     this.outputMessages = new SynchronizedDisposablePool<MsmqOutputMessage<IOutputChannel>>(factory.MaxPoolSize);
     if (factory.IsMsmqX509SecurityConfigured)
     {
         this.certificateTokenProvider = factory.CreateX509TokenProvider(to, via);
     }
     this.factory = factory;
 }
        static async Task<NetworkCredential> GetCredentialCoreAsync(AuthenticationSchemes authenticationScheme,
            SecurityTokenProviderContainer credentialProvider, OutWrapper<TokenImpersonationLevel> impersonationLevelWrapper,
            OutWrapper<AuthenticationLevel> authenticationLevelWrapper, CancellationToken cancellationToken)
        {
            impersonationLevelWrapper.Value = TokenImpersonationLevel.None;
            authenticationLevelWrapper.Value = AuthenticationLevel.None;

            NetworkCredential result = null;

            switch (authenticationScheme)
            {
                case AuthenticationSchemes.Basic:
                    result = await TransportSecurityHelpers.GetUserNameCredentialAsync(credentialProvider, cancellationToken);
                    impersonationLevelWrapper.Value = TokenImpersonationLevel.Delegation;
                    break;

                case AuthenticationSchemes.Digest:
                    result = await TransportSecurityHelpers.GetSspiCredentialAsync(credentialProvider,
                        impersonationLevelWrapper, authenticationLevelWrapper, cancellationToken);
                    ValidateDigestCredential(result, impersonationLevelWrapper.Value);
                    break;

                case AuthenticationSchemes.Negotiate:
                    result = await TransportSecurityHelpers.GetSspiCredentialAsync(credentialProvider,
                        impersonationLevelWrapper, authenticationLevelWrapper, cancellationToken);
                    break;

                case AuthenticationSchemes.Ntlm:
                    result = await TransportSecurityHelpers.GetSspiCredentialAsync(credentialProvider,
                        impersonationLevelWrapper, authenticationLevelWrapper, cancellationToken);
                    if (authenticationLevelWrapper.Value == AuthenticationLevel.MutualAuthRequired)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                            new InvalidOperationException(SR.CredentialDisallowsNtlm));
                    }
                    break;

                default:
                    // The setter for this property should prevent this.
                    throw Fx.AssertAndThrow("GetCredential: Invalid authentication scheme");
            }

            return result;
        }
        void CleanupTokenProviders()
        {
            if (_webRequestTokenProvider != null)
            {
                _webRequestTokenProvider.Abort();
                _webRequestTokenProvider = null;
            }

            if (_webRequestProxyTokenProvider != null)
            {
                _webRequestProxyTokenProvider.Abort();
                _webRequestProxyTokenProvider = null;
            }
        }
Exemple #6
0
        static NetworkCredential GetCredentialCore(AuthenticationSchemes authenticationScheme,
            SecurityTokenProviderContainer credentialProvider, TimeSpan timeout,
            out TokenImpersonationLevel impersonationLevel, out AuthenticationLevel authenticationLevel)
        {
            impersonationLevel = TokenImpersonationLevel.None;
            authenticationLevel = AuthenticationLevel.None;

            NetworkCredential result = null;

            switch (authenticationScheme)
            {
                case AuthenticationSchemes.Basic:
                    result = TransportSecurityHelpers.GetUserNameCredential(credentialProvider, timeout);
                    impersonationLevel = TokenImpersonationLevel.Delegation;
                    break;

                case AuthenticationSchemes.Digest:
                    result = TransportSecurityHelpers.GetSspiCredential(credentialProvider, timeout,
                        out impersonationLevel, out authenticationLevel);

                    HttpChannelUtilities.ValidateDigestCredential(ref result, impersonationLevel);
                    break;

                case AuthenticationSchemes.Negotiate:
                    result = TransportSecurityHelpers.GetSspiCredential(credentialProvider, timeout,
                        out impersonationLevel, out authenticationLevel);
                    break;

                case AuthenticationSchemes.Ntlm:
                    result = TransportSecurityHelpers.GetSspiCredential(credentialProvider, timeout,
                        out impersonationLevel, out authenticationLevel);
                    if (authenticationLevel == AuthenticationLevel.MutualAuthRequired)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                            new InvalidOperationException(SR.GetString(SR.CredentialDisallowsNtlm)));
                    }
                    break;

                default:
                    // The setter for this property should prevent this.
                    throw Fx.AssertAndThrow("GetCredential: Invalid authentication scheme");
            }

            return result;
        }
Exemple #7
0
        public static NetworkCredential GetCredential(AuthenticationSchemes authenticationScheme,
            SecurityTokenProviderContainer credentialProvider, TimeSpan timeout,
            out TokenImpersonationLevel impersonationLevel, out AuthenticationLevel authenticationLevel)
        {
            impersonationLevel = TokenImpersonationLevel.None;
            authenticationLevel = AuthenticationLevel.None;

            NetworkCredential result = null;

            if (authenticationScheme != AuthenticationSchemes.Anonymous)
            {
                result = GetCredentialCore(authenticationScheme, credentialProvider, timeout, out impersonationLevel, out authenticationLevel);
            }

            return result;
        }
        void CleanupTokenProviders()
        {
            if (this.webRequestTokenProvider != null)
            {
                this.webRequestTokenProvider.Abort();
                this.webRequestTokenProvider = null;
            }

            if (this.webRequestProxyTokenProvider != null)
            {
                this.webRequestProxyTokenProvider.Abort();
                this.webRequestProxyTokenProvider = null;
            }
        }
        private static NetworkCredential GetCredentialCore(AuthenticationSchemes authenticationScheme, SecurityTokenProviderContainer credentialProvider, TimeSpan timeout, out TokenImpersonationLevel impersonationLevel, out AuthenticationLevel authenticationLevel)
        {
            impersonationLevel = TokenImpersonationLevel.None;
            authenticationLevel = AuthenticationLevel.None;
            NetworkCredential userNameCredential = null;
            switch (authenticationScheme)
            {
                case AuthenticationSchemes.Digest:
                    userNameCredential = TransportSecurityHelpers.GetSspiCredential(credentialProvider, timeout, out impersonationLevel, out authenticationLevel);
                    ValidateDigestCredential(ref userNameCredential, impersonationLevel);
                    return userNameCredential;

                case AuthenticationSchemes.Negotiate:
                    return TransportSecurityHelpers.GetSspiCredential(credentialProvider, timeout, out impersonationLevel, out authenticationLevel);

                case AuthenticationSchemes.Ntlm:
                    userNameCredential = TransportSecurityHelpers.GetSspiCredential(credentialProvider, timeout, out impersonationLevel, out authenticationLevel);
                    if (authenticationLevel == AuthenticationLevel.MutualAuthRequired)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CredentialDisallowsNtlm")));
                    }
                    return userNameCredential;

                case AuthenticationSchemes.Basic:
                    userNameCredential = TransportSecurityHelpers.GetUserNameCredential(credentialProvider, timeout);
                    impersonationLevel = TokenImpersonationLevel.Delegation;
                    return userNameCredential;
            }
            throw Fx.AssertAndThrow("GetCredential: Invalid authentication scheme");
        }