@@ -20,6 +20,7 @@ import { Adapter, FilteredAdapter, Watcher, BatchAdapter, UpdatableAdapter } fro
20
20
import { DefaultRoleManager , RoleManager } from './rbac' ;
21
21
import { escapeAssertion , generateGFunction , getEvalValue , hasEval , replaceEval , generatorRunSync , generatorRunAsync } from './util' ;
22
22
import { getLogger , logPrint } from './log' ;
23
+ import { MatchingFunc } from './rbac' ;
23
24
24
25
type Matcher = ( ( context : any ) => Promise < any > ) | ( ( context : any ) => any ) ;
25
26
@@ -262,6 +263,32 @@ export class CoreEnforcer {
262
263
this . autoBuildRoleLinks = autoBuildRoleLinks ;
263
264
}
264
265
266
+ /**
267
+ * add matching function to RoleManager by ptype
268
+ * @param ptype g
269
+ * @param fn the function will be added
270
+ */
271
+ public async addNamedMatchingFunc ( ptype : string , fn : MatchingFunc ) : Promise < void > {
272
+ const rm = this . rmMap . get ( ptype ) ;
273
+ if ( rm ) {
274
+ return await ( < DefaultRoleManager > rm ) . addMatchingFunc ( fn ) ;
275
+ }
276
+
277
+ throw Error ( 'Target ptype not found.' ) ;
278
+ }
279
+
280
+ /**
281
+ * add domain matching function to RoleManager by ptype
282
+ * @param ptype g
283
+ * @param fn the function will be added
284
+ */
285
+ public async addNamedDomainMatchingFunc ( ptype : string , fn : MatchingFunc ) : Promise < void > {
286
+ const rm = this . rmMap . get ( ptype ) ;
287
+ if ( rm ) {
288
+ return await ( < DefaultRoleManager > rm ) . addDomainMatchingFunc ( fn ) ;
289
+ }
290
+ }
291
+
265
292
/**
266
293
* buildRoleLinks manually rebuild the role inheritance relations.
267
294
*/
0 commit comments