Beispiel #1
0
        public override void WhenNotLogin(ref ActionExecutingContext filterContext)
        {
            var context      = HttpContext.Current;
            var continue_url = this.SpecifyedContinueUrl;

            if (ValidateHelper.IsPlumpString(continue_url))
            {
                continue_url = RequestHelper.GetBaseUrl(context.Request) + continue_url;
            }
            else
            {
                continue_url = RequestHelper.GetCurrentUrl(context.Request);
            }
            var login_url = SSOClientHelper.BuildSSOLoginUrl(continue_url);

            if (this.NoLoginResultAsInterface)
            {
                filterContext.Result = GetJson(new _()
                {
                    success = false,
                    msg     = "未登录",
                    data    = new { sso_login = login_url },
                    code    = "-999"
                });
            }
            else
            {
                filterContext.Result = new RedirectResult(login_url);
            }
        }
Beispiel #2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            SSOClientHelper.CheckSSOConfig();

            var context = HttpContext.Current;

            var user = AppContext.GetObject <LoginStatus>().GetLoginUser(context);

            if (user == null)
            {
                //没有登陆就跳转登陆
                var url          = context.Request.Url.ToString();
                var redirect_url = AppContext.GetObject <IGetLoginUrl>().GetUrl(url);
                filterContext.Result = new RedirectResult(redirect_url);
                return;
            }
            //验证权限
            if (Permission?.Length > 0)
            {
                foreach (var p in Permission.Split(',').Where(x => x?.Length > 0))
                {
                    if (!user.HasPermission(p))
                    {
                        ActionResult re = null;
                        if (ReDirectUrl?.Length > 0)
                        {
                            re = new RedirectResult(ReDirectUrl);
                        }
                        else
                        {
                            re = new JsonResult()
                            {
                                Data = new ResJson()
                                {
                                    Success = false, ErrorMsg = "没有权限", ErrorCode = p
                                },
                                JsonRequestBehavior = JsonRequestBehavior.AllowGet
                            };
                        }
                        filterContext.Result = re;
                        return;
                    }
                }
            }
        }
Beispiel #3
0
 public SSOCheckAttribute()
 {
     SSOClientHelper.CheckSSOConfig();
 }
Beispiel #4
0
        public string GetUrl(string current_url = null)
        {
            var url = HttpContext.Current.Request.Url.ToString();

            return(SSOClientHelper.BuildSSOLoginUrl(url));
        }