Exemplo n.º 1
0
 private void LogStart(string username, SecureLogonInfo info, IScope context, string opid)
 {
     if (Logg.IsForDebug())
     {
         Logg.Debug(new { opid, username, salt = info.Salt, sign = info.Sign, context }.stringify());
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 3
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());
     }
 }
Exemplo n.º 4
0
        public IIdentity Logon(string username, SecureLogonInfo info, IScope context = null)
        {
            if (null == UserService)
            {
                return(null);
            }
            var user = UserService.GetUser(username);

            if (!StateChecker.IsSecureLogable(user))
            {
                return(null);
            }
            var result = new Identity {
                Name = username,
                AuthenticationType = "secure"
            };
            var state = StateChecker.GetActivityState(user);

            if (state != UserActivityState.Ok)
            {
                result.IsError = true;
                result.Error   = new SecurityException(state.ToStr());
            }
            else
            {
                try {
                    SecureLogonService.CheckSecureInfo(info, user, context);
                    result.IsAuthenticated = true;
                    result.User            = user;
                    result.IsAdmin         = user.IsAdmin;
                }
                catch (Exception e) {
                    result.IsError = true;
                    result.Error   = e;
                }
            }

            return(result);
        }