Example #1
0
        public Task <IResultModel> Install()
        {
            var model = new SystemInstallModel
            {
                Permissions = _permissionHelper.GetAllPermission()
            };

            return(_systemService.Install(model));
        }
Example #2
0
 public Task <IResultModel> Sync()
 {
     return(_service.Sync(_permissionHelper.GetAllPermission()));
 }
Example #3
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var    rd                = httpContext.Request.RequestContext.RouteData;
            string currentAction     = rd.GetRequiredString("action");
            string currentController = rd.GetRequiredString("controller");
            string currentArea       = rd.Values["area"] as string;
            string currentUser       = HttpContext.Current.User.Identity.GetUserId();

            if (string.IsNullOrEmpty(this.ControllerName))
            {
                ControllerName += currentController;
            }
            if (string.IsNullOrEmpty(this.ActionName))
            {
                ActionName += currentAction;
            }

            // this is overriden for kendo menus to hide

            /*
             * var ctrl = filterContext.RequestContext.RouteData.GetRequiredString("controller");
             * var action = filterContext.ActionDescriptor.ActionName;
             */

            var isAuthorized = base.AuthorizeCore(httpContext);

            if (!isAuthorized)
            {
                return(false);
            }

            bool hasPermission = false;


            try
            {
                var perList = PermissionHelper.GetAllPermission();
                //Has data from cache
                if (perList != null && perList.Count > 0)
                {
                    hasPermission = perList.Exists(m => string.Equals(m.Action, currentAction, StringComparison.CurrentCultureIgnoreCase) &&
                                                   (string.Equals(m.Controller, currentController, StringComparison.CurrentCultureIgnoreCase)));
                }
                else
                {
                    hasPermission = false;
                }

                //var cacheProvider = GlobalContainer.IocContainer.Resolve<ICacheProvider>();
                //List<IdentityPermission> perList;
                //var myKey = ALL_PERMISSIONS_KEY + currentUser;

                ////Check from cache first
                //cacheProvider.Get(myKey, out perList);

                ////Has data from cache
                //if(perList != null && perList.Count > 0 )
                //{
                //    hasPermission = perList.Exists(m => string.Equals(m.Action, currentAction, StringComparison.CurrentCultureIgnoreCase)
                //    && (string.Equals(m.Controller, currentController, StringComparison.CurrentCultureIgnoreCase)));
                //}
                //else
                //{
                //    var _rolesIdentityStore = GlobalContainer.IocContainer.Resolve<IAccessRolesStore>();

                //    perList = _rolesIdentityStore.GetPermissionsByUser(currentUser);
                //    if (perList != null && perList.Count > 0)
                //    {
                //        hasPermission = perList.Exists(m => string.Equals(m.Action, currentAction, StringComparison.CurrentCultureIgnoreCase)
                //    && (string.Equals(m.Controller, currentController, StringComparison.CurrentCultureIgnoreCase)));

                //        //Write to cache
                //        cacheProvider.Set(myKey, perList);
                //    }
                //    else
                //    {
                //        hasPermission = false;
                //    }
                //}
            }
            catch (Exception ex)
            {
                var strError = string.Format("Could not check permission of user [{0}] because: {1}", currentUser, ex.ToString());
                logger.Error(strError);
            }

            //var _rolesIdentityStore =  GlobalContainer.IocContainer.Resolve<IAccessRolesStore>();

            //hasPermission = _rolesIdentityStore.GetPermissionsByUser(currentUser,);

            /*
             * string privilegeLevels = string.Join("", GetUserRights(httpContext.User.Identity.Name.ToString())); // Call another method to get rights of the user from DB
             *
             * if (privilegeLevels.Contains(this.AccessLevel))
             * {
             *  return true;
             * }
             * else
             * {
             *  return false;
             * }
             */
            //return true;
            return(hasPermission);
        }