Esempio n. 1
0
        public override LoginUserInfo FindUser(HttpContext context)
        {
            try
            {
                var uid   = ls.GetCookieUID(context);
                var token = ls.GetCookieToken(context);
                if (!ValidateHelper.IsAllPlumpString(uid, token))
                {
                    return(null);
                }

                var user = IocContext.Instance.Scope(s =>
                {
                    var key   = CacheKeyManager.AuthSSOUserInfoKey(uid);
                    var cache = s.Resolve_ <ICacheProvider>();
                    return(cache.GetOrSet(key, () =>
                    {
                        using (var db = new SSODB())
                        {
                            var model = db.T_UserInfo.Where(x => x.UID == uid).FirstOrDefault();
                            if (model == null)
                            {
                                return null;
                            }
                            //load permission
                            //这里只拿了角色关联的权限,部门关联的权限没有拿
                            var roleslist = db.Auth_UserRole.Where(x => x.UserID == uid)
                                            .Select(x => x.RoleID).ToList()
                                            .Select(x => $"role:{x}").ToList();

                            model.Permissions = db.Auth_PermissionMap.Where(x => roleslist.Contains(x.MapKey))
                                                .Select(x => x.PermissionID).ToList()
                                                .Distinct().ToList();

                            return model;
                        }
                    }, TimeSpan.FromSeconds(60)));
                });

                if (user == null || user.CreateToken() != token)
                {
                    return(null);
                }

                return(user.LoginUserInfo());
            }
            catch (Exception e)
            {
                e.AddErrorLog();
                return(null);
            }
        }
Esempio n. 2
0
 public override string AuthSSOUserInfoCacheKey(string user_uid) =>
 CacheKeyManager.AuthSSOUserInfoKey(user_uid);