@celljs/security 3.8.0 → 4.0.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/cell.yml +13 -7
- package/esm/browser/index.d.ts +1 -0
- package/esm/browser/index.js +2 -0
- package/esm/browser/index.js.map +1 -0
- package/esm/browser/module.d.ts +3 -0
- package/esm/browser/module.js +4 -0
- package/esm/browser/module.js.map +1 -0
- package/esm/browser/user/index.d.ts +2 -0
- package/esm/browser/user/index.js +3 -0
- package/esm/browser/user/index.js.map +1 -0
- package/esm/browser/user/user-manager.d.ts +22 -0
- package/esm/browser/user/user-manager.js +122 -0
- package/esm/browser/user/user-manager.js.map +1 -0
- package/esm/browser/user/user-protocol.d.ts +9 -0
- package/esm/browser/user/user-protocol.js +2 -0
- package/esm/browser/user/user-protocol.js.map +1 -0
- package/esm/common/index.d.ts +1 -0
- package/esm/common/index.js +2 -0
- package/esm/common/index.js.map +1 -0
- package/esm/common/security-protocol.d.ts +59 -0
- package/esm/common/security-protocol.js +30 -0
- package/esm/common/security-protocol.js.map +1 -0
- package/esm/node/access/access-decision-manager.d.ts +8 -0
- package/esm/node/access/access-decision-manager.js +53 -0
- package/esm/node/access/access-decision-manager.js.map +1 -0
- package/esm/node/access/access-decision-utils.d.ts +4 -0
- package/esm/node/access/access-decision-utils.js +20 -0
- package/esm/node/access/access-decision-utils.js.map +1 -0
- package/esm/node/access/access-decision-voter.d.ts +13 -0
- package/esm/node/access/access-decision-voter.js +83 -0
- package/esm/node/access/access-decision-voter.js.map +1 -0
- package/esm/node/access/access-protocol.d.ts +74 -0
- package/esm/node/access/access-protocol.js +17 -0
- package/esm/node/access/access-protocol.js.map +1 -0
- package/esm/node/access/action-name-resolver.d.ts +4 -0
- package/esm/node/access/action-name-resolver.js +27 -0
- package/esm/node/access/action-name-resolver.js.map +1 -0
- package/esm/node/access/index.d.ts +11 -0
- package/esm/node/access/index.js +12 -0
- package/esm/node/access/index.js.map +1 -0
- package/esm/node/access/jexl-engine-provider.d.ts +5 -0
- package/esm/node/access/jexl-engine-provider.js +22 -0
- package/esm/node/access/jexl-engine-provider.js.map +1 -0
- package/esm/node/access/method-advice.d.ts +16 -0
- package/esm/node/access/method-advice.js +78 -0
- package/esm/node/access/method-advice.js.map +1 -0
- package/esm/node/access/policy-provider.d.ts +16 -0
- package/esm/node/access/policy-provider.js +82 -0
- package/esm/node/access/policy-provider.js.map +1 -0
- package/esm/node/access/policy-resolver.d.ts +14 -0
- package/esm/node/access/policy-resolver.js +88 -0
- package/esm/node/access/policy-resolver.js.map +1 -0
- package/esm/node/access/resource-name-resolver.d.ts +6 -0
- package/esm/node/access/resource-name-resolver.js +55 -0
- package/esm/node/access/resource-name-resolver.js.map +1 -0
- package/esm/node/access/security-metadata-source.d.ts +6 -0
- package/esm/node/access/security-metadata-source.js +58 -0
- package/esm/node/access/security-metadata-source.js.map +1 -0
- package/esm/node/annotation/action.d.ts +1 -0
- package/esm/node/annotation/action.js +7 -0
- package/esm/node/annotation/action.js.map +1 -0
- package/esm/node/annotation/anonymous.d.ts +1 -0
- package/esm/node/annotation/anonymous.js +6 -0
- package/esm/node/annotation/anonymous.js.map +1 -0
- package/esm/node/annotation/authenticated.d.ts +1 -0
- package/esm/node/annotation/authenticated.js +6 -0
- package/esm/node/annotation/authenticated.js.map +1 -0
- package/esm/node/annotation/authorize.d.ts +10 -0
- package/esm/node/annotation/authorize.js +35 -0
- package/esm/node/annotation/authorize.js.map +1 -0
- package/esm/node/annotation/index.d.ts +7 -0
- package/esm/node/annotation/index.js +8 -0
- package/esm/node/annotation/index.js.map +1 -0
- package/esm/node/annotation/post-authorize.d.ts +1 -0
- package/esm/node/annotation/post-authorize.js +6 -0
- package/esm/node/annotation/post-authorize.js.map +1 -0
- package/esm/node/annotation/pre-authorize.d.ts +1 -0
- package/esm/node/annotation/pre-authorize.js +6 -0
- package/esm/node/annotation/pre-authorize.js.map +1 -0
- package/esm/node/annotation/resource.d.ts +1 -0
- package/esm/node/annotation/resource.js +12 -0
- package/esm/node/annotation/resource.js.map +1 -0
- package/esm/node/authentication/authentication-manager.d.ts +9 -0
- package/esm/node/authentication/authentication-manager.js +78 -0
- package/esm/node/authentication/authentication-manager.js.map +1 -0
- package/esm/node/authentication/authentication-middleware.d.ts +7 -0
- package/esm/node/authentication/authentication-middleware.js +33 -0
- package/esm/node/authentication/authentication-middleware.js.map +1 -0
- package/esm/node/authentication/authentication-protocol.d.ts +29 -0
- package/esm/node/authentication/authentication-protocol.js +9 -0
- package/esm/node/authentication/authentication-protocol.js.map +1 -0
- package/esm/node/authentication/authentication-provider.d.ts +32 -0
- package/esm/node/authentication/authentication-provider.js +171 -0
- package/esm/node/authentication/authentication-provider.js.map +1 -0
- package/esm/node/authentication/authentication-success-handler.d.ts +15 -0
- package/esm/node/authentication/authentication-success-handler.js +94 -0
- package/esm/node/authentication/authentication-success-handler.js.map +1 -0
- package/esm/node/authentication/index.d.ts +5 -0
- package/esm/node/authentication/index.js +6 -0
- package/esm/node/authentication/index.js.map +1 -0
- package/esm/node/cache/cache-protocol.d.ts +15 -0
- package/esm/node/cache/cache-protocol.js +3 -0
- package/esm/node/cache/cache-protocol.js.map +1 -0
- package/esm/node/cache/index.d.ts +2 -0
- package/esm/node/cache/index.js +3 -0
- package/esm/node/cache/index.js.map +1 -0
- package/esm/node/cache/request-cache.d.ts +9 -0
- package/esm/node/cache/request-cache.js +49 -0
- package/esm/node/cache/request-cache.js.map +1 -0
- package/esm/node/constants.d.ts +5 -0
- package/esm/node/constants.js +6 -0
- package/esm/node/constants.js.map +1 -0
- package/esm/node/context/context-protocol.d.ts +21 -0
- package/esm/node/context/context-protocol.js +27 -0
- package/esm/node/context/context-protocol.js.map +1 -0
- package/esm/node/context/index.d.ts +4 -0
- package/esm/node/context/index.js +5 -0
- package/esm/node/context/index.js.map +1 -0
- package/esm/node/context/security-context-middleware.d.ts +8 -0
- package/esm/node/context/security-context-middleware.js +41 -0
- package/esm/node/context/security-context-middleware.js.map +1 -0
- package/esm/node/context/security-context-store.d.ts +7 -0
- package/esm/node/context/security-context-store.js +37 -0
- package/esm/node/context/security-context-store.js.map +1 -0
- package/esm/node/context/security-context-strategy.d.ts +8 -0
- package/esm/node/context/security-context-strategy.js +28 -0
- package/esm/node/context/security-context-strategy.js.map +1 -0
- package/esm/node/crypto/index.d.ts +2 -0
- package/esm/node/crypto/index.js +3 -0
- package/esm/node/crypto/index.js.map +1 -0
- package/esm/node/crypto/keygen/base64-string-key-generator.d.ts +5 -0
- package/esm/node/crypto/keygen/base64-string-key-generator.js +28 -0
- package/esm/node/crypto/keygen/base64-string-key-generator.js.map +1 -0
- package/esm/node/crypto/keygen/index.d.ts +2 -0
- package/esm/node/crypto/keygen/index.js +3 -0
- package/esm/node/crypto/keygen/index.js.map +1 -0
- package/esm/node/crypto/keygen/keygen-protocol.d.ts +4 -0
- package/esm/node/crypto/keygen/keygen-protocol.js +2 -0
- package/esm/node/crypto/keygen/keygen-protocol.js.map +1 -0
- package/esm/node/crypto/password/index.d.ts +2 -0
- package/esm/node/crypto/password/index.js +3 -0
- package/esm/node/crypto/password/index.js.map +1 -0
- package/esm/node/crypto/password/password-encoder.d.ts +8 -0
- package/esm/node/crypto/password/password-encoder.js +49 -0
- package/esm/node/crypto/password/password-encoder.js.map +1 -0
- package/esm/node/crypto/password/password-protocol.d.ts +5 -0
- package/esm/node/crypto/password/password-protocol.js +2 -0
- package/esm/node/crypto/password/password-protocol.js.map +1 -0
- package/esm/node/error/error-handler.d.ts +18 -0
- package/esm/node/error/error-handler.js +78 -0
- package/esm/node/error/error-handler.js.map +1 -0
- package/esm/node/error/error-protocol.d.ts +2 -0
- package/esm/node/error/error-protocol.js +4 -0
- package/esm/node/error/error-protocol.js.map +1 -0
- package/esm/node/error/error.d.ts +20 -0
- package/esm/node/error/error.js +23 -0
- package/esm/node/error/error.js.map +1 -0
- package/esm/node/error/index.d.ts +3 -0
- package/esm/node/error/index.js +4 -0
- package/esm/node/error/index.js.map +1 -0
- package/esm/node/index.d.ts +10 -0
- package/esm/node/index.js +11 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/logout/index.d.ts +4 -0
- package/esm/node/logout/index.js +5 -0
- package/esm/node/logout/index.js.map +1 -0
- package/esm/node/logout/logout-handler.d.ts +4 -0
- package/esm/node/logout/logout-handler.js +19 -0
- package/esm/node/logout/logout-handler.js.map +1 -0
- package/esm/node/logout/logout-middleware.d.ts +15 -0
- package/esm/node/logout/logout-middleware.js +63 -0
- package/esm/node/logout/logout-middleware.js.map +1 -0
- package/esm/node/logout/logout-protocol.d.ts +11 -0
- package/esm/node/logout/logout-protocol.js +6 -0
- package/esm/node/logout/logout-protocol.js.map +1 -0
- package/esm/node/logout/logout-success-handler-provider.d.ts +7 -0
- package/esm/node/logout/logout-success-handler-provider.js +32 -0
- package/esm/node/logout/logout-success-handler-provider.js.map +1 -0
- package/esm/node/logout/logout-success-handler.d.ts +8 -0
- package/esm/node/logout/logout-success-handler.js +36 -0
- package/esm/node/logout/logout-success-handler.js.map +1 -0
- package/esm/node/module.d.ts +4 -0
- package/esm/node/module.js +5 -0
- package/esm/node/module.js.map +1 -0
- package/esm/node/user/index.d.ts +5 -0
- package/esm/node/user/index.js +6 -0
- package/esm/node/user/index.js.map +1 -0
- package/esm/node/user/user-checker.d.ts +7 -0
- package/esm/node/user/user-checker.js +41 -0
- package/esm/node/user/user-checker.js.map +1 -0
- package/esm/node/user/user-mapper.d.ts +8 -0
- package/esm/node/user/user-mapper.js +37 -0
- package/esm/node/user/user-mapper.js.map +1 -0
- package/esm/node/user/user-middleware.d.ts +10 -0
- package/esm/node/user/user-middleware.js +52 -0
- package/esm/node/user/user-middleware.js.map +1 -0
- package/esm/node/user/user-protocol.d.ts +14 -0
- package/esm/node/user/user-protocol.js +6 -0
- package/esm/node/user/user-protocol.js.map +1 -0
- package/esm/node/user/user-service.d.ts +6 -0
- package/esm/node/user/user-service.js +39 -0
- package/esm/node/user/user-service.js.map +1 -0
- package/esm/package.json +3 -0
- package/package.json +93 -6
package/cell.yml
CHANGED
|
@@ -5,7 +5,6 @@ cell:
|
|
|
5
5
|
openNewWindow: false
|
|
6
6
|
usernameKey: username
|
|
7
7
|
passwordKey: password
|
|
8
|
-
loginPage: ${ '/login' | onTarget('backend') || '/login?${cell.security.targetUrlParameter}={redirect}'}
|
|
9
8
|
loginUrl: /login
|
|
10
9
|
loginMethod: POST
|
|
11
10
|
loginSuccessUrl: /
|
|
@@ -15,12 +14,7 @@ cell:
|
|
|
15
14
|
alwaysUseDefaultTargetUrl: false
|
|
16
15
|
useReferer: false
|
|
17
16
|
targetUrlParameter: redirect
|
|
18
|
-
base64StringKeyLength: ${ 32 | onTarget('backend')}
|
|
19
17
|
contextKey: cell:securityContext
|
|
20
|
-
username: ${ 'admin' | onTarget('backend')}
|
|
21
|
-
password: ${ 'MzQ0NTg4ZTk2NzQyYWI1ODA1MDFlNDBjMzZhZDY4OWQ1Zjc5ZDYxYzc2MjQ1NWZk' | onTarget('backend')} # raw password 123456
|
|
22
|
-
passwordEncoder:
|
|
23
|
-
encodeHashAsBase64: ${ true | onTarget('backend')}
|
|
24
18
|
basic:
|
|
25
19
|
enabled: false
|
|
26
20
|
realm: realm
|
|
@@ -33,4 +27,16 @@ cell:
|
|
|
33
27
|
email: email
|
|
34
28
|
login: login
|
|
35
29
|
nickname: login
|
|
36
|
-
|
|
30
|
+
frontend:
|
|
31
|
+
cell:
|
|
32
|
+
security:
|
|
33
|
+
loginPage: /login?${cell.security.targetUrlParameter}={redirect}
|
|
34
|
+
backend:
|
|
35
|
+
cell:
|
|
36
|
+
security:
|
|
37
|
+
loginPage: /login
|
|
38
|
+
base64StringKeyLength: 32
|
|
39
|
+
username: admin
|
|
40
|
+
password: MzQ0NTg4ZTk2NzQyYWI1ODA1MDFlNDBjMzZhZDY4OWQ1Zjc5ZDYxYzc2MjQ1NWZk # raw password 123456
|
|
41
|
+
passwordEncoder:
|
|
42
|
+
encodeHashAsBase64: true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './user/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/browser/module.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,eAAe,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/browser/user/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { UserManager } from './user-protocol.js';
|
|
2
|
+
import { RestOperations, HttpMethod } from '@celljs/http';
|
|
3
|
+
import { PathResolver } from '@celljs/web';
|
|
4
|
+
import { BehaviorSubject } from 'rxjs';
|
|
5
|
+
import { User } from '../../common/index.js';
|
|
6
|
+
export declare class UserManagerImpl implements UserManager {
|
|
7
|
+
protected readonly loginUserInfoStorageKey = "cell:loginUserInfo";
|
|
8
|
+
protected readonly loginPage: string;
|
|
9
|
+
protected readonly openNewWindow: boolean;
|
|
10
|
+
protected readonly logoutUrl: string;
|
|
11
|
+
protected readonly logoutSuccessUrl: string;
|
|
12
|
+
protected readonly logoutMethod: HttpMethod;
|
|
13
|
+
protected readonly userInfoEndpoint: any;
|
|
14
|
+
protected readonly loginRequired: boolean;
|
|
15
|
+
protected restOperations: RestOperations;
|
|
16
|
+
protected readonly pathResolver: PathResolver;
|
|
17
|
+
userInfoSubject: BehaviorSubject<User | undefined>;
|
|
18
|
+
protected init(): void;
|
|
19
|
+
openLoginPage(newWindow?: boolean): Promise<void>;
|
|
20
|
+
logout(): Promise<void>;
|
|
21
|
+
getUserInfo(): Promise<User | undefined>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { UserManager } from './user-protocol.js';
|
|
11
|
+
import { Autowired, Component, Value, PostConstruct } from '@celljs/core';
|
|
12
|
+
import { RestOperations, HttpMethod, HttpStatus, HttpHeaders } from '@celljs/http';
|
|
13
|
+
import { PathResolver } from '@celljs/web';
|
|
14
|
+
import { BehaviorSubject } from 'rxjs';
|
|
15
|
+
let UserManagerImpl = class UserManagerImpl {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.loginUserInfoStorageKey = 'cell:loginUserInfo';
|
|
18
|
+
this.userInfoSubject = new BehaviorSubject(undefined);
|
|
19
|
+
}
|
|
20
|
+
init() {
|
|
21
|
+
this.restOperations.interceptors.response.use(response => response, error => {
|
|
22
|
+
if (error.response) {
|
|
23
|
+
if (error.response.status === HttpStatus.UNAUTHORIZED && !error.response.headers[HttpHeaders.WWW_AUTHENTICATE.toLowerCase()]) {
|
|
24
|
+
this.openLoginPage();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return Promise.reject(error);
|
|
29
|
+
});
|
|
30
|
+
this.userInfoSubject.subscribe(user => {
|
|
31
|
+
if (user) {
|
|
32
|
+
localStorage.setItem(this.loginUserInfoStorageKey, JSON.stringify(user));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
localStorage.removeItem(this.loginUserInfoStorageKey);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const userStr = localStorage.getItem(this.loginUserInfoStorageKey);
|
|
39
|
+
if (userStr) {
|
|
40
|
+
this.userInfoSubject.next(JSON.parse(userStr));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.getUserInfo().then(() => {
|
|
44
|
+
if (this.loginRequired) {
|
|
45
|
+
this.openLoginPage();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async openLoginPage(newWindow) {
|
|
51
|
+
if (newWindow === undefined) {
|
|
52
|
+
newWindow = this.openNewWindow;
|
|
53
|
+
}
|
|
54
|
+
this.userInfoSubject.next(undefined);
|
|
55
|
+
const url = await this.pathResolver.resolve(this.loginPage.replace(/{redirect}/g, encodeURI(window.location.href)));
|
|
56
|
+
if (newWindow) {
|
|
57
|
+
window.open(url);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
window.location.href = url;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async logout() {
|
|
64
|
+
this.userInfoSubject.next(undefined);
|
|
65
|
+
const method = (this.logoutMethod || HttpMethod.POST);
|
|
66
|
+
await this.restOperations.request({ url: this.logoutUrl, method });
|
|
67
|
+
window.location.href = await this.pathResolver.resolve(this.logoutSuccessUrl.replace(/{redirect}/g, encodeURI(window.location.href)));
|
|
68
|
+
}
|
|
69
|
+
async getUserInfo() {
|
|
70
|
+
const { url, method } = this.userInfoEndpoint;
|
|
71
|
+
const { data } = await this.restOperations.request({ url: await this.pathResolver.resolve(url), method });
|
|
72
|
+
this.userInfoSubject.next(data);
|
|
73
|
+
return data;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
__decorate([
|
|
77
|
+
Value('cell.security.loginPage'),
|
|
78
|
+
__metadata("design:type", String)
|
|
79
|
+
], UserManagerImpl.prototype, "loginPage", void 0);
|
|
80
|
+
__decorate([
|
|
81
|
+
Value('cell.security.openNewWindow'),
|
|
82
|
+
__metadata("design:type", Boolean)
|
|
83
|
+
], UserManagerImpl.prototype, "openNewWindow", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
Value('cell.security.logoutUrl'),
|
|
86
|
+
__metadata("design:type", String)
|
|
87
|
+
], UserManagerImpl.prototype, "logoutUrl", void 0);
|
|
88
|
+
__decorate([
|
|
89
|
+
Value('cell.security.logoutSuccessUrl'),
|
|
90
|
+
__metadata("design:type", String)
|
|
91
|
+
], UserManagerImpl.prototype, "logoutSuccessUrl", void 0);
|
|
92
|
+
__decorate([
|
|
93
|
+
Value('cell.security.logoutMethod'),
|
|
94
|
+
__metadata("design:type", String)
|
|
95
|
+
], UserManagerImpl.prototype, "logoutMethod", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
Value('cell.security.userInfoEndpoint'),
|
|
98
|
+
__metadata("design:type", Object)
|
|
99
|
+
], UserManagerImpl.prototype, "userInfoEndpoint", void 0);
|
|
100
|
+
__decorate([
|
|
101
|
+
Value('cell.security.loginRequired'),
|
|
102
|
+
__metadata("design:type", Boolean)
|
|
103
|
+
], UserManagerImpl.prototype, "loginRequired", void 0);
|
|
104
|
+
__decorate([
|
|
105
|
+
Autowired(RestOperations),
|
|
106
|
+
__metadata("design:type", Function)
|
|
107
|
+
], UserManagerImpl.prototype, "restOperations", void 0);
|
|
108
|
+
__decorate([
|
|
109
|
+
Autowired(PathResolver),
|
|
110
|
+
__metadata("design:type", Object)
|
|
111
|
+
], UserManagerImpl.prototype, "pathResolver", void 0);
|
|
112
|
+
__decorate([
|
|
113
|
+
PostConstruct(),
|
|
114
|
+
__metadata("design:type", Function),
|
|
115
|
+
__metadata("design:paramtypes", []),
|
|
116
|
+
__metadata("design:returntype", void 0)
|
|
117
|
+
], UserManagerImpl.prototype, "init", null);
|
|
118
|
+
UserManagerImpl = __decorate([
|
|
119
|
+
Component(UserManager)
|
|
120
|
+
], UserManagerImpl);
|
|
121
|
+
export { UserManagerImpl };
|
|
122
|
+
//# sourceMappingURL=user-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-manager.js","sourceRoot":"","sources":["../../../src/browser/user/user-manager.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAIhC,IAAM,eAAe,GAArB,MAAM,eAAe;IAArB;QAEgB,4BAAuB,GAAG,oBAAoB,CAAC;QA6BlE,oBAAe,GAAsC,IAAI,eAAe,CAAmB,SAAS,CAAC,CAAC;IA8D1G,CAAC;IA3Da,IAAI;QAEV,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE;YACxE,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACjB,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC,YAAY,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;oBAC3H,IAAI,CAAC,aAAa,EAAE,CAAC;oBACrB,OAAO;gBACX,CAAC;YACL,CAAC;YACD,OAAO,OAAO,CAAC,MAAM,CA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Q;AAGzB;IADlB,KAAK,CAAC,gCAAgC,CAAC;;yDACC;AAGtB;IADlB,KAAK,CAAC,6BAA6B,CAAC;;sDACK;AAGhC;IADT,SAAS,CAAC,cAAc,CAAC;;uDACe;AAGtB;IADlB,SAAS,CAAC,YAAY,CAAC;;qDACsB;AAKpC;IADT,aAAa,EAAE;;;;2CA+Bf;AAhEQ,eAAe;IAD3B,SAAS,CAAC,WAAW,CAAC;GACV,eAAe,CA6F3B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { User } from '../../common/index.js';
|
|
2
|
+
import { BehaviorSubject } from 'rxjs';
|
|
3
|
+
export declare const UserManager: unique symbol;
|
|
4
|
+
export interface UserManager {
|
|
5
|
+
openLoginPage(newWindow?: boolean): Promise<void>;
|
|
6
|
+
logout(): Promise<void>;
|
|
7
|
+
getUserInfo(): Promise<User | undefined>;
|
|
8
|
+
userInfoSubject: BehaviorSubject<User | undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-protocol.js","sourceRoot":"","sources":["../../../src/browser/user/user-protocol.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './security-protocol.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare enum AuthorizeType {
|
|
2
|
+
Pre = "Pre",
|
|
3
|
+
Post = "Post"
|
|
4
|
+
}
|
|
5
|
+
export declare enum PolicyType {
|
|
6
|
+
el = "el",
|
|
7
|
+
acl = "Acl"
|
|
8
|
+
}
|
|
9
|
+
export interface Policy {
|
|
10
|
+
type: PolicyType | string;
|
|
11
|
+
authorizeType: AuthorizeType;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
export interface ElPolicy extends Policy {
|
|
15
|
+
context: any;
|
|
16
|
+
el: string;
|
|
17
|
+
}
|
|
18
|
+
export declare enum Effect {
|
|
19
|
+
Allow = "Allow",
|
|
20
|
+
Deny = "Deny"
|
|
21
|
+
}
|
|
22
|
+
export interface Statement {
|
|
23
|
+
effect: Effect;
|
|
24
|
+
action: string | string[];
|
|
25
|
+
resource: string | string[];
|
|
26
|
+
condition: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface AclPolicy extends Policy {
|
|
31
|
+
version?: string;
|
|
32
|
+
statement: Statement[];
|
|
33
|
+
}
|
|
34
|
+
export declare enum UserType {
|
|
35
|
+
Memery = "memory",
|
|
36
|
+
Database = "database"
|
|
37
|
+
}
|
|
38
|
+
export interface User {
|
|
39
|
+
type: string;
|
|
40
|
+
username: string;
|
|
41
|
+
password: string;
|
|
42
|
+
policies: Policy[];
|
|
43
|
+
accountNonExpired: boolean;
|
|
44
|
+
accountNonLocked: boolean;
|
|
45
|
+
credentialsNonExpired: boolean;
|
|
46
|
+
enabled: boolean;
|
|
47
|
+
claims?: {
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
};
|
|
50
|
+
[key: string]: any;
|
|
51
|
+
}
|
|
52
|
+
export declare namespace User {
|
|
53
|
+
function is(user: Object | undefined): user is User;
|
|
54
|
+
}
|
|
55
|
+
export interface UserMapperRule {
|
|
56
|
+
avatar: string;
|
|
57
|
+
nickname: string;
|
|
58
|
+
[key: string]: any;
|
|
59
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export var AuthorizeType;
|
|
2
|
+
(function (AuthorizeType) {
|
|
3
|
+
AuthorizeType["Pre"] = "Pre";
|
|
4
|
+
AuthorizeType["Post"] = "Post";
|
|
5
|
+
})(AuthorizeType || (AuthorizeType = {}));
|
|
6
|
+
export var PolicyType;
|
|
7
|
+
(function (PolicyType) {
|
|
8
|
+
PolicyType["el"] = "el";
|
|
9
|
+
PolicyType["acl"] = "Acl";
|
|
10
|
+
})(PolicyType || (PolicyType = {}));
|
|
11
|
+
export var Effect;
|
|
12
|
+
(function (Effect) {
|
|
13
|
+
Effect["Allow"] = "Allow";
|
|
14
|
+
Effect["Deny"] = "Deny";
|
|
15
|
+
})(Effect || (Effect = {}));
|
|
16
|
+
export var UserType;
|
|
17
|
+
(function (UserType) {
|
|
18
|
+
UserType["Memery"] = "memory";
|
|
19
|
+
UserType["Database"] = "database";
|
|
20
|
+
})(UserType || (UserType = {}));
|
|
21
|
+
export var User;
|
|
22
|
+
(function (User) {
|
|
23
|
+
function is(user) {
|
|
24
|
+
return !!user && 'type' in user && 'username' in user && 'password' in user &&
|
|
25
|
+
'policies' in user && 'accountNonExpired' in user && 'accountNonLocked' in user &&
|
|
26
|
+
'credentialsNonExpired' in user && 'enabled' in user;
|
|
27
|
+
}
|
|
28
|
+
User.is = is;
|
|
29
|
+
})(User || (User = {}));
|
|
30
|
+
//# sourceMappingURL=security-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-protocol.js","sourceRoot":"","sources":["../../src/common/security-protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,aAEX;AAFD,WAAY,aAAa;IACrB,4BAAU,CAAA;IAAE,8BAAY,CAAA;AAC5B,CAAC,EAFW,aAAa,KAAb,aAAa,QAExB;AAED,MAAM,CAAN,IAAY,UAEX;AAFD,WAAY,UAAU;IAClB,uBAAQ,CAAA;IAAE,yBAAU,CAAA;AACxB,CAAC,EAFW,UAAU,KAAV,UAAU,QAErB;AAaD,MAAM,CAAN,IAAY,MAEX;AAFD,WAAY,MAAM;IACd,yBAAc,CAAA;IAAE,uBAAY,CAAA;AAChC,CAAC,EAFW,MAAM,KAAN,MAAM,QAEjB;AAcD,MAAM,CAAN,IAAY,QAEX;AAFD,WAAY,QAAQ;IAChB,6BAAiB,CAAA;IAAE,iCAAqB,CAAA;AAC5C,CAAC,EAFW,QAAQ,KAAR,QAAQ,QAEnB;AAeD,MAAM,KAAW,IAAI,CAMpB;AAND,WAAiB,IAAI;IACjB,SAAgB,EAAE,CAAC,IAAwB;QACvC,OAAO,CAAC,CAAC,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU,IAAI,IAAI;YACvE,UAAU,IAAI,IAAI,IAAI,mBAAmB,IAAI,IAAI,IAAI,kBAAkB,IAAI,IAAI;YAC/E,uBAAuB,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI,CAAC;IAC7D,CAAC;IAJe,KAAA,EAAE,KAIjB,CAAA;AACL,CAAC,EANgB,IAAI,KAAJ,IAAI,QAMpB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AccessDecisionManager, SecurityMetadata, AccessDecisionVoter } from './access-protocol.js';
|
|
2
|
+
export declare class AccessDecisionManagerImpl implements AccessDecisionManager {
|
|
3
|
+
protected readonly accessDecisionVoters: AccessDecisionVoter[];
|
|
4
|
+
protected prioritized: AccessDecisionVoter[];
|
|
5
|
+
constructor(accessDecisionVoters: AccessDecisionVoter[]);
|
|
6
|
+
decide(securityMetadata: SecurityMetadata): Promise<void>;
|
|
7
|
+
protected handleError(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { AccessDecisionManager, AccessDecisionVoter, ACCESS_DENIED, ACCESS_GRANTED } from './access-protocol.js';
|
|
14
|
+
import { Component, Prioritizeable, Autowired } from '@celljs/core';
|
|
15
|
+
import { AccessDeniedError, AuthenticationError } from '../error/index.js';
|
|
16
|
+
import { SecurityContext } from '../context/index.js';
|
|
17
|
+
import { HttpStatus } from '@celljs/http';
|
|
18
|
+
let AccessDecisionManagerImpl = class AccessDecisionManagerImpl {
|
|
19
|
+
constructor(accessDecisionVoters) {
|
|
20
|
+
this.accessDecisionVoters = accessDecisionVoters;
|
|
21
|
+
this.prioritized = Prioritizeable.prioritizeAllSync(this.accessDecisionVoters).map(c => c.value);
|
|
22
|
+
}
|
|
23
|
+
async decide(securityMetadata) {
|
|
24
|
+
let grant = 0;
|
|
25
|
+
for (const voter of this.prioritized) {
|
|
26
|
+
if (await voter.support(securityMetadata)) {
|
|
27
|
+
const result = await voter.vote(securityMetadata);
|
|
28
|
+
if (result === ACCESS_DENIED) {
|
|
29
|
+
this.handleError();
|
|
30
|
+
}
|
|
31
|
+
else if (result === ACCESS_GRANTED) {
|
|
32
|
+
grant++;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (grant <= 0) {
|
|
37
|
+
this.handleError();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
handleError() {
|
|
41
|
+
if (SecurityContext.getAuthentication().authenticated) {
|
|
42
|
+
throw new AccessDeniedError(HttpStatus.FORBIDDEN_REASON_PHRASE);
|
|
43
|
+
}
|
|
44
|
+
throw new AuthenticationError(HttpStatus.UNAUTHORIZED_REASON_PHRASE);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
AccessDecisionManagerImpl = __decorate([
|
|
48
|
+
Component(AccessDecisionManager),
|
|
49
|
+
__param(0, Autowired(AccessDecisionVoter)),
|
|
50
|
+
__metadata("design:paramtypes", [Array])
|
|
51
|
+
], AccessDecisionManagerImpl);
|
|
52
|
+
export { AccessDecisionManagerImpl };
|
|
53
|
+
//# sourceMappingURL=access-decision-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-decision-manager.js","sourceRoot":"","sources":["../../../src/node/access/access-decision-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,qBAAqB,EAAoB,mBAAmB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAChI,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAGnC,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAIlC,YAEuB,oBAA2C;oCAA3C,oBAAoB;QAEvC,IAAI,CAAC,WAAW,GAAG,cAAc,CAAC,iBAAiB,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACrG,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,gBAAkC;QAC3C,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnC,IAAI,MAAM,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;gBACxC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;gBAClD,IAAI,MAAM,KAAK,aAAa,EAAE,CAAC;oBAC3B,IAAI,CAAC,WAAW,EAAE,CAAC;gBACvB,CAAC;qBAAM,IAAI,MAAM,KAAK,cAAc,EAAE,CAAC;oBACnC,KAAK,EAAE,CAAC;gBACZ,CAAC;YACL,CAAC;QACL,CAAC;QACD,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACb,IAAI,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACL,CAAC;IAES,WAAW;QACjB,IAAI,eAAe,CAAC,iBAAiB,EAAE,CAAC,aAAa,EAAE,CAAC;YACpD,MAAM,IAAI,iBAAiB,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC;QACpE,CAAC;QACD,MAAM,IAAI,mBAAmB,CAAC,UAAU,CAAC,0BAA0B,CAAC,CAAC;IACzE,CAAC;CAEJ,CAAA;AAnCY,yBAAyB;IADrC,SAAS,CAAC,qBAAqB,CAAC;IAMxB,WAAA,SAAS,CAAC,mBAAmB,CAAC,CAAA;;GAL1B,yBAAyB,CAmCrC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ContainerUtil } from '@celljs/core';
|
|
2
|
+
import { AuthorizeType } from '../../common/index.js';
|
|
3
|
+
import { SecurityContext } from '../context/index.js';
|
|
4
|
+
import { AccessDecisionManager } from './access-protocol.js';
|
|
5
|
+
export var AccessDecisionUtils;
|
|
6
|
+
(function (AccessDecisionUtils) {
|
|
7
|
+
function decide(resource, action, policies = [], principal) {
|
|
8
|
+
const accessDecisionManager = ContainerUtil.get(AccessDecisionManager);
|
|
9
|
+
return accessDecisionManager.decide({
|
|
10
|
+
authorizeType: AuthorizeType.Pre,
|
|
11
|
+
action,
|
|
12
|
+
resource,
|
|
13
|
+
principal: principal || SecurityContext.getAuthentication().principal,
|
|
14
|
+
policies,
|
|
15
|
+
grant: 0
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
AccessDecisionUtils.decide = decide;
|
|
19
|
+
})(AccessDecisionUtils || (AccessDecisionUtils = {}));
|
|
20
|
+
//# sourceMappingURL=access-decision-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-decision-utils.js","sourceRoot":"","sources":["../../../src/node/access/access-decision-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAU,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,MAAM,KAAW,mBAAmB,CAYnC;AAZD,WAAiB,mBAAmB;IAChC,SAAgB,MAAM,CAAC,QAAgB,EAAE,MAAc,EAAE,QAAQ,GAAa,EAAE,EAAE,SAAe;QAC7F,MAAM,qBAAqB,GAAG,aAAa,CAAC,GAAG,CAAwB,qBAAqB,CAAC,CAAC;QAC9F,OAAO,qBAAqB,CAAC,MAAM,CAAC;YAChC,aAAa,EAAE,aAAa,CAAC,GAAG;YAChC,MAAM;YACN,QAAQ;YACR,SAAS,EAAE,SAAS,IAAI,eAAe,CAAC,iBAAiB,EAAE,CAAC,SAAS;YACrE,QAAQ;YACR,KAAK,EAAE,CAAC;SACX,CAAC,CAAC;IACP,CAAC;IAVe,oBAAA,MAAM,SAUrB,CAAA;AACL,CAAC,EAZgB,mBAAmB,KAAnB,mBAAmB,QAYnC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SecurityMetadata, AccessDecisionVoter, PolicyResolver, PolicyProvider } from './access-protocol.js';
|
|
2
|
+
export declare class PolicyBasedVoter implements AccessDecisionVoter {
|
|
3
|
+
readonly priority: number;
|
|
4
|
+
protected readonly policyResolvers: PolicyResolver[];
|
|
5
|
+
protected readonly policyProviders: PolicyProvider[];
|
|
6
|
+
vote(securityMetadata: SecurityMetadata): Promise<number>;
|
|
7
|
+
support(securityMetadata: SecurityMetadata): Promise<boolean>;
|
|
8
|
+
}
|
|
9
|
+
export declare class TenantVoter implements AccessDecisionVoter {
|
|
10
|
+
readonly priority = 2000;
|
|
11
|
+
vote(securityMetadata: SecurityMetadata): Promise<number>;
|
|
12
|
+
support(securityMetadata: SecurityMetadata): Promise<boolean>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { AccessDecisionVoter, ACCESS_DENIED, ACCESS_GRANTED, ACCESS_ABSTAIN, POLICY_BASED_VOTER_PRIORITY, PolicyResolver, PolicyProvider, TENANT_VOTER_PRIORITY } from './access-protocol.js';
|
|
11
|
+
import { Component, Autowired } from '@celljs/core';
|
|
12
|
+
import { Context } from '@celljs/web/lib/node';
|
|
13
|
+
import { SecurityContext } from '../context/index.js';
|
|
14
|
+
let PolicyBasedVoter = class PolicyBasedVoter {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.priority = POLICY_BASED_VOTER_PRIORITY;
|
|
17
|
+
}
|
|
18
|
+
async vote(securityMetadata) {
|
|
19
|
+
const policies = [...securityMetadata.policies];
|
|
20
|
+
const ctx = {
|
|
21
|
+
resource: securityMetadata.resource,
|
|
22
|
+
principal: securityMetadata.principal,
|
|
23
|
+
type: securityMetadata.authorizeType
|
|
24
|
+
};
|
|
25
|
+
for (const policyProvider of this.policyProviders) {
|
|
26
|
+
policies.push(...await policyProvider.provide(ctx));
|
|
27
|
+
}
|
|
28
|
+
for (const policy of policies) {
|
|
29
|
+
for (const policyResolver of this.policyResolvers) {
|
|
30
|
+
if (await policyResolver.support(policy, securityMetadata)) {
|
|
31
|
+
const result = await policyResolver.resolve(policy, securityMetadata);
|
|
32
|
+
if (result === ACCESS_GRANTED) {
|
|
33
|
+
securityMetadata.grant++;
|
|
34
|
+
}
|
|
35
|
+
else if (result === ACCESS_DENIED) {
|
|
36
|
+
return ACCESS_DENIED;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (securityMetadata.grant > 0) {
|
|
42
|
+
return ACCESS_GRANTED;
|
|
43
|
+
}
|
|
44
|
+
if (securityMetadata.grant === 0) {
|
|
45
|
+
return ACCESS_ABSTAIN;
|
|
46
|
+
}
|
|
47
|
+
return ACCESS_DENIED;
|
|
48
|
+
}
|
|
49
|
+
async support(securityMetadata) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
__decorate([
|
|
54
|
+
Autowired(PolicyResolver),
|
|
55
|
+
__metadata("design:type", Array)
|
|
56
|
+
], PolicyBasedVoter.prototype, "policyResolvers", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
Autowired(PolicyProvider),
|
|
59
|
+
__metadata("design:type", Array)
|
|
60
|
+
], PolicyBasedVoter.prototype, "policyProviders", void 0);
|
|
61
|
+
PolicyBasedVoter = __decorate([
|
|
62
|
+
Component(AccessDecisionVoter)
|
|
63
|
+
], PolicyBasedVoter);
|
|
64
|
+
export { PolicyBasedVoter };
|
|
65
|
+
let TenantVoter = class TenantVoter {
|
|
66
|
+
constructor() {
|
|
67
|
+
this.priority = TENANT_VOTER_PRIORITY;
|
|
68
|
+
}
|
|
69
|
+
async vote(securityMetadata) {
|
|
70
|
+
if (Context.getTenant() === SecurityContext.getAuthentication().name) {
|
|
71
|
+
return ACCESS_GRANTED;
|
|
72
|
+
}
|
|
73
|
+
return ACCESS_ABSTAIN;
|
|
74
|
+
}
|
|
75
|
+
async support(securityMetadata) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
TenantVoter = __decorate([
|
|
80
|
+
Component(AccessDecisionVoter)
|
|
81
|
+
], TenantVoter);
|
|
82
|
+
export { TenantVoter };
|
|
83
|
+
//# sourceMappingURL=access-decision-voter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-decision-voter.js","sourceRoot":"","sources":["../../../src/node/access/access-decision-voter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAoB,mBAAmB,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EACzF,2BAA2B,EAAE,cAAc,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAClH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGtC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAAtB;QAEM,aAAQ,GAAG,2BAA2B,CAAC;IA6CpD,CAAC;IArCG,KAAK,CAAC,IAAI,CAAC,gBAAkC;QACzC,MAAM,QAAQ,GAAG,CAAE,GAAG,gBAAgB,CAAC,QAAQ,CAAE,CAAC;QAClD,MAAM,GAAG,GAAG;YACR,QAAQ,EAAE,gBAAgB,CAAC,QAAQ;YACnC,SAAS,EAAE,gBAAgB,CAAC,SAAS;YACrC,IAAI,EAAE,gBAAgB,CAAC,aAAa;SACvC,CAAC;QAEF,KAAK,MAAM,cAAc,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAChD,QA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,KAAK,eAAe,CAAC,iBAAiB,EAAE,CAAC,IAAI,EAAE,CAAC;YACnE,OAAO,cAAc,CAAC;QAC1B,CAAC;QACD,OAAO,cAAc,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,gBAAkC;QAC5C,OAAO,IAAI,CAAC;IAChB,CAAC;CAEJ,CAAA;AAfY,WAAW;IADvB,SAAS,CAAC,mBAAmB,CAAC;GAClB,WAAW,CAevB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { AuthorizeType, Policy } from '../../common/index.js';
|
|
2
|
+
export declare const AccessDecisionManager: unique symbol;
|
|
3
|
+
export declare const AccessDecisionVoter: unique symbol;
|
|
4
|
+
export declare const SecurityMetadataSource: unique symbol;
|
|
5
|
+
export declare const PolicyResolver: unique symbol;
|
|
6
|
+
export declare const SecurityExpressionContextHandler: unique symbol;
|
|
7
|
+
export declare const JexlEngineProvider: unique symbol;
|
|
8
|
+
export declare const PolicyProvider: unique symbol;
|
|
9
|
+
export declare const PolicyFactory: unique symbol;
|
|
10
|
+
export declare const ResourceNameResolver: unique symbol;
|
|
11
|
+
export declare const ActionNameResolver: unique symbol;
|
|
12
|
+
export declare const SECURITY_EXPRESSION_CONTEXT_KEY = "SecurityExpressionContext";
|
|
13
|
+
export declare const ACCESS_GRANTED = 1;
|
|
14
|
+
export declare const ACCESS_ABSTAIN = 0;
|
|
15
|
+
export declare const ACCESS_DENIED = -1;
|
|
16
|
+
export declare const TENANT_VOTER_PRIORITY = 2000;
|
|
17
|
+
export declare const POLICY_BASED_VOTER_PRIORITY: number;
|
|
18
|
+
export interface PolicyContext {
|
|
19
|
+
principal: any;
|
|
20
|
+
type: AuthorizeType;
|
|
21
|
+
resource: string;
|
|
22
|
+
}
|
|
23
|
+
export interface PolicyProvider {
|
|
24
|
+
provide(ctx: PolicyContext): Promise<Policy[]>;
|
|
25
|
+
}
|
|
26
|
+
export interface PolicyFactory {
|
|
27
|
+
create(options: any): Promise<Policy>;
|
|
28
|
+
support(options: any): Promise<boolean>;
|
|
29
|
+
}
|
|
30
|
+
export interface PolicyResolver {
|
|
31
|
+
resolve(policy: Policy, securityMetadata: SecurityMetadata): Promise<number>;
|
|
32
|
+
support(policy: Policy, securityMetadata: SecurityMetadata): Promise<boolean>;
|
|
33
|
+
}
|
|
34
|
+
export interface JexlEngineProvider<T> {
|
|
35
|
+
provide(): T;
|
|
36
|
+
}
|
|
37
|
+
export interface SecurityExpressionContextHandler {
|
|
38
|
+
handle(context: any): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export interface SecurityMetadata {
|
|
41
|
+
authorizeType: AuthorizeType;
|
|
42
|
+
action: string;
|
|
43
|
+
resource: string;
|
|
44
|
+
principal: any;
|
|
45
|
+
policies: Policy[];
|
|
46
|
+
grant: number;
|
|
47
|
+
}
|
|
48
|
+
export interface SecurityMetadataContext {
|
|
49
|
+
}
|
|
50
|
+
export interface MethodSecurityMetadataContext extends SecurityMetadataContext {
|
|
51
|
+
grant: number;
|
|
52
|
+
authorizeType: AuthorizeType;
|
|
53
|
+
method: string;
|
|
54
|
+
args: any[];
|
|
55
|
+
target: any;
|
|
56
|
+
returnValue?: any;
|
|
57
|
+
}
|
|
58
|
+
export interface SecurityMetadataSource {
|
|
59
|
+
load(context: SecurityMetadataContext): Promise<SecurityMetadata>;
|
|
60
|
+
}
|
|
61
|
+
export interface AccessDecisionManager {
|
|
62
|
+
decide(securityMetadata: SecurityMetadata): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
export interface AccessDecisionVoter {
|
|
65
|
+
vote(securityMetadata: SecurityMetadata): Promise<number>;
|
|
66
|
+
support(securityMetadata: SecurityMetadata): Promise<boolean>;
|
|
67
|
+
readonly priority: number;
|
|
68
|
+
}
|
|
69
|
+
export interface ResourceNameResolver {
|
|
70
|
+
resolve(ctx: MethodSecurityMetadataContext): Promise<string[]>;
|
|
71
|
+
}
|
|
72
|
+
export interface ActionNameResolver {
|
|
73
|
+
resolve(ctx: MethodSecurityMetadataContext): Promise<string>;
|
|
74
|
+
}
|