Esempio n. 1
0
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            if (ReturnEmptyResult || filterContext.IsChildAction)
            {
                filterContext.Result = new EmptyResult();
            }
            else
            {
                if (filterContext.Controller.GetType().GetCustomAttributes(typeof(MaterialCMSAuthorizeAttribute), true).Any())
                {
                    if (filterContext.HttpContext.User.Identity.IsAuthenticated)
                    {
                        var routingErrorHandler = MaterialCMSApplication.Get <IMaterialCMSRoutingErrorHandler>();
                        var routeData           = filterContext.RouteData;
                        routeData.Route = RouteTable.Routes.Last();
                        routeData.DataTokens.Remove("area");

                        var    requestContext = new RequestContext(filterContext.HttpContext, routeData);
                        string message        = string.Format("Not allowed to view {0}", requestContext.HttpContext.Request.Url);
                        var    code           = CurrentRequestData.CurrentUser != null ? 403 : 401;
                        routingErrorHandler.HandleError(requestContext, code, new HttpException(code, message));

                        filterContext.Result = new EmptyResult();
                    }
                    else
                    {
                        base.HandleUnauthorizedRequest(filterContext);
                    }
                }
            }
        }
Esempio n. 2
0
        public override void InitHelpers()
        {
            base.InitHelpers();

            if (CurrentRequestData.DatabaseIsInstalled)
            {
                _kernel = MaterialCMSApplication.Get <IKernel>();
                _stringResourceProvider = MaterialCMSApplication.Get <IStringResourceProvider>();
                GetCurrentLayout        = MaterialCMSApplication.Get <IGetCurrentLayout>();
            }
        }
Esempio n. 3
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var result = filterContext.Result as ViewResult;

            if (result == null)
            {
                return;
            }
            var webpage = result.Model as Webpage;

            if (webpage == null)
            {
                return;
            }
            MaterialCMSApplication.Get <IProcessWebpageViews>().Process(result, webpage);
        }
Esempio n. 4
0
        private static void SetSiteFilter(Site value)
        {
            var session = MaterialCMSApplication.Get <ISession>();

            if (value != null)
            {
                session.EnableFilter("SiteFilter").SetParameter("site", value.Id);
            }
            else
            {
                IFilter enabledFilter = session.GetEnabledFilter("SiteFilter");
                if (enabledFilter != null)
                {
                    session.DisableFilter("SiteFilter");
                }
            }
        }
        protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
        {
            if (!CurrentRequestData.CurrentUser.IsActive)
            {
                return(false);
            }
            object idVal;

            if (httpContext.Request.RequestContext.RouteData.Values.TryGetValue("id", out idVal))
            {
                int id;
                if (int.TryParse(Convert.ToString(idVal), out id))
                {
                    var o = MaterialCMSApplication.Get <ISession>().Get(_type, id);
                    if (o == null)
                    {
                        return(false);
                    }

                    return(new TypeACLRule().CanAccess(CurrentRequestData.CurrentUser, _operation, o.GetType().FullName));
                }
            }
            return(false);
        }