Skip to content

Commit 89a19c3

Browse files
committed
feat: make rulestorage configurable
Signed-off-by: Wouter Termont <wouter.termont@ugent.be>
1 parent 87c967e commit 89a19c3

5 files changed

Lines changed: 23 additions & 28 deletions

File tree

packages/uma/.componentsignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"AccessToken",
33
"AccessToken",
44
"Authorization",
5+
"Authorizer",
56
"Error",
67
"EventEmitter",
78
"Map",
@@ -13,4 +14,4 @@
1314
"ScopeDescription",
1415
"Ticket",
1516
"URL"
16-
]
17+
]

packages/uma/config/policies/authorizers/default.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"@context": [
3-
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma/^0.0.0/components/context.jsonld"
3+
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma/^0.0.0/components/context.jsonld",
4+
"https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/ucp/^0.0.0/components/context.jsonld"
45
],
56
"@graph": [
67
{
@@ -34,8 +35,14 @@
3435
"fallback": {
3536
"@id": "urn:uma:default:PolicyBasedAuthorizer",
3637
"@type": "PolicyBasedAuthorizer",
37-
"policyDir": "config/rules/policy/",
38-
"n3Rules": "config/rules/crud.n3"
38+
"n3Rules": "config/rules/crud.n3",
39+
"rules": {
40+
"@id": "urn:uma:default:RulesStorage",
41+
"@type": "DirectoryUCRulesStorage",
42+
"directoryPath": {
43+
"@id": "urn:uma:variables:policyDir"
44+
}
45+
}
3946
}
4047
}
4148
]

packages/uma/config/variables/default.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"comment": "Hostname of the server.",
1717
"@id": "urn:uma:variables:host",
1818
"@type": "Variable"
19+
},
20+
{
21+
"comment": "Path to the directory containing the policy rules.",
22+
"@id": "urn:uma:variables:policyDir",
23+
"@type": "Variable"
1924
}
2025
]
21-
}
26+
}

packages/uma/src/main.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,16 @@ const port = 4000;
1515
const baseUrl = `${protocol}://${host}:${port}/uma`;
1616
const rootDir = path.join(__dirname, '../');
1717

18-
// const config = {
19-
// jwks_uri: `${baseUrl}/keys`,
20-
// token_endpoint: `${baseUrl}/token`,
21-
// grant_types_supported: ['urn:ietf:params:oauth:grant-type:uma-ticket'],
22-
// issuer: `${baseUrl}`,
23-
// permission_endpoint: `${baseUrl}/ticket`,
24-
// introspection_endpoint: `${baseUrl}/introspect`,
25-
// resource_registration_endpoint: `${baseUrl}/resources`,
26-
// uma_profiles_supported: ['http://openid.net/specs/openid-connect-core-1_0.html#IDToken'],
27-
// dpop_signing_alg_values_supported: [...ASYMMETRIC_CRYPTOGRAPHIC_ALGORITHM],
28-
// response_types_supported: [ResponseType.Token],
29-
// };
30-
3118
export const launch: () => Promise<void> = async () => {
32-
33-
// fs.writeFileSync(
34-
// path.join(rootDir, './config/default.json'),
35-
// JSON.stringify(config),
36-
// );
37-
19+
3820
const variables: Record<string, any> = {};
3921

4022
variables['urn:uma:variables:port'] = port;
4123
variables['urn:uma:variables:host'] = host;
4224
variables['urn:uma:variables:protocol'] = protocol;
4325
variables['urn:uma:variables:baseUrl'] = baseUrl;
26+
27+
variables['urn:uma:variables:policyDir'] = path.join(rootDir, './config/rules/policy');
4428

4529
variables['urn:uma:variables:mainModulePath'] = rootDir;
4630
variables['urn:uma:variables:customConfigPath'] = path.join(rootDir, './config/default.json');

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export class PolicyBasedAuthorizer implements Authorizer {
2121
private plugins = { "http://example.org/dataUsage": new UcpPlugin() };
2222
private executor = new PolicyExecutor(this.plugins);
2323
private enforcer: UcpPatternEnforcement;
24-
private rules: UCRulesStorage;
2524
private n3: string;
2625

2726
/**
@@ -33,12 +32,11 @@ export class PolicyBasedAuthorizer implements Authorizer {
3332
constructor(
3433
// protected rules: UCRulesStorage,
3534
// protected enforcer: UcpPatternEnforcement
36-
policyDir: string,
35+
rules: UCRulesStorage,
3736
n3Rules: string,
3837
) {
39-
this.rules = new DirectoryUCRulesStorage(path.join(__dirname, '../../../', policyDir));
4038
this.n3 = readFileSync(path.join(__dirname, '../../../', n3Rules)).toString();
41-
this.enforcer = new UcpPatternEnforcement(this.rules, [this.n3], this.reasoner, this.executor)
39+
this.enforcer = new UcpPatternEnforcement(rules, [this.n3], this.reasoner, this.executor)
4240
}
4341

4442

0 commit comments

Comments
 (0)