Example #1
0
        public void MasterNotCheckedState()
        {
            var checker = new UserStateChecker();
            var user    = new User {
                Logable = true, Active = true, Expire = DateTime.Now.AddDays(10), Domain = "m1"
            };

            Assert.AreEqual(UserActivityState.MasterNotChecked, checker.GetActivityState(user));
        }
Example #2
0
        public void ExpireActivityState()
        {
            var checker = new UserStateChecker();
            var user    = new User {
                Logable = true, Active = true, Expire = DateTime.Now.AddDays(-10)
            };

            Assert.AreEqual(UserActivityState.Expired, checker.GetActivityState(user));
        }
Example #3
0
        public void InvalidMasterState()
        {
            var us      = new UserService();
            var checker = new UserStateChecker {
                UserService = us
            };
            var user = new User {
                Logable = true, Active = true, Expire = DateTime.Now.AddDays(10), Domain = "m1"
            };

            Assert.AreEqual(UserActivityState.InvalidMaster, checker.GetActivityState(user));
        }
Example #4
0
        private Identity BuildIdentity(Token token)
        {
            var result = new Identity {
                Token              = token,
                Name               = token.User,
                IsAuthenticated    = true,
                AuthenticationType = "form",
                IsAdmin            = token.IsAdmin
            };
            var errormessage = "";
            var user         = UserService.GetUser(token.User);

            if (null != user)
            {
                result.User    = user;
                result.IsAdmin = user.IsAdmin;
                var userstate = UserStateChecker.GetActivityState(user);
                if (userstate != UserActivityState.Ok)
                {
                    result.IsError = true;
                    errormessage  += userstate.ToStr() + "; ";
                }
            }
            if (!string.IsNullOrWhiteSpace(token.ImUser))
            {
                var imtoken = new Token {
                    User = token.ImUser
                };
                var imidentity = BuildIdentity(imtoken);
                result.ImpersonationSource = imidentity;
                if (!imidentity.IsAuthenticated)
                {
                    result.IsError = true;
                    errormessage  += "not-auth impersonation; ";
                }
                else if (!imidentity.IsAdmin)
                {
                    result.IsError = true;
                    errormessage  += "non-admin impersonation;";
                }
            }
            if (result.IsError)
            {
                result.IsAuthenticated = false;
                result.Error           = new SecurityException(errormessage);
            }
            return(result);
        }
Example #5
0
        public void MasterExpireState()
        {
            var us = new UserService();

            us.RegisterExtension(new UserSource(new User {
                Login = "******", IsGroup = true, Active = true, Expire = DateTime.Now.AddDays(-10)
            }));
            var checker = new UserStateChecker {
                UserService = us
            };
            var user = new User {
                Logable = true, Active = true, Expire = DateTime.Now.AddDays(10), Domain = "m1"
            };

            Assert.AreEqual(UserActivityState.MasterExpired, checker.GetActivityState(user));
        }