@celljs/security 3.9.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 +12 -7
- 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 +17 -31
- 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
package/README.md
CHANGED
|
@@ -1 +1,111 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @celljs/security
|
|
2
|
+
|
|
3
|
+
Authentication and authorization for Cell backends: form login, HTTP Basic, logout, `@Authenticated()` / `@Anonymous()` / `@PreAuthorize()` on controllers, and password hashing. Install it and it is active; no registration is needed.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @celljs/security
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Users
|
|
10
|
+
|
|
11
|
+
**There is no built-in user.** Give the login a user source in one of two ways:
|
|
12
|
+
|
|
13
|
+
1. One user in `cell.yml`. `password` is a hash made by the `PasswordEncoder`, never the plain password:
|
|
14
|
+
|
|
15
|
+
```yaml
|
|
16
|
+
backend:
|
|
17
|
+
cell:
|
|
18
|
+
security:
|
|
19
|
+
username: admin
|
|
20
|
+
password: pbkdf2-sha256$600000$<salt>$<key>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Make a hash with the encoder of the version you deploy, for example:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
// hash.mjs — node hash.mjs 'the password'
|
|
27
|
+
import 'reflect-metadata';
|
|
28
|
+
import { Pbkdf2PasswordEncoder } from '@celljs/security/lib/node/crypto/password/password-encoder';
|
|
29
|
+
console.log(await new Pbkdf2PasswordEncoder().encode(process.argv[2]));
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
If you set `cell.security.passwordEncoder.secret` (a pepper), new hashes depend on it: make them inside the application (inject `PasswordEncoder`), not with the script above.
|
|
33
|
+
|
|
34
|
+
2. Your own `UserService`, for users stored in a database:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { Component } from '@celljs/core';
|
|
38
|
+
import { User, UserType } from '@celljs/security/lib/common';
|
|
39
|
+
import { UserService, UsernameNotFoundError } from '@celljs/security/lib/node';
|
|
40
|
+
|
|
41
|
+
@Component({ id: UserService, rebind: true })
|
|
42
|
+
export class DbUserService implements UserService<string, User> {
|
|
43
|
+
async load(username: string): Promise<User> {
|
|
44
|
+
const row = await findUser(username); // your data access
|
|
45
|
+
if (!row) {
|
|
46
|
+
throw new UsernameNotFoundError(`Could not find: ${username}`);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
type: UserType.Database, username, password: row.passwordHash, policies: [],
|
|
50
|
+
accountNonExpired: true, accountNonLocked: true, credentialsNonExpired: true, enabled: true
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Optional: lets a login replace an outdated hash (see "Password hashes").
|
|
55
|
+
async updatePassword(user: User, encodedPassword: string): Promise<void> {
|
|
56
|
+
await saveHash(user.username, encodedPassword);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
With neither, the application starts and logs a warning that no user can log in (an application may log in with OAuth2 only, or use this package for authorization alone).
|
|
62
|
+
|
|
63
|
+
## Logging in
|
|
64
|
+
|
|
65
|
+
| Way | Request | Result |
|
|
66
|
+
| --- | --- | --- |
|
|
67
|
+
| Form | `POST /login` with `username` and `password`, as JSON or as a form (`cell.security.loginUrl`, `loginMethod`, `usernameKey`, `passwordKey`) | `302` to `loginSuccessUrl` (or the `redirect` query parameter) with a session cookie; wrong credentials `401` |
|
|
68
|
+
| Basic | `Authorization: Basic …` on any request, e.g. `curl -u admin:secret http://localhost:3000/users` | The request itself is authenticated and continues to the resource; wrong credentials `401` |
|
|
69
|
+
| Logout | `POST /logout` | `302` to `logoutSuccessUrl` |
|
|
70
|
+
|
|
71
|
+
Basic is **off by default**; turn it on with `cell.security.basic.enabled: true`. It checks the password on **every request**, and one check is one PBKDF2 derivation with 600000 iterations (about 45 ms of CPU). Use Basic only for low-frequency machine-to-machine calls; for frequent calls log in once and use the session, or use JWT (`@celljs/jwt`).
|
|
72
|
+
|
|
73
|
+
## Protecting endpoints
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { Controller, Get } from '@celljs/mvc/lib/node';
|
|
77
|
+
import { Anonymous, Authenticated } from '@celljs/security/lib/node';
|
|
78
|
+
|
|
79
|
+
@Controller('users')
|
|
80
|
+
@Authenticated() // requires a logged-in user; anonymous requests get 401
|
|
81
|
+
export class UserController {
|
|
82
|
+
@Get()
|
|
83
|
+
list() { return []; }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Controller()
|
|
87
|
+
@Anonymous() // reachable without logging in
|
|
88
|
+
export class HomeController {}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`@PreAuthorize(el)` / `@PostAuthorize(el)` check an expression before or after the method; `@Authorize`, `@Resource` and `@Action` work with policies.
|
|
92
|
+
|
|
93
|
+
## Password hashes
|
|
94
|
+
|
|
95
|
+
`PasswordEncoder` (`Pbkdf2PasswordEncoder`) stores `pbkdf2-sha256$<iterations>$<salt>$<key>`: PBKDF2-HMAC-SHA256, 600000 iterations, a random 16-byte salt, compared in constant time.
|
|
96
|
+
|
|
97
|
+
Hashes stored by 4.0.x keep matching. After a successful login (form or Basic), such a hash is replaced by a new one when your `UserService` implements `updatePassword()`. **The upgrade is one-way: once a user has logged in, an application rolled back to 4.0.x can no longer check that user's password.** Hashes made with crypto-js 4.1 or older are not supported.
|
|
98
|
+
|
|
99
|
+
## Configuration
|
|
100
|
+
|
|
101
|
+
Keys under `cell.security` (defaults in this package's `cell.yml`):
|
|
102
|
+
|
|
103
|
+
| Key | Default | |
|
|
104
|
+
| --- | --- | --- |
|
|
105
|
+
| `username`, `password` | — | The single user of the default `UserService`; `password` is a hash |
|
|
106
|
+
| `loginUrl`, `loginMethod` | `/login`, `POST` | Form login endpoint |
|
|
107
|
+
| `usernameKey`, `passwordKey` | `username`, `password` | Field names of the form login |
|
|
108
|
+
| `loginSuccessUrl` | `/` | Where a form login redirects |
|
|
109
|
+
| `logoutUrl`, `logoutMethod`, `logoutSuccessUrl` | `/logout`, `POST`, the login page | Logout |
|
|
110
|
+
| `basic.enabled`, `basic.realm` | `false`, `realm` | HTTP Basic |
|
|
111
|
+
| `passwordEncoder.secret` | — | Optional pepper mixed into new hashes |
|
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,15 @@ 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
|
+
# No built-in user: set username and password (a PasswordEncoder hash) here, or bind a UserService.
|
|
40
|
+
passwordEncoder:
|
|
41
|
+
encodeHashAsBase64: true
|
|
@@ -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
|
}
|
|
@@ -3,7 +3,6 @@ export const AccessDecisionVoter = Symbol('AccessDecisionVoter');
|
|
|
3
3
|
export const SecurityMetadataSource = Symbol('SecurityMetadataSource');
|
|
4
4
|
export const PolicyResolver = Symbol('PolicyResolver');
|
|
5
5
|
export const SecurityExpressionContextHandler = Symbol('SecurityExpressionContextHandler');
|
|
6
|
-
export const JexlEngineProvider = Symbol('JexlEngineProvider');
|
|
7
6
|
export const PolicyProvider = Symbol('PolicyProvider');
|
|
8
7
|
export const PolicyFactory = Symbol('PolicyFactory');
|
|
9
8
|
export const ResourceNameResolver = Symbol('ResourceNameResolver');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-protocol.js","sourceRoot":"","sources":["../../../src/node/access/access-protocol.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AACrE,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;AACvE,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC,kCAAkC,CAAC,CAAC;AAC3F,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"access-protocol.js","sourceRoot":"","sources":["../../../src/node/access/access-protocol.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AACrE,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;AACvE,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC,kCAAkC,CAAC,CAAC;AAC3F,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AACnE,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAE/D,MAAM,CAAC,MAAM,+BAA+B,GAAG,2BAA2B,CAAC;AAE3E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAChC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAChC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAC1C,MAAM,CAAC,MAAM,2BAA2B,GAAG,qBAAqB,GAAG,GAAG,CAAC"}
|
package/esm/node/access/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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
|
|
1
|
+
{"version":3,"file":"index.js","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"}
|
|
@@ -10,8 +10,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
import { PolicyProvider } from './access-protocol.js';
|
|
11
11
|
import { Component, Value, PostConstruct } from '@celljs/core';
|
|
12
12
|
import { AuthorizeType } from '../../common/index.js';
|
|
13
|
-
import
|
|
14
|
-
const { contains } =
|
|
13
|
+
import __cellCjs0 from 'micromatch';
|
|
14
|
+
const { contains } = __cellCjs0;
|
|
15
15
|
let PrincipalPolicyProvider = class PrincipalPolicyProvider {
|
|
16
16
|
async provide(ctx) {
|
|
17
17
|
const { principal, type } = ctx;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PolicyResolver, SecurityMetadata } from './access-protocol.js';
|
|
2
|
+
import { JexlEngineProvider } from '@celljs/core';
|
|
2
3
|
import { AclPolicy, ElPolicy, Policy, Statement } from '../../common/index.js';
|
|
3
4
|
export declare class ElPolicyResolver implements PolicyResolver {
|
|
4
5
|
protected readonly jexlEngineProvider: JexlEngineProvider<any>;
|
|
@@ -7,12 +7,12 @@ 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
|
-
import { ACCESS_ABSTAIN, ACCESS_DENIED, ACCESS_GRANTED,
|
|
11
|
-
import { Autowired, Component } from '@celljs/core';
|
|
10
|
+
import { ACCESS_ABSTAIN, ACCESS_DENIED, ACCESS_GRANTED, PolicyResolver, SECURITY_EXPRESSION_CONTEXT_KEY } from './access-protocol.js';
|
|
11
|
+
import { Autowired, Component, JexlEngineProvider } from '@celljs/core';
|
|
12
12
|
import { Context } from '@celljs/web/lib/node';
|
|
13
13
|
import { Effect, PolicyType } from '../../common/index.js';
|
|
14
|
-
import
|
|
15
|
-
const { contains } =
|
|
14
|
+
import __cellCjs1 from 'micromatch';
|
|
15
|
+
const { contains } = __cellCjs1;
|
|
16
16
|
let ElPolicyResolver = class ElPolicyResolver {
|
|
17
17
|
async resolve(policy, securityMetadata) {
|
|
18
18
|
const expression = this.jexlEngineProvider.provide().createExpression(policy.el);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy-resolver.js","sourceRoot":"","sources":["../../../src/node/access/policy-resolver.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"policy-resolver.js","sourceRoot":"","sources":["../../../src/node/access/policy-resolver.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAoB,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AACrJ,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAa,MAAM,EAAoB,UAAU,EAAa,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;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;QACjF,mCAAmC;QACnC,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC,CAAC;QACzG,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YAClB,OAAO,cAAc,CAAC;QAC1B,CAAC;QACD,OAAO,aAAa,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,gBAAkC;QAC5D,OAAO,MAAM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C,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,MAAM,CAAC,KAAK,EAAE,CAAC;4BACpC,OAAO,cAAc,CAAC;wBAC1B,CAAC;wBACD,OAAO,aAAa,CAAC;oBACzB,CAAC;gBACL,CAAC;gBACD,MAAM;YACV,CAAC;QACL,CAAC;QACD,OAAO,cAAc,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,gBAAkC;QAC5D,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC,GAAG,CAAC;IAC1C,CAAC;CACJ,CAAA;AAlDY,iBAAiB;IAD7B,SAAS,CAAC,cAAc,CAAC;GACb,iBAAiB,CAkD7B"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { MethodSecurityMetadataContext, ResourceNameResolver } from './access-protocol.js';
|
|
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
|
}
|
|
@@ -8,12 +8,13 @@ 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 { ResourceNameResolver } from './access-protocol.js';
|
|
11
|
-
import { Component, Value, TENANT_ENABLED, getOwnMetadata } from '@celljs/core';
|
|
11
|
+
import { Component, Value, Autowired, TENANT_ENABLED, getOwnMetadata, JexlEngineProvider } from '@celljs/core';
|
|
12
12
|
import { METADATA_KEY } from '../constants.js';
|
|
13
|
-
import __cellCjs3 from 'jexl';
|
|
14
|
-
const { evalSync } = __cellCjs3;
|
|
15
13
|
import { Context } from '@celljs/web/lib/node';
|
|
16
14
|
let DefaultResourceNameResolver = class DefaultResourceNameResolver {
|
|
15
|
+
evalSync(expression, ctx) {
|
|
16
|
+
return this.jexlEngineProvider.provide().evalSync(expression, ctx);
|
|
17
|
+
}
|
|
17
18
|
async resolve(ctx) {
|
|
18
19
|
const classResources = getOwnMetadata(METADATA_KEY.resource, ctx.target.constructor);
|
|
19
20
|
const methodResources = getOwnMetadata(METADATA_KEY.resource, ctx.target.constructor, ctx.method);
|
|
@@ -21,12 +22,12 @@ let DefaultResourceNameResolver = class DefaultResourceNameResolver {
|
|
|
21
22
|
if (classResources.length && methodResources.length) {
|
|
22
23
|
for (const resource of methodResources) {
|
|
23
24
|
// eslint-disable-next-line no-eval
|
|
24
|
-
resources.push(`${classResources[0]}:${evalSync(resource === null || resource === void 0 ? void 0 : resource.toString(), ctx)}`);
|
|
25
|
+
resources.push(`${classResources[0]}:${this.evalSync(resource === null || resource === void 0 ? void 0 : resource.toString(), ctx)}`);
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
else if (methodResources.length) {
|
|
28
29
|
// eslint-disable-next-line no-eval
|
|
29
|
-
resources = methodResources.map(r => { var _a; return (_a = evalSync(r === null || r === void 0 ? void 0 : r.toString(), ctx)) === null || _a === void 0 ? void 0 : _a.toString(); });
|
|
30
|
+
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(); });
|
|
30
31
|
}
|
|
31
32
|
else if (classResources.length) {
|
|
32
33
|
resources = classResources;
|
|
@@ -48,6 +49,10 @@ __decorate([
|
|
|
48
49
|
Value(TENANT_ENABLED),
|
|
49
50
|
__metadata("design:type", Boolean)
|
|
50
51
|
], DefaultResourceNameResolver.prototype, "tenantEnabled", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
Autowired(JexlEngineProvider),
|
|
54
|
+
__metadata("design:type", Object)
|
|
55
|
+
], DefaultResourceNameResolver.prototype, "jexlEngineProvider", void 0);
|
|
51
56
|
DefaultResourceNameResolver = __decorate([
|
|
52
57
|
Component(ResourceNameResolver)
|
|
53
58
|
], DefaultResourceNameResolver);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-name-resolver.js","sourceRoot":"","sources":["../../../src/node/access/resource-name-resolver.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAiC,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"resource-name-resolver.js","sourceRoot":"","sources":["../../../src/node/access/resource-name-resolver.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAiC,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC/G,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAGxC,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAQ1B,QAAQ,CAAC,UAAkB,EAAE,GAAkC;QACrE,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,U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AC,kBAAkB,CAAC,SAAmB;QAClD,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,MAAM,MAAM,GAAG,OAAO,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,KAAK,CAAC,cAAc,CAAC;;kEACW;AAGd;IADlB,SAAS,CAAC,kBAAkB,CAAC;;uEACiC;AANtD,2BAA2B;IADvC,SAAS,CAAC,oBAAoB,CAAC;GACnB,2BAA2B,CAwCvC"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { Logger } from '@celljs/core';
|
|
1
2
|
import { AuthenticationProvider, Authentication } from './authentication-protocol.js';
|
|
2
3
|
import { RequestMatcher, RedirectStrategy } from '@celljs/web/lib/node';
|
|
3
4
|
import { PasswordEncoder } from '../crypto/index.js';
|
|
4
5
|
import { UserService, UserChecker, UserMapper } from '../user/index.js';
|
|
5
6
|
import { PathResolver } from '@celljs/web';
|
|
6
7
|
import { User } from '../../common/index.js';
|
|
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>;
|
|
@@ -7,7 +7,7 @@ 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
|
-
import { Component, Autowired, Value } from '@celljs/core';
|
|
10
|
+
import { Component, Autowired, Value, Logger } from '@celljs/core';
|
|
11
11
|
import { AuthenticationProvider, USERNAME_PASSWORD_AUTHENTICATION_PROVIDER_PRIORITY, BASE_AUTHENTICATION_PROVIDER_PRIORITY, AUTHENTICATION_SCHEME_BASIC } from './authentication-protocol.js';
|
|
12
12
|
import { Context, RequestMatcher, RedirectStrategy } from '@celljs/web/lib/node';
|
|
13
13
|
import { PasswordEncoder } from '../crypto/index.js';
|
|
@@ -15,6 +15,23 @@ import { UserService, UserChecker, UserMapper } from '../user/index.js';
|
|
|
15
15
|
import { BadCredentialsError } from '../error/index.js';
|
|
16
16
|
import { HttpHeaders } from '@celljs/http';
|
|
17
17
|
import { PathResolver } from '@celljs/web';
|
|
18
|
+
/**
|
|
19
|
+
* After a password matched: when its stored hash is in a legacy format and the UserService can store
|
|
20
|
+
* passwords, store a new hash of it. A failure is logged and does not fail the login.
|
|
21
|
+
*/
|
|
22
|
+
export async function upgradePasswordHash(passwordEncoder, userService, user, rawPassword, logger) {
|
|
23
|
+
var _a;
|
|
24
|
+
var _b;
|
|
25
|
+
if (!userService.updatePassword || !((_a = passwordEncoder.needsUpgrade) === null || _a === void 0 ? void 0 : _a.call(passwordEncoder, user.password))) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
await userService.updatePassword(user, await passwordEncoder.encode(rawPassword));
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
logger.warn(`Could not upgrade the password hash of ${user.username}: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
18
35
|
let UsernamePasswordAuthenticationProvider = class UsernamePasswordAuthenticationProvider {
|
|
19
36
|
constructor() {
|
|
20
37
|
this.priority = USERNAME_PASSWORD_AUTHENTICATION_PROVIDER_PRIORITY;
|
|
@@ -30,6 +47,7 @@ let UsernamePasswordAuthenticationProvider = class UsernamePasswordAuthenticatio
|
|
|
30
47
|
if (!await this.passwordEncoder.matches(password, user.password)) {
|
|
31
48
|
throw new BadCredentialsError('Bad credentials');
|
|
32
49
|
}
|
|
50
|
+
await upgradePasswordHash(this.passwordEncoder, this.userService, user, password, this.logger);
|
|
33
51
|
await this.userMapper.map(user);
|
|
34
52
|
return {
|
|
35
53
|
name: user.username,
|
|
@@ -84,6 +102,10 @@ __decorate([
|
|
|
84
102
|
Autowired(RedirectStrategy),
|
|
85
103
|
__metadata("design:type", Object)
|
|
86
104
|
], UsernamePasswordAuthenticationProvider.prototype, "redirectStrategy", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
Autowired(Logger),
|
|
107
|
+
__metadata("design:type", Object)
|
|
108
|
+
], UsernamePasswordAuthenticationProvider.prototype, "logger", void 0);
|
|
87
109
|
UsernamePasswordAuthenticationProvider = __decorate([
|
|
88
110
|
Component(AuthenticationProvider)
|
|
89
111
|
], UsernamePasswordAuthenticationProvider);
|
|
@@ -104,7 +126,7 @@ let BasicAuthenticationProvider = class BasicAuthenticationProvider {
|
|
|
104
126
|
throw new BadCredentialsError('Invalid basic authentication token');
|
|
105
127
|
}
|
|
106
128
|
const username = token.substring(0, delim);
|
|
107
|
-
const password = token.substring(delim);
|
|
129
|
+
const password = token.substring(delim + 1);
|
|
108
130
|
if (!password || !username) {
|
|
109
131
|
throw new BadCredentialsError('Bad credentials');
|
|
110
132
|
}
|
|
@@ -113,6 +135,7 @@ let BasicAuthenticationProvider = class BasicAuthenticationProvider {
|
|
|
113
135
|
if (!await this.passwordEncoder.matches(password, user.password)) {
|
|
114
136
|
throw new BadCredentialsError('Bad credentials');
|
|
115
137
|
}
|
|
138
|
+
await upgradePasswordHash(this.passwordEncoder, this.userService, user, password, this.logger);
|
|
116
139
|
await this.userMapper.map(user);
|
|
117
140
|
return {
|
|
118
141
|
name: user.username,
|
|
@@ -164,6 +187,10 @@ __decorate([
|
|
|
164
187
|
Autowired(RedirectStrategy),
|
|
165
188
|
__metadata("design:type", Object)
|
|
166
189
|
], BasicAuthenticationProvider.prototype, "redirectStrategy", void 0);
|
|
190
|
+
__decorate([
|
|
191
|
+
Autowired(Logger),
|
|
192
|
+
__metadata("design:type", Object)
|
|
193
|
+
], BasicAuthenticationProvider.prototype, "logger", void 0);
|
|
167
194
|
BasicAuthenticationProvider = __decorate([
|
|
168
195
|
Component(AuthenticationProvider)
|
|
169
196
|
], BasicAuthenticationProvider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-provider.js","sourceRoot":"","sources":["../../../src/node/authentication/authentication-provider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"authentication-provider.js","sourceRoot":"","sources":["../../../src/node/authentication/authentication-provider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAA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,CAAC;IAEN,CAAC;IAED,KAAK,CAAC,OAAO;QACT,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QACrC,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;QACvB,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,2BAA2B,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;YAC7E,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CAEJ,CAAA;AA3EsB;IADlB,SAAS,CAAC,eAAe,CAAC;;oEACyB;AAGjC;IADlB,SAAS,CAAC,WAAW,CAAC;;gEACmC;AAGvC;IADlB,SAAS,CAAC,WAAW,CAAC;;gEACqB;AAGzB;IADlB,SAAS,CAAC,UAAU,CAAC;;+DACoB;AAGvB;IADlB,SAAS,CAAC,cAAc,CAAC;;mEACwB;AAG/B;IADlB,SAAS,CAAC,YAAY,CAAC;;iEACsB;AAG3B;IADlB,SAAS,CAAC,gBAAgB,CAAC;;qEAC0B;AAGnC;IADlB,SAAS,CAAC,MAAM,CAAC;;2DACgB;AAxBzB,2BAA2B;IADvC,SAAS,CAAC,sBAAsB,CAAC;GACrB,2BAA2B,CA8EvC"}
|
|
@@ -14,6 +14,10 @@ import { HttpHeaders, XML_HTTP_REQUEST } from '@celljs/http';
|
|
|
14
14
|
import { RequestCache } from '../cache/index.js';
|
|
15
15
|
let DefaultAuthenticationSuccessHandler = class DefaultAuthenticationSuccessHandler {
|
|
16
16
|
async onAuthenticationSuccess(authentication) {
|
|
17
|
+
// Authentication that goes on to the requested resource (Basic): nothing to redirect to.
|
|
18
|
+
if (authentication.next) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
17
21
|
const response = Context.getResponse();
|
|
18
22
|
if (Context.getRequest().get(HttpHeaders.X_REQUESTED_WITH) === XML_HTTP_REQUEST) {
|
|
19
23
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-success-handler.js","sourceRoot":"","sources":["../../../src/node/authentication/authentication-success-handler.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,4BAA4B,EAAkB,MAAM,2BAA2B,CAAC;AACzF,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGjC,IAAM,mCAAmC,GAAzC,MAAM,mCAAmC;IAuB5C,KAAK,CAAC,uBAAuB,CAAC,cAA8B;QACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QACvC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,gBAAgB,EAAE,CAAC;YAC9E,OAAO;QACX,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,OAAO;QACX,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;QAChE,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;YACzB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8DAA8D,SAAS,EAAE,CAAC,CAAC;YAC7F,OAAO;QACX,CAAC;QACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IAEQ,KAAK,CAAC,kBAAkB,CAAC,cAA8B;QAC7D,IAA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ED,OAAO,SAAS,CAAC;IACrB,CAAC;CAEJ,CAAA;
|
|
1
|
+
{"version":3,"file":"authentication-success-handler.js","sourceRoot":"","sources":["../../../src/node/authentication/authentication-success-handler.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,4BAA4B,EAAkB,MAAM,2BAA2B,CAAC;AACzF,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGjC,IAAM,mCAAmC,GAAzC,MAAM,mCAAmC;IAuB5C,KAAK,CAAC,uBAAuB,CAAC,cAA8B;QACxD,yFAAyF;QACzF,IAAI,cAAc,CAAC,IAAI,EAAE,CAAC;YACtB,OAAO;QACX,CAAC;QACD,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QACvC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,gBAAgB,EAAE,CAAC;YAC9E,OAAO;QACX,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,OAAO;QACX,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;QAChE,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;YACzB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8DAA8D,SAAS,EAAE,CAAC,CAAC;YAC7F,OAAO;QACX,CAAC;QACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IAEQ,KAAK,CAAC,kBAAkB,CAAC,cAA8B;QAC7D,I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QAED,OAAO,SAAS,CAAC;IACrB,CAAC;CAEJ,CAAA;AA5EsB;IADlB,KAAK,CAAC,kCAAkC,CAAC;;+EACI;AAG3B;IADlB,KAAK,CAAC,+BAA+B,CAAC;;4EACI;AAGxB;IADlB,KAAK,CAAC,wCAAwC,CAAC;;qFACK;AAGlC;IADlB,KAAK,CAAC,0BAA0B,CAAC;;uEACK;AAGpB;IADlB,SAAS,CAAC,MAAM,CAAC;;mEACgB;AAGf;IADlB,SAAS,CAAC,gBAAgB,CAAC;;6EAC0B;AAGnC;IADlB,SAAS,CAAC,YAAY,CAAC;;yEACsB;AArBrC,mCAAmC;IAD/C,SAAS,CAAC,4BAA4B,CAAC;GAC3B,mCAAmC,CA+E/C"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { StringKeyGenerator } from './keygen-protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* Random keys (OAuth2 `state`, PKCE `code_verifier`, OIDC `nonce`) in base64url without padding,
|
|
4
|
+
* so they can go into a URL as they are (RFC 7636 §4.1 allows only unreserved characters).
|
|
5
|
+
*/
|
|
2
6
|
export declare class Base64StringKeyGenerator implements StringKeyGenerator {
|
|
3
7
|
protected readonly keyLength: number;
|
|
4
8
|
generateKey(keyLength?: number): Promise<string>;
|
|
@@ -7,14 +7,16 @@ 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
|
+
import { randomBytes } from 'node:crypto';
|
|
10
11
|
import { StringKeyGenerator } from './keygen-protocol.js';
|
|
11
|
-
import __cellCjs1 from 'crypto-js';
|
|
12
|
-
const { enc, lib } = __cellCjs1;
|
|
13
12
|
import { Value, Component } from '@celljs/core';
|
|
13
|
+
/**
|
|
14
|
+
* Random keys (OAuth2 `state`, PKCE `code_verifier`, OIDC `nonce`) in base64url without padding,
|
|
15
|
+
* so they can go into a URL as they are (RFC 7636 §4.1 allows only unreserved characters).
|
|
16
|
+
*/
|
|
14
17
|
let Base64StringKeyGenerator = class Base64StringKeyGenerator {
|
|
15
18
|
async generateKey(keyLength) {
|
|
16
|
-
|
|
17
|
-
return enc.Base64.stringify(key);
|
|
19
|
+
return randomBytes(keyLength || this.keyLength).toString('base64url');
|
|
18
20
|
}
|
|
19
21
|
};
|
|
20
22
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64-string-key-generator.js","sourceRoot":"","sources":["../../../../src/node/crypto/keygen/base64-string-key-generator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"base64-string-key-generator.js","sourceRoot":"","sources":["../../../../src/node/crypto/keygen/base64-string-key-generator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEhD;;;GAGG;AAEI,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAKjC,KAAK,CAAC,WAAW,CAAC,SAAkB;QAChC,OAAO,WAAW,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC1E,CAAC;CACJ,CAAA;AALsB;IADlB,KAAK,CAAC,qCAAqC,CAAC;;2DACR;AAH5B,wBAAwB;IADpC,SAAS,CAAC,kBAAkB,CAAC;GACjB,wBAAwB,CAQpC"}
|
|
@@ -1,8 +1,45 @@
|
|
|
1
1
|
import { PasswordEncoder } from './password-protocol.js';
|
|
2
|
+
export interface Pbkdf2PasswordEncoderOptions {
|
|
3
|
+
/** Optional pepper. New hashes mix it into the salt when it is set; legacy hashes were made with `String(secret)`. */
|
|
4
|
+
secret?: string | number;
|
|
5
|
+
/** Legacy hashes only: they are base64 of the hex text. */
|
|
6
|
+
encodeHashAsBase64?: boolean;
|
|
7
|
+
/** Legacy hashes only: PBKDF2 iterations they were made with. Default 250000 (crypto-js 4.2.0). */
|
|
8
|
+
iterations?: number;
|
|
9
|
+
/** Legacy hashes only: derived key length in 32-bit words. Default 4 (16 bytes, crypto-js 4.2.0). */
|
|
10
|
+
keySize?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Password hashes with PBKDF2-HMAC-SHA256 on node:crypto, compared in constant time.
|
|
14
|
+
*
|
|
15
|
+
* New hashes: `pbkdf2-sha256$<iterations>$<salt, base64>$<key, base64>` with 600000 iterations, a 16-byte
|
|
16
|
+
* random salt (followed by the UTF-8 bytes of `secret` when one is set) and a 32-byte key.
|
|
17
|
+
*
|
|
18
|
+
* Legacy hashes (no prefix), as the crypto-js 4.2.0 implementation of 4.x stored them, keep matching:
|
|
19
|
+
* optionally base64 of a text that is a 16-character hex salt followed by the hex key; the key is
|
|
20
|
+
* PBKDF2(password, salt + String(secret)) with SHA-256, `iterations` (default 250000) and `keySize` words
|
|
21
|
+
* (default 4). Without a secret the salt text ends in `undefined`, which is how those hashes were made.
|
|
22
|
+
* Hashes made with crypto-js 4.1 or older (SHA-1, 1 iteration) are not supported.
|
|
23
|
+
* {@link needsUpgrade} is true for legacy hashes, so a login replaces them with a new hash.
|
|
24
|
+
*/
|
|
2
25
|
export declare class Pbkdf2PasswordEncoder implements PasswordEncoder {
|
|
3
|
-
|
|
26
|
+
static readonly PREFIX = "pbkdf2-sha256";
|
|
27
|
+
static readonly ITERATIONS = 600000;
|
|
28
|
+
static readonly SALT_BYTES = 16;
|
|
29
|
+
static readonly KEY_BYTES = 32;
|
|
30
|
+
static readonly LEGACY_ITERATIONS = 250000;
|
|
31
|
+
static readonly LEGACY_KEY_SIZE = 4;
|
|
32
|
+
static readonly LEGACY_SALT_LENGTH = 16;
|
|
33
|
+
protected readonly options: Pbkdf2PasswordEncoderOptions | undefined;
|
|
34
|
+
/** Iterations of new hashes. */
|
|
35
|
+
protected get iterations(): number;
|
|
4
36
|
encode(rawPassword: string): Promise<string>;
|
|
5
|
-
protected doEncode(rawPassword: string, salt: string): string;
|
|
6
37
|
matches(rawPassword: string, encodedPassword: string): Promise<boolean>;
|
|
7
|
-
|
|
38
|
+
needsUpgrade(encodedPassword: string): boolean;
|
|
39
|
+
protected isCurrent(encodedPassword: string): boolean;
|
|
40
|
+
protected pepper(salt: Buffer): Buffer;
|
|
41
|
+
protected matchesCurrent(rawPassword: string, encodedPassword: string): Promise<boolean>;
|
|
42
|
+
protected matchesLegacy(rawPassword: string, encodedPassword: string): Promise<boolean>;
|
|
43
|
+
/** The text the crypto-js implementation stored (before the optional base64): salt + hex key. */
|
|
44
|
+
protected legacyEncode(rawPassword: string, salt: string): Promise<string>;
|
|
8
45
|
}
|