chyz 2.0.1-rc.3 → 2.0.1-rc.36

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.
Files changed (229) hide show
  1. package/BaseChyz.ts +623 -0
  2. package/README.md +518 -518
  3. package/base/ActionFilter.ts +88 -0
  4. package/base/BadRequestHttpException.ts +14 -0
  5. package/base/{BaseError.js → BaseError.ts} +26 -18
  6. package/base/Behavior.ts +6 -0
  7. package/base/CBaseObject.ts +17 -0
  8. package/base/CEvents.ts +24 -0
  9. package/base/{CRequest.js → CRequest.ts} +6 -2
  10. package/base/CWebController.ts +90 -0
  11. package/base/Component.ts +66 -0
  12. package/{model/RouteDefinition.js → base/Configurable.ts} +4 -2
  13. package/base/DataErrorDbException.ts +16 -0
  14. package/base/DbConnection.ts +55 -0
  15. package/base/ForbiddenHttpException.ts +15 -0
  16. package/base/InvalidArgumentException.ts +16 -0
  17. package/base/InvalidConfigException.ts +16 -0
  18. package/base/{Logs.js → Logs.ts} +41 -24
  19. package/base/{Model.js → Model.ts} +225 -158
  20. package/base/{ModelManager.js → ModelManager.ts} +7 -7
  21. package/base/NotFoundHttpException.ts +14 -0
  22. package/base/RestClient.ts +26 -0
  23. package/base/UnauthorizedHttpException.ts +17 -0
  24. package/base/ValidationHttpException.ts +14 -0
  25. package/base/db/Exception.ts +14 -0
  26. package/base/index.ts +19 -0
  27. package/decorator/Middleware.ts +9 -0
  28. package/decorator/{controller.js → controller.ts} +7 -9
  29. package/decorator/{delete.js → delete.ts} +9 -9
  30. package/decorator/enums/ControllerDecoratorParams.ts +5 -0
  31. package/decorator/{get.js → get.ts} +11 -10
  32. package/decorator/index.ts +5 -0
  33. package/decorator/{post.js → post.ts} +10 -10
  34. package/decorator/{put.js → put.ts} +9 -9
  35. package/filters/AccessControl.ts +74 -0
  36. package/filters/AccessRule.ts +182 -0
  37. package/filters/auth/{AuthInterface.d.ts → AuthInterface.ts} +15 -7
  38. package/filters/auth/AuthMethod.ts +100 -0
  39. package/filters/auth/HttpBasicAuth.ts +79 -0
  40. package/filters/auth/HttpBearerAuth.ts +34 -0
  41. package/filters/auth/HttpHeaderAuth.ts +61 -0
  42. package/filters/auth/JwtHttpBearerAuth.ts +83 -0
  43. package/filters/auth/KeyCloakHttpBearerAuth.ts +114 -0
  44. package/filters/auth/index.ts +4 -0
  45. package/filters/index.ts +2 -0
  46. package/index.ts +80 -0
  47. package/log/config/log4js.json +55 -55
  48. package/model/RouteDefinition.ts +18 -0
  49. package/package.json +63 -61
  50. package/rbac/AuthAssignment.ts +50 -0
  51. package/rbac/{AuthItem.js → AuthItem.ts} +22 -16
  52. package/rbac/{AuthItemChild.js → AuthItemChild.ts} +21 -14
  53. package/rbac/AuthManager.ts +399 -0
  54. package/rbac/index.ts +12 -0
  55. package/{web/IdentityInterface.js → requiments/Glob.ts} +3 -2
  56. package/requiments/{ReflectUtil.js → ReflectUtil.ts} +6 -4
  57. package/requiments/{Utils.js → Utils.ts} +40 -34
  58. package/validators/BooleanValidator.ts +0 -0
  59. package/validators/CompareValidator.ts +0 -0
  60. package/validators/DateValidator.ts +0 -0
  61. package/validators/EmailValidator.ts +0 -0
  62. package/validators/Validator.ts +27 -0
  63. package/web/{IdentityInterface.d.ts → IdentityInterface.ts} +15 -2
  64. package/web/WebUser.ts +187 -0
  65. package/BaseChyz.d.ts +0 -74
  66. package/BaseChyz.d.ts.map +0 -1
  67. package/BaseChyz.js +0 -569
  68. package/base/ActionFilter.d.ts +0 -33
  69. package/base/ActionFilter.d.ts.map +0 -1
  70. package/base/ActionFilter.js +0 -90
  71. package/base/BadRequestHttpException.d.ts +0 -6
  72. package/base/BadRequestHttpException.d.ts.map +0 -1
  73. package/base/BadRequestHttpException.js +0 -17
  74. package/base/BaseError.d.ts +0 -44
  75. package/base/BaseError.d.ts.map +0 -1
  76. package/base/Behavior.d.ts +0 -4
  77. package/base/Behavior.d.ts.map +0 -1
  78. package/base/Behavior.js +0 -7
  79. package/base/CBaseObject.d.ts +0 -5
  80. package/base/CBaseObject.d.ts.map +0 -1
  81. package/base/CBaseObject.js +0 -16
  82. package/base/CEvents.d.ts +0 -13
  83. package/base/CEvents.d.ts.map +0 -1
  84. package/base/CEvents.js +0 -24
  85. package/base/CRequest.d.ts +0 -2
  86. package/base/CRequest.d.ts.map +0 -1
  87. package/base/CWebController.d.ts +0 -44
  88. package/base/CWebController.d.ts.map +0 -1
  89. package/base/CWebController.js +0 -81
  90. package/base/Component.d.ts +0 -21
  91. package/base/Component.d.ts.map +0 -1
  92. package/base/Component.js +0 -57
  93. package/base/Configurable.d.ts +0 -3
  94. package/base/Configurable.d.ts.map +0 -1
  95. package/base/Configurable.js +0 -8
  96. package/base/DataErrorDbException.d.ts +0 -6
  97. package/base/DataErrorDbException.d.ts.map +0 -1
  98. package/base/DataErrorDbException.js +0 -17
  99. package/base/DbConnection.d.ts +0 -13
  100. package/base/DbConnection.d.ts.map +0 -1
  101. package/base/DbConnection.js +0 -53
  102. package/base/ForbiddenHttpException.d.ts +0 -5
  103. package/base/ForbiddenHttpException.d.ts.map +0 -1
  104. package/base/ForbiddenHttpException.js +0 -16
  105. package/base/InvalidArgumentException.d.ts +0 -6
  106. package/base/InvalidArgumentException.d.ts.map +0 -1
  107. package/base/InvalidArgumentException.js +0 -17
  108. package/base/InvalidConfigException.d.ts +0 -6
  109. package/base/InvalidConfigException.d.ts.map +0 -1
  110. package/base/InvalidConfigException.js +0 -17
  111. package/base/Logs.d.ts +0 -22
  112. package/base/Logs.d.ts.map +0 -1
  113. package/base/Model.d.ts +0 -302
  114. package/base/Model.d.ts.map +0 -1
  115. package/base/ModelManager.d.ts +0 -2
  116. package/base/ModelManager.d.ts.map +0 -1
  117. package/base/NotFoundHttpException.d.ts +0 -6
  118. package/base/NotFoundHttpException.d.ts.map +0 -1
  119. package/base/NotFoundHttpException.js +0 -17
  120. package/base/RestClient.d.ts +0 -7
  121. package/base/RestClient.d.ts.map +0 -1
  122. package/base/RestClient.js +0 -25
  123. package/base/UnauthorizedHttpException.d.ts +0 -6
  124. package/base/UnauthorizedHttpException.d.ts.map +0 -1
  125. package/base/UnauthorizedHttpException.js +0 -17
  126. package/base/ValidationHttpException.d.ts +0 -6
  127. package/base/ValidationHttpException.d.ts.map +0 -1
  128. package/base/ValidationHttpException.js +0 -17
  129. package/base/db/Exception.d.ts +0 -7
  130. package/base/db/Exception.d.ts.map +0 -1
  131. package/base/db/Exception.js +0 -15
  132. package/base/index.d.ts +0 -20
  133. package/base/index.d.ts.map +0 -1
  134. package/base/index.js +0 -41
  135. package/decorator/Middleware.d.ts +0 -4
  136. package/decorator/Middleware.d.ts.map +0 -1
  137. package/decorator/Middleware.js +0 -11
  138. package/decorator/controller.d.ts +0 -3
  139. package/decorator/controller.d.ts.map +0 -1
  140. package/decorator/delete.d.ts +0 -3
  141. package/decorator/delete.d.ts.map +0 -1
  142. package/decorator/enums/ControllerDecoratorParams.d.ts +0 -6
  143. package/decorator/enums/ControllerDecoratorParams.d.ts.map +0 -1
  144. package/decorator/enums/ControllerDecoratorParams.js +0 -9
  145. package/decorator/get.d.ts +0 -3
  146. package/decorator/get.d.ts.map +0 -1
  147. package/decorator/index.d.ts +0 -6
  148. package/decorator/index.d.ts.map +0 -1
  149. package/decorator/index.js +0 -13
  150. package/decorator/post.d.ts +0 -3
  151. package/decorator/post.d.ts.map +0 -1
  152. package/decorator/put.d.ts +0 -3
  153. package/decorator/put.d.ts.map +0 -1
  154. package/filters/AccessControl.d.ts +0 -13
  155. package/filters/AccessControl.d.ts.map +0 -1
  156. package/filters/AccessControl.js +0 -83
  157. package/filters/AccessRule.d.ts +0 -83
  158. package/filters/AccessRule.d.ts.map +0 -1
  159. package/filters/AccessRule.js +0 -136
  160. package/filters/auth/AuthInterface.d.ts.map +0 -1
  161. package/filters/auth/AuthInterface.js +0 -2
  162. package/filters/auth/AuthMethod.d.ts +0 -38
  163. package/filters/auth/AuthMethod.d.ts.map +0 -1
  164. package/filters/auth/AuthMethod.js +0 -82
  165. package/filters/auth/HttpBasicAuth.d.ts +0 -24
  166. package/filters/auth/HttpBasicAuth.d.ts.map +0 -1
  167. package/filters/auth/HttpBasicAuth.js +0 -78
  168. package/filters/auth/HttpBearerAuth.d.ts +0 -18
  169. package/filters/auth/HttpBearerAuth.d.ts.map +0 -1
  170. package/filters/auth/HttpBearerAuth.js +0 -33
  171. package/filters/auth/HttpHeaderAuth.d.ts +0 -19
  172. package/filters/auth/HttpHeaderAuth.d.ts.map +0 -1
  173. package/filters/auth/HttpHeaderAuth.js +0 -64
  174. package/filters/auth/JwtHttpBearerAuth.d.ts +0 -21
  175. package/filters/auth/JwtHttpBearerAuth.d.ts.map +0 -1
  176. package/filters/auth/JwtHttpBearerAuth.js +0 -87
  177. package/filters/auth/KeyCloakHttpBearerAuth.d.ts +0 -23
  178. package/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +0 -1
  179. package/filters/auth/KeyCloakHttpBearerAuth.js +0 -116
  180. package/filters/auth/index.d.ts +0 -5
  181. package/filters/auth/index.d.ts.map +0 -1
  182. package/filters/auth/index.js +0 -11
  183. package/filters/index.d.ts +0 -3
  184. package/filters/index.d.ts.map +0 -1
  185. package/filters/index.js +0 -7
  186. package/index.d.ts +0 -26
  187. package/index.d.ts.map +0 -1
  188. package/index.js +0 -72
  189. package/model/RouteDefinition.d.ts +0 -7
  190. package/model/RouteDefinition.d.ts.map +0 -1
  191. package/rbac/AuthAssignment.d.ts +0 -19
  192. package/rbac/AuthAssignment.d.ts.map +0 -1
  193. package/rbac/AuthAssignment.js +0 -44
  194. package/rbac/AuthItem.d.ts +0 -27
  195. package/rbac/AuthItem.d.ts.map +0 -1
  196. package/rbac/AuthItemChild.d.ts +0 -19
  197. package/rbac/AuthItemChild.d.ts.map +0 -1
  198. package/rbac/AuthManager.d.ts +0 -112
  199. package/rbac/AuthManager.d.ts.map +0 -1
  200. package/rbac/AuthManager.js +0 -356
  201. package/rbac/index.d.ts +0 -5
  202. package/rbac/index.d.ts.map +0 -1
  203. package/rbac/index.js +0 -28
  204. package/requiments/Glob.d.ts +0 -3
  205. package/requiments/Glob.d.ts.map +0 -1
  206. package/requiments/Glob.js +0 -10
  207. package/requiments/ReflectUtil.d.ts +0 -1
  208. package/requiments/ReflectUtil.d.ts.map +0 -1
  209. package/requiments/Utils.d.ts +0 -2
  210. package/requiments/Utils.d.ts.map +0 -1
  211. package/validators/BooleanValidator.d.ts +0 -1
  212. package/validators/BooleanValidator.d.ts.map +0 -1
  213. package/validators/BooleanValidator.js +0 -1
  214. package/validators/CompareValidator.d.ts +0 -1
  215. package/validators/CompareValidator.d.ts.map +0 -1
  216. package/validators/CompareValidator.js +0 -1
  217. package/validators/DateValidator.d.ts +0 -1
  218. package/validators/DateValidator.d.ts.map +0 -1
  219. package/validators/DateValidator.js +0 -1
  220. package/validators/EmailValidator.d.ts +0 -1
  221. package/validators/EmailValidator.d.ts.map +0 -1
  222. package/validators/EmailValidator.js +0 -1
  223. package/validators/Validator.d.ts +0 -18
  224. package/validators/Validator.d.ts.map +0 -1
  225. package/validators/Validator.js +0 -27
  226. package/web/IdentityInterface.d.ts.map +0 -1
  227. package/web/WebUser.d.ts +0 -72
  228. package/web/WebUser.d.ts.map +0 -1
  229. package/web/WebUser.js +0 -165
