@celljs/security 4.0.0 → 4.1.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 +111 -1
- package/cell.yml +1 -2
- package/esm/node/access/access-protocol.d.ts +0 -4
- package/esm/node/access/access-protocol.js +0 -1
- package/esm/node/access/access-protocol.js.map +1 -1
- package/esm/node/access/index.d.ts +0 -1
- package/esm/node/access/index.js +0 -1
- package/esm/node/access/index.js.map +1 -1
- package/esm/node/access/policy-provider.js +2 -2
- package/esm/node/access/policy-resolver.d.ts +2 -1
- package/esm/node/access/policy-resolver.js +4 -4
- package/esm/node/access/policy-resolver.js.map +1 -1
- package/esm/node/access/resource-name-resolver.d.ts +3 -0
- package/esm/node/access/resource-name-resolver.js +10 -5
- package/esm/node/access/resource-name-resolver.js.map +1 -1
- package/esm/node/authentication/authentication-provider.d.ts +8 -0
- package/esm/node/authentication/authentication-provider.js +29 -2
- package/esm/node/authentication/authentication-provider.js.map +1 -1
- package/esm/node/authentication/authentication-success-handler.js +4 -0
- package/esm/node/authentication/authentication-success-handler.js.map +1 -1
- package/esm/node/crypto/keygen/base64-string-key-generator.d.ts +4 -0
- package/esm/node/crypto/keygen/base64-string-key-generator.js +6 -4
- package/esm/node/crypto/keygen/base64-string-key-generator.js.map +1 -1
- package/esm/node/crypto/password/password-encoder.d.ts +40 -3
- package/esm/node/crypto/password/password-encoder.js +80 -24
- package/esm/node/crypto/password/password-encoder.js.map +1 -1
- package/esm/node/crypto/password/password-protocol.d.ts +6 -0
- package/esm/node/module.d.ts +0 -1
- package/esm/node/module.js +0 -1
- package/esm/node/module.js.map +1 -1
- package/esm/node/user/user-protocol.d.ts +5 -0
- package/esm/node/user/user-service.d.ts +14 -0
- package/esm/node/user/user-service.js +33 -2
- package/esm/node/user/user-service.js.map +1 -1
- package/lib/node/access/access-protocol.d.ts +0 -4
- package/lib/node/access/access-protocol.d.ts.map +1 -1
- package/lib/node/access/access-protocol.js +1 -2
- package/lib/node/access/access-protocol.js.map +1 -1
- package/lib/node/access/expression-resolvers.spec.d.ts +2 -0
- package/lib/node/access/expression-resolvers.spec.d.ts.map +1 -0
- package/lib/node/access/expression-resolvers.spec.js +57 -0
- package/lib/node/access/expression-resolvers.spec.js.map +1 -0
- package/lib/node/access/index.d.ts +0 -1
- package/lib/node/access/index.d.ts.map +1 -1
- package/lib/node/access/index.js +0 -1
- package/lib/node/access/index.js.map +1 -1
- package/lib/node/access/policy-resolver.d.ts +2 -1
- package/lib/node/access/policy-resolver.d.ts.map +1 -1
- package/lib/node/access/policy-resolver.js +1 -1
- package/lib/node/access/policy-resolver.js.map +1 -1
- package/lib/node/access/resource-name-resolver.d.ts +3 -0
- package/lib/node/access/resource-name-resolver.d.ts.map +1 -1
- package/lib/node/access/resource-name-resolver.js +9 -3
- package/lib/node/access/resource-name-resolver.js.map +1 -1
- package/lib/node/authentication/authentication-provider.d.ts +8 -0
- package/lib/node/authentication/authentication-provider.d.ts.map +1 -1
- package/lib/node/authentication/authentication-provider.js +29 -1
- package/lib/node/authentication/authentication-provider.js.map +1 -1
- package/lib/node/authentication/authentication-success-handler.d.ts.map +1 -1
- package/lib/node/authentication/authentication-success-handler.js +4 -0
- package/lib/node/authentication/authentication-success-handler.js.map +1 -1
- package/lib/node/authentication/basic-authentication.spec.d.ts +2 -0
- package/lib/node/authentication/basic-authentication.spec.d.ts.map +1 -0
- package/lib/node/authentication/basic-authentication.spec.js +65 -0
- package/lib/node/authentication/basic-authentication.spec.js.map +1 -0
- package/lib/node/crypto/keygen/base64-string-key-generator.d.ts +4 -0
- package/lib/node/crypto/keygen/base64-string-key-generator.d.ts.map +1 -1
- package/lib/node/crypto/keygen/base64-string-key-generator.js +6 -3
- package/lib/node/crypto/keygen/base64-string-key-generator.js.map +1 -1
- package/lib/node/crypto/keygen/base64-string-key-generator.spec.d.ts +2 -0
- package/lib/node/crypto/keygen/base64-string-key-generator.spec.d.ts.map +1 -0
- package/lib/node/crypto/keygen/base64-string-key-generator.spec.js +15 -0
- package/lib/node/crypto/keygen/base64-string-key-generator.spec.js.map +1 -0
- package/lib/node/crypto/password/password-encoder.d.ts +40 -3
- package/lib/node/crypto/password/password-encoder.d.ts.map +1 -1
- package/lib/node/crypto/password/password-encoder.js +80 -23
- package/lib/node/crypto/password/password-encoder.js.map +1 -1
- package/lib/node/crypto/password/password-encoder.spec.d.ts +2 -0
- package/lib/node/crypto/password/password-encoder.spec.d.ts.map +1 -0
- package/lib/node/crypto/password/password-encoder.spec.js +147 -0
- package/lib/node/crypto/password/password-encoder.spec.js.map +1 -0
- package/lib/node/crypto/password/password-protocol.d.ts +6 -0
- package/lib/node/crypto/password/password-protocol.d.ts.map +1 -1
- package/lib/node/module.d.ts +0 -1
- package/lib/node/module.d.ts.map +1 -1
- package/lib/node/module.js +0 -1
- package/lib/node/module.js.map +1 -1
- package/lib/node/user/user-protocol.d.ts +5 -0
- package/lib/node/user/user-protocol.d.ts.map +1 -1
- package/lib/node/user/user-service.d.ts +14 -0
- package/lib/node/user/user-service.d.ts.map +1 -1
- package/lib/node/user/user-service.js +33 -2
- package/lib/node/user/user-service.js.map +1 -1
- package/lib/node/user/user-service.spec.d.ts +2 -0
- package/lib/node/user/user-service.spec.d.ts.map +1 -0
- package/lib/node/user/user-service.spec.js +44 -0
- package/lib/node/user/user-service.spec.js.map +1 -0
- package/package.json +7 -13
- package/src/node/access/access-protocol.ts +0 -5
- package/src/node/access/expression-resolvers.spec.ts +37 -0
- package/src/node/access/index.ts +0 -1
- package/src/node/access/policy-resolver.ts +2 -2
- package/src/node/access/resource-name-resolver.ts +10 -4
- package/src/node/authentication/authentication-provider.ts +26 -2
- package/src/node/authentication/authentication-success-handler.ts +4 -0
- package/src/node/authentication/basic-authentication.spec.ts +68 -0
- package/src/node/crypto/keygen/base64-string-key-generator.spec.ts +13 -0
- package/src/node/crypto/keygen/base64-string-key-generator.ts +6 -3
- package/src/node/crypto/password/password-encoder.spec.ts +162 -0
- package/src/node/crypto/password/password-encoder.ts +99 -21
- package/src/node/crypto/password/password-protocol.ts +6 -0
- package/src/node/module.ts +0 -1
- package/src/node/user/user-protocol.ts +5 -0
- package/src/node/user/user-service.spec.ts +46 -0
- package/src/node/user/user-service.ts +32 -2
- package/esm/node/access/jexl-engine-provider.d.ts +0 -5
- package/esm/node/access/jexl-engine-provider.js +0 -22
- package/esm/node/access/jexl-engine-provider.js.map +0 -1
- package/lib/node/access/jexl-engine-provider.d.ts +0 -6
- package/lib/node/access/jexl-engine-provider.d.ts.map +0 -1
- package/lib/node/access/jexl-engine-provider.js +0 -25
- package/lib/node/access/jexl-engine-provider.js.map +0 -1
- package/src/node/access/jexl-engine-provider.ts +0 -18
|
@@ -7,42 +7,98 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
import
|
|
12
|
-
|
|
10
|
+
var Pbkdf2PasswordEncoder_1;
|
|
11
|
+
import { pbkdf2, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
12
|
+
import { promisify } from 'node:util';
|
|
13
13
|
import { Value, Component } from '@celljs/core';
|
|
14
|
-
|
|
14
|
+
import { PasswordEncoder } from './password-protocol.js';
|
|
15
|
+
const pbkdf2Async = promisify(pbkdf2);
|
|
16
|
+
/**
|
|
17
|
+
* Password hashes with PBKDF2-HMAC-SHA256 on node:crypto, compared in constant time.
|
|
18
|
+
*
|
|
19
|
+
* New hashes: `pbkdf2-sha256$<iterations>$<salt, base64>$<key, base64>` with 600000 iterations, a 16-byte
|
|
20
|
+
* random salt (followed by the UTF-8 bytes of `secret` when one is set) and a 32-byte key.
|
|
21
|
+
*
|
|
22
|
+
* Legacy hashes (no prefix), as the crypto-js 4.2.0 implementation of 4.x stored them, keep matching:
|
|
23
|
+
* optionally base64 of a text that is a 16-character hex salt followed by the hex key; the key is
|
|
24
|
+
* PBKDF2(password, salt + String(secret)) with SHA-256, `iterations` (default 250000) and `keySize` words
|
|
25
|
+
* (default 4). Without a secret the salt text ends in `undefined`, which is how those hashes were made.
|
|
26
|
+
* Hashes made with crypto-js 4.1 or older (SHA-1, 1 iteration) are not supported.
|
|
27
|
+
* {@link needsUpgrade} is true for legacy hashes, so a login replaces them with a new hash.
|
|
28
|
+
*/
|
|
29
|
+
let Pbkdf2PasswordEncoder = Pbkdf2PasswordEncoder_1 = class Pbkdf2PasswordEncoder {
|
|
30
|
+
/** Iterations of new hashes. */
|
|
31
|
+
get iterations() {
|
|
32
|
+
return Pbkdf2PasswordEncoder_1.ITERATIONS;
|
|
33
|
+
}
|
|
15
34
|
async encode(rawPassword) {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
35
|
+
const salt = randomBytes(Pbkdf2PasswordEncoder_1.SALT_BYTES);
|
|
36
|
+
const key = await pbkdf2Async(rawPassword, this.pepper(salt), this.iterations, Pbkdf2PasswordEncoder_1.KEY_BYTES, 'sha256');
|
|
37
|
+
return [Pbkdf2PasswordEncoder_1.PREFIX, this.iterations, salt.toString('base64'), key.toString('base64')].join('$');
|
|
38
|
+
}
|
|
39
|
+
async matches(rawPassword, encodedPassword) {
|
|
40
|
+
if (typeof encodedPassword !== 'string' || typeof rawPassword !== 'string') {
|
|
41
|
+
return false;
|
|
21
42
|
}
|
|
22
|
-
return
|
|
43
|
+
return this.isCurrent(encodedPassword) ? this.matchesCurrent(rawPassword, encodedPassword) : this.matchesLegacy(rawPassword, encodedPassword);
|
|
23
44
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
45
|
+
needsUpgrade(encodedPassword) {
|
|
46
|
+
if (!this.isCurrent(encodedPassword)) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return Number(encodedPassword.split('$')[1]) < this.iterations;
|
|
27
50
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
isCurrent(encodedPassword) {
|
|
52
|
+
return encodedPassword.startsWith(`${Pbkdf2PasswordEncoder_1.PREFIX}$`);
|
|
53
|
+
}
|
|
54
|
+
pepper(salt) {
|
|
55
|
+
var _a;
|
|
56
|
+
const secret = (_a = this.options) === null || _a === void 0 ? void 0 : _a.secret;
|
|
57
|
+
return secret === undefined || secret === null || secret === '' ? salt : Buffer.concat([salt, Buffer.from(String(secret), 'utf8')]);
|
|
58
|
+
}
|
|
59
|
+
async matchesCurrent(rawPassword, encodedPassword) {
|
|
60
|
+
const [, iterationsText, saltText, keyText, ...rest] = encodedPassword.split('$');
|
|
61
|
+
const iterations = Number(iterationsText);
|
|
62
|
+
if (rest.length > 0 || !Number.isSafeInteger(iterations) || iterations < 1 || !saltText || !keyText) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const expected = Buffer.from(keyText, 'base64');
|
|
66
|
+
if (expected.length !== Pbkdf2PasswordEncoder_1.KEY_BYTES) {
|
|
67
|
+
return false;
|
|
37
68
|
}
|
|
38
|
-
|
|
69
|
+
const actual = await pbkdf2Async(rawPassword, this.pepper(Buffer.from(saltText, 'base64')), iterations, Pbkdf2PasswordEncoder_1.KEY_BYTES, 'sha256');
|
|
70
|
+
return timingSafeEqual(actual, expected);
|
|
71
|
+
}
|
|
72
|
+
async matchesLegacy(rawPassword, encodedPassword) {
|
|
73
|
+
var _a;
|
|
74
|
+
const digested = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.encodeHashAsBase64) ? Buffer.from(encodedPassword, 'base64').toString('utf8') : encodedPassword;
|
|
75
|
+
if (digested.length <= Pbkdf2PasswordEncoder_1.LEGACY_SALT_LENGTH) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const expected = Buffer.from(await this.legacyEncode(rawPassword, digested.substring(0, Pbkdf2PasswordEncoder_1.LEGACY_SALT_LENGTH)), 'utf8');
|
|
79
|
+
const actual = Buffer.from(digested, 'utf8');
|
|
80
|
+
return actual.length === expected.length && timingSafeEqual(actual, expected);
|
|
81
|
+
}
|
|
82
|
+
/** The text the crypto-js implementation stored (before the optional base64): salt + hex key. */
|
|
83
|
+
async legacyEncode(rawPassword, salt) {
|
|
84
|
+
var _a;
|
|
85
|
+
const { secret, iterations, keySize } = (_a = this.options) !== null && _a !== void 0 ? _a : {};
|
|
86
|
+
const key = await pbkdf2Async(rawPassword, `${salt}${secret}`, Number(iterations !== null && iterations !== void 0 ? iterations : Pbkdf2PasswordEncoder_1.LEGACY_ITERATIONS), Number(keySize !== null && keySize !== void 0 ? keySize : Pbkdf2PasswordEncoder_1.LEGACY_KEY_SIZE) * 4, 'sha256');
|
|
87
|
+
return salt + key.toString('hex');
|
|
39
88
|
}
|
|
40
89
|
};
|
|
90
|
+
Pbkdf2PasswordEncoder.PREFIX = 'pbkdf2-sha256';
|
|
91
|
+
Pbkdf2PasswordEncoder.ITERATIONS = 600000;
|
|
92
|
+
Pbkdf2PasswordEncoder.SALT_BYTES = 16;
|
|
93
|
+
Pbkdf2PasswordEncoder.KEY_BYTES = 32;
|
|
94
|
+
Pbkdf2PasswordEncoder.LEGACY_ITERATIONS = 250000;
|
|
95
|
+
Pbkdf2PasswordEncoder.LEGACY_KEY_SIZE = 4;
|
|
96
|
+
Pbkdf2PasswordEncoder.LEGACY_SALT_LENGTH = 16;
|
|
41
97
|
__decorate([
|
|
42
98
|
Value('cell.security.passwordEncoder'),
|
|
43
99
|
__metadata("design:type", Object)
|
|
44
100
|
], Pbkdf2PasswordEncoder.prototype, "options", void 0);
|
|
45
|
-
Pbkdf2PasswordEncoder = __decorate([
|
|
101
|
+
Pbkdf2PasswordEncoder = Pbkdf2PasswordEncoder_1 = __decorate([
|
|
46
102
|
Component(PasswordEncoder)
|
|
47
103
|
], Pbkdf2PasswordEncoder);
|
|
48
104
|
export { Pbkdf2PasswordEncoder };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-encoder.js","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-encoder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"password-encoder.js","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-encoder.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAatC;;;;;;;;;;;;GAYG;AAEI,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAc9B,gCAAgC;IAChC,IAAc,UAAU;QACpB,OAAO,wBAAsB,UAAU,CAAC;IAC5C,CAAC;IAEK,AAAN,KAAK,CAAC,MAAM,CAAC,WAAmB;QAC5B,MAAM,IAAI,GAAG,WAAW,CAAC,wBAAsB,UAAU,CAAC,CAAC;QAC3D,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,wBAAsB,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC1H,OAAO,CAAC,wBAAsB,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,WAAmB,EAAE,eAAuB;QACtD,IAAI,OAAO,eAAe,KAAK,QAAQ,I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AQ,EAAE,MAAM,CAAC,CAAC;QAC7C,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,IAAI,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAClF,CAAC;IAED,iGAAiG;IACjF,AAAN,KAAK,CAAC,YAAY,CAAC,WAAmB,EAAE,IAAY;;QAC1D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,SAAG,IAAI,CAAC,OAAO,mCAAI,EAAE,CAAC;QAC3D,MAAM,GAAG,GAAG,MAAM,WAAW,CACzB,WAAW,EACX,GAAG,IAAI,GAAG,MAAM,EAAE,EAClB,MAAM,CAAC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,wBAAsB,iBAAiB,CAAC,EAC7D,MAAM,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,wBAAsB,eAAe,CAAC,GAAG,CAAC,EAC5D,QAAQ,CACX,CAAC;QACF,OAAO,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;CACJ,CAAA;AAlFmB,4BAAM,GAAG,eAAe,AAAlB,CAAmB;AACzB,gCAAU,GAAG,MAAM,AAAT,CAAU;AACpB,gCAAU,GAAG,EAAE,AAAL,CAAM;AAChB,+BAAS,GAAG,EAAE,AAAL,CAAM;AAEf,uCAAiB,GAAG,MAAM,AAAT,CAAU;AAC3B,qCAAe,GAAG,CAAC,AAAJ,CAAK;AACpB,wCAAkB,GAAG,EAAE,AAAL,CAAM;AAGrB;IADlB,KAAK,CAAC,+BAA+B,CAAC;;sDAC8B;AAZ5D,qBAAqB;IADjC,SAAS,CAAC,eAAe,CAAC;GACd,qBAAqB,CAoFjC"}
|
|
@@ -2,4 +2,10 @@ export declare const PasswordEncoder: unique symbol;
|
|
|
2
2
|
export interface PasswordEncoder {
|
|
3
3
|
encode(rawPassword: string): Promise<string>;
|
|
4
4
|
matches(rawPassword: string, encodedPassword: string): Promise<boolean>;
|
|
5
|
+
/**
|
|
6
|
+
* Whether a stored hash should be replaced by `encode()` of the password once it matched (a legacy
|
|
7
|
+
* format, or weaker parameters than new hashes get). Login does so when the UserService can
|
|
8
|
+
* store passwords (`UserService.updatePassword`).
|
|
9
|
+
*/
|
|
10
|
+
needsUpgrade?(encodedPassword: string): boolean;
|
|
5
11
|
}
|
package/esm/node/module.d.ts
CHANGED
package/esm/node/module.js
CHANGED
package/esm/node/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,SAAS,CAAC;AAEjB,eAAe,QAAQ,EAAE,CAAC"}
|
|
@@ -5,6 +5,11 @@ export declare const UserMapper: unique symbol;
|
|
|
5
5
|
export declare const USER_MIDDLEWARE_PRIORITY: number;
|
|
6
6
|
export interface UserService<R, U extends User> {
|
|
7
7
|
load(userRequest: R): Promise<U>;
|
|
8
|
+
/**
|
|
9
|
+
* Stores a new password hash of `user`. Optional: when a service has it, a login whose stored hash
|
|
10
|
+
* `PasswordEncoder.needsUpgrade()` saves the hash in the current format.
|
|
11
|
+
*/
|
|
12
|
+
updatePassword?(user: U, encodedPassword: string): Promise<void>;
|
|
8
13
|
}
|
|
9
14
|
export interface UserChecker {
|
|
10
15
|
check(user: User): Promise<void>;
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { UserService } from './user-protocol.js';
|
|
2
|
+
import { Logger, ApplicationLifecycle, Application } from '@celljs/core';
|
|
2
3
|
import { User } from '../../common/index.js';
|
|
4
|
+
/** The one user of `cell.security.username` / `password`, when they are configured. */
|
|
3
5
|
export declare class UserServiceImpl implements UserService<string, User> {
|
|
4
6
|
protected readonly options: any;
|
|
7
|
+
/** Whether `cell.security` configures a user. */
|
|
8
|
+
get hasConfiguredUser(): boolean;
|
|
5
9
|
load(username: string): Promise<User>;
|
|
6
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Warns at startup when the login (form or Basic) has no user to check: the default UserService is in
|
|
13
|
+
* use and `cell.security` configures no user. A warning, not an error: an application may log in with
|
|
14
|
+
* OAuth2 only, or use @celljs/security for authorization alone.
|
|
15
|
+
*/
|
|
16
|
+
export declare class UserSourceCheck implements ApplicationLifecycle<Application> {
|
|
17
|
+
protected readonly userService: UserService<string, User>;
|
|
18
|
+
protected readonly logger: Logger;
|
|
19
|
+
initialize(): void;
|
|
20
|
+
}
|
|
@@ -8,12 +8,18 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { UserService } from './user-protocol.js';
|
|
11
|
-
import { Value, Component } from '@celljs/core';
|
|
11
|
+
import { Value, Component, Autowired, Logger, ApplicationLifecycle } from '@celljs/core';
|
|
12
12
|
import { UsernameNotFoundError } from '../error/index.js';
|
|
13
13
|
import { UserType } from '../../common/index.js';
|
|
14
|
+
/** The one user of `cell.security.username` / `password`, when they are configured. */
|
|
14
15
|
let UserServiceImpl = class UserServiceImpl {
|
|
16
|
+
/** Whether `cell.security` configures a user. */
|
|
17
|
+
get hasConfiguredUser() {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
return !!((_a = this.options) === null || _a === void 0 ? void 0 : _a.username) && !!((_b = this.options) === null || _b === void 0 ? void 0 : _b.password);
|
|
20
|
+
}
|
|
15
21
|
async load(username) {
|
|
16
|
-
if (this.options.username === username) {
|
|
22
|
+
if (this.hasConfiguredUser && this.options.username === username) {
|
|
17
23
|
return {
|
|
18
24
|
type: UserType.Memery,
|
|
19
25
|
username,
|
|
@@ -36,4 +42,29 @@ UserServiceImpl = __decorate([
|
|
|
36
42
|
Component(UserService)
|
|
37
43
|
], UserServiceImpl);
|
|
38
44
|
export { UserServiceImpl };
|
|
45
|
+
/**
|
|
46
|
+
* Warns at startup when the login (form or Basic) has no user to check: the default UserService is in
|
|
47
|
+
* use and `cell.security` configures no user. A warning, not an error: an application may log in with
|
|
48
|
+
* OAuth2 only, or use @celljs/security for authorization alone.
|
|
49
|
+
*/
|
|
50
|
+
let UserSourceCheck = class UserSourceCheck {
|
|
51
|
+
initialize() {
|
|
52
|
+
if (this.userService instanceof UserServiceImpl && !this.userService.hasConfiguredUser) {
|
|
53
|
+
this.logger.warn('No user can log in: @celljs/security has no built-in user. Set cell.security.username and cell.security.password ' +
|
|
54
|
+
'(a hash made by the PasswordEncoder) in cell.yml, or bind a UserService of your own.');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
__decorate([
|
|
59
|
+
Autowired(UserService),
|
|
60
|
+
__metadata("design:type", Object)
|
|
61
|
+
], UserSourceCheck.prototype, "userService", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
Autowired(Logger),
|
|
64
|
+
__metadata("design:type", Object)
|
|
65
|
+
], UserSourceCheck.prototype, "logger", void 0);
|
|
66
|
+
UserSourceCheck = __decorate([
|
|
67
|
+
Component(ApplicationLifecycle)
|
|
68
|
+
], UserSourceCheck);
|
|
69
|
+
export { UserSourceCheck };
|
|
39
70
|
//# sourceMappingURL=user-service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-service.js","sourceRoot":"","sources":["../../../src/node/user/user-service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"user-service.js","sourceRoot":"","sources":["../../../src/node/user/user-service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;A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C,IAAI,CACZ,mHAAmH;gBACnH,sFAAsF,CACzF,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAA;AAbsB;IADlB,SAAS,CAAC,WAAW,CAAC;;oDACmC;AAGvC;IADlB,SAAS,CAAC,MAAM,CAAC;;+CACgB;AANzB,eAAe;IAD3B,SAAS,CAAC,oBAAoB,CAAC;GACnB,eAAe,CAgB3B"}
|
|
@@ -4,7 +4,6 @@ export declare const AccessDecisionVoter: unique symbol;
|
|
|
4
4
|
export declare const SecurityMetadataSource: unique symbol;
|
|
5
5
|
export declare const PolicyResolver: unique symbol;
|
|
6
6
|
export declare const SecurityExpressionContextHandler: unique symbol;
|
|
7
|
-
export declare const JexlEngineProvider: unique symbol;
|
|
8
7
|
export declare const PolicyProvider: unique symbol;
|
|
9
8
|
export declare const PolicyFactory: unique symbol;
|
|
10
9
|
export declare const ResourceNameResolver: unique symbol;
|
|
@@ -31,9 +30,6 @@ export interface PolicyResolver {
|
|
|
31
30
|
resolve(policy: Policy, securityMetadata: SecurityMetadata): Promise<number>;
|
|
32
31
|
support(policy: Policy, securityMetadata: SecurityMetadata): Promise<boolean>;
|
|
33
32
|
}
|
|
34
|
-
export interface JexlEngineProvider<T> {
|
|
35
|
-
provide(): T;
|
|
36
|
-
}
|
|
37
33
|
export interface SecurityExpressionContextHandler {
|
|
38
34
|
handle(context: any): Promise<void>;
|
|
39
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/access/access-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAErD,eAAO,MAAM,qBAAqB,eAAkC,CAAC;AACrE,eAAO,MAAM,mBAAmB,eAAgC,CAAC;AACjE,eAAO,MAAM,sBAAsB,eAAmC,CAAC;AACvE,eAAO,MAAM,cAAc,eAA2B,CAAC;AACvD,eAAO,MAAM,gCAAgC,eAA6C,CAAC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oB;IACjC,OAAO,CAAC,GAAG,EAAE,6BAA6B,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAClE;AAED,MAAM,WAAW,kBAAkB;IAC/B,OAAO,CAAC,GAAG,EAAE,6BAA6B,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAChE"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.POLICY_BASED_VOTER_PRIORITY = exports.TENANT_VOTER_PRIORITY = exports.ACCESS_DENIED = exports.ACCESS_ABSTAIN = exports.ACCESS_GRANTED = exports.SECURITY_EXPRESSION_CONTEXT_KEY = exports.ActionNameResolver = exports.ResourceNameResolver = exports.PolicyFactory = exports.PolicyProvider = exports.
|
|
3
|
+
exports.POLICY_BASED_VOTER_PRIORITY = exports.TENANT_VOTER_PRIORITY = exports.ACCESS_DENIED = exports.ACCESS_ABSTAIN = exports.ACCESS_GRANTED = exports.SECURITY_EXPRESSION_CONTEXT_KEY = exports.ActionNameResolver = exports.ResourceNameResolver = exports.PolicyFactory = exports.PolicyProvider = exports.SecurityExpressionContextHandler = exports.PolicyResolver = exports.SecurityMetadataSource = exports.AccessDecisionVoter = exports.AccessDecisionManager = void 0;
|
|
4
4
|
exports.AccessDecisionManager = Symbol('AccessDecisionManager');
|
|
5
5
|
exports.AccessDecisionVoter = Symbol('AccessDecisionVoter');
|
|
6
6
|
exports.SecurityMetadataSource = Symbol('SecurityMetadataSource');
|
|
7
7
|
exports.PolicyResolver = Symbol('PolicyResolver');
|
|
8
8
|
exports.SecurityExpressionContextHandler = Symbol('SecurityExpressionContextHandler');
|
|
9
|
-
exports.JexlEngineProvider = Symbol('JexlEngineProvider');
|
|
10
9
|
exports.PolicyProvider = Symbol('PolicyProvider');
|
|
11
10
|
exports.PolicyFactory = Symbol('PolicyFactory');
|
|
12
11
|
exports.ResourceNameResolver = Symbol('ResourceNameResolver');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-protocol.js","sourceRoot":"","sources":["../../../src/node/access/access-protocol.ts"],"names":[],"mappings":";;;AAEa,QAAA,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AACxD,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACpD,QAAA,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;AAC1D,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,QAAA,gCAAgC,GAAG,MAAM,CAAC,kCAAkC,CAAC,CAAC;AAC9E,QAAA,
|
|
1
|
+
{"version":3,"file":"access-protocol.js","sourceRoot":"","sources":["../../../src/node/access/access-protocol.ts"],"names":[],"mappings":";;;AAEa,QAAA,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AACxD,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACpD,QAAA,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;AAC1D,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,QAAA,gCAAgC,GAAG,MAAM,CAAC,kCAAkC,CAAC,CAAC;AAC9E,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,QAAA,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACxC,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AACtD,QAAA,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAElD,QAAA,+BAA+B,GAAG,2BAA2B,CAAC;AAE9D,QAAA,cAAc,GAAG,CAAC,CAAC;AACnB,QAAA,cAAc,GAAG,CAAC,CAAC;AACnB,QAAA,aAAa,GAAG,CAAC,CAAC,CAAC;AAEnB,QAAA,qBAAqB,GAAG,IAAI,CAAC;AAC7B,QAAA,2BAA2B,GAAG,QAAA,qBAAqB,GAAG,GAAG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression-resolvers.spec.d.ts","sourceRoot":"","sources":["../../../src/node/access/expression-resolvers.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const bun_test_1 = require("bun:test");
|
|
13
|
+
const chai_1 = require("chai");
|
|
14
|
+
const core_1 = require("@celljs/core");
|
|
15
|
+
const resource_1 = require("../annotation/resource");
|
|
16
|
+
const access_protocol_1 = require("./access-protocol");
|
|
17
|
+
const policy_resolver_1 = require("./policy-resolver");
|
|
18
|
+
const resource_name_resolver_1 = require("./resource-name-resolver");
|
|
19
|
+
const common_1 = require("../../common");
|
|
20
|
+
let OrderService = class OrderService {
|
|
21
|
+
get(_order) { }
|
|
22
|
+
};
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, resource_1.Resource)('args[0].id'),
|
|
25
|
+
__metadata("design:type", Function),
|
|
26
|
+
__metadata("design:paramtypes", [Object]),
|
|
27
|
+
__metadata("design:returntype", void 0)
|
|
28
|
+
], OrderService.prototype, "get", null);
|
|
29
|
+
OrderService = __decorate([
|
|
30
|
+
(0, resource_1.Resource)('order')
|
|
31
|
+
], OrderService);
|
|
32
|
+
class ItemService {
|
|
33
|
+
get(_id) { }
|
|
34
|
+
}
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, resource_1.Resource)("'item:' + args[0]"),
|
|
37
|
+
__metadata("design:type", Function),
|
|
38
|
+
__metadata("design:paramtypes", [String]),
|
|
39
|
+
__metadata("design:returntype", void 0)
|
|
40
|
+
], ItemService.prototype, "get", null);
|
|
41
|
+
(0, bun_test_1.describe)('security expressions (jexl of @celljs/core)', () => {
|
|
42
|
+
(0, bun_test_1.it)('ElPolicyResolver grants when the expression is true', async () => {
|
|
43
|
+
const resolver = new policy_resolver_1.ElPolicyResolver();
|
|
44
|
+
Object.defineProperty(resolver, 'jexlEngineProvider', { value: new core_1.JexlEngineProviderImpl() });
|
|
45
|
+
const policy = (el) => ({ type: common_1.PolicyType.el, el, context: { user: { name: 'tom', roles: ['admin'] } } });
|
|
46
|
+
(0, chai_1.expect)(await resolver.resolve(policy("user.name == 'tom' && 'admin' in user.roles"), {})).to.equal(access_protocol_1.ACCESS_GRANTED);
|
|
47
|
+
(0, chai_1.expect)(await resolver.resolve(policy("user.name == 'bob'"), {})).to.equal(access_protocol_1.ACCESS_DENIED);
|
|
48
|
+
});
|
|
49
|
+
(0, bun_test_1.it)('DefaultResourceNameResolver evaluates method resources against the call', async () => {
|
|
50
|
+
const resolver = new resource_name_resolver_1.DefaultResourceNameResolver();
|
|
51
|
+
Object.assign(resolver, { tenantEnabled: false, jexlEngineProvider: new core_1.JexlEngineProviderImpl() });
|
|
52
|
+
const target = new OrderService();
|
|
53
|
+
(0, chai_1.expect)(await resolver.resolve({ target, method: 'get', args: [{ id: '42' }] })).to.deep.equal(['order:42']);
|
|
54
|
+
(0, chai_1.expect)(await resolver.resolve({ target: new ItemService(), method: 'get', args: ['7'] })).to.deep.equal(['item:7']);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=expression-resolvers.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression-resolvers.spec.js","sourceRoot":"","sources":["../../../src/node/access/expression-resolvers.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uCAAwC;AACxC,+BAA8B;AAC9B,uCAAsD;AACtD,qDAAkD;AAClD,uDAAkE;AAClE,uDAAqD;AACrD,qEAAuE;AACvE,yCAA0C;AAG1C,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEd,GAAG,CAAC,MAAsB,IAAG,CAAC;CACjC,CAAA;AADG;IADC,IAAA,mBAAQ,EAAC,YAAY,CAAC;;;;uCACO;AAF5B,YAAY;IADjB,IAAA,mBAAQ,EAAC,OAAO,CAAC;GACZ,YAAY,CAGjB;AAED,MAAM,WAAW;IAEb,GAAG,CAAC,GAAW,IAAG,CAAC;CACtB;AADG;IADC,IAAA,mBAAQ,EAAC,mBAAmB,CAAC;;;;sCACX;AAGvB,IAAA,mBAAQ,EAAC,6CAA6C,EAAE,GAAG,EAAE;IACzD,IAAA,aAAE,EAAC,qDAAqD,EAAE,KAAK,IAAI,EAAE;QACjE,MAAM,QAAQ,GAAG,IAAI,kCAAgB,EAAE,CAAC;QACxC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,oBAAoB,EAAE,EAAE,KAAK,EAAE,IAAI,6BAAsB,EAAE,EAAE,CAAC,CAAC;QAC/F,MAAM,MAAM,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,mBAAU,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAQ,CAAC;QAC1H,IAAA,aAAM,EAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,MAAM,CA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BAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/access/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC"}
|
package/lib/node/access/index.js
CHANGED
|
@@ -24,5 +24,4 @@ __exportStar(require("./security-metadata-source"), exports);
|
|
|
24
24
|
__exportStar(require("./resource-name-resolver"), exports);
|
|
25
25
|
__exportStar(require("./action-name-resolver"), exports);
|
|
26
26
|
__exportStar(require("./access-decision-utils"), exports);
|
|
27
|
-
__exportStar(require("./jexl-engine-provider"), exports);
|
|
28
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/access/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,oDAAkC;AAClC,0DAAwC;AACxC,kDAAgC;AAChC,oDAAkC;AAClC,oDAAkC;AAClC,6DAA2C;AAC3C,2DAAyC;AACzC,yDAAuC;AACvC,0DAAwC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/access/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,oDAAkC;AAClC,0DAAwC;AACxC,kDAAgC;AAChC,oDAAkC;AAClC,oDAAkC;AAClC,6DAA2C;AAC3C,2DAAyC;AACzC,yDAAuC;AACvC,0DAAwC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PolicyResolver, SecurityMetadata } from './access-protocol';
|
|
2
|
+
import { JexlEngineProvider } from '@celljs/core';
|
|
2
3
|
import { AclPolicy, ElPolicy, Policy, Statement } from '../../common';
|
|
3
4
|
export declare class ElPolicyResolver implements PolicyResolver {
|
|
4
5
|
protected readonly jexlEngineProvider: JexlEngineProvider<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy-resolver.d.ts","sourceRoot":"","sources":["../../../src/node/access/policy-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,
|
|
1
|
+
{"version":3,"file":"policy-resolver.d.ts","sourceRoot":"","sources":["../../../src/node/access/policy-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,cAAc,EAAE,gBAAgB,EAAmC,MAAM,mBAAmB,CAAC;AACrJ,OAAO,EAAwB,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAExE,OAAO,EAAE,SAAS,EAAU,QAAQ,EAAE,MAAM,EAAc,SAAS,EAAE,MAAM,cAAc,CAAC;AAG1F,qBACa,gBAAiB,YAAW,cAAc;IAGnD,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAEzD,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAQnF;IAEK,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAElF;CACJ;AAED,qBACa,iBAAkB,YAAW,cAAc;IAEpD,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAEhD;IAED,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,YAGzC;IAEK,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAepF;IAED,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,cAiBlF;IAEK,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAElF;CACJ"}
|
|
@@ -31,7 +31,7 @@ let ElPolicyResolver = class ElPolicyResolver {
|
|
|
31
31
|
};
|
|
32
32
|
exports.ElPolicyResolver = ElPolicyResolver;
|
|
33
33
|
__decorate([
|
|
34
|
-
(0, core_1.Autowired)(
|
|
34
|
+
(0, core_1.Autowired)(core_1.JexlEngineProvider),
|
|
35
35
|
__metadata("design:type", Object)
|
|
36
36
|
], ElPolicyResolver.prototype, "jexlEngineProvider", void 0);
|
|
37
37
|
exports.ElPolicyResolver = ElPolicyResolver = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy-resolver.js","sourceRoot":"","sources":["../../../src/node/access/policy-resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"policy-resolver.js","sourceRoot":"","sources":["../../../src/node/access/policy-resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAqJ;AACrJ,uCAAwE;AACxE,+CAA+C;AAC/C,yCAA0F;AAC1F,2CAAsC;AAG/B,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAKzB,KAAK,CAAC,OAAO,CAAC,MAAgB,EAAE,gBAAkC;QAC9D,MAAM,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC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BACnC,KAAK,EAAE,CAAC;YACZ,CAAC;QACL,CAAC;QACD,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACZ,OAAO,gCAAc,CAAC;QAC1B,CAAC;QACD,OAAO,gCAAc,CAAC;IAC1B,CAAC;IAES,gBAAgB,CAAC,SAAoB,EAAE,gBAAkC;QAC/E,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACnD,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE,CAAC;YAC9B,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACjD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBAC/C,KAAK,MAAM,aAAa,IAAI,OAAO,EAAE,CAAC;oBAClC,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;wBACrD,IAAI,SAAS,CAAC,MAAM,KAAK,eAAM,CAAC,KAAK,EAAE,CAAC;4BACpC,OAAO,gCAAc,CAAC;wBAC1B,CAAC;wBACD,OAAO,+BAAa,CAAC;oBACzB,CAAC;gBACL,CAAC;gBACD,MAAM;YACV,CAAC;QACL,CAAC;QACD,OAAO,gCAAc,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,gBAAkC;QAC5D,OAAO,MAAM,CAAC,IAAI,KAAK,mBAAU,CAAC,GAAG,CAAC;IAC1C,CAAC;CACJ,CAAA;;4BAlDY,iBAAiB;IAD7B,IAAA,gBAAS,EAAC,gCAAc,CAAC;GACb,iBAAiB,CAkD7B"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { MethodSecurityMetadataContext, ResourceNameResolver } from './access-protocol';
|
|
2
|
+
import { JexlEngineProvider } from '@celljs/core';
|
|
2
3
|
export declare class DefaultResourceNameResolver implements ResourceNameResolver {
|
|
3
4
|
protected tenantEnabled: boolean;
|
|
5
|
+
protected readonly jexlEngineProvider: JexlEngineProvider<any>;
|
|
6
|
+
protected evalSync(expression: string, ctx: MethodSecurityMetadataContext): any;
|
|
4
7
|
resolve(ctx: MethodSecurityMetadataContext): Promise<string[]>;
|
|
5
8
|
protected appendTenantIfNeed(resources: string[]): Promise<string[]>;
|
|
6
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-name-resolver.d.ts","sourceRoot":"","sources":["../../../src/node/access/resource-name-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"resource-name-resolver.d.ts","sourceRoot":"","sources":["../../../src/node/access/resource-name-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAA+D,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAI/G,qBACa,2BAA4B,YAAW,oBAAoB;IAGpE,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC;IAGjC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAE/D,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,6BAA6B,GAAG,GAAG,CAE9E;IAEK,OAAO,CAAC,GAAG,EAAE,6BAA6B,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAmBnE;IAED,UAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,qBAMrD;CACJ"}
|
|
@@ -13,9 +13,11 @@ exports.DefaultResourceNameResolver = void 0;
|
|
|
13
13
|
const access_protocol_1 = require("./access-protocol");
|
|
14
14
|
const core_1 = require("@celljs/core");
|
|
15
15
|
const constants_1 = require("../constants");
|
|
16
|
-
const jexl_1 = require("jexl");
|
|
17
16
|
const node_1 = require("@celljs/web/lib/node");
|
|
18
17
|
let DefaultResourceNameResolver = class DefaultResourceNameResolver {
|
|
18
|
+
evalSync(expression, ctx) {
|
|
19
|
+
return this.jexlEngineProvider.provide().evalSync(expression, ctx);
|
|
20
|
+
}
|
|
19
21
|
async resolve(ctx) {
|
|
20
22
|
const classResources = (0, core_1.getOwnMetadata)(constants_1.METADATA_KEY.resource, ctx.target.constructor);
|
|
21
23
|
const methodResources = (0, core_1.getOwnMetadata)(constants_1.METADATA_KEY.resource, ctx.target.constructor, ctx.method);
|
|
@@ -23,12 +25,12 @@ let DefaultResourceNameResolver = class DefaultResourceNameResolver {
|
|
|
23
25
|
if (classResources.length && methodResources.length) {
|
|
24
26
|
for (const resource of methodResources) {
|
|
25
27
|
// eslint-disable-next-line no-eval
|
|
26
|
-
resources.push(`${classResources[0]}:${
|
|
28
|
+
resources.push(`${classResources[0]}:${this.evalSync(resource === null || resource === void 0 ? void 0 : resource.toString(), ctx)}`);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
else if (methodResources.length) {
|
|
30
32
|
// eslint-disable-next-line no-eval
|
|
31
|
-
resources = methodResources.map(r => { var _a; return (_a =
|
|
33
|
+
resources = methodResources.map(r => { var _a; return (_a = this.evalSync(r === null || r === void 0 ? void 0 : r.toString(), ctx)) === null || _a === void 0 ? void 0 : _a.toString(); });
|
|
32
34
|
}
|
|
33
35
|
else if (classResources.length) {
|
|
34
36
|
resources = classResources;
|
|
@@ -51,6 +53,10 @@ __decorate([
|
|
|
51
53
|
(0, core_1.Value)(core_1.TENANT_ENABLED),
|
|
52
54
|
__metadata("design:type", Boolean)
|
|
53
55
|
], DefaultResourceNameResolver.prototype, "tenantEnabled", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, core_1.Autowired)(core_1.JexlEngineProvider),
|
|
58
|
+
__metadata("design:type", Object)
|
|
59
|
+
], DefaultResourceNameResolver.prototype, "jexlEngineProvider", void 0);
|
|
54
60
|
exports.DefaultResourceNameResolver = DefaultResourceNameResolver = __decorate([
|
|
55
61
|
(0, core_1.Component)(access_protocol_1.ResourceNameResolver)
|
|
56
62
|
], DefaultResourceNameResolver);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-name-resolver.js","sourceRoot":"","sources":["../../../src/node/access/resource-name-resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAwF;AACxF,
|
|
1
|
+
{"version":3,"file":"resource-name-resolver.js","sourceRoot":"","sources":["../../../src/node/access/resource-name-resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAwF;AACxF,uCAA+G;AAC/G,4CAA4C;AAC5C,+CAA+C;AAGxC,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAQ1B,QAAQ,CAAC,UAAkB,EAAE,GAAkC;QACrE,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IACvE,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAkC;QAC5C,MAAM,cAAc,GAAa,IAAA,qBAAc,EAAC,wBAAY,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAC/F,MAAM,eAAe,GAAa,IAAA,qBAAc,EAAC,wBAAY,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5G,IAAI,SAAS,GAAa,EAAE,CAAC;QAC7B,IAAI,cAAc,CAAC,MAAM,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;YAClD,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE,CAAC;gBACrC,mCAAmC;gBACnC,SAAS,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAQ,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;YACvF,CAAC;QACL,CAAC;aAAM,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;YAChC,mCAAmC;YACnC,SAAS,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,kBAAC,MAAA,IAAI,CAAC,QAAQ,CAAC,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,QAAQ,EAAE,EAAE,GAAG,CAAC,0CAAE,QAAQ,EAAE,GAAA,CAAC,CAAC;QACxF,CAAC;aAAM,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC;YAC/B,SAAS,GAAG,cAAc,CAAC;QAC/B,CAAC;aAAM,CAAC;YACJ,SAAS,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;QAED,OAAO,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;IAES,KAAK,CAAC,kBAAkB,CAAC,SAAmB;QAClD,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,MAAM,MAAM,GAAG,cAAO,CAAC,SAAS,EAAE,CAAC;YACnC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ,CAAA;;AArCa;IADT,IAAA,YAAK,EAAC,qBAAc,CAAC;;kEACW;AAGd;IADlB,IAAA,gBAAS,EAAC,yBAAkB,CAAC;;uEACiC;sCANtD,2BAA2B;IADvC,IAAA,gBAAS,EAAC,sCAAoB,CAAC;GACnB,2BAA2B,CAwCvC"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { Logger } from '@celljs/core';
|
|
1
2
|
import { AuthenticationProvider, Authentication } from './authentication-protocol';
|
|
2
3
|
import { RequestMatcher, RedirectStrategy } from '@celljs/web/lib/node';
|
|
3
4
|
import { PasswordEncoder } from '../crypto';
|
|
4
5
|
import { UserService, UserChecker, UserMapper } from '../user';
|
|
5
6
|
import { PathResolver } from '@celljs/web';
|
|
6
7
|
import { User } from '../../common';
|
|
8
|
+
/**
|
|
9
|
+
* After a password matched: when its stored hash is in a legacy format and the UserService can store
|
|
10
|
+
* passwords, store a new hash of it. A failure is logged and does not fail the login.
|
|
11
|
+
*/
|
|
12
|
+
export declare function upgradePasswordHash(passwordEncoder: PasswordEncoder, userService: UserService<any, User>, user: User, rawPassword: string, logger: Logger): Promise<void>;
|
|
7
13
|
export declare class UsernamePasswordAuthenticationProvider implements AuthenticationProvider {
|
|
8
14
|
protected readonly options: any;
|
|
9
15
|
protected readonly passwordEncoder: PasswordEncoder;
|
|
@@ -13,6 +19,7 @@ export declare class UsernamePasswordAuthenticationProvider implements Authentic
|
|
|
13
19
|
protected readonly requestMatcher: RequestMatcher;
|
|
14
20
|
protected readonly pathResolver: PathResolver;
|
|
15
21
|
protected readonly redirectStrategy: RedirectStrategy;
|
|
22
|
+
protected readonly logger: Logger;
|
|
16
23
|
priority: number;
|
|
17
24
|
authenticate(): Promise<Authentication | undefined>;
|
|
18
25
|
protected doGetValue(key: string): string;
|
|
@@ -26,6 +33,7 @@ export declare class BasicAuthenticationProvider implements AuthenticationProvid
|
|
|
26
33
|
protected readonly requestMatcher: RequestMatcher;
|
|
27
34
|
protected readonly pathResolver: PathResolver;
|
|
28
35
|
protected readonly redirectStrategy: RedirectStrategy;
|
|
36
|
+
protected readonly logger: Logger;
|
|
29
37
|
priority: number;
|
|
30
38
|
authenticate(): Promise<Authentication | undefined>;
|
|
31
39
|
support(): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-provider.d.ts","sourceRoot":"","sources":["../../../src/node/authentication/authentication-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authentication-provider.d.ts","sourceRoot":"","sources":["../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