File tree Expand file tree Collapse file tree 3 files changed +10
-5
lines changed
Expand file tree Collapse file tree 3 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 88 CasbinEnforcerFn ,
99 CasbinAuthorizeFn ,
1010 CasbinEnforcerConfigGetterFn ,
11+ CasbinResourceModifierFn ,
1112} from './types' ;
1213import { CoreBindings } from '@loopback/core' ;
1314import { AuthorizationComponent } from './component' ;
@@ -45,6 +46,10 @@ export namespace AuthorizationBindings {
4546 'sf.userCasbinAuthorization.casbinEnforcerConfigGetter' ,
4647 ) ;
4748
49+ export const CASBIN_RESOURCE_MODIFIER_FN = BindingKey . create < CasbinResourceModifierFn > (
50+ 'sf.userCasbinAuthorization.casbinResourceModifierFn' ,
51+ ) ;
52+
4853 export const CONFIG = BindingKey . create < AuthorizationConfig > (
4954 'sf.userAuthorization.config' ,
5055 ) ;
Original file line number Diff line number Diff line change @@ -18,17 +18,17 @@ export class CasbinAuthorizationProvider implements Provider<CasbinAuthorizeFn>
1818 ) { }
1919
2020 value ( ) : CasbinAuthorizeFn {
21- return ( response ) => this . action ( response ) ;
21+ return ( response , resource ) => this . action ( response , resource ) ;
2222 }
2323
24- async action ( user : IAuthUserWithPermissions ) : Promise < boolean > {
24+ async action ( user : IAuthUserWithPermissions , resource : string ) : Promise < boolean > {
2525 let authDecision = false ;
2626 try {
2727 const metadata : AuthorizationMetadata = await this . getCasbinMetadata ( ) ;
2828
2929 const subject = this . getUserName ( `${ user . id } ` ) ;
3030
31- const object = metadata . resource ;
31+ const object = resource ;
3232
3333 const action = metadata . permissions && metadata . permissions . length > 0 ? metadata . permissions [ 0 ] : DEFAULT_SCOPE ;
3434
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export interface CasbinAuthorizeFn {
2020 // userPermissions - Array of permission keys granted to the user
2121 // This is actually a union of permissions picked up based on role
2222 // attached to the user and allowed permissions at specific user level
23- ( user : IAuthUserWithPermissions ) : Promise < boolean > ;
23+ ( user : IAuthUserWithPermissions , resVal : string ) : Promise < boolean > ;
2424}
2525/**
2626 * Authorization metadata interface for the method decorator
@@ -91,7 +91,7 @@ export interface CasbinEnforcerConfigGetterFn {
9191}
9292
9393export interface CasbinResourceModifierFn {
94- ( authUser : IAuthUserWithPermissions , resource : string , isCasbinPolicy ?: boolean ) : Promise < CasbinConfig > ;
94+ ( pathParams : string [ ] ) : Promise < string > ;
9595}
9696
9797export interface CasbinConfig {
You can’t perform that action at this time.
0 commit comments