Exemplo n.º 1
0
        public SsoUser GetUser()
        {
            //sso逻辑
            var token = HttpContext.Current.Request.QueryString["token"];

            if (token.IsNullOrEmpty())
            {
                token = CookieHelper.GetCookieValue("token");
            }
            //根据token 获取用户信息,并保存token
            if (!token.IsNullOrEmpty())
            {
                try
                {
                    var ssoserver    = ConfigSettingHelper.GetAppStr("ssoserver");
                    var userinfojson = ApiDataHelper.GetData(ssoserver + api + "?token=" + token);
                    var user         = JsonHelper.DeserializeObject <SsoUser>(userinfojson);
                    return(user);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
            //todo 获取用户信息,获取到了直接返回,这里可以替换使用应用程序中的数据
            var userName = CookieHelper.GetCookieValue(SsoClient.UserName);

            if (!userName.IsNullOrEmpty())
            {
                FormsAuthentication.SetAuthCookie(userName, true);
                return;
            }

            var user = SsoClient.Instance.GetUser();

            if (user == null)
            {
                //跳转到sso登录页面
                var ssoserverLogin = ConfigSettingHelper.GetAppStr("ssoserver") + loginurl + "?returnurl=" + filterContext.RequestContext.HttpContext.Request.Url.AbsoluteUri;
                filterContext.Result = new RedirectResult(ssoserverLogin);
                return;
            }

            CookieHelper.SetCookie(SsoClient.Token, user.token);
            CookieHelper.SetCookie(SsoClient.UserName, user.username);
            FormsAuthentication.SetAuthCookie(user.username, true);
            filterContext.Result = new RedirectResult(filterContext.RequestContext.HttpContext.Request.Url.AbsoluteUri);
        }
Exemplo n.º 3
0
        static Composition()
        {
            var pluginName = ConfigSettingHelper.GetAppStr("PluginName");
            var dirCatalog = new DirectoryCatalog(".", pluginName + ".*.dll");

            container = new System.ComponentModel.Composition.Hosting.CompositionContainer(dirCatalog);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据权限生成超链接,当没有权限返回空
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="linkText"></param>
        /// <param name="actionName"></param>
        /// <param name="controllerName"></param>
        /// <param name="class"></param>
        /// <param name="htmlAttrbuites"></param>
        /// <param name="routeAttributes"></param>
        /// <returns></returns>
        public static HtmlString AuthedLink(this HtmlHelper helper,
                                            string linkText,
                                            string actionName,
                                            string controllerName,
                                            string @class,
                                            object htmlAttrbuites,
                                            object routeAttributes)
        {
            var enablePermission = ConfigSettingHelper.GetAppStr <bool>("EnablePermission");
            var area             = "";

            if (helper.ViewContext.RouteData.DataTokens["area"] != null)
            {
                area = helper.ViewContext.RouteData.DataTokens["area"].ToString();
            }
            if (enablePermission)
            {
                var roles = LoginHelper.Instance.GetLoginUserRoles();
                if (roles == null)
                {
                    return(new HtmlString(""));
                }

                if (!roles.CheckRole(controllerName, actionName, area))
                {
                    return(new HtmlString(""));
                }
            }
            TagBuilder tag = new TagBuilder("a");

            tag.AddCssClass(@class);
            if (htmlAttrbuites != null)
            {
                var ats = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttrbuites);
                foreach (var at in ats)
                {
                    tag.Attributes.Add(at.Key, at.Value.ToString());
                }
            }
            var d = new RouteValueDictionary();

            d.Add("area", area);
            if (routeAttributes != null)
            {
                var atts = HtmlHelper.AnonymousObjectToHtmlAttributes(routeAttributes);
                foreach (var att in atts)
                {
                    d.Add(att.Key, att.Value);
                }
            }
            UrlHelper urlhelp = new UrlHelper(helper.ViewContext.RequestContext);

            tag.Attributes.Add("href", urlhelp.Action(actionName, controllerName, d));
            tag.InnerHtml = linkText;
            return(new HtmlString(tag.ToString()));
        }
Exemplo n.º 5
0
        public static HtmlString AuthedLink(this HtmlHelper helper,
                                            string linkText,
                                            string actionName,
                                            string controllerName,
                                            string para   = "",
                                            string @class = "",
                                            string attr   = ""
                                            )
        {
            var area = "";

            if (helper.ViewContext.RouteData.DataTokens["area"] != null)
            {
                area = helper.ViewContext.RouteData.DataTokens["area"].ToString();
            }
            var enablePermission = ConfigSettingHelper.GetAppStr <bool>("EnablePermission");

            if (enablePermission)
            {
                var roles = LoginHelper.Instance.GetLoginUserRoles();
                if (roles == null)
                {
                    return(new HtmlString(""));
                }
                if (!roles.CheckRole(controllerName, actionName, area))
                {
                    return(new HtmlString(""));
                }
            }
            var d = new RouteValueDictionary();

            d.Add("area", area);


            UrlHelper urlhelp = new UrlHelper(helper.ViewContext.RequestContext);
            var       rurl    = urlhelp.Action(actionName, controllerName, d) + "?" + para;

            return(new HtmlString("<a class='" + @class + "' " + attr + " href='" + rurl + "'>" + linkText + "</a>"));
        }
Exemplo n.º 6
0
 /// <summary>
 /// 获取appsetting
 /// </summary>
 /// <param name="knl"></param>
 /// <param name="key"></param>
 /// <returns></returns>
 public static string GetAppSetting(this IKernel knl, string key)
 {
     return(ConfigSettingHelper.GetAppStr(key));
 }
Exemplo n.º 7
0
 public MongoDbRepository()
 {
     this._dbName = ConfigSettingHelper.GetAppStr("MongoDBName");
 }
Exemplo n.º 8
0
 public static void Init()
 {
     Path = ConfigSettingHelper.GetAppStr("indexpath");
     // FSDirectory directory = FSDirectory.Open(new DirectoryInfo(IndexPath), new NoLockFactory());
     //_reader = IndexReader.Open(directory, true);
 }