2626import java .util .List ;
2727
2828import static java .util .Collections .singletonList ;
29+ import static org .casbin .jcasbin .util .Util .splitCommaDelimitedList ;
2930
3031/**
3132 * InternalEnforcer = CoreEnforcer + Internal API.
@@ -73,12 +74,14 @@ private boolean notifyWatcher(String sec, String ptype, List<List<String>> rules
7374 * addPolicy adds a rule to the current policy.
7475 */
7576 boolean addPolicy (String sec , String ptype , List <String > rule ) {
77+ List <String > modifiedRule = splitCommaDelimitedList (rule );
78+
7679 if (mustUseDispatcher ()) {
77- dispatcher .addPolicies (sec , ptype , singletonList (rule ));
80+ dispatcher .addPolicies (sec , ptype , singletonList (modifiedRule ));
7881 return true ;
7982 }
8083
81- if (model .hasPolicy (sec , ptype , rule )) {
84+ if (model .hasPolicy (sec , ptype , modifiedRule )) {
8285 return false ;
8386 }
8487
@@ -93,11 +96,11 @@ boolean addPolicy(String sec, String ptype, List<String> rule) {
9396 }
9497 }
9598
96- model .addPolicy (sec , ptype , rule );
99+ model .addPolicy (sec , ptype , modifiedRule );
97100
98- buildIncrementalRoleLinks (sec , ptype , singletonList (rule ), Model .PolicyOperations .POLICY_ADD );
101+ buildIncrementalRoleLinks (sec , ptype , singletonList (modifiedRule ), Model .PolicyOperations .POLICY_ADD );
99102
100- return notifyWatcher (sec , ptype , singletonList (rule ), WatcherEx .UpdateType .UpdateForAddPolicy );
103+ return notifyWatcher (sec , ptype , singletonList (modifiedRule ), WatcherEx .UpdateType .UpdateForAddPolicy );
101104 }
102105
103106
@@ -156,8 +159,10 @@ public void buildIncrementalRoleLinks(Model.PolicyOperations op, String ptype, L
156159 * removePolicy removes a rule from the current policy.
157160 */
158161 boolean removePolicy (String sec , String ptype , List <String > rule ) {
162+ List <String > modifiedRule = splitCommaDelimitedList (rule );
163+
159164 if (mustUseDispatcher ()) {
160- dispatcher .removePolicies (sec , ptype , singletonList (rule ));
165+ dispatcher .removePolicies (sec , ptype , singletonList (modifiedRule ));
161166 return true ;
162167 }
163168
@@ -172,15 +177,15 @@ boolean removePolicy(String sec, String ptype, List<String> rule) {
172177 }
173178 }
174179
175- boolean ruleRemoved = model .removePolicy (sec , ptype , rule );
180+ boolean ruleRemoved = model .removePolicy (sec , ptype , modifiedRule );
176181
177182 if (!ruleRemoved ) {
178183 return false ;
179184 }
180185
181- buildIncrementalRoleLinks (sec , ptype , singletonList (rule ), Model .PolicyOperations .POLICY_REMOVE );
186+ buildIncrementalRoleLinks (sec , ptype , singletonList (modifiedRule ), Model .PolicyOperations .POLICY_REMOVE );
182187
183- return notifyWatcher (sec , ptype , singletonList (rule ), WatcherEx .UpdateType .UpdateForRemovePolicy );
188+ return notifyWatcher (sec , ptype , singletonList (modifiedRule ), WatcherEx .UpdateType .UpdateForRemovePolicy );
184189 }
185190
186191 /**
@@ -193,8 +198,11 @@ boolean removePolicy(String sec, String ptype, List<String> rule) {
193198 * @return succeeds or not.
194199 */
195200 boolean updatePolicy (String sec , String ptype , List <String > oldRule , List <String > newRule ) {
201+ List <String > modifiedOldRule = splitCommaDelimitedList (oldRule );
202+ List <String > modifiedNewRule = splitCommaDelimitedList (newRule );
203+
196204 if (mustUseDispatcher ()) {
197- dispatcher .updatePolicy (sec , ptype , oldRule , newRule );
205+ dispatcher .updatePolicy (sec , ptype , modifiedOldRule , modifiedNewRule );
198206 return true ;
199207 }
200208
@@ -211,7 +219,7 @@ boolean updatePolicy(String sec, String ptype, List<String> oldRule, List<String
211219 }
212220 }
213221
214- boolean ruleUpdated = model .updatePolicy (sec , ptype , oldRule , newRule );
222+ boolean ruleUpdated = model .updatePolicy (sec , ptype , modifiedOldRule , modifiedNewRule );
215223
216224 if (!ruleUpdated ) {
217225 return false ;
@@ -242,7 +250,7 @@ boolean updatePolicy(String sec, String ptype, List<String> oldRule, List<String
242250 if (watcher != null && autoNotifyWatcher ) {
243251 try {
244252 if (watcher instanceof WatcherUpdatable ) {
245- ((WatcherUpdatable ) watcher ).updateForUpdatePolicy (oldRule , newRule );
253+ ((WatcherUpdatable ) watcher ).updateForUpdatePolicy (modifiedOldRule , modifiedNewRule );
246254 } else {
247255 watcher .update ();
248256 }
0 commit comments