77 RDF
88} from '@solid/community-server' ;
99import { basicPolicy , ODRL , UCPPolicy , UCRulesStorage } from '@solidlab/ucp' ;
10- import { DataFactory , Literal , NamedNode , Quad_Subject , Store } from 'n3' ;
10+ import { DataFactory , Literal , NamedNode , Quad_Subject , Store , Writer } from 'n3' ;
1111import { EyeReasoner , ODRLEngineMultipleSteps , ODRLEvaluator } from 'odrl-evaluator'
1212import { WEBID } from '../../credentials/Claims' ;
1313import { ClaimSet } from '../../credentials/ClaimSet' ;
@@ -62,7 +62,8 @@ export class OdrlAuthorizer implements Authorizer {
6262 }
6363
6464 // key value store for building the permissions to be granted on a resource
65- const grantedPermissions : { [ key : string ] : string [ ] } = { } ;
65+ // Resource -> Action -> Active policy
66+ const grantedPermissions : Record < string , Record < string , string > > = { } ;
6667
6768 // prepare policy
6869 const policyStore = ( await this . policies . getStore ( ) )
@@ -78,7 +79,7 @@ export class OdrlAuthorizer implements Authorizer {
7879 const subject = typeof claims [ WEBID ] === 'string' ? claims [ WEBID ] : 'urn:solidlab:uma:id:anonymous' ;
7980
8081 for ( const { resource_id, resource_scopes} of query ) {
81- grantedPermissions [ resource_id ] = [ ] ;
82+ grantedPermissions [ resource_id ] = { } ;
8283 const actions = transformActionsCssToOdrl ( resource_scopes ) ;
8384 for ( const action of actions ) {
8485 this . logger . info ( `Evaluating Request [S R AR]: [${ subject } ${ resource_id } ${ action } ]` ) ;
@@ -109,7 +110,7 @@ export class OdrlAuthorizer implements Authorizer {
109110 const activeReports = policyReport . ruleReport . filter (
110111 ( report ) => report . activationState === ActivationState . Active ) ;
111112 if ( activeReports . length > 0 && activeReports [ 0 ] . type === RuleReportType . PermissionReport ) {
112- grantedPermissions [ resource_id ] . push ( action ) ;
113+ grantedPermissions [ resource_id ] [ action ] = policyReport . policy . value ;
113114 }
114115 }
115116 }
@@ -118,7 +119,8 @@ export class OdrlAuthorizer implements Authorizer {
118119 Object . keys ( grantedPermissions ) . forEach (
119120 resource_id => permissions . push ( {
120121 resource_id,
121- resource_scopes : transformActionsOdrlToCss ( grantedPermissions [ resource_id ] )
122+ resource_scopes : transformActionsOdrlToCss ( Object . keys ( grantedPermissions [ resource_id ] ) ) ,
123+ policies : [ ...new Set ( Object . values ( grantedPermissions [ resource_id ] ) ) ] ,
122124 } ) ) ;
123125 return permissions ;
124126 }
0 commit comments