chyz 2.0.1-rc.36 → 2.0.1-rc.37

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 (231) hide show
  1. package/dist/BaseChyz.d.ts +74 -0
  2. package/dist/BaseChyz.d.ts.map +1 -0
  3. package/dist/BaseChyz.js +586 -0
  4. package/dist/base/ActionFilter.d.ts +32 -0
  5. package/dist/base/ActionFilter.d.ts.map +1 -0
  6. package/dist/base/ActionFilter.js +90 -0
  7. package/dist/base/BadRequestHttpException.d.ts +6 -0
  8. package/dist/base/BadRequestHttpException.d.ts.map +1 -0
  9. package/dist/base/BadRequestHttpException.js +17 -0
  10. package/dist/base/BaseError.d.ts +44 -0
  11. package/dist/base/BaseError.d.ts.map +1 -0
  12. package/{base/BaseError.ts → dist/base/BaseError.js} +18 -26
  13. package/dist/base/Behavior.d.ts +4 -0
  14. package/dist/base/Behavior.d.ts.map +1 -0
  15. package/dist/base/Behavior.js +7 -0
  16. package/dist/base/CBaseObject.d.ts +5 -0
  17. package/dist/base/CBaseObject.d.ts.map +1 -0
  18. package/dist/base/CBaseObject.js +16 -0
  19. package/dist/base/CEvents.d.ts +13 -0
  20. package/dist/base/CEvents.d.ts.map +1 -0
  21. package/dist/base/CEvents.js +24 -0
  22. package/dist/base/CRequest.d.ts +2 -0
  23. package/dist/base/CRequest.d.ts.map +1 -0
  24. package/{base/CRequest.ts → dist/base/CRequest.js} +2 -6
  25. package/dist/base/CWebController.d.ts +44 -0
  26. package/dist/base/CWebController.d.ts.map +1 -0
  27. package/dist/base/CWebController.js +81 -0
  28. package/dist/base/Component.d.ts +21 -0
  29. package/dist/base/Component.d.ts.map +1 -0
  30. package/dist/base/Component.js +57 -0
  31. package/dist/base/Configurable.d.ts +3 -0
  32. package/dist/base/Configurable.d.ts.map +1 -0
  33. package/{requiments/Glob.ts → dist/base/Configurable.js} +2 -3
  34. package/dist/base/DataErrorDbException.d.ts +6 -0
  35. package/dist/base/DataErrorDbException.d.ts.map +1 -0
  36. package/dist/base/DataErrorDbException.js +17 -0
  37. package/dist/base/DbConnection.d.ts +13 -0
  38. package/dist/base/DbConnection.d.ts.map +1 -0
  39. package/dist/base/DbConnection.js +53 -0
  40. package/dist/base/ForbiddenHttpException.d.ts +5 -0
  41. package/dist/base/ForbiddenHttpException.d.ts.map +1 -0
  42. package/dist/base/ForbiddenHttpException.js +16 -0
  43. package/dist/base/InvalidArgumentException.d.ts +6 -0
  44. package/dist/base/InvalidArgumentException.d.ts.map +1 -0
  45. package/dist/base/InvalidArgumentException.js +17 -0
  46. package/dist/base/InvalidConfigException.d.ts +6 -0
  47. package/dist/base/InvalidConfigException.d.ts.map +1 -0
  48. package/dist/base/InvalidConfigException.js +17 -0
  49. package/dist/base/Logs.d.ts +22 -0
  50. package/dist/base/Logs.d.ts.map +1 -0
  51. package/{base/Logs.ts → dist/base/Logs.js} +24 -41
  52. package/dist/base/Model.d.ts +302 -0
  53. package/dist/base/Model.d.ts.map +1 -0
  54. package/{base/Model.ts → dist/base/Model.js} +158 -225
  55. package/dist/base/ModelManager.d.ts +2 -0
  56. package/dist/base/ModelManager.d.ts.map +1 -0
  57. package/{base/ModelManager.ts → dist/base/ModelManager.js} +7 -7
  58. package/dist/base/NotFoundHttpException.d.ts +6 -0
  59. package/dist/base/NotFoundHttpException.d.ts.map +1 -0
  60. package/dist/base/NotFoundHttpException.js +17 -0
  61. package/dist/base/RestClient.d.ts +7 -0
  62. package/dist/base/RestClient.d.ts.map +1 -0
  63. package/dist/base/RestClient.js +25 -0
  64. package/dist/base/UnauthorizedHttpException.d.ts +6 -0
  65. package/dist/base/UnauthorizedHttpException.d.ts.map +1 -0
  66. package/dist/base/UnauthorizedHttpException.js +17 -0
  67. package/dist/base/ValidationHttpException.d.ts +6 -0
  68. package/dist/base/ValidationHttpException.d.ts.map +1 -0
  69. package/dist/base/ValidationHttpException.js +17 -0
  70. package/dist/base/db/Exception.d.ts +7 -0
  71. package/dist/base/db/Exception.d.ts.map +1 -0
  72. package/dist/base/db/Exception.js +15 -0
  73. package/dist/base/index.d.ts +20 -0
  74. package/dist/base/index.d.ts.map +1 -0
  75. package/dist/base/index.js +41 -0
  76. package/dist/decorator/Middleware.d.ts +4 -0
  77. package/dist/decorator/Middleware.d.ts.map +1 -0
  78. package/dist/decorator/Middleware.js +10 -0
  79. package/dist/decorator/controller.d.ts +3 -0
  80. package/dist/decorator/controller.d.ts.map +1 -0
  81. package/{decorator/controller.ts → dist/decorator/controller.js} +9 -7
  82. package/dist/decorator/delete.d.ts +3 -0
  83. package/dist/decorator/delete.d.ts.map +1 -0
  84. package/{decorator/delete.ts → dist/decorator/delete.js} +9 -9
  85. package/dist/decorator/enums/ControllerDecoratorParams.d.ts +6 -0
  86. package/dist/decorator/enums/ControllerDecoratorParams.d.ts.map +1 -0
  87. package/dist/decorator/enums/ControllerDecoratorParams.js +9 -0
  88. package/dist/decorator/get.d.ts +3 -0
  89. package/dist/decorator/get.d.ts.map +1 -0
  90. package/{decorator/get.ts → dist/decorator/get.js} +10 -11
  91. package/dist/decorator/index.d.ts +6 -0
  92. package/dist/decorator/index.d.ts.map +1 -0
  93. package/dist/decorator/index.js +13 -0
  94. package/dist/decorator/post.d.ts +3 -0
  95. package/dist/decorator/post.d.ts.map +1 -0
  96. package/{decorator/post.ts → dist/decorator/post.js} +10 -10
  97. package/dist/decorator/put.d.ts +3 -0
  98. package/dist/decorator/put.d.ts.map +1 -0
  99. package/{decorator/put.ts → dist/decorator/put.js} +9 -9
  100. package/dist/filters/AccessControl.d.ts +12 -0
  101. package/dist/filters/AccessControl.d.ts.map +1 -0
  102. package/dist/filters/AccessControl.js +83 -0
  103. package/dist/filters/AccessRule.d.ts +83 -0
  104. package/dist/filters/AccessRule.d.ts.map +1 -0
  105. package/dist/filters/AccessRule.js +136 -0
  106. package/{filters/auth/AuthInterface.ts → dist/filters/auth/AuthInterface.d.ts} +7 -15
  107. package/dist/filters/auth/AuthInterface.d.ts.map +1 -0
  108. package/dist/filters/auth/AuthInterface.js +2 -0
  109. package/dist/filters/auth/AuthMethod.d.ts +38 -0
  110. package/dist/filters/auth/AuthMethod.d.ts.map +1 -0
  111. package/dist/filters/auth/AuthMethod.js +82 -0
  112. package/dist/filters/auth/HttpBasicAuth.d.ts +24 -0
  113. package/dist/filters/auth/HttpBasicAuth.d.ts.map +1 -0
  114. package/dist/filters/auth/HttpBasicAuth.js +79 -0
  115. package/dist/filters/auth/HttpBearerAuth.d.ts +18 -0
  116. package/dist/filters/auth/HttpBearerAuth.d.ts.map +1 -0
  117. package/dist/filters/auth/HttpBearerAuth.js +33 -0
  118. package/dist/filters/auth/HttpHeaderAuth.d.ts +19 -0
  119. package/dist/filters/auth/HttpHeaderAuth.d.ts.map +1 -0
  120. package/dist/filters/auth/HttpHeaderAuth.js +64 -0
  121. package/dist/filters/auth/JwtHttpBearerAuth.d.ts +21 -0
  122. package/dist/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -0
  123. package/dist/filters/auth/JwtHttpBearerAuth.js +88 -0
  124. package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts +23 -0
  125. package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +1 -0
  126. package/dist/filters/auth/KeyCloakHttpBearerAuth.js +116 -0
  127. package/dist/filters/auth/index.d.ts +5 -0
  128. package/dist/filters/auth/index.d.ts.map +1 -0
  129. package/dist/filters/auth/index.js +11 -0
  130. package/dist/filters/index.d.ts +3 -0
  131. package/dist/filters/index.d.ts.map +1 -0
  132. package/dist/filters/index.js +7 -0
  133. package/dist/index.d.ts +26 -0
  134. package/dist/index.d.ts.map +1 -0
  135. package/dist/index.js +73 -0
  136. package/dist/log/log/config/log4js.json +55 -0
  137. package/dist/model/RouteDefinition.d.ts +7 -0
  138. package/dist/model/RouteDefinition.d.ts.map +1 -0
  139. package/{base/Configurable.ts → dist/model/RouteDefinition.js} +2 -4
  140. package/dist/package.json +63 -0
  141. package/dist/rbac/AuthAssignment.d.ts +19 -0
  142. package/dist/rbac/AuthAssignment.d.ts.map +1 -0
  143. package/dist/rbac/AuthAssignment.js +44 -0
  144. package/dist/rbac/AuthItem.d.ts +27 -0
  145. package/dist/rbac/AuthItem.d.ts.map +1 -0
  146. package/{rbac/AuthItem.ts → dist/rbac/AuthItem.js} +16 -22
  147. package/dist/rbac/AuthItemChild.d.ts +19 -0
  148. package/dist/rbac/AuthItemChild.d.ts.map +1 -0
  149. package/{rbac/AuthItemChild.ts → dist/rbac/AuthItemChild.js} +14 -21
  150. package/dist/rbac/AuthManager.d.ts +112 -0
  151. package/dist/rbac/AuthManager.d.ts.map +1 -0
  152. package/dist/rbac/AuthManager.js +356 -0
  153. package/dist/rbac/index.d.ts +5 -0
  154. package/dist/rbac/index.d.ts.map +1 -0
  155. package/dist/rbac/index.js +28 -0
  156. package/dist/requiments/Glob.d.ts +3 -0
  157. package/dist/requiments/Glob.d.ts.map +1 -0
  158. package/dist/requiments/Glob.js +10 -0
  159. package/dist/requiments/ReflectUtil.d.ts +1 -0
  160. package/dist/requiments/ReflectUtil.d.ts.map +1 -0
  161. package/{requiments/ReflectUtil.ts → dist/requiments/ReflectUtil.js} +4 -6
  162. package/dist/requiments/Utils.d.ts +2 -0
  163. package/dist/requiments/Utils.d.ts.map +1 -0
  164. package/{requiments/Utils.ts → dist/requiments/Utils.js} +34 -40
  165. package/dist/validators/BooleanValidator.d.ts +1 -0
  166. package/dist/validators/BooleanValidator.d.ts.map +1 -0
  167. package/dist/validators/BooleanValidator.js +1 -0
  168. package/dist/validators/CompareValidator.d.ts +1 -0
  169. package/dist/validators/CompareValidator.d.ts.map +1 -0
  170. package/dist/validators/CompareValidator.js +1 -0
  171. package/dist/validators/DateValidator.d.ts +1 -0
  172. package/dist/validators/DateValidator.d.ts.map +1 -0
  173. package/dist/validators/DateValidator.js +1 -0
  174. package/dist/validators/EmailValidator.d.ts +1 -0
  175. package/dist/validators/EmailValidator.d.ts.map +1 -0
  176. package/dist/validators/EmailValidator.js +1 -0
  177. package/dist/validators/Validator.d.ts +18 -0
  178. package/dist/validators/Validator.d.ts.map +1 -0
  179. package/dist/validators/Validator.js +27 -0
  180. package/{web/IdentityInterface.ts → dist/web/IdentityInterface.d.ts} +2 -15
  181. package/dist/web/IdentityInterface.d.ts.map +1 -0
  182. package/dist/web/IdentityInterface.js +8 -0
  183. package/dist/web/WebUser.d.ts +72 -0
  184. package/dist/web/WebUser.d.ts.map +1 -0
  185. package/dist/web/WebUser.js +165 -0
  186. package/package.json +16 -56
  187. package/BaseChyz.ts +0 -623
  188. package/base/ActionFilter.ts +0 -88
  189. package/base/BadRequestHttpException.ts +0 -14
  190. package/base/Behavior.ts +0 -6
  191. package/base/CBaseObject.ts +0 -17
  192. package/base/CEvents.ts +0 -24
  193. package/base/CWebController.ts +0 -90
  194. package/base/Component.ts +0 -66
  195. package/base/DataErrorDbException.ts +0 -16
  196. package/base/DbConnection.ts +0 -55
  197. package/base/ForbiddenHttpException.ts +0 -15
  198. package/base/InvalidArgumentException.ts +0 -16
  199. package/base/InvalidConfigException.ts +0 -16
  200. package/base/NotFoundHttpException.ts +0 -14
  201. package/base/RestClient.ts +0 -26
  202. package/base/UnauthorizedHttpException.ts +0 -17
  203. package/base/ValidationHttpException.ts +0 -14
  204. package/base/db/Exception.ts +0 -14
  205. package/base/index.ts +0 -19
  206. package/decorator/Middleware.ts +0 -9
  207. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  208. package/decorator/index.ts +0 -5
  209. package/filters/AccessControl.ts +0 -74
  210. package/filters/AccessRule.ts +0 -182
  211. package/filters/auth/AuthMethod.ts +0 -100
  212. package/filters/auth/HttpBasicAuth.ts +0 -79
  213. package/filters/auth/HttpBearerAuth.ts +0 -34
  214. package/filters/auth/HttpHeaderAuth.ts +0 -61
  215. package/filters/auth/JwtHttpBearerAuth.ts +0 -83
  216. package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -114
  217. package/filters/auth/index.ts +0 -4
  218. package/filters/index.ts +0 -2
  219. package/index.ts +0 -80
  220. package/model/RouteDefinition.ts +0 -18
  221. package/rbac/AuthAssignment.ts +0 -50
  222. package/rbac/AuthManager.ts +0 -399
  223. package/rbac/index.ts +0 -12
  224. package/validators/BooleanValidator.ts +0 -0
  225. package/validators/CompareValidator.ts +0 -0
  226. package/validators/DateValidator.ts +0 -0
  227. package/validators/EmailValidator.ts +0 -0
  228. package/validators/Validator.ts +0 -27
  229. package/web/WebUser.ts +0 -187
  230. /package/{README.md → dist/README.md} +0 -0
  231. /package/{log → dist/log}/config/log4js.json +0 -0
