Esempio n. 1
0
        public string GetSalt(string username, IScope context = null)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentException("username");
            }
            var opid = GETSALTOPID + Interlocked.Increment(ref logonid);

            if (Logg.IsForDebug())
            {
                Logg.Debug(new { opid, username, context });
            }
            string result      = null;
            var    securelogon = Extensions.OfType <ISecureLogon>().FirstOrDefault();

            if (null == securelogon)
            {
                if (Logg.IsForError())
                {
                    Logg.Error(new { opid, message = "not secure login confugured" }.stringify());
                }
            }
            else
            {
                result = securelogon.GetSalt(username);
            }
            if (Logg.IsForDebug())
            {
                Logg.Debug(new { opid, username, salt = result }.stringify());
            }
            return(result);
        }
        private void Store(PostMessage message)
        {
            var result = EsClient.ExecuteCommand(BaseUrl() + "/" + message.Id + "?refresh=true", message.stringify());

            if (null == result)
            {
                Logg.Error(new {
                    error_in_es = EsClient.LastError.Message,
                    urls        = EsClient.Urls.ToArray()
                }.stringify());
                throw  EsClient.LastError;
            }
        }
Esempio n. 3
0
        public IIdentity Logon(string username, SecureLogonInfo info, IScope context = null)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentException("username");
            }
            if (null == info)
            {
                throw new ArgumentException("info");
            }
            if (string.IsNullOrWhiteSpace(info.Salt))
            {
                throw new ArgumentException("info.salt");
            }
            if (string.IsNullOrWhiteSpace(info.Sign))
            {
                throw new ArgumentException("info.sign");
            }
            var opid = SECLOGONOPID + Interlocked.Increment(ref logonid);

            LogStart(username, info, context, opid);
            var securelogon = Extensions.OfType <ISecureLogon>().FirstOrDefault();

            if (null == securelogon)
            {
                if (Logg.IsForError())
                {
                    Logg.Error(new { opid, message = "not secure login confugured" });
                }
                return(GetErrorLogon(username,
                                     new SecurityException("secure logon not supported in current configuration")));
            }
            IIdentity result = null;

            try {
                result = securelogon.Logon(username, info, context) ?? GetDefaultLogon(username);
            }
            catch (Exception ex) {
                LogError(username, info, context, opid, ex);
                result = GetErrorLogon(username, ex);
                ((Identity)result).State = UserActivityState.Error;
            }
            Identity ires = (Identity)result;

            if (ires.State == UserActivityState.None)
            {
                ires.State = ires.IsAuthenticated ? UserActivityState.Ok : UserActivityState.InvalidLogonInfo;
            }
            LogResult(result, opid);
            return(result);
        }
Esempio n. 4
0
 private void LogError(string username, string password, IScope context, string opid, Exception ex)
 {
     if (Logg.IsForError())
     {
         Logg.Error(
             new {
             opid,
             username,
             password = password.GetMd5(),
             context,
             logonerror = ex.Message
         }.stringify());
     }
 }
Esempio n. 5
0
 private void LogError(string username, SecureLogonInfo info, IScope context, string opid, Exception ex)
 {
     if (Logg.IsForError())
     {
         Logg.Error(
             new {
             opid,
             username,
             salt = info.Salt,
             sign = info.Sign,
             context,
             logonerror = ex.Message
         }.stringify());
     }
 }
Esempio n. 6
0
        public async Task <IReportContext> Execute(IReportRequest request)
        {
            Logg.Debug(new { op = "start", r = request }.stringify());
            var context = InitializeContext(request);

            try {
                var scope = new Scope();
                await ExecutePhase(context, ReportPhase.Init, scope);
                await ExecutePhase(context, ReportPhase.Data, scope);
                await ExecutePhase(context, ReportPhase.Prepare, scope);

                if (request.DataOnly)
                {
                    if (null != context.Data)
                    {
                        context.SetHeader("Content-Type", "application/json; charset=utf-8");
                        context.Write(context.Data.stringify());
                    }
                }
                else
                {
                    await ExecutePhase(context, ReportPhase.Render, scope);
                }
                await ExecutePhase(context, ReportPhase.Finalize, scope);

                context.Finish();
            }
            catch (Exception e) {
                Logg.Error(e);
                context.Error = e;
                if (!context.Request.NoFinalizeOnError)
                {
                    context.Finish(e);
                }
            }
            finally {
                Logg.Trace(new { op = "success", r = request }.stringify());
            }
            return(context);
        }