Exemple #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);
        }
Exemple #2
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);
        }
Exemple #3
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());
     }
 }
Exemple #4
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());
     }
 }