1- import { createVocabulary , DC , getLoggerFor , RDF } from '@solid/community-server' ;
1+ import {
2+ BadRequestHttpError ,
3+ createVocabulary ,
4+ DC ,
5+ getLoggerFor ,
6+ NotImplementedHttpError ,
7+ RDF
8+ } from '@solid/community-server' ;
29import { basicPolicy , ODRL , UCPPolicy , UCRulesStorage } from '@solidlab/ucp' ;
3- import { DataFactory , Literal , NamedNode , Quad_Subject , Store , Writer } from 'n3' ;
10+ import { DataFactory , Literal , NamedNode , Quad_Subject , Store } from 'n3' ;
411import { EyeReasoner , ODRLEngineMultipleSteps , ODRLEvaluator } from 'odrl-evaluator'
512import { WEBID } from '../../credentials/Claims' ;
613import { ClaimSet } from '../../credentials/ClaimSet' ;
@@ -62,19 +69,17 @@ export class OdrlAuthorizer implements Authorizer {
6269
6370 // prepare sotw
6471 const sotw = new Store ( ) ;
65- sotw . add ( quad ( namedNode ( 'http://example.com/request/currentTime' ) , namedNode ( 'http://purl.org/dc/terms/issued' ) , literal ( new Date ( ) . toISOString ( ) , namedNode ( "http://www.w3.org/2001/XMLSchema#dateTime" ) ) ) ) ;
72+ sotw . add ( quad (
73+ namedNode ( 'http://example.com/request/currentTime' ) ,
74+ namedNode ( 'http://purl.org/dc/terms/issued' ) ,
75+ literal ( new Date ( ) . toISOString ( ) , namedNode ( "http://www.w3.org/2001/XMLSchema#dateTime" ) ) ) ,
76+ ) ;
6677
6778 const subject = typeof claims [ WEBID ] === 'string' ? claims [ WEBID ] : 'urn:solidlab:uma:id:anonymous' ;
6879
69-
7080 for ( const { resource_id, resource_scopes} of query ) {
71- if ( ! resource_id ) {
72- this . logger . warn ( 'The OdrlAuthorizer can only calculate permissions for explicit resources.' ) ;
73- continue ;
74- }
75-
7681 grantedPermissions [ resource_id ] = [ ] ;
77- const actions = resource_scopes ? transformActionsCssToOdrl ( resource_scopes ) : [ "http://www.w3.org/ns/odrl/2/use" ]
82+ const actions = transformActionsCssToOdrl ( resource_scopes ) ;
7883 for ( const action of actions ) {
7984 this . logger . info ( `Evaluating Request [S R AR]: [${ subject } ${ resource_id } ${ action } ]` ) ;
8085 const requestPolicy : UCPPolicy = {
@@ -119,7 +124,7 @@ export class OdrlAuthorizer implements Authorizer {
119124 }
120125
121126 public async credentials ( permissions : Permission [ ] , query ?: Requirements | undefined ) : Promise < Requirements [ ] > {
122- throw new Error ( " Method not implemented." ) ;
127+ throw new NotImplementedHttpError ( ' Method not implemented.' ) ;
123128 }
124129
125130}
@@ -141,7 +146,13 @@ function transformActionsCssToOdrl(actions: string[]): string[] {
141146
142147 // in UMAPermissionReader, only the last part of the URN will be used, divided by a colon
143148 // again, see CSS package
144- return actions . map ( action => scopeCssToOdrl . get ( action ) ! ) ;
149+ return actions . map ( action => {
150+ const result = scopeCssToOdrl . get ( action ) ;
151+ if ( ! result ) {
152+ throw new BadRequestHttpError ( `Unsupported action ${ action } ` ) ;
153+ }
154+ return result ;
155+ } ) ;
145156}
146157/**
147158 * Transform ODRL Actions to equivalent Actions enforced by the Community Solid Server
0 commit comments