@twin.org/rights-management-pdp-service 0.0.2-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +21 -0
- package/dist/cjs/index.cjs +156 -0
- package/dist/esm/index.mjs +154 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/models/IPolicyDecisionPointServiceConfig.d.ts +13 -0
- package/dist/types/models/IPolicyDecisionPointServiceConstructorOptions.d.ts +30 -0
- package/dist/types/policyDecisionPointService.d.ts +40 -0
- package/docs/changelog.md +178 -0
- package/docs/examples.md +1 -0
- package/docs/reference/classes/PolicyDecisionPointService.md +139 -0
- package/docs/reference/index.md +10 -0
- package/docs/reference/interfaces/IPolicyDecisionPointServiceConfig.md +19 -0
- package/docs/reference/interfaces/IPolicyDecisionPointServiceConstructorOptions.md +67 -0
- package/locales/en.json +14 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 IOTA Stiftung.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# TWIN Rights Management Policy Decision Point Service
|
|
2
|
+
|
|
3
|
+
Policy decision point implementation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install @twin.org/rights-management-pdp-service
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
Usage of the APIs is shown in the examples [docs/examples.md](docs/examples.md)
|
|
14
|
+
|
|
15
|
+
## Reference
|
|
16
|
+
|
|
17
|
+
Detailed reference documentation for the API can be found in [docs/reference/index.md](docs/reference/index.md)
|
|
18
|
+
|
|
19
|
+
## Changelog
|
|
20
|
+
|
|
21
|
+
The changes between each version can be found in [docs/changelog.md](docs/changelog.md)
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@twin.org/core');
|
|
4
|
+
var rightsManagementModels = require('@twin.org/rights-management-models');
|
|
5
|
+
|
|
6
|
+
// Copyright 2024 IOTA Stiftung.
|
|
7
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
8
|
+
/**
|
|
9
|
+
* Class implementation of Policy Decision Point Component.
|
|
10
|
+
*/
|
|
11
|
+
class PolicyDecisionPointService {
|
|
12
|
+
/**
|
|
13
|
+
* The class name of the Policy Decision Point Service.
|
|
14
|
+
*/
|
|
15
|
+
CLASS_NAME = "PolicyDecisionPointService";
|
|
16
|
+
/**
|
|
17
|
+
* The logging component.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
_logging;
|
|
21
|
+
/**
|
|
22
|
+
* The policy management point component.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
_policyManagementPointComponent;
|
|
26
|
+
/**
|
|
27
|
+
* The policy information point component.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
_policyInformationPointComponent;
|
|
31
|
+
/**
|
|
32
|
+
* The policy execution point component.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
_policyExecutionPointComponent;
|
|
36
|
+
/**
|
|
37
|
+
* These arbiters can be registered to make decision on specific types.
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
_arbiters;
|
|
41
|
+
/**
|
|
42
|
+
* Create a new instance of PolicyDecisionPointService (PDP).
|
|
43
|
+
* @param options The options for the component.
|
|
44
|
+
*/
|
|
45
|
+
constructor(options) {
|
|
46
|
+
this._logging = core.ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
|
|
47
|
+
this._policyManagementPointComponent = core.ComponentFactory.get(options?.policyManagementPointComponentType ?? "policy-management-point");
|
|
48
|
+
this._policyInformationPointComponent = core.ComponentFactory.get(options?.policyInformationPointComponentType ?? "policy-information-point");
|
|
49
|
+
this._policyExecutionPointComponent = core.ComponentFactory.get(options?.policyExecutionPointComponentType ?? "policy-execution-point");
|
|
50
|
+
this._arbiters = options?.config?.arbiters ?? [];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Evaluate requests from a Policy Enforcement Point (PEP).
|
|
54
|
+
* Uses the Policy Management Point (PMP) to retrieve the policies and the
|
|
55
|
+
* Policy Information Point (PIP) to retrieve additional information.
|
|
56
|
+
* Executes any actions on the Policy Execution Point (PXP) before and after decision is made.
|
|
57
|
+
* @param locator The locator to find relevant policies.
|
|
58
|
+
* @param data The data to make a decision on.
|
|
59
|
+
* @returns Returns the policy decisions which apply to the data so that the PEP
|
|
60
|
+
* can manipulate the data accordingly.
|
|
61
|
+
*/
|
|
62
|
+
async evaluate(locator, data) {
|
|
63
|
+
core.Guards.objectValue(this.CLASS_NAME, "locator", locator);
|
|
64
|
+
const supportedArbiters = this._arbiters.filter(({ arbiter }) => {
|
|
65
|
+
const supportedPolicies = arbiter.supportedPolicies();
|
|
66
|
+
return (supportedPolicies.length === 0 ||
|
|
67
|
+
rightsManagementModels.LocatorHelper.findMatchingLocator(supportedPolicies, locator));
|
|
68
|
+
});
|
|
69
|
+
if (supportedArbiters.length === 0) {
|
|
70
|
+
throw new core.GeneralError(this.CLASS_NAME, "noSupportedArbiters", {
|
|
71
|
+
locator: rightsManagementModels.LocatorHelper.toString(locator)
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const policies = [];
|
|
75
|
+
let cursor;
|
|
76
|
+
do {
|
|
77
|
+
const retrieveResult = await this._policyManagementPointComponent.retrieve(locator, data);
|
|
78
|
+
cursor = retrieveResult.cursor;
|
|
79
|
+
policies.push(...retrieveResult.policies);
|
|
80
|
+
} while (core.Is.stringValue(cursor));
|
|
81
|
+
const decisions = [];
|
|
82
|
+
await this._policyExecutionPointComponent.executeActions(rightsManagementModels.PolicyDecisionStage.Before, locator, policies, decisions, data);
|
|
83
|
+
const information = await this._policyInformationPointComponent.retrieve(locator, rightsManagementModels.PolicyInformationAccessMode.Any, policies, data);
|
|
84
|
+
for (const { arbiterId, arbiter } of supportedArbiters) {
|
|
85
|
+
try {
|
|
86
|
+
const arbiterDecisions = await arbiter.decide(locator, information, policies, data);
|
|
87
|
+
decisions.push(...arbiterDecisions);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
this._logging?.log({
|
|
91
|
+
level: "error",
|
|
92
|
+
source: this.CLASS_NAME,
|
|
93
|
+
ts: Date.now(),
|
|
94
|
+
message: "decidingFailed",
|
|
95
|
+
data: {
|
|
96
|
+
arbiterId,
|
|
97
|
+
locator: rightsManagementModels.LocatorHelper.toString(locator)
|
|
98
|
+
},
|
|
99
|
+
error: core.BaseError.fromError(error)
|
|
100
|
+
});
|
|
101
|
+
throw new core.GeneralError(this.CLASS_NAME, "decidingFailed", { arbiterId, locator: rightsManagementModels.LocatorHelper.toString(locator) }, error);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
await this._policyExecutionPointComponent.executeActions(rightsManagementModels.PolicyDecisionStage.After, locator, policies, decisions, data);
|
|
105
|
+
return decisions;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Register an arbiter to use for making decisions.
|
|
109
|
+
* @param arbiterId The id of the arbiter to register.
|
|
110
|
+
* @param arbiter The arbiter to register.
|
|
111
|
+
* @returns Nothing.
|
|
112
|
+
*/
|
|
113
|
+
async registerArbiter(arbiterId, arbiter) {
|
|
114
|
+
core.Guards.stringValue(this.CLASS_NAME, "arbiterId", arbiterId);
|
|
115
|
+
core.Guards.object(this.CLASS_NAME, "arbiter", arbiter);
|
|
116
|
+
const currentIndex = this._arbiters.findIndex(a => a.arbiterId === arbiterId);
|
|
117
|
+
if (currentIndex !== -1) {
|
|
118
|
+
this._arbiters[currentIndex].arbiter = arbiter;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this._arbiters.push({ arbiterId, arbiter });
|
|
122
|
+
}
|
|
123
|
+
this._logging?.log({
|
|
124
|
+
level: "info",
|
|
125
|
+
source: this.CLASS_NAME,
|
|
126
|
+
ts: Date.now(),
|
|
127
|
+
message: "registeredArbiter",
|
|
128
|
+
data: {
|
|
129
|
+
arbiterId
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Unregister an arbiter from making decisions.
|
|
135
|
+
* @param arbiterId The id of the arbiter to unregister.
|
|
136
|
+
* @returns Nothing.
|
|
137
|
+
*/
|
|
138
|
+
async unregisterArbiter(arbiterId) {
|
|
139
|
+
core.Guards.stringValue(this.CLASS_NAME, "arbiterId", arbiterId);
|
|
140
|
+
const currentIndex = this._arbiters.findIndex(a => a.arbiterId === arbiterId);
|
|
141
|
+
if (currentIndex !== -1) {
|
|
142
|
+
this._arbiters.splice(currentIndex, 1);
|
|
143
|
+
}
|
|
144
|
+
this._logging?.log({
|
|
145
|
+
level: "info",
|
|
146
|
+
source: this.CLASS_NAME,
|
|
147
|
+
ts: Date.now(),
|
|
148
|
+
message: "unregisteredArbiter",
|
|
149
|
+
data: {
|
|
150
|
+
arbiterId
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
exports.PolicyDecisionPointService = PolicyDecisionPointService;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { ComponentFactory, Guards, GeneralError, Is, BaseError } from '@twin.org/core';
|
|
2
|
+
import { LocatorHelper, PolicyDecisionStage, PolicyInformationAccessMode } from '@twin.org/rights-management-models';
|
|
3
|
+
|
|
4
|
+
// Copyright 2024 IOTA Stiftung.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
6
|
+
/**
|
|
7
|
+
* Class implementation of Policy Decision Point Component.
|
|
8
|
+
*/
|
|
9
|
+
class PolicyDecisionPointService {
|
|
10
|
+
/**
|
|
11
|
+
* The class name of the Policy Decision Point Service.
|
|
12
|
+
*/
|
|
13
|
+
CLASS_NAME = "PolicyDecisionPointService";
|
|
14
|
+
/**
|
|
15
|
+
* The logging component.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
_logging;
|
|
19
|
+
/**
|
|
20
|
+
* The policy management point component.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
_policyManagementPointComponent;
|
|
24
|
+
/**
|
|
25
|
+
* The policy information point component.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
_policyInformationPointComponent;
|
|
29
|
+
/**
|
|
30
|
+
* The policy execution point component.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
_policyExecutionPointComponent;
|
|
34
|
+
/**
|
|
35
|
+
* These arbiters can be registered to make decision on specific types.
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
_arbiters;
|
|
39
|
+
/**
|
|
40
|
+
* Create a new instance of PolicyDecisionPointService (PDP).
|
|
41
|
+
* @param options The options for the component.
|
|
42
|
+
*/
|
|
43
|
+
constructor(options) {
|
|
44
|
+
this._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
|
|
45
|
+
this._policyManagementPointComponent = ComponentFactory.get(options?.policyManagementPointComponentType ?? "policy-management-point");
|
|
46
|
+
this._policyInformationPointComponent = ComponentFactory.get(options?.policyInformationPointComponentType ?? "policy-information-point");
|
|
47
|
+
this._policyExecutionPointComponent = ComponentFactory.get(options?.policyExecutionPointComponentType ?? "policy-execution-point");
|
|
48
|
+
this._arbiters = options?.config?.arbiters ?? [];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Evaluate requests from a Policy Enforcement Point (PEP).
|
|
52
|
+
* Uses the Policy Management Point (PMP) to retrieve the policies and the
|
|
53
|
+
* Policy Information Point (PIP) to retrieve additional information.
|
|
54
|
+
* Executes any actions on the Policy Execution Point (PXP) before and after decision is made.
|
|
55
|
+
* @param locator The locator to find relevant policies.
|
|
56
|
+
* @param data The data to make a decision on.
|
|
57
|
+
* @returns Returns the policy decisions which apply to the data so that the PEP
|
|
58
|
+
* can manipulate the data accordingly.
|
|
59
|
+
*/
|
|
60
|
+
async evaluate(locator, data) {
|
|
61
|
+
Guards.objectValue(this.CLASS_NAME, "locator", locator);
|
|
62
|
+
const supportedArbiters = this._arbiters.filter(({ arbiter }) => {
|
|
63
|
+
const supportedPolicies = arbiter.supportedPolicies();
|
|
64
|
+
return (supportedPolicies.length === 0 ||
|
|
65
|
+
LocatorHelper.findMatchingLocator(supportedPolicies, locator));
|
|
66
|
+
});
|
|
67
|
+
if (supportedArbiters.length === 0) {
|
|
68
|
+
throw new GeneralError(this.CLASS_NAME, "noSupportedArbiters", {
|
|
69
|
+
locator: LocatorHelper.toString(locator)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const policies = [];
|
|
73
|
+
let cursor;
|
|
74
|
+
do {
|
|
75
|
+
const retrieveResult = await this._policyManagementPointComponent.retrieve(locator, data);
|
|
76
|
+
cursor = retrieveResult.cursor;
|
|
77
|
+
policies.push(...retrieveResult.policies);
|
|
78
|
+
} while (Is.stringValue(cursor));
|
|
79
|
+
const decisions = [];
|
|
80
|
+
await this._policyExecutionPointComponent.executeActions(PolicyDecisionStage.Before, locator, policies, decisions, data);
|
|
81
|
+
const information = await this._policyInformationPointComponent.retrieve(locator, PolicyInformationAccessMode.Any, policies, data);
|
|
82
|
+
for (const { arbiterId, arbiter } of supportedArbiters) {
|
|
83
|
+
try {
|
|
84
|
+
const arbiterDecisions = await arbiter.decide(locator, information, policies, data);
|
|
85
|
+
decisions.push(...arbiterDecisions);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
this._logging?.log({
|
|
89
|
+
level: "error",
|
|
90
|
+
source: this.CLASS_NAME,
|
|
91
|
+
ts: Date.now(),
|
|
92
|
+
message: "decidingFailed",
|
|
93
|
+
data: {
|
|
94
|
+
arbiterId,
|
|
95
|
+
locator: LocatorHelper.toString(locator)
|
|
96
|
+
},
|
|
97
|
+
error: BaseError.fromError(error)
|
|
98
|
+
});
|
|
99
|
+
throw new GeneralError(this.CLASS_NAME, "decidingFailed", { arbiterId, locator: LocatorHelper.toString(locator) }, error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
await this._policyExecutionPointComponent.executeActions(PolicyDecisionStage.After, locator, policies, decisions, data);
|
|
103
|
+
return decisions;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Register an arbiter to use for making decisions.
|
|
107
|
+
* @param arbiterId The id of the arbiter to register.
|
|
108
|
+
* @param arbiter The arbiter to register.
|
|
109
|
+
* @returns Nothing.
|
|
110
|
+
*/
|
|
111
|
+
async registerArbiter(arbiterId, arbiter) {
|
|
112
|
+
Guards.stringValue(this.CLASS_NAME, "arbiterId", arbiterId);
|
|
113
|
+
Guards.object(this.CLASS_NAME, "arbiter", arbiter);
|
|
114
|
+
const currentIndex = this._arbiters.findIndex(a => a.arbiterId === arbiterId);
|
|
115
|
+
if (currentIndex !== -1) {
|
|
116
|
+
this._arbiters[currentIndex].arbiter = arbiter;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
this._arbiters.push({ arbiterId, arbiter });
|
|
120
|
+
}
|
|
121
|
+
this._logging?.log({
|
|
122
|
+
level: "info",
|
|
123
|
+
source: this.CLASS_NAME,
|
|
124
|
+
ts: Date.now(),
|
|
125
|
+
message: "registeredArbiter",
|
|
126
|
+
data: {
|
|
127
|
+
arbiterId
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Unregister an arbiter from making decisions.
|
|
133
|
+
* @param arbiterId The id of the arbiter to unregister.
|
|
134
|
+
* @returns Nothing.
|
|
135
|
+
*/
|
|
136
|
+
async unregisterArbiter(arbiterId) {
|
|
137
|
+
Guards.stringValue(this.CLASS_NAME, "arbiterId", arbiterId);
|
|
138
|
+
const currentIndex = this._arbiters.findIndex(a => a.arbiterId === arbiterId);
|
|
139
|
+
if (currentIndex !== -1) {
|
|
140
|
+
this._arbiters.splice(currentIndex, 1);
|
|
141
|
+
}
|
|
142
|
+
this._logging?.log({
|
|
143
|
+
level: "info",
|
|
144
|
+
source: this.CLASS_NAME,
|
|
145
|
+
ts: Date.now(),
|
|
146
|
+
message: "unregisteredArbiter",
|
|
147
|
+
data: {
|
|
148
|
+
arbiterId
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { PolicyDecisionPointService };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IPolicyArbiter } from "@twin.org/rights-management-models";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the Policy Decision Point Component.
|
|
4
|
+
*/
|
|
5
|
+
export interface IPolicyDecisionPointServiceConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Initial arbiters to register with the PDP.
|
|
8
|
+
*/
|
|
9
|
+
arbiters?: {
|
|
10
|
+
arbiterId: string;
|
|
11
|
+
arbiter: IPolicyArbiter;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { IPolicyDecisionPointServiceConfig } from "./IPolicyDecisionPointServiceConfig";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the Policy Decision Point Component.
|
|
4
|
+
*/
|
|
5
|
+
export interface IPolicyDecisionPointServiceConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The logging component for logging policy decisions.
|
|
8
|
+
* @default logging
|
|
9
|
+
*/
|
|
10
|
+
loggingComponentType?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The type of the policy information point component.
|
|
13
|
+
* @default policy-information-point
|
|
14
|
+
*/
|
|
15
|
+
policyInformationPointComponentType?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The type of the policy management point component.
|
|
18
|
+
* @default policy-management-point
|
|
19
|
+
*/
|
|
20
|
+
policyManagementPointComponentType?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The type of the policy execution point component.
|
|
23
|
+
* @default policy-execution-point
|
|
24
|
+
*/
|
|
25
|
+
policyExecutionPointComponentType?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The configuration for the Policy Decision Point Service.
|
|
28
|
+
*/
|
|
29
|
+
config?: IPolicyDecisionPointServiceConfig;
|
|
30
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type IPolicyLocator, type IPolicyArbiter, type IPolicyDecision, type IPolicyDecisionPointComponent } from "@twin.org/rights-management-models";
|
|
2
|
+
import type { IPolicyDecisionPointServiceConstructorOptions } from "./models/IPolicyDecisionPointServiceConstructorOptions";
|
|
3
|
+
/**
|
|
4
|
+
* Class implementation of Policy Decision Point Component.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PolicyDecisionPointService implements IPolicyDecisionPointComponent {
|
|
7
|
+
/**
|
|
8
|
+
* The class name of the Policy Decision Point Service.
|
|
9
|
+
*/
|
|
10
|
+
readonly CLASS_NAME: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new instance of PolicyDecisionPointService (PDP).
|
|
13
|
+
* @param options The options for the component.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options?: IPolicyDecisionPointServiceConstructorOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Evaluate requests from a Policy Enforcement Point (PEP).
|
|
18
|
+
* Uses the Policy Management Point (PMP) to retrieve the policies and the
|
|
19
|
+
* Policy Information Point (PIP) to retrieve additional information.
|
|
20
|
+
* Executes any actions on the Policy Execution Point (PXP) before and after decision is made.
|
|
21
|
+
* @param locator The locator to find relevant policies.
|
|
22
|
+
* @param data The data to make a decision on.
|
|
23
|
+
* @returns Returns the policy decisions which apply to the data so that the PEP
|
|
24
|
+
* can manipulate the data accordingly.
|
|
25
|
+
*/
|
|
26
|
+
evaluate<D = unknown>(locator: IPolicyLocator, data?: D): Promise<IPolicyDecision[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Register an arbiter to use for making decisions.
|
|
29
|
+
* @param arbiterId The id of the arbiter to register.
|
|
30
|
+
* @param arbiter The arbiter to register.
|
|
31
|
+
* @returns Nothing.
|
|
32
|
+
*/
|
|
33
|
+
registerArbiter(arbiterId: string, arbiter: IPolicyArbiter): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Unregister an arbiter from making decisions.
|
|
36
|
+
* @param arbiterId The id of the arbiter to unregister.
|
|
37
|
+
* @returns Nothing.
|
|
38
|
+
*/
|
|
39
|
+
unregisterArbiter(arbiterId: string): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.2-next.10](https://github.com/twinfoundation/rights-management/compare/rights-management-pdp-service-v0.0.2-next.9...rights-management-pdp-service-v0.0.2-next.10) (2025-09-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add pdp tests ([87a0c29](https://github.com/twinfoundation/rights-management/commit/87a0c29674ac5b97c3b2a1723d14f56a582f36c4))
|
|
9
|
+
* pdp add ([#39](https://github.com/twinfoundation/rights-management/issues/39)) ([68b9a8a](https://github.com/twinfoundation/rights-management/commit/68b9a8a7a3cf2902f9eecb590ca3316c6b1671f0))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Dependencies
|
|
13
|
+
|
|
14
|
+
* The following workspace dependencies were updated
|
|
15
|
+
* dependencies
|
|
16
|
+
* @twin.org/rights-management-models bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
17
|
+
* devDependencies
|
|
18
|
+
* @twin.org/rights-management-pap-service bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
19
|
+
* @twin.org/rights-management-pip-service bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
20
|
+
* @twin.org/rights-management-pmp-service bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
21
|
+
* @twin.org/rights-management-pxp-service bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
22
|
+
|
|
23
|
+
## [0.0.2-next.9](https://github.com/twinfoundation/rights-management/compare/rights-management-pdp-service-v0.0.2-next.8...rights-management-pdp-service-v0.0.2-next.9) (2025-09-08)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
* add JSON-LD types for negotiation ([6be61f8](https://github.com/twinfoundation/rights-management/commit/6be61f890537cb9d22d4fad90092b858de2c9c2d))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Dependencies
|
|
32
|
+
|
|
33
|
+
* The following workspace dependencies were updated
|
|
34
|
+
* dependencies
|
|
35
|
+
* @twin.org/rights-management-models bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
36
|
+
* devDependencies
|
|
37
|
+
* @twin.org/rights-management-pap-service bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
38
|
+
* @twin.org/rights-management-pip-service bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
39
|
+
* @twin.org/rights-management-pmp-service bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
40
|
+
* @twin.org/rights-management-pxp-service bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
41
|
+
|
|
42
|
+
## [0.0.2-next.8](https://github.com/twinfoundation/rights-management/compare/rights-management-pdp-service-v0.0.2-next.7...rights-management-pdp-service-v0.0.2-next.8) (2025-09-05)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Miscellaneous Chores
|
|
46
|
+
|
|
47
|
+
* **rights-management-pdp-service:** Synchronize repo versions
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Dependencies
|
|
51
|
+
|
|
52
|
+
* The following workspace dependencies were updated
|
|
53
|
+
* dependencies
|
|
54
|
+
* @twin.org/rights-management-models bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
55
|
+
* devDependencies
|
|
56
|
+
* @twin.org/rights-management-pap-service bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
57
|
+
* @twin.org/rights-management-pip-service bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
58
|
+
* @twin.org/rights-management-pmp-service bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
59
|
+
* @twin.org/rights-management-pxp-service bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
60
|
+
|
|
61
|
+
## [0.0.2-next.7](https://github.com/twinfoundation/rights-management/compare/rights-management-pdp-service-v0.0.2-next.6...rights-management-pdp-service-v0.0.2-next.7) (2025-09-05)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### Miscellaneous Chores
|
|
65
|
+
|
|
66
|
+
* **rights-management-pdp-service:** Synchronize repo versions
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
### Dependencies
|
|
70
|
+
|
|
71
|
+
* The following workspace dependencies were updated
|
|
72
|
+
* dependencies
|
|
73
|
+
* @twin.org/rights-management-models bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
74
|
+
* devDependencies
|
|
75
|
+
* @twin.org/rights-management-pap-service bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
76
|
+
* @twin.org/rights-management-pip-service bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
77
|
+
* @twin.org/rights-management-pmp-service bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
78
|
+
* @twin.org/rights-management-pxp-service bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
79
|
+
|
|
80
|
+
## [0.0.2-next.6](https://github.com/twinfoundation/rights-management/compare/rights-management-pdp-service-v0.0.2-next.5...rights-management-pdp-service-v0.0.2-next.6) (2025-09-05)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Miscellaneous Chores
|
|
84
|
+
|
|
85
|
+
* **rights-management-pdp-service:** Synchronize repo versions
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
### Dependencies
|
|
89
|
+
|
|
90
|
+
* The following workspace dependencies were updated
|
|
91
|
+
* dependencies
|
|
92
|
+
* @twin.org/rights-management-models bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
93
|
+
* devDependencies
|
|
94
|
+
* @twin.org/rights-management-pap-service bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
95
|
+
* @twin.org/rights-management-pip-service bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
96
|
+
* @twin.org/rights-management-pmp-service bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
97
|
+
* @twin.org/rights-management-pxp-service bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
98
|
+
|
|
99
|
+
## [0.0.2-next.5](https://github.com/twinfoundation/rights-management/compare/rights-management-pdp-service-v0.0.2-next.4...rights-management-pdp-service-v0.0.2-next.5) (2025-09-05)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
### Features
|
|
103
|
+
|
|
104
|
+
* add policy negotiation point PNP, PNAP and PNRP ([#32](https://github.com/twinfoundation/rights-management/issues/32)) ([90f0659](https://github.com/twinfoundation/rights-management/commit/90f06593a1126df3c2f4ca23cf95a08260fd6415))
|
|
105
|
+
* introduce context for additional environment input ([e1d0392](https://github.com/twinfoundation/rights-management/commit/e1d0392622e5a018b695644f423c5b23cc40d3b7))
|
|
106
|
+
* remove optional for components ([a354232](https://github.com/twinfoundation/rights-management/commit/a354232ff97fe49cbcdc18c73c4e17cf9346ccfd))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
### Dependencies
|
|
110
|
+
|
|
111
|
+
* The following workspace dependencies were updated
|
|
112
|
+
* dependencies
|
|
113
|
+
* @twin.org/rights-management-models bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
114
|
+
* devDependencies
|
|
115
|
+
* @twin.org/rights-management-pap-service bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
116
|
+
* @twin.org/rights-management-pip-service bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
117
|
+
* @twin.org/rights-management-pmp-service bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
118
|
+
* @twin.org/rights-management-pxp-service bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
119
|
+
|
|
120
|
+
## [0.0.2-next.4](https://github.com/twinfoundation/rights-management/compare/rights-management-pdp-service-v0.0.2-next.3...rights-management-pdp-service-v0.0.2-next.4) (2025-08-29)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
### Features
|
|
124
|
+
|
|
125
|
+
* eslint migration to flat config ([5698a8c](https://github.com/twinfoundation/rights-management/commit/5698a8c399a020a13be0bcdff5a7c5050272cfcc))
|
|
126
|
+
* improve constructor option naming ([c89a7e8](https://github.com/twinfoundation/rights-management/commit/c89a7e8df43a5017ac5cf84b549f5a26cc41e089))
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
### Dependencies
|
|
130
|
+
|
|
131
|
+
* The following workspace dependencies were updated
|
|
132
|
+
* dependencies
|
|
133
|
+
* @twin.org/rights-management-models bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
134
|
+
* devDependencies
|
|
135
|
+
* @twin.org/rights-management-pap-service bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
136
|
+
* @twin.org/rights-management-pip-service bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
137
|
+
* @twin.org/rights-management-pmp-service bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
138
|
+
* @twin.org/rights-management-pxp-service bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
139
|
+
|
|
140
|
+
## [0.0.2-next.3](https://github.com/twinfoundation/rights-management/compare/rights-management-pdp-service-v0.0.2-next.2...rights-management-pdp-service-v0.0.2-next.3) (2025-08-29)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
### Features
|
|
144
|
+
|
|
145
|
+
* eslint migration to flat config ([23a0c08](https://github.com/twinfoundation/rights-management/commit/23a0c085e7fc2e522c8d85d325dc5844b9c3fd8e))
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### Dependencies
|
|
149
|
+
|
|
150
|
+
* The following workspace dependencies were updated
|
|
151
|
+
* dependencies
|
|
152
|
+
* @twin.org/rights-management-models bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
153
|
+
* devDependencies
|
|
154
|
+
* @twin.org/rights-management-pap-service bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
155
|
+
* @twin.org/rights-management-pip-service bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
156
|
+
* @twin.org/rights-management-pmp-service bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
157
|
+
* @twin.org/rights-management-pxp-service bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
158
|
+
|
|
159
|
+
## [0.0.2-next.2](https://github.com/twinfoundation/rights-management/compare/rights-management-pdp-service-v0.0.2-next.1...rights-management-pdp-service-v0.0.2-next.2) (2025-08-22)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
### Features
|
|
163
|
+
|
|
164
|
+
* add scaffold for other services ([de25f34](https://github.com/twinfoundation/rights-management/commit/de25f34c40fb65b6d73df98965ea4e368019da84))
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
### Dependencies
|
|
168
|
+
|
|
169
|
+
* The following workspace dependencies were updated
|
|
170
|
+
* dependencies
|
|
171
|
+
* @twin.org/rights-management-models bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
172
|
+
* devDependencies
|
|
173
|
+
* @twin.org/rights-management-pap-service bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
174
|
+
* @twin.org/rights-management-pip-service bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
175
|
+
* @twin.org/rights-management-pmp-service bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
176
|
+
* @twin.org/rights-management-pxp-service bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
177
|
+
|
|
178
|
+
## @twin.org/rights-management-pdp-service - Changelog
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @twin.org/rights-management-pdp-service - Examples
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Class: PolicyDecisionPointService
|
|
2
|
+
|
|
3
|
+
Class implementation of Policy Decision Point Component.
|
|
4
|
+
|
|
5
|
+
## Implements
|
|
6
|
+
|
|
7
|
+
- `IPolicyDecisionPointComponent`
|
|
8
|
+
|
|
9
|
+
## Constructors
|
|
10
|
+
|
|
11
|
+
### Constructor
|
|
12
|
+
|
|
13
|
+
> **new PolicyDecisionPointService**(`options?`): `PolicyDecisionPointService`
|
|
14
|
+
|
|
15
|
+
Create a new instance of PolicyDecisionPointService (PDP).
|
|
16
|
+
|
|
17
|
+
#### Parameters
|
|
18
|
+
|
|
19
|
+
##### options?
|
|
20
|
+
|
|
21
|
+
[`IPolicyDecisionPointServiceConstructorOptions`](../interfaces/IPolicyDecisionPointServiceConstructorOptions.md)
|
|
22
|
+
|
|
23
|
+
The options for the component.
|
|
24
|
+
|
|
25
|
+
#### Returns
|
|
26
|
+
|
|
27
|
+
`PolicyDecisionPointService`
|
|
28
|
+
|
|
29
|
+
## Properties
|
|
30
|
+
|
|
31
|
+
### CLASS\_NAME
|
|
32
|
+
|
|
33
|
+
> `readonly` **CLASS\_NAME**: `string`
|
|
34
|
+
|
|
35
|
+
The class name of the Policy Decision Point Service.
|
|
36
|
+
|
|
37
|
+
#### Implementation of
|
|
38
|
+
|
|
39
|
+
`IPolicyDecisionPointComponent.CLASS_NAME`
|
|
40
|
+
|
|
41
|
+
## Methods
|
|
42
|
+
|
|
43
|
+
### evaluate()
|
|
44
|
+
|
|
45
|
+
> **evaluate**\<`D`\>(`locator`, `data?`): `Promise`\<`IPolicyDecision`[]\>
|
|
46
|
+
|
|
47
|
+
Evaluate requests from a Policy Enforcement Point (PEP).
|
|
48
|
+
Uses the Policy Management Point (PMP) to retrieve the policies and the
|
|
49
|
+
Policy Information Point (PIP) to retrieve additional information.
|
|
50
|
+
Executes any actions on the Policy Execution Point (PXP) before and after decision is made.
|
|
51
|
+
|
|
52
|
+
#### Type Parameters
|
|
53
|
+
|
|
54
|
+
##### D
|
|
55
|
+
|
|
56
|
+
`D` = `unknown`
|
|
57
|
+
|
|
58
|
+
#### Parameters
|
|
59
|
+
|
|
60
|
+
##### locator
|
|
61
|
+
|
|
62
|
+
`IPolicyLocator`
|
|
63
|
+
|
|
64
|
+
The locator to find relevant policies.
|
|
65
|
+
|
|
66
|
+
##### data?
|
|
67
|
+
|
|
68
|
+
`D`
|
|
69
|
+
|
|
70
|
+
The data to make a decision on.
|
|
71
|
+
|
|
72
|
+
#### Returns
|
|
73
|
+
|
|
74
|
+
`Promise`\<`IPolicyDecision`[]\>
|
|
75
|
+
|
|
76
|
+
Returns the policy decisions which apply to the data so that the PEP
|
|
77
|
+
can manipulate the data accordingly.
|
|
78
|
+
|
|
79
|
+
#### Implementation of
|
|
80
|
+
|
|
81
|
+
`IPolicyDecisionPointComponent.evaluate`
|
|
82
|
+
|
|
83
|
+
***
|
|
84
|
+
|
|
85
|
+
### registerArbiter()
|
|
86
|
+
|
|
87
|
+
> **registerArbiter**(`arbiterId`, `arbiter`): `Promise`\<`void`\>
|
|
88
|
+
|
|
89
|
+
Register an arbiter to use for making decisions.
|
|
90
|
+
|
|
91
|
+
#### Parameters
|
|
92
|
+
|
|
93
|
+
##### arbiterId
|
|
94
|
+
|
|
95
|
+
`string`
|
|
96
|
+
|
|
97
|
+
The id of the arbiter to register.
|
|
98
|
+
|
|
99
|
+
##### arbiter
|
|
100
|
+
|
|
101
|
+
`IPolicyArbiter`
|
|
102
|
+
|
|
103
|
+
The arbiter to register.
|
|
104
|
+
|
|
105
|
+
#### Returns
|
|
106
|
+
|
|
107
|
+
`Promise`\<`void`\>
|
|
108
|
+
|
|
109
|
+
Nothing.
|
|
110
|
+
|
|
111
|
+
#### Implementation of
|
|
112
|
+
|
|
113
|
+
`IPolicyDecisionPointComponent.registerArbiter`
|
|
114
|
+
|
|
115
|
+
***
|
|
116
|
+
|
|
117
|
+
### unregisterArbiter()
|
|
118
|
+
|
|
119
|
+
> **unregisterArbiter**(`arbiterId`): `Promise`\<`void`\>
|
|
120
|
+
|
|
121
|
+
Unregister an arbiter from making decisions.
|
|
122
|
+
|
|
123
|
+
#### Parameters
|
|
124
|
+
|
|
125
|
+
##### arbiterId
|
|
126
|
+
|
|
127
|
+
`string`
|
|
128
|
+
|
|
129
|
+
The id of the arbiter to unregister.
|
|
130
|
+
|
|
131
|
+
#### Returns
|
|
132
|
+
|
|
133
|
+
`Promise`\<`void`\>
|
|
134
|
+
|
|
135
|
+
Nothing.
|
|
136
|
+
|
|
137
|
+
#### Implementation of
|
|
138
|
+
|
|
139
|
+
`IPolicyDecisionPointComponent.unregisterArbiter`
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @twin.org/rights-management-pdp-service
|
|
2
|
+
|
|
3
|
+
## Classes
|
|
4
|
+
|
|
5
|
+
- [PolicyDecisionPointService](classes/PolicyDecisionPointService.md)
|
|
6
|
+
|
|
7
|
+
## Interfaces
|
|
8
|
+
|
|
9
|
+
- [IPolicyDecisionPointServiceConfig](interfaces/IPolicyDecisionPointServiceConfig.md)
|
|
10
|
+
- [IPolicyDecisionPointServiceConstructorOptions](interfaces/IPolicyDecisionPointServiceConstructorOptions.md)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Interface: IPolicyDecisionPointServiceConfig
|
|
2
|
+
|
|
3
|
+
Options for the Policy Decision Point Component.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### arbiters?
|
|
8
|
+
|
|
9
|
+
> `optional` **arbiters**: `object`[]
|
|
10
|
+
|
|
11
|
+
Initial arbiters to register with the PDP.
|
|
12
|
+
|
|
13
|
+
#### arbiterId
|
|
14
|
+
|
|
15
|
+
> **arbiterId**: `string`
|
|
16
|
+
|
|
17
|
+
#### arbiter
|
|
18
|
+
|
|
19
|
+
> **arbiter**: `IPolicyArbiter`
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Interface: IPolicyDecisionPointServiceConstructorOptions
|
|
2
|
+
|
|
3
|
+
Options for the Policy Decision Point Component.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### loggingComponentType?
|
|
8
|
+
|
|
9
|
+
> `optional` **loggingComponentType**: `string`
|
|
10
|
+
|
|
11
|
+
The logging component for logging policy decisions.
|
|
12
|
+
|
|
13
|
+
#### Default
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
logging
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
***
|
|
20
|
+
|
|
21
|
+
### policyInformationPointComponentType?
|
|
22
|
+
|
|
23
|
+
> `optional` **policyInformationPointComponentType**: `string`
|
|
24
|
+
|
|
25
|
+
The type of the policy information point component.
|
|
26
|
+
|
|
27
|
+
#### Default
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
policy-information-point
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### policyManagementPointComponentType?
|
|
36
|
+
|
|
37
|
+
> `optional` **policyManagementPointComponentType**: `string`
|
|
38
|
+
|
|
39
|
+
The type of the policy management point component.
|
|
40
|
+
|
|
41
|
+
#### Default
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
policy-management-point
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
***
|
|
48
|
+
|
|
49
|
+
### policyExecutionPointComponentType?
|
|
50
|
+
|
|
51
|
+
> `optional` **policyExecutionPointComponentType**: `string`
|
|
52
|
+
|
|
53
|
+
The type of the policy execution point component.
|
|
54
|
+
|
|
55
|
+
#### Default
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
policy-execution-point
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
***
|
|
62
|
+
|
|
63
|
+
### config?
|
|
64
|
+
|
|
65
|
+
> `optional` **config**: [`IPolicyDecisionPointServiceConfig`](IPolicyDecisionPointServiceConfig.md)
|
|
66
|
+
|
|
67
|
+
The configuration for the Policy Decision Point Service.
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"error": {
|
|
3
|
+
"policyDecisionPointService": {
|
|
4
|
+
"decidingFailed": "Deciding on policies for locator \"{locator}\" failed in arbiter with id: \"{arbiterId}\"",
|
|
5
|
+
"noSupportedArbiters": "No arbiters found that support the given locator: \"{locator}\""
|
|
6
|
+
}
|
|
7
|
+
},
|
|
8
|
+
"info": {
|
|
9
|
+
"policyDecisionPointService": {
|
|
10
|
+
"registeredArbiter": "Arbiter registered with id: \"{arbiterId}\"",
|
|
11
|
+
"unregisteredArbiter": "Arbiter unregistered with id: \"{arbiterId}\""
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@twin.org/rights-management-pdp-service",
|
|
3
|
+
"version": "0.0.2-next.10",
|
|
4
|
+
"description": "Policy decision point implementation",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/twinfoundation/rights-management.git",
|
|
8
|
+
"directory": "packages/rights-management-pdp-service"
|
|
9
|
+
},
|
|
10
|
+
"author": "martyn.janes@iota.org",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=20.0.0"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@twin.org/core": "next",
|
|
18
|
+
"@twin.org/logging-models": "next",
|
|
19
|
+
"@twin.org/nameof": "next",
|
|
20
|
+
"@twin.org/rights-management-models": "0.0.2-next.10",
|
|
21
|
+
"@twin.org/standards-w3c-odrl": "next"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/cjs/index.cjs",
|
|
24
|
+
"module": "./dist/esm/index.mjs",
|
|
25
|
+
"types": "./dist/types/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
29
|
+
"require": "./dist/cjs/index.cjs",
|
|
30
|
+
"import": "./dist/esm/index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./locales/*.json": "./locales/*.json"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/cjs",
|
|
36
|
+
"dist/esm",
|
|
37
|
+
"dist/types",
|
|
38
|
+
"locales",
|
|
39
|
+
"docs"
|
|
40
|
+
]
|
|
41
|
+
}
|