@@ -82,20 +82,26 @@ public void testAddAndRemovePolicy() {
82
82
Enforcer e = new Enforcer ("examples/rbac_model.conf" , a );
83
83
testEnforce (e , "cathy" , "data1" , "read" , false );
84
84
85
- //add a policy
85
+ // AutoSave is enabled by default.
86
+ // It can be disabled by:
87
+ // e.enableAutoSave(false);
88
+
89
+ // Because AutoSave is enabled, the policy change not only affects the policy in Casbin enforcer,
90
+ // but also affects the policy in the storage.
86
91
e .addPolicy ("cathy" , "data1" , "read" );
87
92
testEnforce (e , "cathy" , "data1" , "read" , true );
88
93
89
- //reload policies from DB
94
+ // Reload the policy from the storage to see the effect.
90
95
e .clearPolicy ();
91
96
a .loadPolicy (e .getModel ());
97
+ // The policy has a new rule: {"cathy", "data1", "read"}.
92
98
testEnforce (e , "cathy" , "data1" , "read" , true );
93
99
94
- //remove a policy
100
+ // Remove the added rule.
95
101
e .removePolicy ("cathy" , "data1" , "read" );
96
102
testEnforce (e , "cathy" , "data1" , "read" , false );
97
103
98
- //reload policies from DB
104
+ // Reload the policy from the storage to see the effect.
99
105
e .clearPolicy ();
100
106
a .loadPolicy (e .getModel ());
101
107
testEnforce (e , "cathy" , "data1" , "read" , false );
0 commit comments