@@ -120,8 +120,9 @@ public void enableCache(boolean enable) {
120
120
* @param rvals Parameters for the enforcement check.
121
121
* @return The result of the enforcement check.
122
122
*/
123
+ @ Override
123
124
public boolean enforce (Object ... rvals ) {
124
- if (enableCache .get ()) {
125
+ if (! enableCache .get ()) {
125
126
return super .enforce (rvals );
126
127
}
127
128
@@ -143,6 +144,7 @@ public boolean enforce(Object... rvals) {
143
144
/**
144
145
* Loads the policy, clearing the cache if enabled.
145
146
*/
147
+ @ Override
146
148
public void loadPolicy () {
147
149
if (enableCache == null || !enableCache .get ()){
148
150
super .loadPolicy ();
@@ -160,6 +162,7 @@ public void loadPolicy() {
160
162
* @param params Policy parameters.
161
163
* @return Whether the addition was successful.
162
164
*/
165
+ @ Override
163
166
public boolean addPolicy (String ... params ) {
164
167
if (!checkOneAndRemoveCache (params )) {
165
168
return false ;
@@ -173,19 +176,35 @@ public boolean addPolicy(String... params) {
173
176
* @param rules Policy rules.
174
177
* @return Whether the addition was successful.
175
178
*/
179
+ @ Override
176
180
public boolean addPolicies (List <List <String >> rules ) {
177
181
if (!checkManyAndRemoveCache (rules )) {
178
182
return false ;
179
183
}
180
184
return super .addPolicies (rules );
181
185
}
182
186
187
+ /**
188
+ * Adds multiple policies while checking and removing the cache.
189
+ *
190
+ * @param rules Policy rules.
191
+ * @return Whether the addition was successful.
192
+ */
193
+ @ Override
194
+ public boolean addPolicies (String [][] rules ) {
195
+ if (!checkManyAndRemoveCache (rules )) {
196
+ return false ;
197
+ }
198
+ return super .addPolicies (rules );
199
+ }
200
+
183
201
/**
184
202
* Removes a single policy while checking and removing the cache.
185
203
*
186
204
* @param params Policy parameters.
187
205
* @return Whether the removal was successful.
188
206
*/
207
+ @ Override
189
208
public boolean removePolicy (String ... params ) {
190
209
if (!checkOneAndRemoveCache (params )) {
191
210
return false ;
@@ -199,13 +218,28 @@ public boolean removePolicy(String... params) {
199
218
* @param rules Policy rules.
200
219
* @return Whether the removal was successful.
201
220
*/
221
+ @ Override
202
222
public boolean removePolicies (List <List <String >>rules ) {
203
223
if (!checkManyAndRemoveCache (rules )) {
204
224
return false ;
205
225
}
206
226
return super .removePolicies (rules );
207
227
}
208
228
229
+ /**
230
+ * Removes multiple policies while checking and removing the cache.
231
+ *
232
+ * @param rules Policy rules.
233
+ * @return Whether the removal was successful.
234
+ */
235
+ @ Override
236
+ public boolean removePolicies (String [][] rules ) {
237
+ if (!checkManyAndRemoveCache (rules )) {
238
+ return false ;
239
+ }
240
+ return super .removePolicies (rules );
241
+ }
242
+
209
243
/**
210
244
* Retrieves a cached result based on the given key.
211
245
*
@@ -306,7 +340,7 @@ public void invalidateCache() {
306
340
*/
307
341
private boolean checkOneAndRemoveCache (String ... params ) {
308
342
if (enableCache .get ()) {
309
- String key = getKey ((Object ) params );
343
+ String key = getKey ((Object [] ) params );
310
344
if (key != null ) {
311
345
cache .delete (key );
312
346
}
@@ -323,7 +357,25 @@ private boolean checkOneAndRemoveCache(String... params) {
323
357
private boolean checkManyAndRemoveCache (List <List <String >> rules ) {
324
358
if (!rules .isEmpty () && enableCache .get ()) {
325
359
for (List <String > rule : rules ) {
326
- String key = getKey (rule );
360
+ String key = getKey (rule .toArray ());
361
+ if (key != null ) {
362
+ cache .delete (key );
363
+ }
364
+ }
365
+ }
366
+ return true ;
367
+ }
368
+
369
+ /**
370
+ * Checks and removes cache for multiple policies.
371
+ *
372
+ * @param rules Policy rules.
373
+ * @return Whether the check was successful.
374
+ */
375
+ private boolean checkManyAndRemoveCache (String [][] rules ) {
376
+ if (rules != null && enableCache .get ()) {
377
+ for (String [] rule : rules ) {
378
+ String key = getKey ((Object []) rule );
327
379
if (key != null ) {
328
380
cache .delete (key );
329
381
}
0 commit comments