@@ -1,3 +0,0 @@
1
- import "reflect-metadata";
2
- export declare const post: (path: string) => MethodDecorator;
3
- //# sourceMappingURL=post.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../src/decorator/post.ts"],"names":[],"mappings":"AAOA,OAAQ,kBAAkB,CAAC;AAG3B,eAAO,MAAM,IAAI,SAAU,MAAM,KAAG,eAyBnC,CAAC"}
@@ -1,3 +0,0 @@
1
- import "reflect-metadata";
2
- export declare const put: (path: string) => MethodDecorator;
3
- //# sourceMappingURL=put.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"put.d.ts","sourceRoot":"","sources":["../../src/decorator/put.ts"],"names":[],"mappings":"AAOA,OAAQ,kBAAkB,CAAC;AAG3B,eAAO,MAAM,GAAG,SAAU,MAAM,KAAG,eAyBlC,CAAC"}
@@ -1,13 +0,0 @@
1
- /// <reference types="express" />
2
- import { Request, Response } from "../index";
3
- import { ActionFilter } from "../base";
4
- import { WebUser } from "../web/WebUser";
5
- export declare class AccessControl extends ActionFilter {
6
- user: any;
7
- rules: any;
8
- denyCallback: any;
9
- init(): void;
10
- beforeAction(action: any, request: Request, res: Response): Promise<boolean>;
11
- denyAccess(user: WebUser): void;
12
- }
13
- //# sourceMappingURL=AccessControl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccessControl.d.ts","sourceRoot":"","sources":["../../src/filters/AccessControl.ts"],"names":[],"mappings":";AAMA,OAAO,EAAC,OAAO,EAAC,QAAQ,EAAU,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AAErC,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AAIvC,qBAAa,aAAc,SAAQ,YAAY;IAEpC,IAAI,EAAE,GAAG,CAAQ;IACjB,KAAK,EAAE,GAAG,CAAC;IACX,YAAY,EAAE,GAAG,CAAQ;IAEzB,IAAI;IAgBE,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAC,GAAG,EAAC,QAAQ;IAiC7D,UAAU,CAAC,IAAI,EAAE,OAAO;CAMlC"}
@@ -1,83 +0,0 @@
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.AccessControl = void 0;
13
- /*
14
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
15
- * Author: Cihan Ozturk
16
- * E-mail: cihan@chy.com.tr
17
- * Github:https://github.com/cihan53/
18
- */
19
- const index_1 = require("../index");
20
- const base_1 = require("../base");
21
- const base_2 = require("../base");
22
- const AccessRule_1 = require("./AccessRule");
23
- const WebUser_1 = require("../web/WebUser");
24
- const Utils_1 = require("../requiments/Utils");
25
- class AccessControl extends base_2.ActionFilter {
26
- constructor() {
27
- super(...arguments);
28
- this.user = null;
29
- this.denyCallback = null;
30
- }
31
- init() {
32
- var _a;
33
- super.init();
34
- if (this.user == undefined) {
35
- this.user = (_a = Utils_1.Utils.cloneDeep(index_1.BaseChyz.getComponent("user"))) !== null && _a !== void 0 ? _a : new WebUser_1.WebUser();
36
- }
37
- this.rules.forEach((rule, index) => {
38
- if (rule === Object(rule)) {
39
- this.rules[index] = Utils_1.Utils.createObject(new AccessRule_1.AccessRule(), rule);
40
- }
41
- });
42
- }
43
- beforeAction(action, request, res) {
44
- var _a, _b;
45
- return __awaiter(this, void 0, void 0, function* () {
46
- let allow;
47
- // @ts-ignore
48
- let user = (_a = request.user) !== null && _a !== void 0 ? _a : this.user;
49
- // @ts-ignore
50
- user.identity = (_b = request.identity) !== null && _b !== void 0 ? _b : null;
51
- for (const rulesKey in this.rules) {
52
- let rule = this.rules[rulesKey];
53
- if ((allow = yield rule.allows(action, user, request))) {
54
- return true;
55
- }
56
- else if (allow === false) {
57
- if (this.denyCallback != null) {
58
- rule.denyCallback.apply(rule, action);
59
- }
60
- else {
61
- this.denyAccess(user);
62
- }
63
- return false;
64
- }
65
- }
66
- if (this.denyCallback != null) {
67
- this.denyCallback.apply(null, action);
68
- }
69
- else {
70
- this.denyAccess(user);
71
- }
72
- return false;
73
- });
74
- }
75
- denyAccess(user) {
76
- if (user != undefined && user.getIsGuest()) {
77
- user.loginRequired();
78
- }
79
- else
80
- throw new base_1.ForbiddenHttpException(index_1.BaseChyz.t('You are not allowed to perform this action.'));
81
- }
82
- }
83
- exports.AccessControl = AccessControl;
@@ -1,83 +0,0 @@
1
- import { WebUser } from "../web/WebUser";
2
- import { Component } from "../base";
3
- import { Request } from "express";
4
- export declare class AccessRule extends Component {
5
- /**
6
- * @var allow whether this is an 'allow' rule or 'deny' rule.
7
- */
8
- allow: any;
9
- /**
10
- * @var array list of action IDs that this rule applies to. The comparison is case-sensitive.
11
- * If not set or empty, it means this rule applies to all actions.
12
- */
13
- actions: any;
14
- /**
15
- * @var array list of the controller IDs that this rule applies to.
16
- */
17
- controllers: any;
18
- /**
19
- * - `?`: matches a guest user (not authenticated yet)
20
- * - `@`: matches an authenticated user
21
- */
22
- roles: any;
23
- /**
24
- * @var array list of RBAC (Role-Based Access Control) permissions that this rules applies to.
25
- */
26
- permissions: any;
27
- /**
28
- * @var array|Closure parameters to pass to the [[User::can()]] function for evaluating
29
- * user permissions in [[$roles]].
30
- *
31
- * If this is an array, it will be passed directly to [[User::can()]]. For example for passing an
32
- * ID from the current request, you may use the following:
33
- *
34
- * ```php
35
- * ['postId' => Yii::$app->request->get('id')]
36
- * ```
37
- *
38
- * You may also specify a closure that returns an array. This can be used to
39
- * evaluate the array values only if they are needed, for example when a model needs to be
40
- * loaded like in the following code:
41
- *
42
- * ```php
43
- * 'rules' => [
44
- * [
45
- * 'allow' => true,
46
- * 'actions' => ['update'],
47
- * 'roles' => ['updatePost'],
48
- * 'roleParams' => function($rule) {
49
- * return ['post' => Post::findOne(Yii::$app->request->get('id'))];
50
- * },
51
- * ],
52
- * ],
53
- * ```
54
- *
55
- * A reference to the [[AccessRule]] instance will be passed to the closure as the first parameter.
56
- *
57
- * @see roles
58
- * @since 2.0.12
59
- */
60
- roleParams: any;
61
- /**
62
- * @var array list of user IP addresses that this rule applies to. An IP address
63
- * can contain the wildcard `*` at the end so that it matches IP addresses with the same prefix.
64
- * For example, '192.168.*' matches all IP addresses in the segment '192.168.'.
65
- * It may also contain a pattern/mask like '172.16.0.0/12' which would match all IPs from the
66
- * 20-bit private network block in RFC1918.
67
- * If not set or empty, it means this rule applies to all IP addresses.
68
- */
69
- ips: any;
70
- allows(action: any, user: WebUser, request: Request): Promise<any>;
71
- /**
72
- * @param action $action the action
73
- * @return bool whether the rule applies to the action
74
- */
75
- protected matchAction(action: any): any;
76
- /**
77
- * @param controller $controller the controller
78
- * @return bool whether the rule applies to the controller
79
- */
80
- protected matchController(controller: any): boolean;
81
- protected matchRole(user: WebUser): Promise<boolean>;
82
- }
83
- //# sourceMappingURL=AccessRule.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccessRule.d.ts","sourceRoot":"","sources":["../../src/filters/AccessRule.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAElC,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAIhC,qBAAa,UAAW,SAAQ,SAAS;IAErC;;OAEG;IACI,KAAK,EAAE,GAAG,CAAC;IAClB;;;OAGG;IACI,OAAO,EAAE,GAAG,CAAC;IAEpB;;OAEG;IACI,WAAW,EAAE,GAAG,CAAC;IAExB;;;OAGG;IAEI,KAAK,EAAE,GAAG,CAAC;IAElB;;OAEG;IACI,WAAW,EAAE,GAAG,CAAC;IAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACI,UAAU,EAAE,GAAG,CAAM;IAG5B;;;;;;;OAOG;IACI,GAAG,EAAE,GAAG,CAAC;IAGH,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO;IAoBhE;;;OAGG;IACH,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,GAAG;IAIjC;;;OAGG;IACH,SAAS,CAAC,eAAe,CAAC,UAAU,EAAE,GAAG;cAezB,SAAS,CAAC,IAAI,EAAE,OAAO;CA6C1C"}
@@ -1,136 +0,0 @@
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 +0,0 @@
1
- {"version":3,"file":"AuthInterface.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/AuthInterface.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE1C,MAAM,WAAW,aAAa;IAC1B;;;;;;;OAOG;IACF,YAAY,CAAC,IAAI,EAAC,GAAG,EAAE,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,QAAQ,GAAE,GAAG,CAAC;IAEhE;;;;OAIG;IACF,SAAS,CAAC,QAAQ,EAAC,QAAQ,GAAE,QAAQ,CAAC;IAEvC;;;;;OAKG;IACF,aAAa,CAAC,QAAQ,EAAC,QAAQ,GAAE,QAAQ,CAAC;CAC9C"}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,38 +0,0 @@
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
- //# sourceMappingURL=AuthMethod.d.ts.map
@@ -1 +0,0 @@
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 +0,0 @@
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,24 +0,0 @@
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
- }
24
- //# sourceMappingURL=HttpBasicAuth.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,78 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.HttpBasicAuth = void 0;
22
- const AuthMethod_1 = require("./AuthMethod");
23
- const base_1 = require("../../base");
24
- const BaseChyz_1 = __importDefault(require("../../BaseChyz"));
25
- class HttpBasicAuth extends AuthMethod_1.AuthMethod {
26
- constructor() {
27
- super(...arguments);
28
- /**
29
- * @var string the HTTP header name
30
- */
31
- this.header = 'Authorization';
32
- /**
33
- * @var string a pattern to use to extract the HTTP authentication value
34
- */
35
- this.pattern = /^Basic\s+(.*?)$/;
36
- this.auth = null;
37
- }
38
- /**
39
- * @throws InvalidConfigException
40
- */
41
- init() {
42
- var _a;
43
- super.init();
44
- if (!this.pattern) {
45
- throw new base_1.InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
46
- }
47
- this.user = (_a = BaseChyz_1.default.getComponent("user")) !== null && _a !== void 0 ? _a : null;
48
- }
49
- authenticate(user, request, response) {
50
- return __awaiter(this, arguments, void 0, function* () {
51
- let autHeader = this.getHeaderByKey(request.headers, this.header);
52
- if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
53
- return this.fail(response);
54
- }
55
- let identity = null;
56
- let token = null;
57
- let buff = new Buffer(autHeader[1], "base64");
58
- let basicauth = buff.toString().split(":");
59
- if (this.auth != null) {
60
- identity = yield this.auth(autHeader[1], ...arguments, basicauth);
61
- }
62
- else {
63
- identity = yield user.loginByAccessToken(basicauth, "HttpBasicAuth");
64
- }
65
- if (identity == null)
66
- this.fail(response);
67
- return identity;
68
- });
69
- }
70
- /**
71
- * @throws UnauthorizedHttpException
72
- */
73
- fail(response) {
74
- this.challenge(response);
75
- this.handleFailure(response);
76
- }
77
- }
78
- exports.HttpBasicAuth = HttpBasicAuth;
@@ -1,18 +0,0 @@
1
- import { HttpHeaderAuth } from "./HttpHeaderAuth";
2
- import { Response } from "express";
3
- export declare class HttpBearerAuth extends HttpHeaderAuth {
4
- /**
5
- * {@inheritdoc}
6
- */
7
- header: string;
8
- pattern: RegExp;
9
- /**
10
- * @var string the HTTP authentication realm
11
- */
12
- realm: string;
13
- /**
14
- * {@inheritdoc}
15
- */
16
- challenge(response: Response): Response;
17
- }
18
- //# sourceMappingURL=HttpBearerAuth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"HttpBearerAuth.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/HttpBearerAuth.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEjC,qBAAa,cAAe,SAAQ,cAAc;IAE9C;;OAEG;IACI,MAAM,SAAmB;IAEzB,OAAO,SAAsB;IACpC;;OAEG;IACI,KAAK,SAAS;IAGrB;;OAEG;IACI,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAE,QAAQ;CAMhD"}
@@ -1,33 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.HttpBearerAuth = void 0;
10
- const HttpHeaderAuth_1 = require("./HttpHeaderAuth");
11
- class HttpBearerAuth extends HttpHeaderAuth_1.HttpHeaderAuth {
12
- constructor() {
13
- super(...arguments);
14
- /**
15
- * {@inheritdoc}
16
- */
17
- this.header = 'Authorization';
18
- // @ts-ignore
19
- this.pattern = /^Bearer\s+(.*?)$/;
20
- /**
21
- * @var string the HTTP authentication realm
22
- */
23
- this.realm = 'api';
24
- }
25
- /**
26
- * {@inheritdoc}
27
- */
28
- challenge(response) {
29
- response.set('WWW-Authenticate', `Bearer realm="${this.realm}"`);
30
- return response;
31
- }
32
- }
33
- exports.HttpBearerAuth = HttpBearerAuth;
@@ -1,19 +0,0 @@
1
- import { AuthMethod } from "./AuthMethod";
2
- import { WebUser } from "../../web/WebUser";
3
- import { Request, Response } from "express";
4
- export declare class HttpHeaderAuth 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: string;
13
- authenticate(user: WebUser, request: Request, response: Response): Promise<any>;
14
- /**
15
- * @throws UnauthorizedHttpException
16
- */
17
- fail(response: Response): void;
18
- }
19
- //# sourceMappingURL=HttpHeaderAuth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"HttpHeaderAuth.d.ts","sourceRoot":"","sources":["../../../src/filters/auth/HttpHeaderAuth.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE1C,qBAAa,cAAe,SAAQ,UAAU;IAC1C;;OAEG;IACI,MAAM,SAAe;IAG5B;;OAEG;IAEI,OAAO,EAAG,MAAM,CAAC;IAGlB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,QAAQ;IA2BpE;;OAEG;IACI,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAIxC"}