@@ -0,0 +1,83 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +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 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,12 +1,5 @@
1
- /*
2
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
- * Author: Cihan Ozturk
4
- * E-mail: cihan@chy.com.tr
5
- * Github:https://github.com/cihan53/
6
- */
7
- import {Request, Response} from "express";
8
-
9
- export interface AuthInterface{
1
+ import { Request, Response } from "express";
2
+ export interface AuthInterface {
10
3
  /**
11
4
  * Authenticates the current user.
12
5
  * @param User $user
@@ -15,20 +8,19 @@ export interface AuthInterface{
15
8
  * @return IdentityInterface the authenticated user identity. If authentication information is not provided, null will be returned.
16
9
  * @throws UnauthorizedHttpException if authentication information is provided but is invalid.
17
10
  */
18
- authenticate(user:any, request:Request, response:Response):any;
19
-
11
+ authenticate(user: any, request: Request, response: Response): any;
20
12
  /**
21
13
  * Generates challenges upon authentication failure.
22
14
  * For example, some appropriate HTTP headers may be generated.
23
15
  * @param Response $response
24
16
  */
25
- challenge(response:Response):Response;
26
-
17
+ challenge(response: Response): Response;
27
18
  /**
28
19
  * Handles authentication failure.
29
20
  * The implementation should normally throw UnauthorizedHttpException to indicate authentication failure.
30
21
  * @param Response $response
31
22
  * @throws UnauthorizedHttpException
32
23
  */
33
- handleFailure(response:Response):Response;
34
- }
24
+ handleFailure(response: Response): Response;
25
+ }
26
+ //# sourceMappingURL=AuthInterface.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +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 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
@@ -0,0 +1 @@
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"}
@@ -0,0 +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 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
+ return __awaiter(this, void 0, void 0, function* () {
35
+ var _a;
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;
@@ -0,0 +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
+ 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
@@ -0,0 +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;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"}
@@ -0,0 +1,79 @@
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
+ var arguments_1 = arguments;
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ let autHeader = this.getHeaderByKey(request.headers, this.header);
53
+ if (autHeader == null || (autHeader = this.patternCheck(autHeader, this.pattern)) == null) {
54
+ return this.fail(response);
55
+ }
56
+ let identity = null;
57
+ let token = null;
58
+ let buff = new Buffer(autHeader[1], "base64");
59
+ let basicauth = buff.toString().split(":");
60
+ if (this.auth != null) {
61
+ identity = yield this.auth(autHeader[1], ...arguments_1, basicauth);
62
+ }
63
+ else {
64
+ identity = yield user.loginByAccessToken(basicauth, "HttpBasicAuth");
65
+ }
66
+ if (identity == null)
67
+ this.fail(response);
68
+ return identity;
69
+ });
70
+ }
71
+ /**
72
+ * @throws UnauthorizedHttpException
73
+ */
74
+ fail(response) {
75
+ this.challenge(response);
76
+ this.handleFailure(response);
77
+ }
78
+ }
79
+ exports.HttpBasicAuth = HttpBasicAuth;
@@ -0,0 +1,18 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,33 @@
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;
@@ -0,0 +1,19 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,64 @@
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.HttpHeaderAuth = void 0;
19
+ const AuthMethod_1 = require("./AuthMethod");
20
+ const Utils_1 = require("../../requiments/Utils");
21
+ class HttpHeaderAuth extends AuthMethod_1.AuthMethod {
22
+ constructor() {
23
+ super(...arguments);
24
+ /**
25
+ * @var string the HTTP header name
26
+ */
27
+ this.header = 'X-Api-Key';
28
+ }
29
+ authenticate(user, request, response) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ let key = Object.keys(request.headers).find(key => key.toLowerCase() === this.header.toLowerCase());
32
+ if (key) {
33
+ let authHeader = request.headers[key];
34
+ if (!Utils_1.Utils.isEmpty(authHeader)) {
35
+ if (this.pattern) {
36
+ //preg_match
37
+ let matches = authHeader.match(this.pattern);
38
+ if (matches && matches.length > 0) {
39
+ authHeader = matches[1];
40
+ }
41
+ else {
42
+ return this.fail(response);
43
+ }
44
+ }
45
+ let identity = yield user.loginByAccessToken(authHeader, "HttpHeaderAuth");
46
+ if (identity === null) {
47
+ this.challenge(response);
48
+ this.handleFailure(response);
49
+ }
50
+ return identity;
51
+ }
52
+ }
53
+ return this.fail(response);
54
+ });
55
+ }
56
+ /**
57
+ * @throws UnauthorizedHttpException
58
+ */
59
+ fail(response) {
60
+ this.challenge(response);
61
+ this.handleFailure(response);
62
+ }
63
+ }
64
+ exports.HttpHeaderAuth = HttpHeaderAuth;