Пример #1
0
 public void UpdateRule(AccessRuleEntity rule)
 {
     using (IUnitOfWork uow = persistenceManager.UnitOfWorkFactory.CreateUnitOfWork(false, true))
     {
         IRepository <AccessRuleEntity> repo = uow.GetRepository <AccessRuleEntity>();
         repo.Put(rule);
         uow.Commit();
     }
 }
Пример #2
0
        public AccessRuleEntity GetRule(Int64 id)
        {
            AccessRuleEntity rule = null;

            using (IUnitOfWork uow = persistenceManager.UnitOfWorkFactory.CreateUnitOfWork(false, true))
            {
                IRepository <AccessRuleEntity> repo = uow.GetRepository <AccessRuleEntity>();
                rule = repo.Get(id);
            }
            return(rule);
        }
Пример #3
0
 public void ExportSecuirtyFeaturesToDatabase()
 {
     foreach (var area in ModuleHelper.Areas)
     {
         // complete feature key + display name
         // add the area to the DB
         AccessRuleEntity areaEntity = addFeatureToDB(area.AreaName, area.AreaName, null);
         foreach (var controller in ModuleHelper.GetControllersByArea(area))
         {
             // add area.controller to the DB
             string           controllerName   = controller.Name.Replace("Controller", "");
             string           controllerKey    = string.Format("{0}.{1}", area.AreaName, controllerName);
             AccessRuleEntity controllerEntity = addFeatureToDB(controllerKey, controllerName, areaEntity);
             var securedActions = ModuleHelper.GetActionsByController(controller).Where(p => p.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Count() <= 0).ToList();
             var openActions    = ModuleHelper.GetActionsByController(controller).Where(p => p.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Count() > 0).ToList();
             foreach (var action in securedActions)
             {
                 // add the area.controller.action to the DB
                 AccessRuleEntity actionEntity = addFeatureToDB(string.Format("{0}.{1}", controllerKey, action.Name), action.Name, controllerEntity);
             }
         }
     }
 }
Пример #4
0
        private AccessRuleEntity addFeatureToDB(string featureKey, string displayName, AccessRuleEntity parent)
        {
            //IUnitOfWork uow = persistenceManager.CreateUnitOfWork(false, true, false);
            using (IUnitOfWork uow = persistenceManager.UnitOfWorkFactory.CreateUnitOfWork(false, true))
            {
                IRepository <AccessRuleEntity> repo = uow.GetRepository <AccessRuleEntity>();

                AccessRuleEntity rule = repo.Query(p => p.SecurityKey.Equals(featureKey)).FirstOrDefault();
                if (rule == null)
                {
                    rule = new AccessRuleEntity()
                    {
                        SecurityKey        = featureKey,
                        DisplayName        = displayName,
                        SecurityObjectType = SecurityObjectType.Feature,
                        RuleBody           = string.Empty,
                        Parent             = parent,
                    };
                    repo.Put(rule);
                    uow.Commit();
                }
                return(rule);
            }
        }