@@ -801,6 +801,35 @@ public void testCommentModel(){
801
801
testEnforce (e , "bob" , "data2" , "write" , true );
802
802
}
803
803
804
+ @ Test
805
+ public void testDomainMatchModel (){
806
+ Enforcer e = new Enforcer ("examples/rbac_with_domain_pattern_model.conf" , "examples/rbac_with_domain_pattern_policy.csv" );
807
+ e .addNamedDomainMatchingFunc ("g" , "keyMatch2" , BuiltInFunctions ::keyMatch2 );
808
+
809
+ testDomainEnforce (e , "alice" , "domain1" , "data1" , "read" , true );
810
+ testDomainEnforce (e , "alice" , "domain1" , "data1" , "write" , true );
811
+ testDomainEnforce (e , "alice" , "domain1" , "data2" , "read" , false );
812
+ testDomainEnforce (e , "alice" , "domain1" , "data2" , "write" , false );
813
+ testDomainEnforce (e , "alice" , "domain2" , "data2" , "read" , true );
814
+ testDomainEnforce (e , "alice" , "domain2" , "data2" , "write" , true );
815
+ testDomainEnforce (e , "bob" , "domain2" , "data1" , "read" , false );
816
+ testDomainEnforce (e , "bob" , "domain2" , "data1" , "write" , false );
817
+ testDomainEnforce (e , "bob" , "domain2" , "data2" , "read" , true );
818
+ testDomainEnforce (e , "bob" , "domain2" , "data2" , "write" , true );
819
+ }
820
+
821
+ @ Test
822
+ public void testAllMatchModel (){
823
+ Enforcer e = new Enforcer ("examples/rbac_with_all_pattern_model.conf" , "examples/rbac_with_all_pattern_policy.csv" );
824
+ e .addNamedMatchingFunc ("g" , "keyMatch2" , BuiltInFunctions ::keyMatch2 );
825
+ e .addNamedDomainMatchingFunc ("g" , "keyMatch2" , BuiltInFunctions ::keyMatch2 );
826
+
827
+ testDomainEnforce (e , "alice" , "domain1" , "/book/1" , "read" , true );
828
+ testDomainEnforce (e , "alice" , "domain1" , "/book/1" , "write" , false );
829
+ testDomainEnforce (e , "alice" , "domain2" , "/book/1" , "read" , false );
830
+ testDomainEnforce (e , "alice" , "domain2" , "/book/1" , "write" , true );
831
+ }
832
+
804
833
@ Test
805
834
public void testSubjectPriorityWithDomain () {
806
835
Enforcer e = new Enforcer ("examples/subject_priority_model_with_domain.conf" , "examples/subject_priority_policy_with_domain.csv" );
0 commit comments