chyz 2.0.0-rc.8 → 2.0.1-rc.1
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/BaseChyz.d.ts +73 -56
- package/BaseChyz.d.ts.map +1 -1
- package/BaseChyz.js +569 -404
- package/README.md +1 -1
- package/base/ActionFilter.d.ts +32 -32
- package/base/ActionFilter.d.ts.map +1 -1
- package/base/ActionFilter.js +82 -82
- package/base/BadRequestHttpException.d.ts +6 -0
- package/base/BadRequestHttpException.d.ts.map +1 -0
- package/base/BadRequestHttpException.js +17 -0
- package/base/BaseError.d.ts +43 -10
- package/base/BaseError.d.ts.map +1 -1
- package/base/BaseError.js +58 -26
- package/base/Behavior.d.ts +3 -3
- package/base/Behavior.js +7 -7
- package/base/CBaseObject.d.ts +4 -4
- package/base/CBaseObject.d.ts.map +1 -1
- package/base/CBaseObject.js +16 -16
- package/base/CEvents.d.ts +13 -0
- package/base/CEvents.d.ts.map +1 -0
- package/base/CEvents.js +24 -0
- package/base/CRequest.d.ts +1 -1
- package/base/CRequest.js +10 -10
- package/base/CWebController.d.ts +43 -43
- package/base/CWebController.d.ts.map +1 -1
- package/base/CWebController.js +81 -74
- package/base/Component.d.ts +20 -20
- package/base/Component.d.ts.map +1 -1
- package/base/Component.js +57 -57
- package/base/Configurable.d.ts +2 -2
- package/base/Configurable.js +8 -8
- package/base/DataErrorDbException.d.ts +5 -5
- package/base/DataErrorDbException.d.ts.map +1 -1
- package/base/DataErrorDbException.js +17 -17
- package/base/DbConnection.d.ts +12 -12
- package/base/DbConnection.js +53 -53
- package/base/ForbiddenHttpException.d.ts +4 -4
- package/base/ForbiddenHttpException.d.ts.map +1 -1
- package/base/ForbiddenHttpException.js +16 -16
- package/base/InvalidArgumentException.d.ts +5 -5
- package/base/InvalidArgumentException.d.ts.map +1 -1
- package/base/InvalidArgumentException.js +17 -17
- package/base/InvalidConfigException.d.ts +5 -5
- package/base/InvalidConfigException.d.ts.map +1 -1
- package/base/InvalidConfigException.js +17 -17
- package/base/Logs.d.ts +21 -21
- package/base/Logs.d.ts.map +1 -1
- package/base/Logs.js +57 -57
- package/base/Model.d.ts +301 -298
- package/base/Model.d.ts.map +1 -1
- package/base/Model.js +545 -507
- package/base/ModelManager.d.ts +1 -1
- package/base/ModelManager.js +19 -19
- package/base/NotFoundHttpException.d.ts +5 -5
- package/base/NotFoundHttpException.d.ts.map +1 -1
- package/base/NotFoundHttpException.js +17 -17
- package/base/RestClient.d.ts +6 -6
- package/base/RestClient.d.ts.map +1 -1
- package/base/RestClient.js +25 -25
- package/base/UnauthorizedHttpException.d.ts +5 -5
- package/base/UnauthorizedHttpException.d.ts.map +1 -1
- package/base/UnauthorizedHttpException.js +17 -17
- package/base/ValidationHttpException.d.ts +5 -5
- package/base/ValidationHttpException.d.ts.map +1 -1
- package/base/ValidationHttpException.js +17 -17
- package/base/db/Exception.d.ts +6 -6
- package/base/db/Exception.js +15 -15
- package/base/index.d.ts +19 -18
- package/base/index.d.ts.map +1 -1
- package/base/index.js +41 -39
- package/decorator/Middleware.d.ts +3 -3
- package/decorator/Middleware.js +11 -11
- package/decorator/controller.d.ts +2 -2
- package/decorator/controller.js +24 -24
- package/decorator/delete.d.ts +3 -0
- package/decorator/delete.d.ts.map +1 -0
- package/decorator/delete.js +36 -0
- package/decorator/enums/ControllerDecoratorParams.d.ts +5 -5
- package/decorator/enums/ControllerDecoratorParams.js +9 -9
- package/decorator/get.d.ts +2 -2
- package/decorator/get.js +36 -36
- package/decorator/index.d.ts +5 -3
- package/decorator/index.d.ts.map +1 -1
- package/decorator/index.js +13 -9
- package/decorator/post.d.ts +2 -2
- package/decorator/post.js +36 -36
- package/decorator/put.d.ts +3 -0
- package/decorator/put.d.ts.map +1 -0
- package/decorator/put.js +36 -0
- package/filters/AccessControl.d.ts +12 -12
- package/filters/AccessControl.d.ts.map +1 -1
- package/filters/AccessControl.js +83 -83
- package/filters/AccessRule.d.ts +82 -82
- package/filters/AccessRule.d.ts.map +1 -1
- package/filters/AccessRule.js +136 -137
- package/filters/auth/AuthInterface.d.ts +25 -25
- package/filters/auth/AuthInterface.js +2 -2
- package/filters/auth/AuthMethod.d.ts +37 -37
- package/filters/auth/AuthMethod.d.ts.map +1 -1
- package/filters/auth/AuthMethod.js +82 -82
- package/filters/auth/HttpBasicAuth.d.ts +23 -22
- package/filters/auth/HttpBasicAuth.d.ts.map +1 -1
- package/filters/auth/HttpBasicAuth.js +78 -72
- package/filters/auth/HttpBearerAuth.d.ts +17 -17
- package/filters/auth/HttpBearerAuth.d.ts.map +1 -1
- package/filters/auth/HttpBearerAuth.js +33 -32
- package/filters/auth/HttpHeaderAuth.d.ts +18 -14
- package/filters/auth/HttpHeaderAuth.d.ts.map +1 -1
- package/filters/auth/HttpHeaderAuth.js +64 -57
- package/filters/auth/JwtHttpBearerAuth.d.ts +20 -20
- package/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -1
- package/filters/auth/JwtHttpBearerAuth.js +87 -81
- package/filters/auth/KeyCloakHttpBearerAuth.d.ts +22 -22
- package/filters/auth/KeyCloakHttpBearerAuth.js +116 -116
- package/filters/auth/index.d.ts +4 -4
- package/filters/auth/index.js +11 -11
- package/filters/index.d.ts +2 -2
- package/filters/index.js +7 -7
- package/index.d.ts +28 -21
- package/index.d.ts.map +1 -1
- package/index.js +71 -60
- package/model/RouteDefinition.d.ts +6 -6
- package/model/RouteDefinition.js +8 -8
- package/package.json +22 -24
- package/rbac/AuthAssignment.d.ts +18 -18
- package/rbac/AuthAssignment.js +44 -44
- package/rbac/AuthItem.d.ts +26 -26
- package/rbac/AuthItem.js +51 -51
- package/rbac/AuthItemChild.d.ts +18 -18
- package/rbac/AuthItemChild.js +43 -43
- package/rbac/AuthManager.d.ts +111 -111
- package/rbac/AuthManager.d.ts.map +1 -1
- package/rbac/AuthManager.js +356 -355
- package/rbac/index.d.ts +5 -0
- package/rbac/index.d.ts.map +1 -0
- package/rbac/index.js +28 -0
- package/requiments/Glob.d.ts +2 -2
- package/requiments/Glob.js +10 -10
- package/requiments/ReflectUtil.js +24 -24
- package/requiments/Utils.d.ts +1 -8
- package/requiments/Utils.d.ts.map +1 -1
- package/requiments/Utils.js +115 -112
- package/validators/BooleanValidator.js +1 -1
- package/validators/CompareValidator.js +1 -1
- package/validators/DateValidator.js +1 -1
- package/validators/EmailValidator.js +1 -1
- package/validators/Validator.d.ts +17 -17
- package/validators/Validator.js +27 -27
- package/web/IdentityInterface.d.ts +55 -54
- package/web/IdentityInterface.d.ts.map +1 -1
- package/web/IdentityInterface.js +8 -8
- package/web/WebUser.d.ts +71 -71
- package/web/WebUser.js +165 -165
package/filters/AccessRule.js
CHANGED
|
@@ -1,137 +1,136 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AccessRule = void 0;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const Utils_1 = require("../requiments/Utils");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* '
|
|
39
|
-
* '
|
|
40
|
-
* '
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* @
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
// && this.
|
|
64
|
-
// && this.
|
|
65
|
-
// && this.
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* @
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* @
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
// $
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
exports.AccessRule = AccessRule;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AccessRule = void 0;
|
|
13
|
+
const base_1 = require("../base");
|
|
14
|
+
const base_2 = require("../base");
|
|
15
|
+
const Utils_1 = require("../requiments/Utils");
|
|
16
|
+
class AccessRule extends base_1.Component {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
/**
|
|
20
|
+
* @var array|Closure parameters to pass to the [[User::can()]] function for evaluating
|
|
21
|
+
* user permissions in [[$roles]].
|
|
22
|
+
*
|
|
23
|
+
* If this is an array, it will be passed directly to [[User::can()]]. For example for passing an
|
|
24
|
+
* ID from the current request, you may use the following:
|
|
25
|
+
*
|
|
26
|
+
* ```php
|
|
27
|
+
* ['postId' => Yii::$app->request->get('id')]
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* You may also specify a closure that returns an array. This can be used to
|
|
31
|
+
* evaluate the array values only if they are needed, for example when a model needs to be
|
|
32
|
+
* loaded like in the following code:
|
|
33
|
+
*
|
|
34
|
+
* ```php
|
|
35
|
+
* 'rules' => [
|
|
36
|
+
* [
|
|
37
|
+
* 'allow' => true,
|
|
38
|
+
* 'actions' => ['update'],
|
|
39
|
+
* 'roles' => ['updatePost'],
|
|
40
|
+
* 'roleParams' => function($rule) {
|
|
41
|
+
* return ['post' => Post::findOne(Yii::$app->request->get('id'))];
|
|
42
|
+
* },
|
|
43
|
+
* ],
|
|
44
|
+
* ],
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* A reference to the [[AccessRule]] instance will be passed to the closure as the first parameter.
|
|
48
|
+
*
|
|
49
|
+
* @see roles
|
|
50
|
+
* @since 2.0.12
|
|
51
|
+
*/
|
|
52
|
+
this.roleParams = [];
|
|
53
|
+
}
|
|
54
|
+
allows(action, user, request) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
if (this.matchAction(action)
|
|
57
|
+
&& (yield this.matchRole(user))) {
|
|
58
|
+
return this.allow;
|
|
59
|
+
}
|
|
60
|
+
// if (this.matchAction($action)
|
|
61
|
+
// && this.matchRole($user)
|
|
62
|
+
// && this.matchIP($request->getUserIP())
|
|
63
|
+
// && this.matchVerb($request->getMethod())
|
|
64
|
+
// && this.matchController($action->controller)
|
|
65
|
+
// && this.matchCustom($action)
|
|
66
|
+
// ) {
|
|
67
|
+
// return $this->allow ? true : false;
|
|
68
|
+
// }
|
|
69
|
+
return null;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @param action $action the action
|
|
74
|
+
* @return bool whether the rule applies to the action
|
|
75
|
+
*/
|
|
76
|
+
matchAction(action) {
|
|
77
|
+
return Utils_1.Utils.isEmpty(this.actions) || this.actions.includes(action.id);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @param controller $controller the controller
|
|
81
|
+
* @return bool whether the rule applies to the controller
|
|
82
|
+
*/
|
|
83
|
+
matchController(controller) {
|
|
84
|
+
// if (empty($this->controllers)) {
|
|
85
|
+
// return true;
|
|
86
|
+
// }
|
|
87
|
+
//
|
|
88
|
+
// $id = $controller->getUniqueId();
|
|
89
|
+
// foreach ($this->controllers as $pattern) {
|
|
90
|
+
// if (StringHelper::matchWildcard($pattern, $id)) {
|
|
91
|
+
// return true;
|
|
92
|
+
// }
|
|
93
|
+
// }
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
matchRole(user) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
let items = Utils_1.Utils.isEmpty(this.roles) ? [] : this.roles;
|
|
99
|
+
if (!Utils_1.Utils.isEmpty(this.permissions)) {
|
|
100
|
+
items = Utils_1.Utils.merge(items, this.permissions);
|
|
101
|
+
}
|
|
102
|
+
if (Utils_1.Utils.isEmpty(items)) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (!user) {
|
|
106
|
+
throw new base_2.InvalidConfigException('The user application component must be available to specify roles in AccessRule.');
|
|
107
|
+
}
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
let roleParams = [];
|
|
110
|
+
for (const itemsKey in items) {
|
|
111
|
+
let item = items[itemsKey];
|
|
112
|
+
if (item === '?') {
|
|
113
|
+
if (user.getIsGuest()) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (item === '@') {
|
|
118
|
+
if (!user.getIsGuest()) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
//role-params
|
|
124
|
+
if (!Utils_1.Utils.isEmpty(this.roleParams)) {
|
|
125
|
+
roleParams = !Utils_1.Utils.isArray(this.roleParams) ? this.roleParams.apply(this) : this.roleParams;
|
|
126
|
+
}
|
|
127
|
+
if (yield user.can(item, this.roleParams)) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.AccessRule = AccessRule;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { Request, Response } from "express";
|
|
2
|
-
export interface AuthInterface {
|
|
3
|
-
/**
|
|
4
|
-
* Authenticates the current user.
|
|
5
|
-
* @param User $user
|
|
6
|
-
* @param Request $request
|
|
7
|
-
* @param Response $response
|
|
8
|
-
* @return IdentityInterface the authenticated user identity. If authentication information is not provided, null will be returned.
|
|
9
|
-
* @throws UnauthorizedHttpException if authentication information is provided but is invalid.
|
|
10
|
-
*/
|
|
11
|
-
authenticate(user: any, request: Request, response: Response): any;
|
|
12
|
-
/**
|
|
13
|
-
* Generates challenges upon authentication failure.
|
|
14
|
-
* For example, some appropriate HTTP headers may be generated.
|
|
15
|
-
* @param Response $response
|
|
16
|
-
*/
|
|
17
|
-
challenge(response: Response): Response;
|
|
18
|
-
/**
|
|
19
|
-
* Handles authentication failure.
|
|
20
|
-
* The implementation should normally throw UnauthorizedHttpException to indicate authentication failure.
|
|
21
|
-
* @param Response $response
|
|
22
|
-
* @throws UnauthorizedHttpException
|
|
23
|
-
*/
|
|
24
|
-
handleFailure(response: Response): Response;
|
|
25
|
-
}
|
|
1
|
+
import { Request, Response } from "express";
|
|
2
|
+
export interface AuthInterface {
|
|
3
|
+
/**
|
|
4
|
+
* Authenticates the current user.
|
|
5
|
+
* @param User $user
|
|
6
|
+
* @param Request $request
|
|
7
|
+
* @param Response $response
|
|
8
|
+
* @return IdentityInterface the authenticated user identity. If authentication information is not provided, null will be returned.
|
|
9
|
+
* @throws UnauthorizedHttpException if authentication information is provided but is invalid.
|
|
10
|
+
*/
|
|
11
|
+
authenticate(user: any, request: Request, response: Response): any;
|
|
12
|
+
/**
|
|
13
|
+
* Generates challenges upon authentication failure.
|
|
14
|
+
* For example, some appropriate HTTP headers may be generated.
|
|
15
|
+
* @param Response $response
|
|
16
|
+
*/
|
|
17
|
+
challenge(response: Response): Response;
|
|
18
|
+
/**
|
|
19
|
+
* Handles authentication failure.
|
|
20
|
+
* The implementation should normally throw UnauthorizedHttpException to indicate authentication failure.
|
|
21
|
+
* @param Response $response
|
|
22
|
+
* @throws UnauthorizedHttpException
|
|
23
|
+
*/
|
|
24
|
+
handleFailure(response: Response): Response;
|
|
25
|
+
}
|
|
26
26
|
//# sourceMappingURL=AuthInterface.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { ActionFilter } from "../../base
|
|
2
|
-
import { AuthInterface } from "./AuthInterface";
|
|
3
|
-
import { WebUser } from "../../web/WebUser";
|
|
4
|
-
import { Request, Response } from "express";
|
|
5
|
-
export declare abstract class AuthMethod extends ActionFilter implements AuthInterface {
|
|
6
|
-
/**
|
|
7
|
-
* @var
|
|
8
|
-
*/
|
|
9
|
-
user: WebUser | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* @var Request the current request. If not set, the `request` application component will be used.
|
|
12
|
-
*/
|
|
13
|
-
request: Request | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* @var Response the response to be sent. If not set, the `response` application component will be used.
|
|
16
|
-
*/
|
|
17
|
-
response: Response | undefined;
|
|
18
|
-
optional: never[];
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @param action
|
|
22
|
-
* @param request
|
|
23
|
-
* @param response
|
|
24
|
-
*/
|
|
25
|
-
beforeAction(action: any, request: Request, response: Response): Promise<boolean>;
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
* @param user
|
|
29
|
-
* @param request
|
|
30
|
-
* @param response
|
|
31
|
-
*/
|
|
32
|
-
authenticate(user: WebUser, request: Request, response: Response): void;
|
|
33
|
-
challenge(response: Response):
|
|
34
|
-
handleFailure(response: Response):
|
|
35
|
-
getHeaderByKey(headers: any, findKey: any): any;
|
|
36
|
-
patternCheck(headerText: any, pattern: RegExp): any;
|
|
37
|
-
}
|
|
1
|
+
import { ActionFilter } from "../../base";
|
|
2
|
+
import { AuthInterface } from "./AuthInterface";
|
|
3
|
+
import { WebUser } from "../../web/WebUser";
|
|
4
|
+
import { Request, Response } from "express";
|
|
5
|
+
export declare abstract class AuthMethod extends ActionFilter implements AuthInterface {
|
|
6
|
+
/**
|
|
7
|
+
* @var user the user object representing the user authentication status. If not set, the `user` application component will be used.
|
|
8
|
+
*/
|
|
9
|
+
user: WebUser | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* @var Request the current request. If not set, the `request` application component will be used.
|
|
12
|
+
*/
|
|
13
|
+
request: Request | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* @var Response the response to be sent. If not set, the `response` application component will be used.
|
|
16
|
+
*/
|
|
17
|
+
response: Response | undefined;
|
|
18
|
+
optional: never[];
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param action
|
|
22
|
+
* @param request
|
|
23
|
+
* @param response
|
|
24
|
+
*/
|
|
25
|
+
beforeAction(action: any, request: Request, response: Response): Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param user
|
|
29
|
+
* @param request
|
|
30
|
+
* @param response
|
|
31
|
+
*/
|
|
32
|
+
authenticate(user: WebUser, request: Request, response: Response): void;
|
|
33
|
+
challenge(response: Response): Response;
|
|
34
|
+
handleFailure(response: Response): Response;
|
|
35
|
+
getHeaderByKey(headers: any, findKey: any): any;
|
|
36
|
+
patternCheck(headerText: any, pattern: RegExp): any;
|
|
37
|
+
}
|
|
38
38
|
//# sourceMappingURL=AuthMethod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthMethod.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/AuthMethod.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,YAAY,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"AuthMethod.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/AuthMethod.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AACxC,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE1C,8BAAsB,UAAW,SAAQ,YAAa,YAAW,aAAa;IAE1E;;OAEG;IACI,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAEjC;;OAEG;IACI,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAEpC;;OAEG;IACI,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;IAG/B,QAAQ,UAAM;IAErB;;;;;OAKG;IACU,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;IAmB3E;;;;;OAKG;IACH,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;IAKhE,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ;IAKvC,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ;IAI3C,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG;IASzC,YAAY,CAAC,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;CAYhD"}
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
4
|
-
* Author: Cihan Ozturk
|
|
5
|
-
* E-mail: cihan@chy.com.tr
|
|
6
|
-
* Github:https://github.com/cihan53/
|
|
7
|
-
*/
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AuthMethod = void 0;
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const WebUser_1 = require("../../web/WebUser");
|
|
22
|
-
class AuthMethod extends
|
|
23
|
-
constructor() {
|
|
24
|
-
super(...arguments);
|
|
25
|
-
this.optional = [];
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
* @param action
|
|
30
|
-
* @param request
|
|
31
|
-
* @param response
|
|
32
|
-
*/
|
|
33
|
-
beforeAction(action, request, response) {
|
|
34
|
-
var _a;
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
let identity = yield this.authenticate((_a = this.user) !== null && _a !== void 0 ? _a : new WebUser_1.WebUser(), request, response);
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
request.identity = identity;
|
|
39
|
-
if (identity !== null) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
this.challenge(response);
|
|
43
|
-
this.handleFailure(response);
|
|
44
|
-
return false;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param user
|
|
50
|
-
* @param request
|
|
51
|
-
* @param response
|
|
52
|
-
*/
|
|
53
|
-
authenticate(user, request, response) {
|
|
54
|
-
}
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
challenge(response) {
|
|
57
|
-
}
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
handleFailure(response) {
|
|
60
|
-
throw new
|
|
61
|
-
}
|
|
62
|
-
getHeaderByKey(headers, findKey) {
|
|
63
|
-
let key = Object.keys(headers).find(key => key.toLowerCase() === findKey.toLowerCase());
|
|
64
|
-
if (key) {
|
|
65
|
-
return headers[key];
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
patternCheck(headerText, pattern) {
|
|
70
|
-
if (pattern) {
|
|
71
|
-
let matches = headerText.match(pattern);
|
|
72
|
-
if (matches && matches.length > 0) {
|
|
73
|
-
return matches;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.AuthMethod = AuthMethod;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
4
|
+
* Author: Cihan Ozturk
|
|
5
|
+
* E-mail: cihan@chy.com.tr
|
|
6
|
+
* Github:https://github.com/cihan53/
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AuthMethod = void 0;
|
|
19
|
+
const base_1 = require("../../base");
|
|
20
|
+
const base_2 = require("../../base");
|
|
21
|
+
const WebUser_1 = require("../../web/WebUser");
|
|
22
|
+
class AuthMethod extends base_1.ActionFilter {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.optional = [];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param action
|
|
30
|
+
* @param request
|
|
31
|
+
* @param response
|
|
32
|
+
*/
|
|
33
|
+
beforeAction(action, request, response) {
|
|
34
|
+
var _a;
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
let identity = yield this.authenticate((_a = this.user) !== null && _a !== void 0 ? _a : new WebUser_1.WebUser(), request, response);
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
request.identity = identity;
|
|
39
|
+
if (identity !== null) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
this.challenge(response);
|
|
43
|
+
this.handleFailure(response);
|
|
44
|
+
return false;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param user
|
|
50
|
+
* @param request
|
|
51
|
+
* @param response
|
|
52
|
+
*/
|
|
53
|
+
authenticate(user, request, response) {
|
|
54
|
+
}
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
challenge(response) {
|
|
57
|
+
}
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
handleFailure(response) {
|
|
60
|
+
throw new base_2.UnauthorizedHttpException('Your request was made with invalid credentials.');
|
|
61
|
+
}
|
|
62
|
+
getHeaderByKey(headers, findKey) {
|
|
63
|
+
let key = Object.keys(headers).find(key => key.toLowerCase() === findKey.toLowerCase());
|
|
64
|
+
if (key) {
|
|
65
|
+
return headers[key];
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
patternCheck(headerText, pattern) {
|
|
70
|
+
if (pattern) {
|
|
71
|
+
let matches = headerText.match(pattern);
|
|
72
|
+
if (matches && matches.length > 0) {
|
|
73
|
+
return matches;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.AuthMethod = AuthMethod;
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { Request, Response } from "express";
|
|
2
|
-
import { WebUser } from "../../web/WebUser";
|
|
3
|
-
import { AuthMethod } from "./AuthMethod";
|
|
4
|
-
export declare class HttpBasicAuth extends AuthMethod {
|
|
5
|
-
/**
|
|
6
|
-
* @var string the HTTP header name
|
|
7
|
-
*/
|
|
8
|
-
header: string;
|
|
9
|
-
/**
|
|
10
|
-
* @var string a pattern to use to extract the HTTP authentication value
|
|
11
|
-
*/
|
|
12
|
-
pattern: RegExp;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { Request, Response } from "express";
|
|
2
|
+
import { WebUser } from "../../web/WebUser";
|
|
3
|
+
import { AuthMethod } from "./AuthMethod";
|
|
4
|
+
export declare class HttpBasicAuth extends AuthMethod {
|
|
5
|
+
/**
|
|
6
|
+
* @var string the HTTP header name
|
|
7
|
+
*/
|
|
8
|
+
header: string;
|
|
9
|
+
/**
|
|
10
|
+
* @var string a pattern to use to extract the HTTP authentication value
|
|
11
|
+
*/
|
|
12
|
+
pattern: RegExp;
|
|
13
|
+
auth: any;
|
|
14
|
+
/**
|
|
15
|
+
* @throws InvalidConfigException
|
|
16
|
+
*/
|
|
17
|
+
init(): void;
|
|
18
|
+
authenticate(user: WebUser, request: Request, response: Response): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* @throws UnauthorizedHttpException
|
|
21
|
+
*/
|
|
22
|
+
fail(response: Response): void;
|
|
23
|
+
}
|
|
23
24
|
//# sourceMappingURL=HttpBasicAuth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpBasicAuth.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/HttpBasicAuth.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAIxC,qBAAa,aAAc,SAAQ,UAAU;IAEzC;;OAEG;IACI,MAAM,SAAmB;IAGhC;;OAEG;IAEI,OAAO,SAAqB;
|
|
1
|
+
{"version":3,"file":"HttpBasicAuth.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/HttpBasicAuth.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAIxC,qBAAa,aAAc,SAAQ,UAAU;IAEzC;;OAEG;IACI,MAAM,SAAmB;IAGhC;;OAEG;IAEI,OAAO,SAAqB;IAG5B,IAAI,EAAE,GAAG,CAAQ;IAExB;;OAEG;IACI,IAAI,IAAI,IAAI;IAWb,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ;IA2BtE;;OAEG;IACI,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAIxC"}
|