Skip to content

Commit ba9b29c

Browse files
committed
feat: Encode active policies in access token
1 parent 76e34e5 commit ba9b29c

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

packages/uma/config/dialog/negotiators/default.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"@graph": [
66
{
77
"@id": "urn:uma:default:Negotiator",
8-
"@type": "ContractNegotiator",
8+
"@type": "BaseNegotiator",
99
"verifier": { "@id": "urn:uma:default:Verifier" },
1010
"ticketStore": { "@id": "urn:uma:default:TicketStore" },
1111
"ticketingStrategy": { "@id": "urn:uma:default:TicketingStrategy" },
1212
"tokenFactory": { "@id": "urn:uma:default:TokenFactory" }
1313
}
1414
]
15-
}
15+
}

packages/uma/src/policies/authorizers/OdrlAuthorizer.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
RDF
88
} from '@solid/community-server';
99
import { 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';
1111
import { EyeReasoner, ODRLEngineMultipleSteps, ODRLEvaluator } from 'odrl-evaluator'
1212
import { WEBID } from '../../credentials/Claims';
1313
import { 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
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Type, array, string } from "../util/ReType";
1+
import { array, optional as $, string, Type } from '../util/ReType';
22

33
export const Permission = {
44
resource_id: string,
55
resource_scopes: array(string),
6+
policies: $(array(string)),
67
};
78

8-
export type Permission = Type<typeof Permission>;
9+
export type Permission = Type<typeof Permission>;

0 commit comments

Comments
 (0)