private static void CreateTestOperations(ObjectCache cache) { IAuthorizationManager manager = Afcas.GetAuthorizationManager( ); using (new ObjectCacheScope(cache)) { Operation op1 = Operation.CreateOperation("op1", "operation 1"); Operation op2 = Operation.CreateOperation("op2", "operation 2"); op1.Description = "op1 desc"; op2.Description = "op2 desc"; manager.AddOrUpdate(op1); manager.AddOrUpdate(op2); } }
public async Task WhenRemovingAccessPredicate_TracksChanges() { DBHelper.ExecuteNonQuery("Test_DeleteAllData"); IAuthorizationManager manager = Afcas.GetAuthorizationManager(); ObjectCache.PushCurrent(new ObjectCache()); Principal G = Principal.CreatePrincipal("G", "G", PrincipalType.Group, ""); Principal U1 = Principal.CreatePrincipal("U1", "U1", PrincipalType.User, ""); Operation O = Operation.CreateOperation("O", "O"); manager.AddOrUpdate(G, ""); manager.AddOrUpdate(U1, ""); manager.AddOrUpdate(O); manager.AddGroupMember(G, U1); ResourceHandleFactory resFac = Afcas.GetHandleFactory("SampleResource"); ResourceHandle R = resFac.GenerateResourceHandleByKey("R"); ResourceHandle R1 = resFac.GenerateResourceHandleByKey("R1"); ResourceHandle R21 = resFac.GenerateResourceHandleByKey("R2.1"); manager.AddSubResource(R, R1); manager.AddSubResource(R1, R21); manager.AddAccessPredicate(G.Key, O.Key, R, ResourceAccessPredicateType.Grant); Assert.IsTrue(manager.IsAuthorized(U1.Key, O.Key, R)); Assert.IsTrue(manager.IsAuthorized(G.Key, O.Key, R)); var rows = GetAuthRows(); var lastChange = rows.Max(r => r.Modified); // Act await Task.Delay(250); manager.RemoveAccessPredicate(G.Key, O.Key, R, ResourceAccessPredicateType.Grant); var rows2 = GetAuthRows().Where(r => r.PrincipalId == "U1" && r.ResourceId == R21.AfcasKey && r.Deleted == new DateTime(1753, 01, 01, 0, 0, 0, DateTimeKind.Utc)).ToList(); var deletedRows = GetDeletedAuthRows(lastChange).Where(r => r.PrincipalId == "U1" && r.ResourceId == R21.AfcasKey).ToList(); var dr = GetDeletedAuthRows(); // Assert Assert.AreEqual(0, rows2.Count, "should have lost permission"); Assert.AreEqual(1, deletedRows.Count); Assert.GreaterOrEqual(deletedRows[0].Deleted, lastChange, "deletion must have happened after last change!"); }
public void TestUpdatePrincipal( ) { DBHelper.ExecuteNonQuery("Test_DeleteAllData"); IAuthorizationManager manager = Afcas.GetAuthorizationManager( ); using (new ObjectCacheScope( )) { CreateTestPrincipals(ObjectCache.Current); Principal grp1 = ObjectCache.Current.Get <Principal>("grp1"); grp1.Description = "new grp1 desc"; grp1.EMail = "*****@*****.**"; manager.GetPrincipalList(PrincipalType.Group); Assert.AreEqual(4, ObjectCache.Current.GetAll <Principal>( ).Count); Assert.AreEqual(grp1.Description, "new grp1 desc"); Assert.AreEqual(grp1.EMail, "*****@*****.**"); manager.AddOrUpdate(grp1, ""); } using (new ObjectCacheScope( )) { manager.GetPrincipalList(PrincipalType.Group); Principal grp1 = ObjectCache.Current.Get <Principal>("grp1"); Assert.AreEqual(grp1.Description, "new grp1 desc"); Assert.AreEqual(grp1.EMail, "*****@*****.**"); } }
public async Task WhenAddingUserToGroup_OfGroup_TracksChanges() { DBHelper.ExecuteNonQuery("Test_DeleteAllData"); IAuthorizationManager manager = Afcas.GetAuthorizationManager(); ObjectCache.PushCurrent(new ObjectCache()); Principal G = Principal.CreatePrincipal("G", "G", PrincipalType.Group, ""); Principal G1 = Principal.CreatePrincipal("G1", "G1", PrincipalType.Group, ""); Principal U1 = Principal.CreatePrincipal("U1", "U1", PrincipalType.User, ""); Operation O = Operation.CreateOperation("O", "O"); manager.AddOrUpdate(G, ""); manager.AddOrUpdate(G1, ""); manager.AddOrUpdate(U1, ""); manager.AddOrUpdate(O); manager.AddGroupMember(G1, U1); ResourceHandleFactory resFac = Afcas.GetHandleFactory("SampleResource"); ResourceHandle R = resFac.GenerateResourceHandleByKey("R"); ResourceHandle R1 = resFac.GenerateResourceHandleByKey("R1"); ResourceHandle R2 = resFac.GenerateResourceHandleByKey("R2"); manager.AddAccessPredicate(G.Key, O.Key, R, ResourceAccessPredicateType.Grant); Assert.IsFalse(manager.IsAuthorized(U1.Key, O.Key, R)); Assert.IsTrue(manager.IsAuthorized(G.Key, O.Key, R)); var rows = GetAuthRows(); //manager.AddSubResource(R, R1); //manager.AddSubResource(R, R2); var lastChange = rows.Max(r => r.Modified); // Act manager.AddGroupMember(G, G1); var rows2 = GetAuthRows(lastChange).Where(r => r.PrincipalId == "U1").ToList(); var max2 = rows2.Max(r => r.Modified); // Assert //Assert.IsTrue(manager.IsAuthorized(U1.Key, O.Key, R)); Assert.GreaterOrEqual(max2, lastChange, $"{lastChange} should be lower!"); }
private static ObjectCache SetupSimpleData() { DBHelper.ExecuteNonQuery("Test_DeleteAllData"); IAuthorizationManager manager = Afcas.GetAuthorizationManager(); ObjectCache.PushCurrent(new ObjectCache()); Principal G = Principal.CreatePrincipal("G", "G", PrincipalType.Group, ""); Principal G1 = Principal.CreatePrincipal("G1", "G1", PrincipalType.Group, ""); Principal G2 = Principal.CreatePrincipal("G2", "G2", PrincipalType.Group, ""); Principal U1 = Principal.CreatePrincipal("U1", "U1", PrincipalType.User, ""); Operation O = Operation.CreateOperation("O", "O"); Operation O1 = Operation.CreateOperation("O1", "O2"); Operation O2 = Operation.CreateOperation("O2", "O2"); Operation O3 = Operation.CreateOperation("O3", "O3"); manager.AddOrUpdate(G, ""); manager.AddOrUpdate(G1, ""); manager.AddOrUpdate(G2, ""); manager.AddOrUpdate(U1, ""); manager.AddOrUpdate(O); manager.AddOrUpdate(O1); manager.AddOrUpdate(O2); manager.AddOrUpdate(O3); ResourceHandleFactory resFac = Afcas.GetHandleFactory("SampleResource"); ResourceHandle R = resFac.GenerateResourceHandleByKey("R"); ResourceHandle R1 = resFac.GenerateResourceHandleByKey("R1"); ResourceHandle R2 = resFac.GenerateResourceHandleByKey("R2"); manager.AddAccessPredicate(G.Key, O.Key, R, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(U1.Key, O.Key, R, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(U1.Key, O1.Key, R1, ResourceAccessPredicateType.Grant); manager.AddGroupMember(G, G1); manager.AddGroupMember(G, G2); manager.AddGroupMember(G, U1); manager.AddSubOperation(O, O1); manager.AddSubOperation(O, O2); manager.AddSubOperation(O, O3); manager.AddSubResource(R, R1); manager.AddSubResource(R, R2); return(ObjectCache.Current); }
private static void CreateTestPrincipals(ObjectCache cache) { IAuthorizationManager manager = Afcas.GetAuthorizationManager( ); using (new ObjectCacheScope(cache)) { Principal grp1 = Principal.CreatePrincipal("grp1", "Group 1", PrincipalType.Group, "*****@*****.**"); Principal grp2 = Principal.CreatePrincipal("grp2", "Group 2", PrincipalType.Group, "*****@*****.**"); Principal usr1 = Principal.CreatePrincipal("usr1", "User 1", PrincipalType.User, "*****@*****.**"); Principal usr2 = Principal.CreatePrincipal("usr2", "User 2", PrincipalType.User, "*****@*****.**"); grp1.Description = "grp1 desc"; grp2.Description = "grp2 desc"; usr1.Description = "usr1 desc"; usr2.Description = "usr2 desc"; Assert.That(ObjectCache.Current.GetAll <Principal>( ).Count == 4); manager.AddOrUpdate(grp1, ""); manager.AddOrUpdate(grp2, ""); manager.AddOrUpdate(usr1, ""); manager.AddOrUpdate(usr2, ""); } }
public void TestDeleteOperation( ) { DBHelper.ExecuteNonQuery("Test_DeleteAllData"); IAuthorizationManager manager = Afcas.GetAuthorizationManager( ); using (new ObjectCacheScope( )) { Operation op1 = Operation.CreateOperation("op1", "operation 1"); Operation op2 = Operation.CreateOperation("op2", "operation 2"); Operation op3 = Operation.CreateOperation("op3", "operation 3"); manager.AddOrUpdate(op1); manager.AddOrUpdate(op2); manager.AddOrUpdate(op3); Assert.AreEqual(3, manager.GetOperationList( ).Count); Assert.AreEqual(3, ObjectCache.Current.GetAll <Operation>( ).Count); manager.RemoveOperation(op1.Key); Assert.AreEqual(2, manager.GetOperationList( ).Count); Assert.AreEqual(2, ObjectCache.Current.GetAll <Operation>( ).Count); } }
public void TestUpdateOperation( ) { DBHelper.ExecuteNonQuery("Test_DeleteAllData"); IAuthorizationManager manager = Afcas.GetAuthorizationManager( ); using (new ObjectCacheScope( )) { CreateTestOperations(ObjectCache.Current); Operation op1 = ObjectCache.Current.Get <Operation>("op1"); op1.Description = "new op1 desc"; manager.GetOperationList( ); Assert.AreEqual("new op1 desc", op1.Description); manager.AddOrUpdate(op1); } using (new ObjectCacheScope( )) { manager.GetOperationList( ); Operation op1 = ObjectCache.Current.Get <Operation>("op1"); Assert.AreEqual("new op1 desc", op1.Description); } }
private static ObjectCache SetupComplexData() { DBHelper.ExecuteNonQuery("Test_DeleteAllData"); ObjectCache.PushCurrent(new ObjectCache()); IAuthorizationManager manager = Afcas.GetAuthorizationManager(); Principal PA = Principal.CreatePrincipal("PA", "PA", PrincipalType.Group, ""); Principal PB = Principal.CreatePrincipal("PB", "PB", PrincipalType.Group, ""); Principal PC = Principal.CreatePrincipal("PC", "PC", PrincipalType.Group, ""); Principal PD = Principal.CreatePrincipal("PD", "PD", PrincipalType.Group, ""); Principal PE = Principal.CreatePrincipal("PE", "PE", PrincipalType.User, ""); Principal PF = Principal.CreatePrincipal("PF", "PF", PrincipalType.User, ""); Principal PG = Principal.CreatePrincipal("PG", "PG", PrincipalType.User, ""); Principal PH = Principal.CreatePrincipal("PH", "PH", PrincipalType.Group, ""); Principal PI = Principal.CreatePrincipal("PI", "PI", PrincipalType.Group, ""); Principal PJ = Principal.CreatePrincipal("PJ", "PJ", PrincipalType.User, ""); Principal PK = Principal.CreatePrincipal("PK", "PK", PrincipalType.User, ""); Principal PP = Principal.CreatePrincipal("PP", "PP", PrincipalType.Group, ""); Principal PQ = Principal.CreatePrincipal("PQ", "PQ", PrincipalType.Group, ""); Principal PR = Principal.CreatePrincipal("PR", "PR", PrincipalType.Group, ""); Principal PS = Principal.CreatePrincipal("PS", "PS", PrincipalType.User, ""); Principal PT = Principal.CreatePrincipal("PT", "PT", PrincipalType.User, ""); manager.AddOrUpdate(PA, ""); manager.AddOrUpdate(PB, ""); manager.AddOrUpdate(PC, ""); manager.AddOrUpdate(PD, ""); manager.AddOrUpdate(PE, ""); manager.AddOrUpdate(PF, ""); manager.AddOrUpdate(PG, ""); manager.AddOrUpdate(PH, ""); manager.AddOrUpdate(PI, ""); manager.AddOrUpdate(PJ, ""); manager.AddOrUpdate(PK, ""); manager.AddOrUpdate(PP, ""); manager.AddOrUpdate(PQ, ""); manager.AddOrUpdate(PR, ""); manager.AddOrUpdate(PS, ""); manager.AddOrUpdate(PT, ""); manager.AddGroupMember(PA, PB); manager.AddGroupMember(PA, PC); manager.AddGroupMember(PA, PD); manager.AddGroupMember(PB, PD); manager.AddGroupMember(PB, PE); manager.AddGroupMember(PC, PE); manager.AddGroupMember(PC, PH); manager.AddGroupMember(PC, PI); manager.AddGroupMember(PD, PF); manager.AddGroupMember(PD, PG); manager.AddGroupMember(PD, PH); manager.AddGroupMember(PH, PP); manager.AddGroupMember(PI, PJ); manager.AddGroupMember(PI, PK); manager.AddGroupMember(PP, PQ); manager.AddGroupMember(PP, PR); manager.AddGroupMember(PQ, PS); manager.AddGroupMember(PQ, PT); manager.AddGroupMember(PR, PT); Operation OA = Operation.CreateOperation("OA", "OA"); Operation OB = Operation.CreateOperation("OB", "OB"); Operation OC = Operation.CreateOperation("OC", "OC"); Operation OD = Operation.CreateOperation("OD", "OD"); Operation OE = Operation.CreateOperation("OE", "OE"); Operation OF = Operation.CreateOperation("OF", "OF"); Operation OG = Operation.CreateOperation("OG", "OG"); Operation OH = Operation.CreateOperation("OH", "OH"); manager.AddSubOperation(OA, OB); manager.AddSubOperation(OA, OC); manager.AddSubOperation(OA, OD); manager.AddSubOperation(OE, OF); manager.AddSubOperation(OE, OG); manager.AddSubOperation(OH, OA); manager.AddSubOperation(OH, OE); ResourceHandleFactory resFac = Afcas.GetHandleFactory("SampleResource"); ResourceHandle RA = resFac.GenerateResourceHandleByKey("RA"); ResourceHandle RB = resFac.GenerateResourceHandleByKey("RB"); ResourceHandle RC = resFac.GenerateResourceHandleByKey("RC"); ResourceHandle RD = resFac.GenerateResourceHandleByKey("RD"); ResourceHandle RE = resFac.GenerateResourceHandleByKey("RE"); ResourceHandle RF = resFac.GenerateResourceHandleByKey("RF"); ResourceHandle RG = resFac.GenerateResourceHandleByKey("RG"); ResourceHandle RH = resFac.GenerateResourceHandleByKey("RH"); ResourceHandle RI = resFac.GenerateResourceHandleByKey("RI"); ResourceHandle RJ = resFac.GenerateResourceHandleByKey("RJ"); ResourceHandle RK = resFac.GenerateResourceHandleByKey("RK"); ResourceHandle RL = resFac.GenerateResourceHandleByKey("RL"); manager.AddSubResource(RA, RB); manager.AddSubResource(RA, RC); manager.AddSubResource(RB, RD); manager.AddSubResource(RB, RE); manager.AddSubResource(RC, RE); manager.AddSubResource(RC, RF); manager.AddSubResource(RC, RG); manager.AddSubResource(RH, RI); manager.AddSubResource(RH, RJ); manager.AddSubResource(RH, RK); manager.AddSubResource(RL, RA); manager.AddSubResource(RL, RH); manager.AddAccessPredicate(PI.Key, OH.Key, RL, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PD.Key, OA.Key, RA, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PP.Key, OE.Key, RH, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PA.Key, OG.Key, RL, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PQ.Key, OB.Key, RL, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PF.Key, OC.Key, RB, ResourceAccessPredicateType.Grant); return(ObjectCache.Current); }
private ObjectCache SetupHugeTestData() { //DBHelper.ExecuteNonQuery("Test_DeleteAllData"); ObjectCache.PushCurrent(new ObjectCache()); IAuthorizationManager manager = Afcas.GetAuthorizationManager(); Principal PA = Principal.CreatePrincipal("PA", "PA", PrincipalType.Group, ""); Principal PB = Principal.CreatePrincipal("PB", "PB", PrincipalType.Group, ""); Principal PC = Principal.CreatePrincipal("PC", "PC", PrincipalType.Group, ""); Principal PD = Principal.CreatePrincipal("PD", "PD", PrincipalType.Group, ""); Principal PE = Principal.CreatePrincipal("PE", "PE", PrincipalType.User, ""); Principal PF = Principal.CreatePrincipal("PF", "PF", PrincipalType.User, ""); Principal PG = Principal.CreatePrincipal("PG", "PG", PrincipalType.User, ""); Principal PH = Principal.CreatePrincipal("PH", "PH", PrincipalType.Group, ""); Principal PI = Principal.CreatePrincipal("PI", "PI", PrincipalType.Group, ""); Principal PJ = Principal.CreatePrincipal("PJ", "PJ", PrincipalType.User, ""); Principal PK = Principal.CreatePrincipal("PK", "PK", PrincipalType.User, ""); Principal PP = Principal.CreatePrincipal("PP", "PP", PrincipalType.Group, ""); Principal PQ = Principal.CreatePrincipal("PQ", "PQ", PrincipalType.Group, ""); Principal PR = Principal.CreatePrincipal("PR", "PR", PrincipalType.Group, ""); Principal PS = Principal.CreatePrincipal("PS", "PS", PrincipalType.User, ""); Principal PT = Principal.CreatePrincipal("PT", "PT", PrincipalType.User, ""); manager.AddOrUpdate(PA, ""); manager.AddOrUpdate(PB, ""); manager.AddOrUpdate(PC, ""); manager.AddOrUpdate(PD, ""); manager.AddOrUpdate(PE, ""); manager.AddOrUpdate(PF, ""); manager.AddOrUpdate(PG, ""); manager.AddOrUpdate(PH, ""); manager.AddOrUpdate(PI, ""); manager.AddOrUpdate(PJ, ""); manager.AddOrUpdate(PK, ""); manager.AddOrUpdate(PP, ""); manager.AddOrUpdate(PQ, ""); manager.AddOrUpdate(PR, ""); manager.AddOrUpdate(PS, ""); manager.AddOrUpdate(PT, ""); manager.AddGroupMember(PA, PB); manager.AddGroupMember(PA, PC); manager.AddGroupMember(PA, PD); manager.AddGroupMember(PB, PD); manager.AddGroupMember(PB, PE); manager.AddGroupMember(PC, PE); manager.AddGroupMember(PC, PH); manager.AddGroupMember(PC, PI); manager.AddGroupMember(PD, PF); manager.AddGroupMember(PD, PG); manager.AddGroupMember(PD, PH); manager.AddGroupMember(PH, PP); manager.AddGroupMember(PI, PJ); manager.AddGroupMember(PI, PK); manager.AddGroupMember(PP, PQ); manager.AddGroupMember(PP, PR); manager.AddGroupMember(PQ, PS); manager.AddGroupMember(PQ, PT); manager.AddGroupMember(PR, PT); Operation OA = Operation.CreateOperation("OA", "OA"); Operation OB = Operation.CreateOperation("OB", "OB"); Operation OC = Operation.CreateOperation("OC", "OC"); Operation OD = Operation.CreateOperation("OD", "OD"); Operation OE = Operation.CreateOperation("OE", "OE"); Operation OF = Operation.CreateOperation("OF", "OF"); Operation OG = Operation.CreateOperation("OG", "OG"); Operation OH = Operation.CreateOperation("OH", "OH"); manager.AddSubOperation(OA, OB); manager.AddSubOperation(OA, OC); manager.AddSubOperation(OA, OD); manager.AddSubOperation(OE, OF); manager.AddSubOperation(OE, OG); manager.AddSubOperation(OH, OA); manager.AddSubOperation(OH, OE); ResourceHandleFactory resFac = Afcas.GetHandleFactory("SampleResource"); //ResourceHandle RA = resFac.GenerateResourceHandleByKey("RA"); //ResourceHandle RB = resFac.GenerateResourceHandleByKey("RB"); //ResourceHandle RC = resFac.GenerateResourceHandleByKey("RC"); //ResourceHandle RD = resFac.GenerateResourceHandleByKey("RD"); //ResourceHandle RE = resFac.GenerateResourceHandleByKey("RE"); //ResourceHandle RF = resFac.GenerateResourceHandleByKey("RF"); //ResourceHandle RG = resFac.GenerateResourceHandleByKey("RG"); //ResourceHandle RH = resFac.GenerateResourceHandleByKey("RH"); //ResourceHandle RI = resFac.GenerateResourceHandleByKey("RI"); //ResourceHandle RJ = resFac.GenerateResourceHandleByKey("RJ"); //ResourceHandle RK = resFac.GenerateResourceHandleByKey("RK"); //ResourceHandle RL = resFac.GenerateResourceHandleByKey("RL"); //manager.AddSubResource(RA, RB); //manager.AddSubResource(RA, RC); //manager.AddSubResource(RB, RD); //manager.AddSubResource(RB, RE); //manager.AddSubResource(RC, RE); //manager.AddSubResource(RC, RF); //manager.AddSubResource(RC, RG); //manager.AddSubResource(RH, RI); //manager.AddSubResource(RH, RJ); //manager.AddSubResource(RH, RK); //manager.AddSubResource(RL, RA); //manager.AddSubResource(RL, RH); var customers = new List <ResourceHandle>(); int customerCount = 5; int deviceCount = 250000; var edges = new List <(string start, string end)>(); using (Track($"Creating 50 customers ")) for (int i = 0; i < customerCount; i++) { var customer = resFac.GenerateResourceHandleByKey($"x customer {i+1}"); customers.Add(customer); // create equipments per customer using (Track($"\tCreating {deviceCount} device for {customer.Key} ")) { for (int j = 0; j < deviceCount / 10; j++) { var device = resFac.GenerateResourceHandleByKey($"device {j+1} ({customer.Key})"); //manager.AddSubResource(customer, device); edges.Add((customer.AfcasKey, device.AfcasKey)); for (int k = 0; k < 10; k++) { var subDevice = resFac.GenerateResourceHandleByKey($"device {j+1}.{k+1} ({customer.Key})"); //manager.AddSubResource(device, subDevice); edges.Add((device.AfcasKey, subDevice.AfcasKey)); device = subDevice; } } } } // six permissions per customer Console.WriteLine(" "); using (Track($"Adding permissions to customers ")) foreach (var customer in customers) { using (Track($"\tAdding permissions on customer {customer.Key} ")) { manager.AddAccessPredicate(PI.Key, OH.Key, customer, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PD.Key, OA.Key, customer, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PP.Key, OE.Key, customer, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PA.Key, OG.Key, customer, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PQ.Key, OB.Key, customer, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PF.Key, OC.Key, customer, ResourceAccessPredicateType.Grant); } } var chunks = edges.ToChunks(500).Select(tuples => { var d = new DataTable(); d.Columns.Add("StartVertexId", typeof(string)); d.Columns.Add("EndVertexId", typeof(string)); d.Columns.Add("Source", typeof(string)); foreach (var r in tuples) { d.Rows.Add(r.start, r.end, EdgeSource.Resource); } return(d); }); // bulk insert edges using (Track($"Adding Edges")) foreach (var chunk in chunks) { DBHelper.RunInTransaction(conn => { conn.Execute("dbo.AddEdgesWithSpaceSaving", new { TVP = chunk.AsTableValuedParameter("dbo.AddEdges") }, commandType: CommandType.StoredProcedure); }); } //DBHelper.RunInTransaction(conn => //{ // conn.Execute("dbo.AddEdgesWithSpaceSaving", new { TVP = edges.AsTableValuedParameter("dbo.AddEdges") }, // commandType: CommandType.StoredProcedure); //}); //// create messmittel //Console.WriteLine(" "); //using (Track($"Creating 300 messmittel ")) //for (int i = 0; i < 3000; i++) //{ // var measurementDevice = resFac.GenerateResourceHandleByKey($"messgerät {i + 1}"); // manager.AddAccessPredicate(PI.Key, OH.Key, measurementDevice, ResourceAccessPredicateType.Grant); // manager.AddAccessPredicate(PD.Key, OA.Key, measurementDevice, ResourceAccessPredicateType.Grant); // manager.AddAccessPredicate(PP.Key, OE.Key, measurementDevice, ResourceAccessPredicateType.Grant); // manager.AddAccessPredicate(PA.Key, OG.Key, measurementDevice, ResourceAccessPredicateType.Grant); // manager.AddAccessPredicate(PQ.Key, OB.Key, measurementDevice, ResourceAccessPredicateType.Grant); // manager.AddAccessPredicate(PF.Key, OC.Key, measurementDevice, ResourceAccessPredicateType.Grant); //} return(ObjectCache.Current); }
public void TestLongPath() { DBHelper.ExecuteNonQuery("Test_DeleteAllData"); ObjectCache.PushCurrent(new ObjectCache()); IAuthorizationManager manager = Afcas.GetAuthorizationManager(); Principal PA = Principal.CreatePrincipal("PA", "PA", PrincipalType.Group, ""); Principal PB = Principal.CreatePrincipal("PB", "PB", PrincipalType.Group, ""); Principal PC = Principal.CreatePrincipal("PC", "PC", PrincipalType.Group, ""); Principal PD = Principal.CreatePrincipal("PD", "PD", PrincipalType.Group, ""); Principal PE = Principal.CreatePrincipal("PE", "PE", PrincipalType.User, ""); Principal PF = Principal.CreatePrincipal("PF", "PF", PrincipalType.User, ""); Principal PG = Principal.CreatePrincipal("PG", "PG", PrincipalType.User, ""); Principal PH = Principal.CreatePrincipal("PH", "PH", PrincipalType.Group, ""); Principal PI = Principal.CreatePrincipal("PI", "PI", PrincipalType.Group, ""); Principal PJ = Principal.CreatePrincipal("PJ", "PJ", PrincipalType.User, ""); Principal PK = Principal.CreatePrincipal("PK", "PK", PrincipalType.User, ""); Principal PP = Principal.CreatePrincipal("PP", "PP", PrincipalType.Group, ""); Principal PQ = Principal.CreatePrincipal("PQ", "PQ", PrincipalType.Group, ""); Principal PR = Principal.CreatePrincipal("PR", "PR", PrincipalType.Group, ""); Principal PS = Principal.CreatePrincipal("PS", "PS", PrincipalType.User, ""); Principal PT = Principal.CreatePrincipal("PT", "PT", PrincipalType.User, ""); manager.AddOrUpdate(PA, ""); manager.AddOrUpdate(PB, ""); manager.AddOrUpdate(PC, ""); manager.AddOrUpdate(PD, ""); manager.AddOrUpdate(PE, ""); manager.AddOrUpdate(PF, ""); manager.AddOrUpdate(PG, ""); manager.AddOrUpdate(PH, ""); manager.AddOrUpdate(PI, ""); manager.AddOrUpdate(PJ, ""); manager.AddOrUpdate(PK, ""); manager.AddOrUpdate(PP, ""); manager.AddOrUpdate(PQ, ""); manager.AddOrUpdate(PR, ""); manager.AddOrUpdate(PS, ""); manager.AddOrUpdate(PT, ""); manager.AddGroupMember(PA, PB); manager.AddGroupMember(PA, PC); manager.AddGroupMember(PA, PD); manager.AddGroupMember(PB, PD); manager.AddGroupMember(PB, PE); manager.AddGroupMember(PC, PE); manager.AddGroupMember(PC, PH); manager.AddGroupMember(PC, PI); manager.AddGroupMember(PD, PF); manager.AddGroupMember(PD, PG); manager.AddGroupMember(PD, PH); manager.AddGroupMember(PH, PP); manager.AddGroupMember(PI, PJ); manager.AddGroupMember(PI, PK); manager.AddGroupMember(PP, PQ); manager.AddGroupMember(PP, PR); manager.AddGroupMember(PQ, PS); manager.AddGroupMember(PQ, PT); manager.AddGroupMember(PR, PT); Operation OA = Operation.CreateOperation("OA", "OA"); Operation OB = Operation.CreateOperation("OB", "OB"); Operation OC = Operation.CreateOperation("OC", "OC"); Operation OD = Operation.CreateOperation("OD", "OD"); Operation OE = Operation.CreateOperation("OE", "OE"); Operation OF = Operation.CreateOperation("OF", "OF"); Operation OG = Operation.CreateOperation("OG", "OG"); Operation OH = Operation.CreateOperation("OH", "OH"); manager.AddSubOperation(OA, OB); manager.AddSubOperation(OA, OC); manager.AddSubOperation(OA, OD); manager.AddSubOperation(OE, OF); manager.AddSubOperation(OE, OG); manager.AddSubOperation(OH, OA); manager.AddSubOperation(OH, OE); ResourceHandleFactory resFac = Afcas.GetHandleFactory("SampleResource"); List <ResourceHandle> devices; using (Track("creating devices")) { devices = Enumerable.Range(0, 500000).Select(i => resFac.GenerateResourceHandleByKey($"device {i + 1}")).ToList(); } using (Track($"Creating long graph ")) for (int i = 1; i < devices.Count; i++) { var parent = devices[0]; var child = devices[i]; //using (Track($"setting {parent.Key} -> {child.Key}")) { manager.AddSubResource(parent, child); } } // six permissions per customer Console.WriteLine(" "); using (Track($"Adding permissions to customers ")) { var device = devices[0]; manager.AddAccessPredicate(PI.Key, OH.Key, device, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PD.Key, OA.Key, device, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PP.Key, OE.Key, device, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PA.Key, OG.Key, device, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PQ.Key, OB.Key, device, ResourceAccessPredicateType.Grant); manager.AddAccessPredicate(PF.Key, OC.Key, device, ResourceAccessPredicateType.Grant); } }