Exemplo n.º 1
0
        private static void RunACL(ProgramArguments arguments)
        {
            var entities    = SystemStartTests.CreateTestEntities();
            var groups      = SystemStartTests.CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = SystemStartTests.CreateTestAces();
            var storage     = new DatabaseStorage {
                Aces = aces, Memberships = memberships, Entities = entities, Messages = new List <Tuple <int, DateTime, byte[]> >()
            };

            StartTheSystem(new MemoryDataProvider(storage));

            var ctx = new SecurityContextForConcurrencyTests(TestUser.User2);
            var ok  = ctx.HasPermission(1, PermissionType.See);

            AclEditor.Create(ctx)
            .Allow(1, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(2, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(5, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(14, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(50, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(51, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(52, TestUser.User3.Id, false, PermissionType.Custom10)
            .Apply();
            ok = ctx.HasPermission(52, PermissionType.See);

            started = DateTime.UtcNow;

            Task.Run(() => ACLExercise1(0));
            Enumerable.Range(1, arguments.Agents).Select(x => Task.Run(() => ACLExercise(x))).ToArray();
        }
Exemplo n.º 2
0
        private static void RunAcl(ProgramArguments arguments)
        {
            var entities    = SystemStartTests.CreateTestEntities();
            var groups      = SystemStartTests.CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = SystemStartTests.CreateTestAces();
            var storage     = new DatabaseStorage {
                Aces = aces, Memberships = memberships, Entities = entities, Messages = new List <Tuple <int, DateTime, byte[]> >()
            };

            var securitySystem = StartTheSystem(new MemoryDataProvider(storage));

            var ctx = new SecurityContext(TestUser.User2, securitySystem);
            // ReSharper disable once NotAccessedVariable
            var ok = ctx.HasPermission(1, PermissionType.See);

            new AclEditor(ctx)
            .Allow(1, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(2, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(5, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(14, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(50, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(51, TestUser.User3.Id, false, PermissionType.Custom10)
            .Allow(52, TestUser.User3.Id, false, PermissionType.Custom10)
            .Apply();
            // ReSharper disable once RedundantAssignment
            ok = ctx.HasPermission(52, PermissionType.See);

            _started = DateTime.UtcNow;

            Task.Run(() => AclExercise1(0, securitySystem));
            var _ = Enumerable.Range(1, arguments.Agents).Select(x => Task.Run(() => AclExercise(x, securitySystem))).ToArray();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //---- Ensure test data
            var entities    = SystemStartTests.CreateTestEntities();
            var groups      = SystemStartTests.CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = SystemStartTests.CreateTestAces();
            var storage     = new DatabaseStorage {
                Aces = aces, Memberships = memberships, Entities = entities
            };

            //---- Start the system
            Context.StartTheSystem(new MemoryDataProvider(storage));

            //---- Start the request
            var context = new Context(TestUser.User1);


            //======== Test
            var channel = context.Security.MessageProvider;

            channel.MessageReceived  += new MessageReceivedEventHandler(MessageReceived);
            channel.SendException    += new SendExceptionEventHandler(SendException);
            channel.ReceiveException += new ReceiveExceptionEventHandler(ReceiveException);

            Console.WriteLine("S<enter>: sent test, <enter>: clear screen, X<enter>: exit...");
            Console.WriteLine("Receiver: " + channel.ReceiverName);
            while (true)
            {
                var s = Console.ReadLine();
                if ("S" == s.ToUpper())
                {
                    channel.SendMessage(new PingMessage());
                    Console.WriteLine("A ping message was sent.");
                    //var activity = new Transperfect.Infrastructure.Security.Messaging.SecurityMessages.BreakInheritanceActivity(Id("E2"));
                    var activity = new SenseNet.Security.Messaging.SecurityMessages.SetAclActivity(
                        acls: new[] { new AclInfo(1) },
                        breaks: new List <int>(),
                        unbreaks: new List <int>()
                        );
                    activity.Execute(context.Security);
                }
                else if ("X" == s.ToUpper())
                {
                    break;
                }
                else if ("" == s)
                {
                    Console.Clear();
                    Console.WriteLine("S<enter>: sent test, <enter>: clear screen, X<enter>: exit...");
                    Console.WriteLine("Receiver: " + channel.ReceiverName);
                }
            }

            channel.ShutDown();
        }
Exemplo n.º 4
0
        private static void RunSAQ(ProgramArguments arguments)
        {
            var entities    = SystemStartTests.CreateTestEntities();
            var groups      = SystemStartTests.CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = SystemStartTests.CreateTestAces();
            var storage     = new DatabaseStorage {
                Aces = aces, Memberships = memberships, Entities = entities, Messages = new List <Tuple <int, DateTime, byte[]> >()
            };

            StartTheSystem(new MemoryDataProvider(storage));

            started = DateTime.UtcNow;

            Enumerable.Range(1, arguments.Agents).Select(x => Task.Run(() => SAQExercise(x))).ToArray();
        }
Exemplo n.º 5
0
        private static void RunMOVE(ProgramArguments arguments)
        {
            var entities    = SystemStartTests.CreateTestEntities();
            var groups      = SystemStartTests.CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = SystemStartTests.CreateTestAces();

            aces.Add(new StoredAce {
                EntityId = Id("E1"), IdentityId = Id("U3"), LocalOnly = false, AllowBits = 0x100000000, DenyBits = 0x000
            });

            var storage = new DatabaseStorage {
                Aces = aces, Memberships = memberships, Entities = entities, Messages = new List <Tuple <int, DateTime, byte[]> >()
            };

            StartTheSystem(new MemoryDataProvider(storage));

            var ctx = new TestSecurityContext(TestUser.User3);
            var ok  = ctx.HasPermission(52, PermissionType.Custom01);

            started = DateTime.UtcNow;

            Enumerable.Range(1, 4).Select(x => Task.Run(() => MOVEExercise(x))).ToArray();
        }