Exemple #1
0
 private cCredentials(eAccountType pType, cLogin pLogin, bool pTryAllSASLs = false)
 {
     Type        = pType;
     UserId      = null;
     Login       = pLogin;
     TryAllSASLs = pTryAllSASLs;
 }
Exemple #2
0
        /**<summary></summary>*/
        protected cCredentials(string pUserId, cLogin pLogin, bool pTryAllSASLs = false)
        {
            if (string.IsNullOrEmpty(pUserId))
            {
                throw new ArgumentOutOfRangeException(nameof(pUserId));
            }

            Type        = eAccountType.userid;
            UserId      = pUserId;
            Login       = pLogin;
            TryAllSASLs = pTryAllSASLs;
        }
Exemple #3
0
        internal static bool TryConstruct(string pUserId, string pPassword, eTLSRequirement pTLSRequirement, out cLogin rLogin)
        {
            if (string.IsNullOrEmpty(pUserId) || string.IsNullOrEmpty(pPassword))
            {
                rLogin = null; return(false);
            }

            if (!cCommandPartFactory.TryAsASCIILiteral(pUserId, true, out _))
            {
                rLogin = null; return(false);
            }
            if (!cCommandPartFactory.TryAsASCIILiteral(pPassword, true, out _))
            {
                rLogin = null; return(false);
            }

            rLogin = new cLogin(pUserId, pPassword, pTLSRequirement, true);
            return(true);
        }
Exemple #4
0
            public async Task <Exception> LoginAsync(cMethodControl pMC, cAccountId pAccountId, cLogin pLogin, cTrace.cContext pParentContext)
            {
                var lContext = pParentContext.NewMethod(nameof(cSession), nameof(LoginAsync), pMC, pAccountId);

                if (mDisposed)
                {
                    throw new ObjectDisposedException(nameof(cSession));
                }
                if (_ConnectionState != eConnectionState.notauthenticated)
                {
                    throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotUnauthenticated);
                }

                using (var lBuilder = new cCommandDetailsBuilder())
                {
                    //  note the lack of locking - this is only called during connect

                    lBuilder.Add(kLoginCommandPartLogin, cCommandPartFactory.AsASCIILiteral(pLogin.UserId), cCommandPart.Space, cCommandPartFactory.AsASCIILiteral(pLogin.Password));

                    var lHook = new cCommandHookInitial();
                    lBuilder.Add(lHook);

                    var lCapabilities = mPipeline.Capabilities;

                    var lResult = await mPipeline.ExecuteAsync(pMC, lBuilder.EmitCommandDetails(), lContext).ConfigureAwait(false);

                    if (lResult.ResultType == eCommandResultType.ok)
                    {
                        lContext.TraceInformation("login success");
                        ZAuthenticated(lCapabilities, lHook, lResult.ResponseText, pAccountId, lContext);
                        return(null);
                    }

                    if (lHook.Capabilities != null)
                    {
                        lContext.TraceError("received capability on a failed login");
                    }

                    if (lResult.ResultType == eCommandResultType.no)
                    {
                        lContext.TraceInformation("login failed: {0}", lResult.ResponseText);

                        if (ZSetHomeServerReferral(lResult.ResponseText, lContext))
                        {
                            return(new cHomeServerReferralException(lResult.ResponseText, lContext));
                        }

                        if (lResult.ResponseText.Code == eResponseTextCode.authenticationfailed || lResult.ResponseText.Code == eResponseTextCode.authorizationfailed || lResult.ResponseText.Code == eResponseTextCode.expired)
                        {
                            return(new cCredentialsException(lResult.ResponseText, lContext));
                        }

                        return(null);
                    }

                    throw new cProtocolErrorException(lResult, 0, lContext);
                }
            }