Beispiel #1
0
        public void Test_AuthorizationDeletion()
        {
            UserAccount            userAccount;
            EntityType             entityType;
            IEntity                entity;
            Authorization          authorization;
            CachingQueryRepository cachingQueryRepository;

            cachingQueryRepository = (CachingQueryRepository) new EntityAccessControlFactory().Caches.First(c => c is CachingQueryRepository);

            userAccount      = new UserAccount();
            userAccount.Name = Guid.NewGuid().ToString();
            userAccount.Save();

            entityType = new EntityType();
            entityType.Save();

            entity = Entity.Create(entityType);
            entity.Save();

            authorization = new AccessControlHelper().AddAllowReadQuery(userAccount.As <Subject>(),
                                                                        entityType.As <SecurableEntity>(), TestQueries.GetAllEntitiesReport());

            Assert.That(cachingQueryRepository.Cache,
                        Has.Exactly(0)
                        .Property("Key").Property("SubjectId").EqualTo(userAccount.Id)
                        .And.Property("Key").Property("PermissionId").EqualTo(Permission.Read.Id)
                        .And.Property("Key").Property("EntityTypes").Contains(entityType.Id),
                        "Entry initially present in cache");

            using (new SetUser(userAccount))
            {
                Assert.That(() => Entity.Get(entity.Id), Throws.Nothing);
            }

            Assert.That(cachingQueryRepository.Cache,
                        Has.Exactly(1)
                        .Property("Key").Property("SubjectId").EqualTo(userAccount.Id)
                        .And.Property("Key").Property("PermissionId").EqualTo(Permission.Read.Id)
                        .And.Property("Key").Property("EntityTypes").Contains(entityType.Id),
                        "Entry not added to cache");

            authorization.Delete();

            Assert.That(cachingQueryRepository.Cache,
                        Has.Exactly(0)
                        .Property("Key").Property("SubjectId").EqualTo(userAccount.Id)
                        .And.Property("Key").Property("PermissionId").EqualTo(Permission.Read.Id)
                        .And.Property("Key").Property("EntityTypes").Contains(entityType.Id),
                        "Entry not removed from cache");
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var builder = new ContainerBuilder();

            // etc..
            // register access control
            builder.RegisterType <ActionAccessStrategy>().As <IResourceAccessStrategy>();
            builder.RegisterType <ControlAccessStrategy>().As <IControlAccessStrategy>();
            var container = builder.Build();

            AccessControlHelper.RegisterAccessControlHelper <ActionAccessStrategy, ControlAccessStrategy>(type => container.Resolve(type));
        }