@lanaqi/rsr 0.0.1-rc.0
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/README.md +49 -0
- package/dist/access/aaa.d.ts +177 -0
- package/dist/access/addon.d.ts +92 -0
- package/dist/access/blocker.d.ts +94 -0
- package/dist/access/common.d.ts +63 -0
- package/dist/access/context.d.ts +162 -0
- package/dist/access/guarder.d.ts +173 -0
- package/dist/access/handler.d.ts +183 -0
- package/dist/access/index.d.ts +56 -0
- package/dist/access/manager.d.ts +109 -0
- package/dist/access/matcher.d.ts +70 -0
- package/dist/access/navigator.d.ts +33 -0
- package/dist/access/recorder.d.ts +291 -0
- package/dist/access/resource.d.ts +215 -0
- package/dist/access/storer.d.ts +197 -0
- package/dist/access/voter.d.ts +156 -0
- package/dist/addons/index.d.ts +4 -0
- package/dist/addons/micro.d.ts +53 -0
- package/dist/bridge.d.ts +8 -0
- package/dist/builder/blocker.d.ts +24 -0
- package/dist/builder/builder.d.ts +9 -0
- package/dist/builder/context.d.ts +112 -0
- package/dist/builder/guarder.d.ts +54 -0
- package/dist/builder/handler.d.ts +21 -0
- package/dist/builder/index.d.ts +48 -0
- package/dist/builder/manager.d.ts +55 -0
- package/dist/builder/matcher.d.ts +37 -0
- package/dist/builder/navigator.d.ts +22 -0
- package/dist/builder/recorder.d.ts +11 -0
- package/dist/builder/resource.d.ts +101 -0
- package/dist/builder/storer.d.ts +83 -0
- package/dist/builder/voter.d.ts +41 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +1778 -0
- package/dist/security/blocker.d.ts +14 -0
- package/dist/security/index.d.ts +8 -0
- package/dist/security/provider.d.ts +31 -0
- package/dist/support/aaa.d.ts +29 -0
- package/dist/support/blocker.d.ts +28 -0
- package/dist/support/index.d.ts +20 -0
- package/dist/support/permission.d.ts +5 -0
- package/dist/support/signature.d.ts +21 -0
- package/dist/support/user.d.ts +14 -0
- package/dist/warpper/index.d.ts +4 -0
- package/dist/warpper/permission.d.ts +24 -0
- package/package.json +74 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1778 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__ from "react-router-dom";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
4
|
+
var common_AccessDecision = /*#__PURE__*/ function(AccessDecision) {
|
|
5
|
+
AccessDecision["notResource"] = "notResource";
|
|
6
|
+
AccessDecision["notAuthentication"] = "notAuthentication";
|
|
7
|
+
AccessDecision["invalidAuthentication"] = "invalidAuthentication";
|
|
8
|
+
AccessDecision["notAuthorization"] = "notAuthorization";
|
|
9
|
+
AccessDecision["notSignature"] = "notSignature";
|
|
10
|
+
AccessDecision["accessDenied"] = "accessDenied";
|
|
11
|
+
AccessDecision["allowAccess"] = "allowAccess";
|
|
12
|
+
return AccessDecision;
|
|
13
|
+
}({});
|
|
14
|
+
var common_AccessBehave = /*#__PURE__*/ function(AccessBehave) {
|
|
15
|
+
AccessBehave["doNothing"] = "doNothing";
|
|
16
|
+
AccessBehave["goNavigate"] = "goNavigate";
|
|
17
|
+
AccessBehave["reDecision"] = "reDecision";
|
|
18
|
+
return AccessBehave;
|
|
19
|
+
}({});
|
|
20
|
+
class SimpleAuthentication {
|
|
21
|
+
datasheet;
|
|
22
|
+
authenticated;
|
|
23
|
+
constructor(datasheet){
|
|
24
|
+
this.datasheet = datasheet;
|
|
25
|
+
this.authenticated = this.datasheet.authenticated ?? false;
|
|
26
|
+
}
|
|
27
|
+
isAuthenticated() {
|
|
28
|
+
return this.authenticated;
|
|
29
|
+
}
|
|
30
|
+
setAuthenticated(authenticated) {
|
|
31
|
+
this.authenticated = authenticated;
|
|
32
|
+
}
|
|
33
|
+
getDatasheet() {
|
|
34
|
+
return this.datasheet;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
class SimpleAuthorization {
|
|
38
|
+
datasheet;
|
|
39
|
+
permissions;
|
|
40
|
+
constructor(datasheet){
|
|
41
|
+
this.datasheet = datasheet;
|
|
42
|
+
this.permissions = new Set(this.datasheet.permissions);
|
|
43
|
+
}
|
|
44
|
+
getPermissions() {
|
|
45
|
+
return this.permissions;
|
|
46
|
+
}
|
|
47
|
+
getDatasheet() {
|
|
48
|
+
return this.datasheet;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class SimpleUser {
|
|
52
|
+
datasheet;
|
|
53
|
+
permissions;
|
|
54
|
+
authenticated;
|
|
55
|
+
invalid;
|
|
56
|
+
constructor(datasheet){
|
|
57
|
+
this.datasheet = datasheet;
|
|
58
|
+
this.permissions = new Set(this.datasheet.permissions);
|
|
59
|
+
this.authenticated = this.datasheet.authenticated ?? false;
|
|
60
|
+
this.invalid = this.datasheet.invalid ?? false;
|
|
61
|
+
}
|
|
62
|
+
isAuthenticated() {
|
|
63
|
+
return this.authenticated;
|
|
64
|
+
}
|
|
65
|
+
setAuthenticated(authenticated) {
|
|
66
|
+
this.authenticated = authenticated;
|
|
67
|
+
}
|
|
68
|
+
getPermissions() {
|
|
69
|
+
return this.permissions;
|
|
70
|
+
}
|
|
71
|
+
getDatasheet() {
|
|
72
|
+
return this.datasheet;
|
|
73
|
+
}
|
|
74
|
+
isInvalid() {
|
|
75
|
+
return this.invalid;
|
|
76
|
+
}
|
|
77
|
+
setInvalid(invalid) {
|
|
78
|
+
this.invalid = invalid;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
class SimpleResource {
|
|
82
|
+
static PERMISSION_ANONYMOUS = '__anonymous__';
|
|
83
|
+
static PERMISSION_AUTHENTICATED = '__authenticated__';
|
|
84
|
+
static PERMISSION_AUTHORIZED = '__authorized__';
|
|
85
|
+
static LABEL_SIGNATURED = '__signatured__';
|
|
86
|
+
static LABEL_ALWAYS_SIGNATURE = '__always_signature__';
|
|
87
|
+
patterns;
|
|
88
|
+
permissions;
|
|
89
|
+
labels;
|
|
90
|
+
anonymous;
|
|
91
|
+
authenticated;
|
|
92
|
+
authorized;
|
|
93
|
+
signatured;
|
|
94
|
+
alwaysSignature;
|
|
95
|
+
basename;
|
|
96
|
+
constructor(patterns, permissions, labels, basename){
|
|
97
|
+
this.patterns = new Set(patterns);
|
|
98
|
+
this.permissions = new Set(permissions);
|
|
99
|
+
this.labels = new Set(labels);
|
|
100
|
+
if (0 === this.patterns.size) throw new Error('访问资源模式集合不能为空,请检查!');
|
|
101
|
+
if (0 === this.permissions.size) {
|
|
102
|
+
this.anonymous = true;
|
|
103
|
+
this.authenticated = false;
|
|
104
|
+
this.authorized = false;
|
|
105
|
+
} else {
|
|
106
|
+
if (this.permissions.has(SimpleResource.PERMISSION_ANONYMOUS)) {
|
|
107
|
+
this.permissions.clear();
|
|
108
|
+
this.anonymous = true;
|
|
109
|
+
} else this.anonymous = false;
|
|
110
|
+
if (this.permissions.has(SimpleResource.PERMISSION_AUTHENTICATED)) {
|
|
111
|
+
this.permissions.clear();
|
|
112
|
+
this.authenticated = true;
|
|
113
|
+
} else this.authenticated = false;
|
|
114
|
+
if (this.permissions.has(SimpleResource.PERMISSION_AUTHORIZED)) {
|
|
115
|
+
this.permissions.clear();
|
|
116
|
+
this.authorized = true;
|
|
117
|
+
} else this.authorized = false;
|
|
118
|
+
}
|
|
119
|
+
if (0 === this.labels.size) {
|
|
120
|
+
this.signatured = false;
|
|
121
|
+
this.alwaysSignature = false;
|
|
122
|
+
} else {
|
|
123
|
+
if (this.labels.has(SimpleResource.LABEL_SIGNATURED)) {
|
|
124
|
+
this.labels.delete(SimpleResource.LABEL_SIGNATURED);
|
|
125
|
+
this.signatured = true;
|
|
126
|
+
} else this.signatured = false;
|
|
127
|
+
if (this.labels.has(SimpleResource.LABEL_ALWAYS_SIGNATURE)) {
|
|
128
|
+
this.labels.delete(SimpleResource.LABEL_ALWAYS_SIGNATURE);
|
|
129
|
+
this.signatured = true;
|
|
130
|
+
this.alwaysSignature = true;
|
|
131
|
+
} else this.alwaysSignature = false;
|
|
132
|
+
}
|
|
133
|
+
this.basename = basename;
|
|
134
|
+
}
|
|
135
|
+
getPatterns() {
|
|
136
|
+
return this.patterns;
|
|
137
|
+
}
|
|
138
|
+
getPermissions() {
|
|
139
|
+
return this.permissions;
|
|
140
|
+
}
|
|
141
|
+
getLabels() {
|
|
142
|
+
return this.labels;
|
|
143
|
+
}
|
|
144
|
+
hasPattern(pattern) {
|
|
145
|
+
return this.patterns.has(pattern);
|
|
146
|
+
}
|
|
147
|
+
hasPermission(permission) {
|
|
148
|
+
return this.permissions.has(permission);
|
|
149
|
+
}
|
|
150
|
+
hasLabel(label) {
|
|
151
|
+
return this.labels.has(label);
|
|
152
|
+
}
|
|
153
|
+
isAnonymous() {
|
|
154
|
+
return this.anonymous;
|
|
155
|
+
}
|
|
156
|
+
isAuthenticated() {
|
|
157
|
+
return this.authenticated;
|
|
158
|
+
}
|
|
159
|
+
isAuthorized() {
|
|
160
|
+
return this.authorized;
|
|
161
|
+
}
|
|
162
|
+
isSignatured() {
|
|
163
|
+
return this.signatured;
|
|
164
|
+
}
|
|
165
|
+
isAlwaysSignature() {
|
|
166
|
+
return this.alwaysSignature;
|
|
167
|
+
}
|
|
168
|
+
getBasename() {
|
|
169
|
+
return this.basename;
|
|
170
|
+
}
|
|
171
|
+
setBasename(basename) {
|
|
172
|
+
this.basename = basename;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
class SimpleRecorder {
|
|
176
|
+
currentPath;
|
|
177
|
+
allowPath;
|
|
178
|
+
originPath;
|
|
179
|
+
accessResource;
|
|
180
|
+
accessAuthentication;
|
|
181
|
+
accessAuthorization;
|
|
182
|
+
getCurrentPath() {
|
|
183
|
+
return this.currentPath;
|
|
184
|
+
}
|
|
185
|
+
setCurrentPath(currentPath) {
|
|
186
|
+
this.currentPath = currentPath;
|
|
187
|
+
}
|
|
188
|
+
existCurrentPath() {
|
|
189
|
+
return !!this.currentPath;
|
|
190
|
+
}
|
|
191
|
+
isCurrentPath(pathname) {
|
|
192
|
+
if (this.currentPath) return this.currentPath.pathname === pathname;
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
isCurrentPaths(...pathnames) {
|
|
196
|
+
for (const pathname of pathnames){
|
|
197
|
+
const yes = this.isCurrentPath(pathname);
|
|
198
|
+
if (yes) return true;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
getAllowPath() {
|
|
203
|
+
return this.allowPath;
|
|
204
|
+
}
|
|
205
|
+
setAllowPath(allowPath) {
|
|
206
|
+
this.allowPath = allowPath;
|
|
207
|
+
}
|
|
208
|
+
existAllowPath() {
|
|
209
|
+
return !!this.allowPath;
|
|
210
|
+
}
|
|
211
|
+
isAllowPath(pathname) {
|
|
212
|
+
if (this.allowPath) return this.allowPath.pathname === pathname;
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
isAllowPaths(...pathnames) {
|
|
216
|
+
for (const pathname of pathnames){
|
|
217
|
+
const yes = this.isAllowPath(pathname);
|
|
218
|
+
if (yes) return true;
|
|
219
|
+
}
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
getOriginPath() {
|
|
223
|
+
return this.originPath;
|
|
224
|
+
}
|
|
225
|
+
setOriginPath(originPath) {
|
|
226
|
+
this.originPath = originPath;
|
|
227
|
+
}
|
|
228
|
+
existOriginPath() {
|
|
229
|
+
return !!this.originPath;
|
|
230
|
+
}
|
|
231
|
+
isOriginPath(pathname) {
|
|
232
|
+
if (this.originPath) return this.originPath.pathname === pathname;
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
isOriginPaths(...pathnames) {
|
|
236
|
+
for (const pathname of pathnames){
|
|
237
|
+
const yes = this.isOriginPath(pathname);
|
|
238
|
+
if (yes) return true;
|
|
239
|
+
}
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
getAccessResource() {
|
|
243
|
+
return this.accessResource;
|
|
244
|
+
}
|
|
245
|
+
setAccessResource(accessResource) {
|
|
246
|
+
this.accessResource = accessResource;
|
|
247
|
+
}
|
|
248
|
+
existAccessResource() {
|
|
249
|
+
return !!this.accessResource;
|
|
250
|
+
}
|
|
251
|
+
getAccessAuthentication() {
|
|
252
|
+
return this.accessAuthentication;
|
|
253
|
+
}
|
|
254
|
+
setAccessAuthentication(accessAuthentication) {
|
|
255
|
+
this.accessAuthentication = accessAuthentication;
|
|
256
|
+
}
|
|
257
|
+
existAccessAuthentication() {
|
|
258
|
+
return !!this.accessAuthentication;
|
|
259
|
+
}
|
|
260
|
+
getAccessAuthorization() {
|
|
261
|
+
return this.accessAuthorization;
|
|
262
|
+
}
|
|
263
|
+
setAccessAuthorization(accessAuthorization) {
|
|
264
|
+
this.accessAuthorization = accessAuthorization;
|
|
265
|
+
}
|
|
266
|
+
existAccessAuthorization() {
|
|
267
|
+
return !!this.accessAuthorization;
|
|
268
|
+
}
|
|
269
|
+
clearOriginPath() {
|
|
270
|
+
this.originPath = void 0;
|
|
271
|
+
}
|
|
272
|
+
clearAccessResource() {
|
|
273
|
+
this.accessResource = void 0;
|
|
274
|
+
}
|
|
275
|
+
clearAccessAuthentication() {
|
|
276
|
+
this.accessAuthentication = void 0;
|
|
277
|
+
}
|
|
278
|
+
clearAccessAuthorization() {
|
|
279
|
+
this.accessAuthorization = void 0;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
class CacheVoter {
|
|
283
|
+
cache;
|
|
284
|
+
constructor(){
|
|
285
|
+
this.cache = new Map();
|
|
286
|
+
}
|
|
287
|
+
cacheKey(term, have) {
|
|
288
|
+
return `${[
|
|
289
|
+
...have
|
|
290
|
+
].join('.')}_${[
|
|
291
|
+
...term
|
|
292
|
+
].join('.')}`;
|
|
293
|
+
}
|
|
294
|
+
clearCache() {
|
|
295
|
+
this.cache.clear();
|
|
296
|
+
}
|
|
297
|
+
vote(term, have) {
|
|
298
|
+
if (0 === term.size || 0 === have.size) return false;
|
|
299
|
+
const key = this.cacheKey(term, have);
|
|
300
|
+
if (this.cache.has(key)) return this.cache.get(key);
|
|
301
|
+
const result = this.execVote(term, have);
|
|
302
|
+
this.cache.set(key, result);
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
class SimpleVoter extends CacheVoter {
|
|
307
|
+
all;
|
|
308
|
+
constructor(all = false){
|
|
309
|
+
super();
|
|
310
|
+
this.all = all;
|
|
311
|
+
}
|
|
312
|
+
setAll(all) {
|
|
313
|
+
this.all = all;
|
|
314
|
+
}
|
|
315
|
+
execVote(term, have) {
|
|
316
|
+
for (const item of term)if (this.all) {
|
|
317
|
+
if (!have.has(item)) return false;
|
|
318
|
+
} else if (have.has(item)) return true;
|
|
319
|
+
return this.all;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
class HierarchyPermission {
|
|
323
|
+
permission;
|
|
324
|
+
parent;
|
|
325
|
+
constructor(permission){
|
|
326
|
+
this.permission = permission;
|
|
327
|
+
}
|
|
328
|
+
getPermission() {
|
|
329
|
+
return this.permission;
|
|
330
|
+
}
|
|
331
|
+
setParent(parent) {
|
|
332
|
+
this.parent = parent;
|
|
333
|
+
}
|
|
334
|
+
getParent() {
|
|
335
|
+
return this.parent;
|
|
336
|
+
}
|
|
337
|
+
includeMy(permission) {
|
|
338
|
+
if (this.permission === permission) return true;
|
|
339
|
+
if (this.parent) return this.parent.includeMy(permission);
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const OriginRelationResolver = (relation)=>relation;
|
|
344
|
+
class HierarchyVoter extends CacheVoter {
|
|
345
|
+
mapping;
|
|
346
|
+
relation;
|
|
347
|
+
all;
|
|
348
|
+
resolver;
|
|
349
|
+
constructor(resolver, relation, all = false){
|
|
350
|
+
super();
|
|
351
|
+
this.mapping = new Map();
|
|
352
|
+
this.relation = relation;
|
|
353
|
+
this.all = all;
|
|
354
|
+
this.resetResolver(resolver);
|
|
355
|
+
}
|
|
356
|
+
setAll(all) {
|
|
357
|
+
this.all = all;
|
|
358
|
+
}
|
|
359
|
+
resetRelation(relation) {
|
|
360
|
+
this.relation = relation;
|
|
361
|
+
this.initHierarchy();
|
|
362
|
+
}
|
|
363
|
+
resetResolver(resolver) {
|
|
364
|
+
this.resolver = resolver;
|
|
365
|
+
this.initHierarchy();
|
|
366
|
+
}
|
|
367
|
+
initHierarchy() {
|
|
368
|
+
const hierarchy = this.resolver(this.relation);
|
|
369
|
+
const group = hierarchy.split(';');
|
|
370
|
+
if (group.length > 0) {
|
|
371
|
+
this.clearCache();
|
|
372
|
+
this.mapping.clear();
|
|
373
|
+
for (const item of group){
|
|
374
|
+
const ps = item.split('>');
|
|
375
|
+
if (2 === ps.length) {
|
|
376
|
+
const p1 = ps[0];
|
|
377
|
+
const p2 = ps[1];
|
|
378
|
+
let h1;
|
|
379
|
+
if (this.mapping.has(p1)) h1 = this.mapping.get(p1);
|
|
380
|
+
else {
|
|
381
|
+
h1 = new HierarchyPermission(p1);
|
|
382
|
+
this.mapping.set(p1, h1);
|
|
383
|
+
}
|
|
384
|
+
let h2;
|
|
385
|
+
if (this.mapping.has(p2)) h2 = this.mapping.get(p2);
|
|
386
|
+
else {
|
|
387
|
+
h2 = new HierarchyPermission(p2);
|
|
388
|
+
this.mapping.set(p2, h2);
|
|
389
|
+
}
|
|
390
|
+
h2.setParent(h1);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
includePermission(p1, p2) {
|
|
396
|
+
if (this.mapping.has(p2)) return this.mapping.get(p2).includeMy(p1);
|
|
397
|
+
return p1 === p2;
|
|
398
|
+
}
|
|
399
|
+
execVote(term, have) {
|
|
400
|
+
for (const tp of term)for (const hp of have){
|
|
401
|
+
const hi = this.includePermission(hp, tp);
|
|
402
|
+
if (hi) {
|
|
403
|
+
if (!this.all) return true;
|
|
404
|
+
} else if (this.all) return false;
|
|
405
|
+
}
|
|
406
|
+
return this.all;
|
|
407
|
+
}
|
|
408
|
+
getRelation() {
|
|
409
|
+
return this.relation;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
class SimpleStorer {
|
|
413
|
+
static KEY_AUTHENTICATION = '__authentication__';
|
|
414
|
+
static KEY_AUTHORIZATION = '__authorization__';
|
|
415
|
+
static KEY_SIGNATURE = '__signature__';
|
|
416
|
+
aaaStorage;
|
|
417
|
+
signStorage;
|
|
418
|
+
authenticationKey;
|
|
419
|
+
authorizationKey;
|
|
420
|
+
signatureKey;
|
|
421
|
+
authenticationValidator;
|
|
422
|
+
constructor(aaaStorage, signStorage, authenticationKey = SimpleStorer.KEY_AUTHENTICATION, authorizationKey = SimpleStorer.KEY_AUTHORIZATION, signatureKey = SimpleStorer.KEY_SIGNATURE, authenticationValidator){
|
|
423
|
+
this.aaaStorage = aaaStorage;
|
|
424
|
+
this.signStorage = signStorage;
|
|
425
|
+
this.authenticationKey = authenticationKey;
|
|
426
|
+
this.authorizationKey = authorizationKey;
|
|
427
|
+
this.signatureKey = signatureKey;
|
|
428
|
+
this.authenticationValidator = authenticationValidator;
|
|
429
|
+
}
|
|
430
|
+
loadAuthentication(recorder) {
|
|
431
|
+
const authenticationStr = this.aaaStorage.getItem(this.authenticationKey);
|
|
432
|
+
if (authenticationStr) {
|
|
433
|
+
const authenticationObj = JSON.parse(authenticationStr);
|
|
434
|
+
if ('boolean' == typeof authenticationObj.authenticated) {
|
|
435
|
+
if (void 0 !== authenticationObj.permissions && Array.isArray(authenticationObj.permissions)) return new SimpleUser(authenticationObj);
|
|
436
|
+
return new SimpleAuthentication(authenticationObj);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
verifyAuthentication(recorder, authentication) {
|
|
441
|
+
if (this.authenticationValidator) return this.authenticationValidator(recorder, authentication);
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
deleteAuthentication(recorder) {
|
|
445
|
+
this.aaaStorage.removeItem(this.authenticationKey);
|
|
446
|
+
}
|
|
447
|
+
saveAuthentication(recorder, datasheet) {
|
|
448
|
+
const ds = datasheet.getDatasheet();
|
|
449
|
+
const authenticationStr = JSON.stringify(ds);
|
|
450
|
+
this.aaaStorage.setItem(this.authenticationKey, authenticationStr);
|
|
451
|
+
}
|
|
452
|
+
loadAuthorization(recorder, authentication) {
|
|
453
|
+
if (authentication && authentication instanceof SimpleUser) return authentication;
|
|
454
|
+
const authorizationStr = this.aaaStorage.getItem(this.authorizationKey);
|
|
455
|
+
if (authorizationStr) {
|
|
456
|
+
const authorizationObj = JSON.parse(authorizationStr);
|
|
457
|
+
if (void 0 !== authorizationObj.permissions && Array.isArray(authorizationObj.permissions)) return new SimpleAuthorization(authorizationObj);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
deleteAuthorization(recorder) {
|
|
461
|
+
const authentication = recorder.getAccessAuthentication();
|
|
462
|
+
if (authentication && authentication instanceof SimpleUser) return;
|
|
463
|
+
this.aaaStorage.removeItem(this.authorizationKey);
|
|
464
|
+
}
|
|
465
|
+
saveAuthorization(recorder, datasheet) {
|
|
466
|
+
const authentication = recorder.getAccessAuthentication();
|
|
467
|
+
if (authentication && authentication instanceof SimpleUser) return;
|
|
468
|
+
const ds = datasheet.getDatasheet();
|
|
469
|
+
const authorizationStr = JSON.stringify(ds);
|
|
470
|
+
this.aaaStorage.setItem(this.authorizationKey, authorizationStr);
|
|
471
|
+
}
|
|
472
|
+
loadSignature(recorder, path, authentication, authorization) {
|
|
473
|
+
const signatureStr = this.signStorage.getItem(this.signatureKey);
|
|
474
|
+
if (signatureStr) {
|
|
475
|
+
const signatureList = JSON.parse(signatureStr);
|
|
476
|
+
if (Array.isArray(signatureList) && signatureList.includes(path.pathname)) return true;
|
|
477
|
+
}
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
removeSignature(recorder, path) {
|
|
481
|
+
const signatureStr = this.signStorage.getItem(this.signatureKey);
|
|
482
|
+
if (signatureStr) {
|
|
483
|
+
const signatureList = JSON.parse(signatureStr);
|
|
484
|
+
if (Array.isArray(signatureList)) {
|
|
485
|
+
const newSignatureList = signatureList.filter((signature)=>signature !== path.pathname);
|
|
486
|
+
const newSignatureStr = JSON.stringify(newSignatureList);
|
|
487
|
+
this.signStorage.setItem(this.signatureKey, newSignatureStr);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
deleteSignature(recorder) {
|
|
492
|
+
this.signStorage.removeItem(this.signatureKey);
|
|
493
|
+
}
|
|
494
|
+
saveSignature(recorder, path) {
|
|
495
|
+
let signatureList;
|
|
496
|
+
const signatureStr = this.signStorage.getItem(this.signatureKey);
|
|
497
|
+
if (signatureStr) {
|
|
498
|
+
signatureList = JSON.parse(signatureStr);
|
|
499
|
+
if (!Array.isArray(signatureList)) signatureList = [];
|
|
500
|
+
} else signatureList = [];
|
|
501
|
+
const signatureSet = new Set(signatureList);
|
|
502
|
+
signatureSet.add(path.pathname);
|
|
503
|
+
const signatures = Array.from(signatureSet);
|
|
504
|
+
const newSignatureStr = JSON.stringify(signatures);
|
|
505
|
+
this.signStorage.setItem(this.signatureKey, newSignatureStr);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
class SimpleMatcher {
|
|
509
|
+
cache;
|
|
510
|
+
resources;
|
|
511
|
+
basename;
|
|
512
|
+
constructor(resources){
|
|
513
|
+
this.cache = new Map();
|
|
514
|
+
this.resources = resources;
|
|
515
|
+
}
|
|
516
|
+
match(resource, path) {
|
|
517
|
+
let basename = resource.getBasename();
|
|
518
|
+
if (!basename) basename = this.getBasename();
|
|
519
|
+
const patterns = resource.getPatterns();
|
|
520
|
+
if (basename && basename.trim().length > 0) for (const pattern of patterns){
|
|
521
|
+
let matchPattern;
|
|
522
|
+
matchPattern = 'string' == typeof pattern ? basename + pattern : {
|
|
523
|
+
...pattern,
|
|
524
|
+
path: basename + pattern.path
|
|
525
|
+
};
|
|
526
|
+
const pm = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__.matchPath)(matchPattern, path.pathname);
|
|
527
|
+
if (pm) return true;
|
|
528
|
+
}
|
|
529
|
+
else for (const pattern of patterns){
|
|
530
|
+
const pm = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__.matchPath)(pattern, path.pathname);
|
|
531
|
+
if (pm) return true;
|
|
532
|
+
}
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
obtain(path) {
|
|
536
|
+
const pathname = path.pathname;
|
|
537
|
+
if (this.cache.has(pathname)) return this.cache.get(pathname);
|
|
538
|
+
for (const resource of this.resources){
|
|
539
|
+
const mp = this.match(resource, path);
|
|
540
|
+
if (mp) {
|
|
541
|
+
this.cache.set(pathname, resource);
|
|
542
|
+
return resource;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
getBasename() {
|
|
548
|
+
return this.basename;
|
|
549
|
+
}
|
|
550
|
+
setBasename(basename) {
|
|
551
|
+
this.basename = basename;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
class SimpleNavigator {
|
|
555
|
+
_navigate;
|
|
556
|
+
constructor(navigate){
|
|
557
|
+
this._navigate = navigate;
|
|
558
|
+
}
|
|
559
|
+
navigate(to, options) {
|
|
560
|
+
this._navigate(to, options);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
class SimpleContext {
|
|
564
|
+
recorder;
|
|
565
|
+
voter;
|
|
566
|
+
storer;
|
|
567
|
+
matcher;
|
|
568
|
+
navigator;
|
|
569
|
+
parent;
|
|
570
|
+
constructor(recorder, voter, storer, matcher, navigator){
|
|
571
|
+
this.recorder = recorder;
|
|
572
|
+
this.voter = voter;
|
|
573
|
+
this.storer = storer;
|
|
574
|
+
this.matcher = matcher;
|
|
575
|
+
this.navigator = navigator;
|
|
576
|
+
}
|
|
577
|
+
getRecorder() {
|
|
578
|
+
return this.recorder;
|
|
579
|
+
}
|
|
580
|
+
setRecorder(recorder) {
|
|
581
|
+
this.recorder = recorder;
|
|
582
|
+
}
|
|
583
|
+
getVoter() {
|
|
584
|
+
return this.voter;
|
|
585
|
+
}
|
|
586
|
+
setVoter(voter) {
|
|
587
|
+
this.voter = voter;
|
|
588
|
+
}
|
|
589
|
+
getStorer() {
|
|
590
|
+
return this.storer;
|
|
591
|
+
}
|
|
592
|
+
setStorer(storer) {
|
|
593
|
+
this.storer = storer;
|
|
594
|
+
}
|
|
595
|
+
getMatcher() {
|
|
596
|
+
return this.matcher;
|
|
597
|
+
}
|
|
598
|
+
setMatcher(matcher) {
|
|
599
|
+
this.matcher = matcher;
|
|
600
|
+
}
|
|
601
|
+
getNavigator() {
|
|
602
|
+
return this.navigator;
|
|
603
|
+
}
|
|
604
|
+
setNavigator(navigator) {
|
|
605
|
+
this.navigator = navigator;
|
|
606
|
+
}
|
|
607
|
+
getParent() {
|
|
608
|
+
return this.parent;
|
|
609
|
+
}
|
|
610
|
+
setParent(parent) {
|
|
611
|
+
this.parent = parent;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
class AbstractAddon {
|
|
615
|
+
guardBefore(context, manager, currentPath, currentResource) {}
|
|
616
|
+
guardAfter(context, manager, currentPath, currentResource, currentDecision) {}
|
|
617
|
+
permitBefore(context, manager, stayPath, blockPath, stayResource, blockResource) {}
|
|
618
|
+
permitAfter(context, manager, stayPath, blockPath, stayResource, blockResource) {}
|
|
619
|
+
}
|
|
620
|
+
class BehaveHandler {
|
|
621
|
+
_config;
|
|
622
|
+
constructor(config){
|
|
623
|
+
this._config = config;
|
|
624
|
+
}
|
|
625
|
+
config(config) {
|
|
626
|
+
this._config = config;
|
|
627
|
+
}
|
|
628
|
+
notResource(context) {
|
|
629
|
+
if (this._config.notResourcePath) {
|
|
630
|
+
context.getNavigator().navigate(this._config.notResourcePath);
|
|
631
|
+
return common_AccessBehave.goNavigate;
|
|
632
|
+
}
|
|
633
|
+
if (this._config.notResourceFunc) return this._config.notResourceFunc(context);
|
|
634
|
+
return this.accessDenied(context);
|
|
635
|
+
}
|
|
636
|
+
notAuthentication(context) {
|
|
637
|
+
if (this._config.notAuthenticationPath) {
|
|
638
|
+
context.getNavigator().navigate(this._config.notAuthenticationPath);
|
|
639
|
+
return common_AccessBehave.goNavigate;
|
|
640
|
+
}
|
|
641
|
+
if (this._config.notAuthenticationFunc) return this._config.notAuthenticationFunc(context);
|
|
642
|
+
throw new Error('没有认证的行为是必须配置的,请检查!');
|
|
643
|
+
}
|
|
644
|
+
invalidAuthentication(context) {
|
|
645
|
+
if (this._config.invalidAuthenticationPath) {
|
|
646
|
+
context.getNavigator().navigate(this._config.invalidAuthenticationPath);
|
|
647
|
+
return common_AccessBehave.goNavigate;
|
|
648
|
+
}
|
|
649
|
+
if (this._config.invalidAuthenticationFunc) return this._config.invalidAuthenticationFunc(context);
|
|
650
|
+
return this.notAuthentication(context);
|
|
651
|
+
}
|
|
652
|
+
notAuthorization(context) {
|
|
653
|
+
if (this._config.notAuthorizationPath) {
|
|
654
|
+
context.getNavigator().navigate(this._config.notAuthorizationPath);
|
|
655
|
+
return common_AccessBehave.goNavigate;
|
|
656
|
+
}
|
|
657
|
+
if (this._config.notAuthorizationFunc) return this._config.notAuthorizationFunc(context);
|
|
658
|
+
return this.accessDenied(context);
|
|
659
|
+
}
|
|
660
|
+
notSignature(context) {
|
|
661
|
+
if (this._config.notSignaturePath) {
|
|
662
|
+
context.getNavigator().navigate(this._config.notSignaturePath);
|
|
663
|
+
return common_AccessBehave.goNavigate;
|
|
664
|
+
}
|
|
665
|
+
if (this._config.notSignatureFunc) return this._config.notSignatureFunc(context);
|
|
666
|
+
return this.accessDenied(context);
|
|
667
|
+
}
|
|
668
|
+
accessDenied(context) {
|
|
669
|
+
if (this._config.accessDeniedPath) {
|
|
670
|
+
context.getNavigator().navigate(this._config.accessDeniedPath);
|
|
671
|
+
return common_AccessBehave.goNavigate;
|
|
672
|
+
}
|
|
673
|
+
if (this._config.accessDeniedFunc) return this._config.accessDeniedFunc(context);
|
|
674
|
+
throw new Error('拒绝访问的行为是必须配置的,请检查!');
|
|
675
|
+
}
|
|
676
|
+
allowAccess(context) {
|
|
677
|
+
if (this._config.allowAccessFunc) this._config.allowAccessFunc(context);
|
|
678
|
+
return common_AccessBehave.doNothing;
|
|
679
|
+
}
|
|
680
|
+
errorDecision(context, decision) {
|
|
681
|
+
if (this._config.errorDecisionFunc) {
|
|
682
|
+
this._config.errorDecisionFunc(context, decision);
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
if (decision === common_AccessDecision.notSignature) return;
|
|
686
|
+
switch(decision){
|
|
687
|
+
case common_AccessDecision.notResource:
|
|
688
|
+
this.accessDenied(context);
|
|
689
|
+
break;
|
|
690
|
+
case common_AccessDecision.notAuthentication:
|
|
691
|
+
throw new Error('没有认证的错误决策,请检查!');
|
|
692
|
+
case common_AccessDecision.invalidAuthentication:
|
|
693
|
+
this.notAuthentication(context);
|
|
694
|
+
break;
|
|
695
|
+
case common_AccessDecision.notAuthorization:
|
|
696
|
+
this.accessDenied(context);
|
|
697
|
+
break;
|
|
698
|
+
case common_AccessDecision.accessDenied:
|
|
699
|
+
default:
|
|
700
|
+
throw new Error('拒绝访问的错误决策,请检查!');
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
class SingleBlocker {
|
|
705
|
+
handler;
|
|
706
|
+
block(context, currentPath, currentResource) {
|
|
707
|
+
if (this.handler) return this.handler(context, currentPath, currentResource);
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
register(handler) {
|
|
711
|
+
this.handler = handler;
|
|
712
|
+
}
|
|
713
|
+
unregister(handler) {
|
|
714
|
+
this.handler = void 0;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
class MultiBlocker {
|
|
718
|
+
handlers;
|
|
719
|
+
constructor(){
|
|
720
|
+
this.handlers = new Set();
|
|
721
|
+
}
|
|
722
|
+
block(context, currentPath, currentResource) {
|
|
723
|
+
for (const handler of this.handlers){
|
|
724
|
+
const blocked = handler(context, currentPath, currentResource);
|
|
725
|
+
if (blocked) return true;
|
|
726
|
+
}
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
register(handler) {
|
|
730
|
+
this.handlers.add(handler);
|
|
731
|
+
}
|
|
732
|
+
unregister(handler) {
|
|
733
|
+
this.handlers.delete(handler);
|
|
734
|
+
}
|
|
735
|
+
clear() {
|
|
736
|
+
this.handlers.clear();
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
class SimpleManager {
|
|
740
|
+
disabled;
|
|
741
|
+
handler;
|
|
742
|
+
blocker;
|
|
743
|
+
parent;
|
|
744
|
+
constructor(disabled, handler, blocker){
|
|
745
|
+
this.disabled = disabled;
|
|
746
|
+
this.handler = handler;
|
|
747
|
+
this.blocker = blocker;
|
|
748
|
+
}
|
|
749
|
+
isDisabled() {
|
|
750
|
+
return this.disabled;
|
|
751
|
+
}
|
|
752
|
+
setDisabled(disabled) {
|
|
753
|
+
this.disabled = disabled;
|
|
754
|
+
}
|
|
755
|
+
getHandler() {
|
|
756
|
+
return this.handler;
|
|
757
|
+
}
|
|
758
|
+
setHandler(handler) {
|
|
759
|
+
this.handler = handler;
|
|
760
|
+
}
|
|
761
|
+
getBlocker() {
|
|
762
|
+
return this.blocker;
|
|
763
|
+
}
|
|
764
|
+
setBlocker(blocker) {
|
|
765
|
+
this.blocker = blocker;
|
|
766
|
+
}
|
|
767
|
+
getParent() {
|
|
768
|
+
return this.parent;
|
|
769
|
+
}
|
|
770
|
+
setParent(parent) {
|
|
771
|
+
this.parent = parent;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
class SimpleGuarder {
|
|
775
|
+
context;
|
|
776
|
+
manager;
|
|
777
|
+
addons;
|
|
778
|
+
constructor(context, manager, addons){
|
|
779
|
+
this.context = context;
|
|
780
|
+
this.manager = manager;
|
|
781
|
+
this.addons = addons;
|
|
782
|
+
}
|
|
783
|
+
guardDecision(blockPath) {
|
|
784
|
+
const recorder = this.context.getRecorder();
|
|
785
|
+
recorder.setCurrentPath(blockPath);
|
|
786
|
+
const resource = this.obtainResource(blockPath);
|
|
787
|
+
let authentication;
|
|
788
|
+
if (recorder.existAccessAuthentication()) authentication = recorder.getAccessAuthentication();
|
|
789
|
+
else {
|
|
790
|
+
authentication = this.obtainAuthentication();
|
|
791
|
+
if (authentication) recorder.setAccessAuthentication(authentication);
|
|
792
|
+
}
|
|
793
|
+
let authorization;
|
|
794
|
+
if (recorder.existAccessAuthorization()) authorization = recorder.getAccessAuthorization();
|
|
795
|
+
else {
|
|
796
|
+
authorization = this.obtainAuthorization(authentication);
|
|
797
|
+
if (authorization) recorder.setAccessAuthorization(authorization);
|
|
798
|
+
}
|
|
799
|
+
if (resource) recorder.setAccessResource(resource);
|
|
800
|
+
else {
|
|
801
|
+
recorder.clearAccessResource();
|
|
802
|
+
return common_AccessDecision.notResource;
|
|
803
|
+
}
|
|
804
|
+
if (resource.isAnonymous()) {
|
|
805
|
+
recorder.setAllowPath(blockPath);
|
|
806
|
+
return common_AccessDecision.allowAccess;
|
|
807
|
+
}
|
|
808
|
+
if (authentication && authentication.isAuthenticated()) recorder.clearOriginPath();
|
|
809
|
+
else {
|
|
810
|
+
recorder.setOriginPath(blockPath);
|
|
811
|
+
return common_AccessDecision.notAuthentication;
|
|
812
|
+
}
|
|
813
|
+
const valid = this.checkAuthentication(authentication);
|
|
814
|
+
if (valid) recorder.clearOriginPath();
|
|
815
|
+
else {
|
|
816
|
+
recorder.setOriginPath(blockPath);
|
|
817
|
+
return common_AccessDecision.invalidAuthentication;
|
|
818
|
+
}
|
|
819
|
+
if (resource.isAuthenticated()) {
|
|
820
|
+
recorder.setAllowPath(blockPath);
|
|
821
|
+
return common_AccessDecision.allowAccess;
|
|
822
|
+
}
|
|
823
|
+
if (authorization) recorder.clearOriginPath();
|
|
824
|
+
else {
|
|
825
|
+
recorder.setOriginPath(blockPath);
|
|
826
|
+
return common_AccessDecision.notAuthorization;
|
|
827
|
+
}
|
|
828
|
+
if (resource.isAuthorized()) {
|
|
829
|
+
recorder.setAllowPath(blockPath);
|
|
830
|
+
return common_AccessDecision.allowAccess;
|
|
831
|
+
}
|
|
832
|
+
const authorized = this.checkPermission(resource, authorization);
|
|
833
|
+
if (authorized) recorder.clearOriginPath();
|
|
834
|
+
else {
|
|
835
|
+
recorder.setOriginPath(blockPath);
|
|
836
|
+
return common_AccessDecision.accessDenied;
|
|
837
|
+
}
|
|
838
|
+
if (resource.isSignatured() && !this.checkSignature(blockPath, authentication, authorization)) {
|
|
839
|
+
recorder.setOriginPath(blockPath);
|
|
840
|
+
return common_AccessDecision.notSignature;
|
|
841
|
+
}
|
|
842
|
+
recorder.clearOriginPath();
|
|
843
|
+
recorder.setAllowPath(blockPath);
|
|
844
|
+
return common_AccessDecision.allowAccess;
|
|
845
|
+
}
|
|
846
|
+
guardHandle(currentDecision, beforeDecision) {
|
|
847
|
+
const recorder = this.context.getRecorder();
|
|
848
|
+
const storer = this.context.getStorer();
|
|
849
|
+
const handler = this.manager.getHandler();
|
|
850
|
+
if (beforeDecision && beforeDecision !== common_AccessDecision.allowAccess && beforeDecision === currentDecision) {
|
|
851
|
+
if (beforeDecision === common_AccessDecision.invalidAuthentication) {
|
|
852
|
+
recorder.clearAccessAuthentication();
|
|
853
|
+
recorder.clearAccessAuthorization();
|
|
854
|
+
storer.deleteAuthentication(recorder);
|
|
855
|
+
storer.deleteAuthorization(recorder);
|
|
856
|
+
storer.deleteSignature(recorder);
|
|
857
|
+
}
|
|
858
|
+
handler.errorDecision(this.context, currentDecision);
|
|
859
|
+
return common_AccessBehave.doNothing;
|
|
860
|
+
}
|
|
861
|
+
let behave;
|
|
862
|
+
switch(currentDecision){
|
|
863
|
+
case common_AccessDecision.notResource:
|
|
864
|
+
behave = handler.notResource(this.context);
|
|
865
|
+
break;
|
|
866
|
+
case common_AccessDecision.notAuthentication:
|
|
867
|
+
recorder.clearAccessAuthentication();
|
|
868
|
+
recorder.clearAccessAuthorization();
|
|
869
|
+
storer.deleteAuthentication(recorder);
|
|
870
|
+
storer.deleteAuthorization(recorder);
|
|
871
|
+
storer.deleteSignature(recorder);
|
|
872
|
+
behave = handler.notAuthentication(this.context);
|
|
873
|
+
break;
|
|
874
|
+
case common_AccessDecision.invalidAuthentication:
|
|
875
|
+
behave = handler.invalidAuthentication(this.context);
|
|
876
|
+
break;
|
|
877
|
+
case common_AccessDecision.notAuthorization:
|
|
878
|
+
recorder.clearAccessAuthorization();
|
|
879
|
+
storer.deleteAuthorization(recorder);
|
|
880
|
+
storer.deleteSignature(recorder);
|
|
881
|
+
behave = handler.notAuthorization(this.context);
|
|
882
|
+
break;
|
|
883
|
+
case common_AccessDecision.notSignature:
|
|
884
|
+
behave = handler.notSignature(this.context);
|
|
885
|
+
break;
|
|
886
|
+
case common_AccessDecision.allowAccess:
|
|
887
|
+
behave = handler.allowAccess(this.context);
|
|
888
|
+
break;
|
|
889
|
+
case common_AccessDecision.accessDenied:
|
|
890
|
+
default:
|
|
891
|
+
behave = handler.accessDenied(this.context);
|
|
892
|
+
break;
|
|
893
|
+
}
|
|
894
|
+
return behave;
|
|
895
|
+
}
|
|
896
|
+
guardBlock(currentPath) {
|
|
897
|
+
const currentResource = this.obtainResource(currentPath);
|
|
898
|
+
const blocker = this.manager.getBlocker();
|
|
899
|
+
return blocker.block(this.context, currentPath, currentResource);
|
|
900
|
+
}
|
|
901
|
+
guardBefore(currentPath) {
|
|
902
|
+
const currentResource = this.obtainResource(currentPath);
|
|
903
|
+
this.forAddons((addon)=>{
|
|
904
|
+
addon.guardBefore(this.context, this.manager, currentPath, currentResource);
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
guardAfter(currentPath, currentDecision) {
|
|
908
|
+
const currentResource = this.obtainResource(currentPath);
|
|
909
|
+
this.forAddons((addon)=>{
|
|
910
|
+
addon.guardAfter(this.context, this.manager, currentPath, currentResource, currentDecision);
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
permitBefore(stayPath, blockPath) {
|
|
914
|
+
const stayResource = this.obtainResource(stayPath);
|
|
915
|
+
const blockResource = this.obtainResource(blockPath);
|
|
916
|
+
this.clearSignature(stayPath, stayResource);
|
|
917
|
+
this.forAddons((addon)=>{
|
|
918
|
+
addon.permitBefore(this.context, this.manager, stayPath, blockPath, stayResource, blockResource);
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
permitAfter(stayPath, blockPath) {
|
|
922
|
+
const stayResource = this.obtainResource(stayPath);
|
|
923
|
+
const blockResource = this.obtainResource(blockPath);
|
|
924
|
+
this.forAddons((addon)=>{
|
|
925
|
+
addon.permitAfter(this.context, this.manager, stayPath, blockPath, stayResource, blockResource);
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
forAddons(fn) {
|
|
929
|
+
if (Array.isArray(this.addons) && this.addons.length > 0) for (const addon of this.addons)fn(addon);
|
|
930
|
+
}
|
|
931
|
+
obtainResource(path) {
|
|
932
|
+
const matcher = this.context.getMatcher();
|
|
933
|
+
return matcher.obtain(path);
|
|
934
|
+
}
|
|
935
|
+
obtainAuthentication() {
|
|
936
|
+
const storer = this.context.getStorer();
|
|
937
|
+
const recorder = this.context.getRecorder();
|
|
938
|
+
return storer.loadAuthentication(recorder);
|
|
939
|
+
}
|
|
940
|
+
checkAuthentication(authentication) {
|
|
941
|
+
const storer = this.context.getStorer();
|
|
942
|
+
const recorder = this.context.getRecorder();
|
|
943
|
+
return storer.verifyAuthentication(recorder, authentication);
|
|
944
|
+
}
|
|
945
|
+
obtainAuthorization(authentication) {
|
|
946
|
+
const storer = this.context.getStorer();
|
|
947
|
+
const recorder = this.context.getRecorder();
|
|
948
|
+
return storer.loadAuthorization(recorder, authentication);
|
|
949
|
+
}
|
|
950
|
+
checkPermission(resource, authorization) {
|
|
951
|
+
const voter = this.context.getVoter();
|
|
952
|
+
return voter.vote(resource.getPermissions(), authorization.getPermissions());
|
|
953
|
+
}
|
|
954
|
+
checkSignature(path, authentication, authorization) {
|
|
955
|
+
const storer = this.context.getStorer();
|
|
956
|
+
const recorder = this.context.getRecorder();
|
|
957
|
+
return storer.loadSignature(recorder, path, authentication, authorization);
|
|
958
|
+
}
|
|
959
|
+
clearSignature(stayPath, stayResource) {
|
|
960
|
+
if (stayResource?.isSignatured() && stayResource.isAlwaysSignature()) {
|
|
961
|
+
const storer = this.context.getStorer();
|
|
962
|
+
const recorder = this.context.getRecorder();
|
|
963
|
+
storer.removeSignature(recorder, stayPath);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
class AccessRecorderBuilder {
|
|
968
|
+
build() {
|
|
969
|
+
return new SimpleRecorder();
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
class AccessVoterBuilder {
|
|
973
|
+
_resolver;
|
|
974
|
+
_hierarchy;
|
|
975
|
+
_all = false;
|
|
976
|
+
resolver(resolver) {
|
|
977
|
+
this._resolver = resolver;
|
|
978
|
+
return this;
|
|
979
|
+
}
|
|
980
|
+
hierarchy(hierarchy) {
|
|
981
|
+
this._hierarchy = hierarchy;
|
|
982
|
+
return this;
|
|
983
|
+
}
|
|
984
|
+
all(all) {
|
|
985
|
+
this._all = all;
|
|
986
|
+
return this;
|
|
987
|
+
}
|
|
988
|
+
build() {
|
|
989
|
+
if (this._hierarchy && this._hierarchy.trim().length > 0) {
|
|
990
|
+
if (!this._resolver) this._resolver = OriginRelationResolver;
|
|
991
|
+
return new HierarchyVoter(this._resolver, this._hierarchy, this._all);
|
|
992
|
+
}
|
|
993
|
+
return new SimpleVoter(this._all);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
class AccessStorerBuilder {
|
|
997
|
+
_aaaStorage;
|
|
998
|
+
_signStorage;
|
|
999
|
+
_authenticationKey;
|
|
1000
|
+
_authorizationKey;
|
|
1001
|
+
_signatureKey;
|
|
1002
|
+
_authenticationValidator;
|
|
1003
|
+
aaaStorage(aaaStorage) {
|
|
1004
|
+
this._aaaStorage = aaaStorage;
|
|
1005
|
+
return this;
|
|
1006
|
+
}
|
|
1007
|
+
signStorage(signStorage) {
|
|
1008
|
+
this._signStorage = signStorage;
|
|
1009
|
+
return this;
|
|
1010
|
+
}
|
|
1011
|
+
authenticationKey(authenticationKey) {
|
|
1012
|
+
this._authenticationKey = authenticationKey;
|
|
1013
|
+
return this;
|
|
1014
|
+
}
|
|
1015
|
+
authorizationKey(authorizationKey) {
|
|
1016
|
+
this._authorizationKey = authorizationKey;
|
|
1017
|
+
return this;
|
|
1018
|
+
}
|
|
1019
|
+
signatureKey(signatureKey) {
|
|
1020
|
+
this._signatureKey = signatureKey;
|
|
1021
|
+
return this;
|
|
1022
|
+
}
|
|
1023
|
+
authenticationValidator(authenticationValidator) {
|
|
1024
|
+
this._authenticationValidator = authenticationValidator;
|
|
1025
|
+
return this;
|
|
1026
|
+
}
|
|
1027
|
+
local() {
|
|
1028
|
+
return this.aaaStorage(window.localStorage).signStorage(window.localStorage);
|
|
1029
|
+
}
|
|
1030
|
+
session() {
|
|
1031
|
+
return this.aaaStorage(window.sessionStorage).signStorage(window.sessionStorage);
|
|
1032
|
+
}
|
|
1033
|
+
blend() {
|
|
1034
|
+
return this.aaaStorage(window.localStorage).signStorage(window.sessionStorage);
|
|
1035
|
+
}
|
|
1036
|
+
build() {
|
|
1037
|
+
if (!this._aaaStorage && !this._signStorage) this.session();
|
|
1038
|
+
if (!this._aaaStorage) this.aaaStorage(window.localStorage);
|
|
1039
|
+
if (!this._signStorage) this.signStorage(window.sessionStorage);
|
|
1040
|
+
return new SimpleStorer(this._aaaStorage, this._signStorage, this._authenticationKey, this._authorizationKey, this._signatureKey, this._authenticationValidator);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
class AccessResourceBuilder {
|
|
1044
|
+
_patterns = new Set();
|
|
1045
|
+
_permissions = new Set();
|
|
1046
|
+
_labels = new Set();
|
|
1047
|
+
_basename;
|
|
1048
|
+
patterns(...patterns) {
|
|
1049
|
+
for (const pattern of patterns)this._patterns.add(pattern);
|
|
1050
|
+
return this;
|
|
1051
|
+
}
|
|
1052
|
+
permissions(...permissions) {
|
|
1053
|
+
for (const permission of permissions)this._permissions.add(permission);
|
|
1054
|
+
return this;
|
|
1055
|
+
}
|
|
1056
|
+
labels(...labels) {
|
|
1057
|
+
for (const label of labels)this._labels.add(label);
|
|
1058
|
+
return this;
|
|
1059
|
+
}
|
|
1060
|
+
anonymous() {
|
|
1061
|
+
this._permissions.add(SimpleResource.PERMISSION_ANONYMOUS);
|
|
1062
|
+
return this;
|
|
1063
|
+
}
|
|
1064
|
+
authenticated() {
|
|
1065
|
+
this._permissions.add(SimpleResource.PERMISSION_AUTHENTICATED);
|
|
1066
|
+
return this;
|
|
1067
|
+
}
|
|
1068
|
+
authorized() {
|
|
1069
|
+
this._permissions.add(SimpleResource.PERMISSION_AUTHORIZED);
|
|
1070
|
+
return this;
|
|
1071
|
+
}
|
|
1072
|
+
signatured() {
|
|
1073
|
+
this._labels.add(SimpleResource.LABEL_SIGNATURED);
|
|
1074
|
+
return this;
|
|
1075
|
+
}
|
|
1076
|
+
alwaysSignature() {
|
|
1077
|
+
this.signatured();
|
|
1078
|
+
this._labels.add(SimpleResource.LABEL_ALWAYS_SIGNATURE);
|
|
1079
|
+
return this;
|
|
1080
|
+
}
|
|
1081
|
+
basename(basename) {
|
|
1082
|
+
this._basename = basename;
|
|
1083
|
+
return this;
|
|
1084
|
+
}
|
|
1085
|
+
config(config) {
|
|
1086
|
+
this.patterns(...config.patterns).permissions(...config.permissions);
|
|
1087
|
+
if (config.labels) this.labels(...config.labels);
|
|
1088
|
+
if (config.basename) this.basename(config.basename);
|
|
1089
|
+
return this;
|
|
1090
|
+
}
|
|
1091
|
+
build() {
|
|
1092
|
+
return new SimpleResource(this._patterns, this._permissions, this._labels, this._basename);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
class AccessMatcherBuilder {
|
|
1096
|
+
_resources = [];
|
|
1097
|
+
config(config) {
|
|
1098
|
+
this._resources.push(new AccessResourceBuilder().config(config).build());
|
|
1099
|
+
return this;
|
|
1100
|
+
}
|
|
1101
|
+
configs(...configs) {
|
|
1102
|
+
for (const config of configs)this.config(config);
|
|
1103
|
+
return this;
|
|
1104
|
+
}
|
|
1105
|
+
resource(builder) {
|
|
1106
|
+
this._resources.push(builder(new AccessResourceBuilder()));
|
|
1107
|
+
return this;
|
|
1108
|
+
}
|
|
1109
|
+
resources(resources) {
|
|
1110
|
+
this._resources.push(...resources);
|
|
1111
|
+
return this;
|
|
1112
|
+
}
|
|
1113
|
+
build() {
|
|
1114
|
+
return new SimpleMatcher(this._resources);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
class AccessNavigatorBuilder {
|
|
1118
|
+
_navigate;
|
|
1119
|
+
navigate(navigate) {
|
|
1120
|
+
this._navigate = navigate;
|
|
1121
|
+
return this;
|
|
1122
|
+
}
|
|
1123
|
+
build() {
|
|
1124
|
+
if (!this._navigate) throw new Error('导航函数是必须设置的,请检查!');
|
|
1125
|
+
return new SimpleNavigator(this._navigate);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
class AccessContextBuilder {
|
|
1129
|
+
_recorder;
|
|
1130
|
+
_voter;
|
|
1131
|
+
_storer;
|
|
1132
|
+
_matcher;
|
|
1133
|
+
_navigator;
|
|
1134
|
+
_hierarchy;
|
|
1135
|
+
_validator;
|
|
1136
|
+
_resources = [];
|
|
1137
|
+
_navigate;
|
|
1138
|
+
recorder(recorder) {
|
|
1139
|
+
if ('function' == typeof recorder) this._recorder = recorder(new AccessRecorderBuilder());
|
|
1140
|
+
else this._recorder = recorder;
|
|
1141
|
+
return this;
|
|
1142
|
+
}
|
|
1143
|
+
voter(voter) {
|
|
1144
|
+
if ('function' == typeof voter) this._voter = voter(new AccessVoterBuilder());
|
|
1145
|
+
else this._voter = voter;
|
|
1146
|
+
return this;
|
|
1147
|
+
}
|
|
1148
|
+
storer(storer) {
|
|
1149
|
+
if ('function' == typeof storer) this._storer = storer(new AccessStorerBuilder());
|
|
1150
|
+
else this._storer = storer;
|
|
1151
|
+
return this;
|
|
1152
|
+
}
|
|
1153
|
+
matcher(matcher) {
|
|
1154
|
+
if ('function' == typeof matcher) this._matcher = matcher(new AccessMatcherBuilder());
|
|
1155
|
+
else this._matcher = matcher;
|
|
1156
|
+
return this;
|
|
1157
|
+
}
|
|
1158
|
+
navigator(navigator) {
|
|
1159
|
+
if ('function' == typeof navigator) this._navigator = navigator(new AccessNavigatorBuilder());
|
|
1160
|
+
else this._navigator = navigator;
|
|
1161
|
+
return this;
|
|
1162
|
+
}
|
|
1163
|
+
hierarchy(hierarchy) {
|
|
1164
|
+
this._hierarchy = hierarchy;
|
|
1165
|
+
return this;
|
|
1166
|
+
}
|
|
1167
|
+
validator(validator) {
|
|
1168
|
+
this._validator = validator;
|
|
1169
|
+
return this;
|
|
1170
|
+
}
|
|
1171
|
+
resource(builder) {
|
|
1172
|
+
const resource = builder(new AccessResourceBuilder());
|
|
1173
|
+
this._resources.push(resource);
|
|
1174
|
+
return this;
|
|
1175
|
+
}
|
|
1176
|
+
navigate(navigate) {
|
|
1177
|
+
this._navigate = navigate;
|
|
1178
|
+
return this;
|
|
1179
|
+
}
|
|
1180
|
+
drs() {
|
|
1181
|
+
this.resource((rb)=>rb.patterns('/login', '/logout', '/denied', '/signature').anonymous().build());
|
|
1182
|
+
this.resource((rb)=>rb.patterns('/*').authenticated().build());
|
|
1183
|
+
return this;
|
|
1184
|
+
}
|
|
1185
|
+
build() {
|
|
1186
|
+
if (!this._recorder) this.recorder((builder)=>builder.build());
|
|
1187
|
+
if (!this._voter) this.voter((builder)=>{
|
|
1188
|
+
if (this._hierarchy) builder.hierarchy(this._hierarchy);
|
|
1189
|
+
return builder.build();
|
|
1190
|
+
});
|
|
1191
|
+
if (!this._storer) this.storer((builder)=>{
|
|
1192
|
+
if (this._validator) builder.authenticationValidator(this._validator);
|
|
1193
|
+
return builder.build();
|
|
1194
|
+
});
|
|
1195
|
+
if (!this._matcher) {
|
|
1196
|
+
if (0 === this._resources.length) this.drs();
|
|
1197
|
+
this.matcher((builder)=>builder.resources(this._resources).build());
|
|
1198
|
+
}
|
|
1199
|
+
if (!this._navigator) this.navigator((builder)=>{
|
|
1200
|
+
if (this._navigate) builder.navigate(this._navigate);
|
|
1201
|
+
return builder.build();
|
|
1202
|
+
});
|
|
1203
|
+
return new SimpleContext(this._recorder, this._voter, this._storer, this._matcher, this._navigator);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
class AccessHandlerBuilder {
|
|
1207
|
+
_config;
|
|
1208
|
+
config(config) {
|
|
1209
|
+
this._config = config;
|
|
1210
|
+
return this;
|
|
1211
|
+
}
|
|
1212
|
+
build() {
|
|
1213
|
+
if (!this._config) throw new Error('行为配置是必须设置,请检查!');
|
|
1214
|
+
return new BehaveHandler(this._config);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
class AccessBlockerBuilder {
|
|
1218
|
+
_multi;
|
|
1219
|
+
multi() {
|
|
1220
|
+
this._multi = true;
|
|
1221
|
+
return this;
|
|
1222
|
+
}
|
|
1223
|
+
single() {
|
|
1224
|
+
this._multi = false;
|
|
1225
|
+
return this;
|
|
1226
|
+
}
|
|
1227
|
+
build() {
|
|
1228
|
+
if (this._multi) return new MultiBlocker();
|
|
1229
|
+
return new SingleBlocker();
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
class AccessManagerBuilder {
|
|
1233
|
+
_disabled = false;
|
|
1234
|
+
_handler;
|
|
1235
|
+
_blocker;
|
|
1236
|
+
_behave;
|
|
1237
|
+
disabled() {
|
|
1238
|
+
this._disabled = true;
|
|
1239
|
+
return this;
|
|
1240
|
+
}
|
|
1241
|
+
handler(handler) {
|
|
1242
|
+
if ('function' == typeof handler) this._handler = handler(new AccessHandlerBuilder());
|
|
1243
|
+
else this._handler = handler;
|
|
1244
|
+
return this;
|
|
1245
|
+
}
|
|
1246
|
+
blocker(blocker) {
|
|
1247
|
+
if ('function' == typeof blocker) this._blocker = blocker(new AccessBlockerBuilder());
|
|
1248
|
+
else this._blocker = blocker;
|
|
1249
|
+
return this;
|
|
1250
|
+
}
|
|
1251
|
+
behave(behave) {
|
|
1252
|
+
this._behave = behave;
|
|
1253
|
+
return this;
|
|
1254
|
+
}
|
|
1255
|
+
dbc() {
|
|
1256
|
+
return this.behave({
|
|
1257
|
+
notAuthenticationPath: '/login',
|
|
1258
|
+
accessDeniedPath: '/denied',
|
|
1259
|
+
notSignaturePath: '/signature'
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
build() {
|
|
1263
|
+
if (!this._handler) this.handler((builder)=>{
|
|
1264
|
+
if (!this._behave) this.dbc();
|
|
1265
|
+
return builder.config(this._behave).build();
|
|
1266
|
+
});
|
|
1267
|
+
if (!this._blocker) this.blocker((builder)=>builder.single().build());
|
|
1268
|
+
return new SimpleManager(this._disabled ?? false, this._handler, this._blocker);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
class AccessGuarderBuilder {
|
|
1272
|
+
_context;
|
|
1273
|
+
_manager;
|
|
1274
|
+
_addons = [];
|
|
1275
|
+
_navigate;
|
|
1276
|
+
context(context) {
|
|
1277
|
+
if ('function' == typeof context) {
|
|
1278
|
+
const builder = new AccessContextBuilder();
|
|
1279
|
+
if (this._navigate) builder.navigate(this._navigate);
|
|
1280
|
+
this._context = context(builder);
|
|
1281
|
+
} else this._context = context;
|
|
1282
|
+
return this;
|
|
1283
|
+
}
|
|
1284
|
+
manager(manager) {
|
|
1285
|
+
if ('function' == typeof manager) this._manager = manager(new AccessManagerBuilder());
|
|
1286
|
+
else this._manager = manager;
|
|
1287
|
+
return this;
|
|
1288
|
+
}
|
|
1289
|
+
addons(...addons) {
|
|
1290
|
+
for (const addon of addons)this._addons.push(addon);
|
|
1291
|
+
return this;
|
|
1292
|
+
}
|
|
1293
|
+
navigate(navigate) {
|
|
1294
|
+
this._navigate = navigate;
|
|
1295
|
+
return this;
|
|
1296
|
+
}
|
|
1297
|
+
build() {
|
|
1298
|
+
if (!this._context) this.context((builder)=>builder.build());
|
|
1299
|
+
if (!this._manager) this.manager((builder)=>builder.build());
|
|
1300
|
+
return {
|
|
1301
|
+
context: this._context,
|
|
1302
|
+
manager: this._manager,
|
|
1303
|
+
guarder: new SimpleGuarder(this._context, this._manager, this._addons)
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
const SecurityContext = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)(null);
|
|
1308
|
+
const useSecurityContext = ()=>{
|
|
1309
|
+
const sc = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(SecurityContext);
|
|
1310
|
+
if (!sc) throw new Error('安全上下文为空,必须使用安全提供者包裹组件来设置安全上下文');
|
|
1311
|
+
return sc;
|
|
1312
|
+
};
|
|
1313
|
+
function SecurityProvider({ children, bundler }) {
|
|
1314
|
+
const navigate = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__.useNavigate)();
|
|
1315
|
+
const provide = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>bundler(new AccessGuarderBuilder().navigate(navigate)), [
|
|
1316
|
+
bundler,
|
|
1317
|
+
navigate
|
|
1318
|
+
]);
|
|
1319
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(SecurityContext.Provider, {
|
|
1320
|
+
value: provide,
|
|
1321
|
+
children: children
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
function SecurityBlocker({ children }) {
|
|
1325
|
+
const { context, manager, guarder } = useSecurityContext();
|
|
1326
|
+
if (manager.isDisabled()) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {
|
|
1327
|
+
children: children
|
|
1328
|
+
});
|
|
1329
|
+
const blocker = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__.useBlocker)(({ currentLocation, nextLocation })=>currentLocation.pathname !== nextLocation.pathname);
|
|
1330
|
+
const [guarded, setGuarded] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
|
|
1331
|
+
const [nextPath, setNextPath] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)((0, __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__.useLocation)());
|
|
1332
|
+
const [firstAccess, setFirstAccess] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(true);
|
|
1333
|
+
const [firstHandle, setFirstHandle] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(true);
|
|
1334
|
+
const [firstSignature, setFirstSignature] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(1);
|
|
1335
|
+
const [handleDecision, setHandleDecision] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
|
|
1336
|
+
const [beforeDecision, setBeforeDecision] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(void 0);
|
|
1337
|
+
const [currentDecision, setCurrentDecision] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(void 0);
|
|
1338
|
+
const [executeBlock, setExecuteBlock] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
|
|
1339
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
1340
|
+
if ('blocked' === blocker.state) {
|
|
1341
|
+
const recorder = context.getRecorder();
|
|
1342
|
+
const stayPath = recorder.getAllowPath();
|
|
1343
|
+
const blockPath = blocker.location;
|
|
1344
|
+
let guardBlocked = false;
|
|
1345
|
+
if (executeBlock) guardBlocked = guarder.guardBlock(blockPath);
|
|
1346
|
+
if (guardBlocked) {
|
|
1347
|
+
blocker.reset();
|
|
1348
|
+
setNextPath(blockPath);
|
|
1349
|
+
setHandleDecision(false);
|
|
1350
|
+
setCurrentDecision(void 0);
|
|
1351
|
+
} else {
|
|
1352
|
+
if (!beforeDecision) guarder.guardBefore(blockPath);
|
|
1353
|
+
const blockedDecision = guarder.guardDecision(blockPath);
|
|
1354
|
+
if (blockedDecision === common_AccessDecision.allowAccess) {
|
|
1355
|
+
const isDiff = !!stayPath && stayPath.pathname !== blockPath.pathname;
|
|
1356
|
+
if (isDiff) guarder.permitBefore(stayPath, blockPath);
|
|
1357
|
+
blocker.proceed();
|
|
1358
|
+
if (isDiff) guarder.permitAfter(stayPath, blockPath);
|
|
1359
|
+
} else blocker.reset();
|
|
1360
|
+
setNextPath(blockPath);
|
|
1361
|
+
setHandleDecision(true);
|
|
1362
|
+
setCurrentDecision(blockedDecision);
|
|
1363
|
+
}
|
|
1364
|
+
} else if ('unblocked' === blocker.state) {
|
|
1365
|
+
if (handleDecision && currentDecision) {
|
|
1366
|
+
let navNext;
|
|
1367
|
+
const behave = guarder.guardHandle(currentDecision, beforeDecision);
|
|
1368
|
+
switch(behave){
|
|
1369
|
+
case common_AccessBehave.reDecision:
|
|
1370
|
+
setBeforeDecision(currentDecision);
|
|
1371
|
+
setExecuteBlock(false);
|
|
1372
|
+
navNext = true;
|
|
1373
|
+
break;
|
|
1374
|
+
case common_AccessBehave.goNavigate:
|
|
1375
|
+
setBeforeDecision(void 0);
|
|
1376
|
+
navNext = false;
|
|
1377
|
+
setExecuteBlock(false);
|
|
1378
|
+
break;
|
|
1379
|
+
case common_AccessBehave.doNothing:
|
|
1380
|
+
default:
|
|
1381
|
+
setBeforeDecision(void 0);
|
|
1382
|
+
navNext = false;
|
|
1383
|
+
setExecuteBlock(true);
|
|
1384
|
+
break;
|
|
1385
|
+
}
|
|
1386
|
+
if (firstHandle && currentDecision === common_AccessDecision.notSignature && behave === common_AccessBehave.reDecision) {
|
|
1387
|
+
if (firstSignature >= 3) {
|
|
1388
|
+
setFirstHandle(false);
|
|
1389
|
+
setBeforeDecision(common_AccessDecision.notSignature);
|
|
1390
|
+
setHandleDecision(true);
|
|
1391
|
+
setCurrentDecision(common_AccessDecision.accessDenied);
|
|
1392
|
+
} else {
|
|
1393
|
+
const signDecision = guarder.guardDecision(nextPath);
|
|
1394
|
+
setHandleDecision(true);
|
|
1395
|
+
setBeforeDecision(void 0);
|
|
1396
|
+
setCurrentDecision(signDecision);
|
|
1397
|
+
setFirstSignature(firstSignature + 1);
|
|
1398
|
+
}
|
|
1399
|
+
} else {
|
|
1400
|
+
setFirstHandle(false);
|
|
1401
|
+
setHandleDecision(false);
|
|
1402
|
+
setCurrentDecision(void 0);
|
|
1403
|
+
if (navNext) context.getNavigator().navigate(nextPath);
|
|
1404
|
+
else {
|
|
1405
|
+
guarder.guardAfter(nextPath, currentDecision);
|
|
1406
|
+
setGuarded(true);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
} else if (firstAccess) {
|
|
1410
|
+
guarder.guardBefore(nextPath);
|
|
1411
|
+
const firstDecision = guarder.guardDecision(nextPath);
|
|
1412
|
+
setFirstAccess(false);
|
|
1413
|
+
setHandleDecision(true);
|
|
1414
|
+
setCurrentDecision(firstDecision);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
}, [
|
|
1418
|
+
blocker,
|
|
1419
|
+
context,
|
|
1420
|
+
guarder,
|
|
1421
|
+
nextPath,
|
|
1422
|
+
firstAccess,
|
|
1423
|
+
firstHandle,
|
|
1424
|
+
firstSignature,
|
|
1425
|
+
handleDecision,
|
|
1426
|
+
beforeDecision,
|
|
1427
|
+
currentDecision,
|
|
1428
|
+
executeBlock
|
|
1429
|
+
]);
|
|
1430
|
+
if (!guarded) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {});
|
|
1431
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {
|
|
1432
|
+
children: children
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
const withSecurityBlocker = (Component, bundler)=>()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(SecurityProvider, {
|
|
1436
|
+
bundler: bundler,
|
|
1437
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(SecurityBlocker, {
|
|
1438
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(Component, {})
|
|
1439
|
+
})
|
|
1440
|
+
});
|
|
1441
|
+
const useObtainAuthentication = ()=>{
|
|
1442
|
+
const { context } = useSecurityContext();
|
|
1443
|
+
const storer = context.getStorer();
|
|
1444
|
+
const recorder = context.getRecorder();
|
|
1445
|
+
return ()=>{
|
|
1446
|
+
let authentication = recorder.getAccessAuthentication();
|
|
1447
|
+
if (!authentication) {
|
|
1448
|
+
authentication = storer.loadAuthentication(recorder);
|
|
1449
|
+
if (authentication) recorder.setAccessAuthentication(authentication);
|
|
1450
|
+
}
|
|
1451
|
+
return authentication;
|
|
1452
|
+
};
|
|
1453
|
+
};
|
|
1454
|
+
const useObtainAuthorization = ()=>{
|
|
1455
|
+
const obtainAuthentication = useObtainAuthentication();
|
|
1456
|
+
const { context } = useSecurityContext();
|
|
1457
|
+
const storer = context.getStorer();
|
|
1458
|
+
const recorder = context.getRecorder();
|
|
1459
|
+
return ()=>{
|
|
1460
|
+
let authorization = recorder.getAccessAuthorization();
|
|
1461
|
+
if (!authorization) {
|
|
1462
|
+
const authentication = obtainAuthentication();
|
|
1463
|
+
authorization = storer.loadAuthorization(recorder, authentication);
|
|
1464
|
+
if (authorization) recorder.setAccessAuthorization(authorization);
|
|
1465
|
+
}
|
|
1466
|
+
return authorization;
|
|
1467
|
+
};
|
|
1468
|
+
};
|
|
1469
|
+
const useDeleteAuthentication = ()=>{
|
|
1470
|
+
const { context } = useSecurityContext();
|
|
1471
|
+
const storer = context.getStorer();
|
|
1472
|
+
const recorder = context.getRecorder();
|
|
1473
|
+
return ()=>{
|
|
1474
|
+
storer.deleteAuthentication(recorder);
|
|
1475
|
+
storer.deleteAuthorization(recorder);
|
|
1476
|
+
recorder.clearAccessAuthentication();
|
|
1477
|
+
recorder.clearAccessAuthorization();
|
|
1478
|
+
const parent = context.getParent();
|
|
1479
|
+
if (parent) {
|
|
1480
|
+
const p_recorder = parent.getRecorder();
|
|
1481
|
+
const p_storer = parent.getStorer();
|
|
1482
|
+
p_storer.deleteAuthentication(p_recorder);
|
|
1483
|
+
p_storer.deleteAuthorization(p_recorder);
|
|
1484
|
+
p_recorder.clearAccessAuthentication();
|
|
1485
|
+
p_recorder.clearAccessAuthorization();
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
};
|
|
1489
|
+
const useDeleteAuthorization = ()=>{
|
|
1490
|
+
const { context } = useSecurityContext();
|
|
1491
|
+
const storer = context.getStorer();
|
|
1492
|
+
const recorder = context.getRecorder();
|
|
1493
|
+
return ()=>{
|
|
1494
|
+
storer.deleteAuthorization(recorder);
|
|
1495
|
+
recorder.clearAccessAuthorization();
|
|
1496
|
+
const parent = context.getParent();
|
|
1497
|
+
if (parent) {
|
|
1498
|
+
const p_recorder = parent.getRecorder();
|
|
1499
|
+
const p_storer = parent.getStorer();
|
|
1500
|
+
p_storer.deleteAuthorization(p_recorder);
|
|
1501
|
+
p_recorder.clearAccessAuthorization();
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
};
|
|
1505
|
+
const useSaveAuthentication = (navigate = false, redirect = '/')=>{
|
|
1506
|
+
const { context } = useSecurityContext();
|
|
1507
|
+
const recorder = context.getRecorder();
|
|
1508
|
+
const storer = context.getStorer();
|
|
1509
|
+
const navigator = context.getNavigator();
|
|
1510
|
+
return (datasheet)=>{
|
|
1511
|
+
storer.saveAuthentication(recorder, datasheet);
|
|
1512
|
+
recorder.clearAccessAuthentication();
|
|
1513
|
+
recorder.clearAccessAuthorization();
|
|
1514
|
+
if (navigate) {
|
|
1515
|
+
const path = recorder.getOriginPath();
|
|
1516
|
+
if (path) navigator.navigate(path);
|
|
1517
|
+
else navigator.navigate(redirect);
|
|
1518
|
+
}
|
|
1519
|
+
};
|
|
1520
|
+
};
|
|
1521
|
+
const useSaveAuthorization = (navigate = false, redirect = '/')=>{
|
|
1522
|
+
const { context } = useSecurityContext();
|
|
1523
|
+
const recorder = context.getRecorder();
|
|
1524
|
+
const storer = context.getStorer();
|
|
1525
|
+
const navigator = context.getNavigator();
|
|
1526
|
+
return (datasheet)=>{
|
|
1527
|
+
storer.saveAuthorization(recorder, datasheet);
|
|
1528
|
+
recorder.clearAccessAuthorization();
|
|
1529
|
+
if (navigate) {
|
|
1530
|
+
const path = recorder.getOriginPath();
|
|
1531
|
+
if (path) navigator.navigate(path);
|
|
1532
|
+
else navigator.navigate(redirect);
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
};
|
|
1536
|
+
const useHavePermission = ()=>{
|
|
1537
|
+
const obtainAuthorization = useObtainAuthorization();
|
|
1538
|
+
const { context } = useSecurityContext();
|
|
1539
|
+
const voter = context.getVoter();
|
|
1540
|
+
return (term)=>{
|
|
1541
|
+
let have = false;
|
|
1542
|
+
const authorization = obtainAuthorization();
|
|
1543
|
+
if (authorization) {
|
|
1544
|
+
let permissions;
|
|
1545
|
+
permissions = Array.isArray(term) ? term : [
|
|
1546
|
+
term
|
|
1547
|
+
];
|
|
1548
|
+
have = voter.vote(new Set(permissions), authorization.getPermissions());
|
|
1549
|
+
}
|
|
1550
|
+
return have;
|
|
1551
|
+
};
|
|
1552
|
+
};
|
|
1553
|
+
const useSaveSignature = (navigate = true, redirect = '/')=>{
|
|
1554
|
+
const { context } = useSecurityContext();
|
|
1555
|
+
const recorder = context.getRecorder();
|
|
1556
|
+
const storer = context.getStorer();
|
|
1557
|
+
const navigator = context.getNavigator();
|
|
1558
|
+
return (path)=>{
|
|
1559
|
+
let target;
|
|
1560
|
+
target = path ? path : recorder.getOriginPath();
|
|
1561
|
+
if (target) storer.saveSignature(recorder, target);
|
|
1562
|
+
if (navigate) {
|
|
1563
|
+
if (target) navigator.navigate(target);
|
|
1564
|
+
else navigator.navigate(redirect);
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
};
|
|
1568
|
+
const useDeleteSignature = ()=>{
|
|
1569
|
+
const { context } = useSecurityContext();
|
|
1570
|
+
const recorder = context.getRecorder();
|
|
1571
|
+
const storer = context.getStorer();
|
|
1572
|
+
return ()=>{
|
|
1573
|
+
storer.deleteSignature(recorder);
|
|
1574
|
+
};
|
|
1575
|
+
};
|
|
1576
|
+
const useRemoveSignature = ()=>{
|
|
1577
|
+
const { context } = useSecurityContext();
|
|
1578
|
+
const recorder = context.getRecorder();
|
|
1579
|
+
const storer = context.getStorer();
|
|
1580
|
+
return (path)=>{
|
|
1581
|
+
if ('string' == typeof path) storer.removeSignature(recorder, {
|
|
1582
|
+
pathname: path,
|
|
1583
|
+
search: '',
|
|
1584
|
+
hash: ''
|
|
1585
|
+
});
|
|
1586
|
+
else storer.removeSignature(recorder, path);
|
|
1587
|
+
};
|
|
1588
|
+
};
|
|
1589
|
+
const usePurgeSignature = ()=>{
|
|
1590
|
+
const { context } = useSecurityContext();
|
|
1591
|
+
const recorder = context.getRecorder();
|
|
1592
|
+
const storer = context.getStorer();
|
|
1593
|
+
const path = recorder.getCurrentPath();
|
|
1594
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>()=>{
|
|
1595
|
+
if (path) storer.removeSignature(recorder, path);
|
|
1596
|
+
}, [
|
|
1597
|
+
recorder,
|
|
1598
|
+
storer,
|
|
1599
|
+
path
|
|
1600
|
+
]);
|
|
1601
|
+
};
|
|
1602
|
+
const useLogout = (navigate = true, redirect = '/')=>{
|
|
1603
|
+
const { context } = useSecurityContext();
|
|
1604
|
+
const recorder = context.getRecorder();
|
|
1605
|
+
const storer = context.getStorer();
|
|
1606
|
+
const navigator = context.getNavigator();
|
|
1607
|
+
return ()=>{
|
|
1608
|
+
storer.deleteAuthentication(recorder);
|
|
1609
|
+
storer.deleteAuthorization(recorder);
|
|
1610
|
+
storer.deleteSignature(recorder);
|
|
1611
|
+
recorder.clearAccessAuthentication();
|
|
1612
|
+
recorder.clearAccessAuthorization();
|
|
1613
|
+
if (navigate) navigator.navigate(redirect);
|
|
1614
|
+
const parent = context.getParent();
|
|
1615
|
+
if (parent) {
|
|
1616
|
+
const p_recorder = parent.getRecorder();
|
|
1617
|
+
const p_storer = parent.getStorer();
|
|
1618
|
+
const p_navigator = parent.getNavigator();
|
|
1619
|
+
p_storer.deleteAuthentication(p_recorder);
|
|
1620
|
+
p_storer.deleteAuthorization(p_recorder);
|
|
1621
|
+
p_storer.deleteSignature(p_recorder);
|
|
1622
|
+
p_recorder.clearAccessAuthentication();
|
|
1623
|
+
p_recorder.clearAccessAuthorization();
|
|
1624
|
+
if (navigate) p_navigator.navigate(redirect);
|
|
1625
|
+
}
|
|
1626
|
+
};
|
|
1627
|
+
};
|
|
1628
|
+
const useLogin = (logined = false, navigate = true, redirect = '/')=>{
|
|
1629
|
+
const { context } = useSecurityContext();
|
|
1630
|
+
const recorder = context.getRecorder();
|
|
1631
|
+
const storer = context.getStorer();
|
|
1632
|
+
const navigator = context.getNavigator();
|
|
1633
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
1634
|
+
const isAuthentication = recorder.existAccessAuthentication() || !!storer.loadAuthentication(recorder);
|
|
1635
|
+
if (logined && isAuthentication) navigator.navigate(redirect);
|
|
1636
|
+
}, [
|
|
1637
|
+
logined,
|
|
1638
|
+
redirect,
|
|
1639
|
+
recorder,
|
|
1640
|
+
storer,
|
|
1641
|
+
navigator
|
|
1642
|
+
]);
|
|
1643
|
+
return (datasheet)=>{
|
|
1644
|
+
storer.saveAuthentication(recorder, datasheet);
|
|
1645
|
+
recorder.clearAccessAuthentication();
|
|
1646
|
+
recorder.clearAccessAuthorization();
|
|
1647
|
+
if (navigate) {
|
|
1648
|
+
const path = recorder.getOriginPath();
|
|
1649
|
+
if (path) navigator.navigate(path);
|
|
1650
|
+
else navigator.navigate(redirect);
|
|
1651
|
+
}
|
|
1652
|
+
};
|
|
1653
|
+
};
|
|
1654
|
+
const useCustomBlocker = (handler)=>{
|
|
1655
|
+
const { manager } = useSecurityContext();
|
|
1656
|
+
const blocker = manager.getBlocker();
|
|
1657
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
1658
|
+
blocker.register(handler);
|
|
1659
|
+
return ()=>{
|
|
1660
|
+
blocker.unregister(handler);
|
|
1661
|
+
};
|
|
1662
|
+
}, [
|
|
1663
|
+
blocker,
|
|
1664
|
+
handler
|
|
1665
|
+
]);
|
|
1666
|
+
};
|
|
1667
|
+
const useSecurityBlocker = (recover = true)=>{
|
|
1668
|
+
const { context, manager } = useSecurityContext();
|
|
1669
|
+
const blocker = manager.getBlocker();
|
|
1670
|
+
const [path, setPath] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)();
|
|
1671
|
+
const [jump, setJump] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
|
|
1672
|
+
const [blocked, setBlocked] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
|
|
1673
|
+
const proceed = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
1674
|
+
if (path) {
|
|
1675
|
+
setJump(true);
|
|
1676
|
+
if (recover) {
|
|
1677
|
+
setPath(void 0);
|
|
1678
|
+
setBlocked(false);
|
|
1679
|
+
}
|
|
1680
|
+
context.getNavigator().navigate(path);
|
|
1681
|
+
}
|
|
1682
|
+
}, [
|
|
1683
|
+
context,
|
|
1684
|
+
path,
|
|
1685
|
+
recover
|
|
1686
|
+
]);
|
|
1687
|
+
const reset = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
1688
|
+
setPath(void 0);
|
|
1689
|
+
setJump(false);
|
|
1690
|
+
setBlocked(false);
|
|
1691
|
+
}, []);
|
|
1692
|
+
const handler = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((context, currentPath, currentResource)=>{
|
|
1693
|
+
setJump(false);
|
|
1694
|
+
if (jump) return false;
|
|
1695
|
+
setPath(currentPath);
|
|
1696
|
+
setBlocked(true);
|
|
1697
|
+
return true;
|
|
1698
|
+
}, [
|
|
1699
|
+
jump
|
|
1700
|
+
]);
|
|
1701
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
1702
|
+
blocker.register(handler);
|
|
1703
|
+
return ()=>{
|
|
1704
|
+
blocker.unregister(handler);
|
|
1705
|
+
};
|
|
1706
|
+
}, [
|
|
1707
|
+
blocker,
|
|
1708
|
+
handler
|
|
1709
|
+
]);
|
|
1710
|
+
return {
|
|
1711
|
+
blocked,
|
|
1712
|
+
proceed,
|
|
1713
|
+
reset,
|
|
1714
|
+
path
|
|
1715
|
+
};
|
|
1716
|
+
};
|
|
1717
|
+
function HavePermission({ children, term }) {
|
|
1718
|
+
const havePermission = useHavePermission();
|
|
1719
|
+
const have = havePermission(term);
|
|
1720
|
+
if (!have) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {});
|
|
1721
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {
|
|
1722
|
+
children: children
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
const withHavePermission = (Component, term)=>()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(HavePermission, {
|
|
1726
|
+
term: term,
|
|
1727
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(Component, {})
|
|
1728
|
+
});
|
|
1729
|
+
class MicroAppAddon extends AbstractAddon {
|
|
1730
|
+
static HIERARCHY_JOIN_IGNORE = 'ignore';
|
|
1731
|
+
static HIERARCHY_JOIN_MERGE = 'merge';
|
|
1732
|
+
static HIERARCHY_JOIN_PARENT = 'parent';
|
|
1733
|
+
microJoin;
|
|
1734
|
+
basenameJoin;
|
|
1735
|
+
hierarchyJoin;
|
|
1736
|
+
constructor(basenameJoin, hierarchyJoin){
|
|
1737
|
+
super();
|
|
1738
|
+
this.microJoin = false;
|
|
1739
|
+
this.basenameJoin = basenameJoin;
|
|
1740
|
+
this.hierarchyJoin = hierarchyJoin;
|
|
1741
|
+
}
|
|
1742
|
+
guardBefore(context, manager, currentPath, currentResource) {
|
|
1743
|
+
if (this.microJoin) return;
|
|
1744
|
+
if (window.__MICRO_APP_BASE_APPLICATION__) {
|
|
1745
|
+
window.__RSR_MICRO_APP_PARENT_CONTEXT__ = context;
|
|
1746
|
+
window.__RSR_MICRO_APP_PARENT_MANAGER__ = manager;
|
|
1747
|
+
}
|
|
1748
|
+
if (window.__MICRO_APP_ENVIRONMENT__) {
|
|
1749
|
+
if (this.basenameJoin) {
|
|
1750
|
+
const baseRoute = window.__MICRO_APP_BASE_ROUTE__;
|
|
1751
|
+
if (baseRoute && baseRoute.trim().length > 0) {
|
|
1752
|
+
const matcher = context.getMatcher();
|
|
1753
|
+
matcher.setBasename(baseRoute);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
const c_parent = window.rawWindow?.__RSR_MICRO_APP_PARENT_CONTEXT__;
|
|
1757
|
+
if (c_parent) {
|
|
1758
|
+
if (!context.getParent()) context.setParent(c_parent);
|
|
1759
|
+
if (this.hierarchyJoin !== MicroAppAddon.HIERARCHY_JOIN_IGNORE) {
|
|
1760
|
+
const p_voter = c_parent.getVoter();
|
|
1761
|
+
const c_voter = context.getVoter();
|
|
1762
|
+
if (p_voter instanceof HierarchyVoter && c_voter instanceof HierarchyVoter) {
|
|
1763
|
+
const p_relation = p_voter.getRelation();
|
|
1764
|
+
if (this.hierarchyJoin === MicroAppAddon.HIERARCHY_JOIN_MERGE) c_voter.resetResolver((relation)=>`${p_relation};${relation}`);
|
|
1765
|
+
else if (this.hierarchyJoin === MicroAppAddon.HIERARCHY_JOIN_PARENT) c_voter.resetResolver((relation)=>p_relation);
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
const m_parent = window.rawWindow?.__RSR_MICRO_APP_PARENT_MANAGER__;
|
|
1770
|
+
if (m_parent) {
|
|
1771
|
+
if (!manager.getParent()) manager.setParent(m_parent);
|
|
1772
|
+
}
|
|
1773
|
+
this.microJoin = true;
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
const microAppAddon = (basenameJoin = true, hierarchyJoin = MicroAppAddon.HIERARCHY_JOIN_IGNORE)=>new MicroAppAddon(basenameJoin, hierarchyJoin);
|
|
1778
|
+
export { AbstractAddon, common_AccessBehave as AccessBehave, AccessBlockerBuilder, AccessContextBuilder, common_AccessDecision as AccessDecision, AccessGuarderBuilder, AccessHandlerBuilder, AccessManagerBuilder, AccessMatcherBuilder, AccessNavigatorBuilder, AccessRecorderBuilder, AccessResourceBuilder, AccessStorerBuilder, AccessVoterBuilder, BehaveHandler, CacheVoter, HavePermission, HierarchyVoter, MicroAppAddon, MultiBlocker, OriginRelationResolver, SecurityBlocker, SecurityContext, SecurityProvider, SimpleAuthentication, SimpleAuthorization, SimpleContext, SimpleGuarder, SimpleManager, SimpleMatcher, SimpleNavigator, SimpleRecorder, SimpleResource, SimpleStorer, SimpleUser, SimpleVoter, SingleBlocker, microAppAddon, useCustomBlocker, useDeleteAuthentication, useDeleteAuthorization, useDeleteSignature, useHavePermission, useLogin, useLogout, useObtainAuthentication, useObtainAuthorization, usePurgeSignature, useRemoveSignature, useSaveAuthentication, useSaveAuthorization, useSaveSignature, useSecurityBlocker, useSecurityContext, withHavePermission, withSecurityBlocker };
|